[项目] mysite.settings.py(LOAMAW v1.0)

"""
Django settings for mysite project.

Generated by 'django-admin startproject' using Django 3.2.6.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-ln+%tp_-5(i0cg8&62!tg)7ht)_n=t4ihz#7!&don5_ob_-9+9'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'server'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'mysite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'mysite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'server',
        'HOST': '10.10.10.5',
        'PORT': '3306',
        'USER': 'root',
        'PASSWORD': 'password',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

[命令] Linux SSL 证书的生成 (OpenSSL 版)

内容一:生成 SSL 证书
1.1 交互式生成 SSL 证书

# openssl req -nodes -newkey rsa:4096 -sha512 -keyout eternalcenter.com.key -out eternalcenter.com.csr

(补充:这里以同时生成长度 4096 位,加密格式为 512 的私钥 eternalcenter.com.key 和公钥 eternalcenter.com.csr 为例)

1.2 非交互式生成 SSL 证书

# openssl req -nodes -newkey rsa:4096 -sha512 -out eternalcenter.com.csr -keyout eternalcenter.com.key -subj "/C=CN/ST=Sichuan/L=Chengdu/O=Eternal Center/OU=Mingyu Zhu/CN=eternalcenter.com/emailAddress=contact@mingyuzhu.com"


补充:这里以同时生成
1) 长度为 4096 位
2) 加密格式为 512
3) 国家为 CN
4) 州或省为 Sichuan
5) 城市为 Chengdu
6) 组织为 Eternal Center
7) 部门为 Mingyu Zhu
8) 域名为 eternalcenter.com
9) 邮箱地址为 contact@mingyuzhu.com
的私钥 eternalcenter.com.key 和公钥 eternalcenter.com.csr 为例

内容二:测试 SSL 证书

# openssl req -in eternalcenter.com.csr -noout -text

[内容] 实现数据存储高可用的思路

方法一:以目录级数据同步工具 rsync 为核心的同步方法

通过 inotify + rsync 实现两个目录的数据实时同步
特点:如果数据量太大就不合适了,数据量最好小于 10G,如果文件多最好要小于 5G 甚至小于 3G

方法二:以硬盘级数据同步工具 drbd 为核心的同步方法

drbd + heartbeat 或者 drbd + keepalive + shell 实现两个数据存储节点的主从同步、主从切换
特点:最好用于小于 300G 的数据同步

方法三:分布式云存储

通过 hdfs 或者 ceph 实现分布式云存储
特点:可以用于大于 300G 的数据同步

[步骤] WordPress 数据库的修复 (通过 WordPress 官方修复工具实现)

步骤一:修改网页文件 wp-config.php
1.1 修改使用默认源码安装的 nginx 网页文件的方法

# vim /usr/local/nginx/html/wp-config.php

添加以下内容:

......
define('WP_ALLOW_REPAIR', true);
?>

1.2 修改使用 CentOS&RHEL yum 默认安装的 nginx 网页的方法

# vim /usr/share/nginx/html/wp-config.php

添加以下内容:

......
define('WP_ALLOW_REPAIR', true);
?>

步骤二:在图形浏览器上输入以下网址

<网站的网址>/wp-admin/maint/repair.php

步骤三:根据网页提示修复数据库

(步骤略)