部署环境系统使用centos8stream
cd /data/
git clone https://github.com/nineaiyu/xbook
cd /data/xbook/docker/init
sh init.sh
- 域名: xbook.hehelucky.cn
- 证书(nginx)[可选,参考文档末尾说明]
nginx.conf.d/xbook.conf
VITE_API_DOMAIN=''
cd /data/xbook/docker/scripts
sh build.sh
docker pull 'bitnami/mariadb:10.7.3'
docker pull 'bitnami/redis:6.2.7'
docker pull 'nginx:1.21.3'
cd /data/xbook/docker/scripts
sh start_all.sh
cd /data/xbook/docker/scripts
sh stop_all.sh
docker exec -it xbook python manage.py createsuperuser
端口80和443,浏览器输入配置的域名即可访问或者服务器的ip直接访问
dnf module reset nodejs -y
dnf module enable nodejs:16-epel -y
dnf install nodejs -y
npm install -g yarn
cd client
yarn install
yarn build
构建成功的文件位于dist
目录下,该目录下为前端页面,拷贝到相应前端目录
dnf install python39 python39-devel mariadb-devel -y
python3.9 -m venv py39
source py39/bin/activate
pip install -U setuptools pip
pip install -r requirements.txt
dnf install mariadb-server -y
create database xbook default character set utf8 COLLATE utf8_general_ci;
grant all on xbook.* to xbook@'127.0.0.1' identified by 'KGzKjZpWBp4R4RSa';
或者根据现有的mariadb修改相应的配置
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'xbook',
'USER': 'xbook',
'PASSWORD': 'KGzKjZpWBp4R4RSa',
'HOST': 'mariadb',
'PORT': 3306,
'CONN_MAX_AGE': 600,
'OPTIONS': {'init_command': 'SET sql_mode="STRICT_TRANS_TABLES"', 'charset': 'utf8mb4'}
}
}
dnf install redis -y
根据redis修改相应的配置文件
REDIS_PASSWORD = "nineven"
REDIS_HOST = "redis"
REDIS_PORT = 6379
python manage.py makemigrations
python manage.py migrate
# -u nginx 指需要启动的用户,需要有nginx用户,或者其他用户也行
python manage.py start all -u nginx
- 证书可以从阿里云或者腾讯云申请,每次可免费申请一年
- 还可以使用免费的letsencrypt证书
vim docker/nginx/nginx.conf.d/xbook.conf
增加下面ssl支持配置
listen 443 ssl http2;
ssl_certificate /etc/nginx/conf.d/xbook.hehelucky.cn.pem;
ssl_certificate_key /etc/nginx/conf.d/xbook.hehelucky.cn.key;
ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
重新nginx容器
cd docker/nginx
docker compose down
docker compose up -d