66# 功能
77看图。
88
9-
109# 预览
1110![ 效果] ( ./screenshots/1.PNG )
1211![ 效果] ( ./screenshots/2.PNG )
3231![ 效果] ( ./screenshots/24.PNG )
3332![ 效果] ( ./screenshots/25.PNG )
3433
35-
3634# 部署安装
3735
3836## kubernetes(k8s) 集群部署
5452
5553此部署方式在本人 k8s v1.19.9 集群上测试正常,不保证其他版本兼容性。且只做测试用。
5654
57-
5855## 物理机安装
5956
6057环境:Centos 7.5,python 3.7.9,docker 1.13.1,项目目录为 ` /home/workspace/devops ` 。
6158
6259** 1. 安装依赖**
60+
6361``` bash
6462yum install -y epel-release
6563yum install -y gcc sshpass python3-devel mysql-devel
@@ -69,11 +67,20 @@ yum install -y gcc sshpass python3-devel mysql-devel
6967- 不建议使用 pymysql 代替 mysqlclient ,因为 pymysql 为纯 python 编写的库,性能较低
7068
7169** 2. 安装 mysql(docker 方式)**
70+
7271``` bash
7372docker run -d --name mysql -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 mysql:5.7.31
73+
74+ # 创建数据库并授权
75+ docker exec -it mysql /bin/bash
76+ mysql -uroot -p
77+ create database devops default character set utf8mb4 collate utf8mb4_unicode_ci;
78+ grant all privileges on devops.* to ' devops' @' %' identified by ' 123456' ;
79+ flush privileges;
7480```
7581
7682** 3. 安装 redis(docker 方式)**
83+
7784``` bash
7885docker run --name redis-server -p 6379:6379 -d redis:6.0.8
7986```
@@ -88,11 +95,18 @@ docker run --name guacd -e GUACD_LOG_LEVEL=info -v /home/workspace/devops/media/
8895- ` -v /home/workspace/devops/media/guacd:/fs ` 挂载磁盘,用于远程挂载文件系统实现上传和下载文件
8996
9097** 5. 安装 python 依赖库**
98+
9199``` bash
100+ # 创建python虚拟环境
101+ python -m venv venv
102+
103+ # 加载python虚拟环境,特别注意:后面的步骤均在此虚拟环境下运行
104+ source venv/bin/activate
105+
92106# 安装相关库
93107pip3 install -i https://mirrors.aliyun.com/pypi/simple -r requirements.txt
94108```
95- - -i 指定阿里源,速度飞起,我大 TC 威武,局域网玩得贼 6
109+ - -i 指定阿里源,速度飞起
96110
97111** 6. 修改 devops/settings.py 配置**
98112
@@ -103,7 +117,7 @@ pip3 install -i https://mirrors.aliyun.com/pypi/simple -r requirements.txt
103117DATABASES = {
104118 ' default' : {
105119 # 'ENGINE': 'django.db.backends.mysql',
106- ' ENGINE' : ' db_pool.mysql' , # db_pool.mysql 为重写 django 官方 mysql 连接库实现了真正的连接池
120+ ' ENGINE' : ' db_pool.mysql' , # db_pool.mysql 重写了 django 官方 mysql 连接库实现了真正的连接池
107121 ' NAME' : ' devops' ,
108122 ' USER' :' devops' ,
109123 ' PASSWORD' :' devops' ,
@@ -122,9 +136,11 @@ DATABASES = {
122136
123137** 7. 迁移数据库**
124138``` bash
139+ # 删除可能存在的开发环境遗留数据
125140sh delete_makemigrations.sh
126141rm -f db.sqlite3
127- # 以上是删除可能存在的开发环境遗留数据
142+
143+ # 数据库迁移,创建表
128144python3 manage.py makemigrations
129145python3 manage.py migrate
130146```
@@ -140,12 +156,18 @@ python3 init.py
140156** 9. 启动相关服务**
141157``` bash
142158rm -rf logs/*
159+
143160export PYTHONOPTIMIZE=1 # 解决 celery 不允许创建子进程的问题
144- nohup celery -A devops worker -l info -c 3 --max-tasks-per-child 40 --prefetch-multiplier 1 --pidfile logs/celery_worker.pid > logs/celery.log 2>&1 &
145- nohup celery -A devops beat -l info --pidfile logs/celery_worker.pid > logs/celery_beat.log 2>&1 &
161+
162+ nohup celery -A devops worker -l info -c 3 --max-tasks-per-child 40 --prefetch-multiplier 1 --pidfile logs/celery_worker.pid > logs/celery_worker.log 2>&1 &
163+
164+ nohup celery -A devops beat -l info --pidfile logs/celery_beat.pid > logs/celery_beat.log 2>&1 &
165+
146166nohup python3 manage.py sshd > logs/sshd.log 2>&1 &
167+
147168nohup daphne -b 0.0.0.0 -p 8001 --access-log=logs/daphne_access.log devops.asgi:application > logs/daphne.log 2>&1 &
148- nohup gunicorn -c gunicorn.cfg devops.wsgi:application > logs/gunicorn.log 2>&1 &
169+
170+ nohup gunicorn -c gunicorn.py devops.wsgi:application > logs/gunicorn.log 2>&1 &
149171```
150172- gunicorn 处理 http 请求,监听 8000 端口
151173- daphne 处理 websocket 请求,监听 8001 端口
@@ -158,15 +180,15 @@ nohup gunicorn -c gunicorn.cfg devops.wsgi:application > logs/gunicorn.log 2>&1
158180```
159181yum install -y nginx
160182```
161- - 为了方便,就不编译安装,直接 yum 安装,版本为 ` nginx-1.16.1 `
183+ - 为了方便,就不编译安装,直接 yum 安装,版本为 ` nginx-1.20.1-9.el7.x86_64 `
162184
163185修改 nginx 配置 /etc/nginx/nginx.conf 如下:
164186```
165187# For more information on configuration, see:
166188# * Official English Documentation: http://nginx.org/en/docs/
167189# * Official Russian Documentation: http://nginx.org/ru/docs/
168190
169- # base on nginx 1.16.1
191+ # base on nginx-1.20.1-9.el7.x86_64
170192
171193user nginx;
172194worker_processes auto;
0 commit comments