部署yasql
初始化环境
部署Python环境
首先准备Python环境
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum -y install \
net-tools bzip2-devel gcc gcc-c++ make automake unzip curl curl-devel \
libffi-devel perl perl-devel expat expat-devel zlib zlib-devel asciidoc \
xmlto gettext-devel openssl openssl-devel mlocate python-devel openldap-devel \
readline-devel git mysql-devel p7zip
[root@localhost ~]# tar -xvf Python-3.7.17.tar.gz
[root@localhost ~]# cd Python-3.7.17
[root@localhost Python-3.7.17]# ./configure
[root@localhost Python-3.7.17]# make
[root@localhost Python-3.7.17]# make install
创建python3.7虚拟环境
[root@localhost Python-3.7.17]# /usr/local/bin/python3.7 -m pip install --upgrade pip
[root@localhost Python-3.7.17]# /usr/local/bin/pip3.7 install virtualenv -i https://mirrors.aliyun.com/pypi/simple
[root@localhost Python-3.7.17]# /usr/local/bin/virtualenv /venvyasql --python=/usr/local/bin/python3.7
部署前端
useradd www -s /bin/bash
chown -R www. /data/www/
chown -R www. /venvyasql/
部署nginx
首先需要安装nginx
[root@localhost ~]# tar -xvf YaSQL-1.0.1.tar.gz
[root@localhost ~]# mv ./YaSQL-1.0.1 /usr/share/nginx/html/
[root@localhost ~]# cd /usr/share/nginx/html/
[root@localhost html]# mv YaSQL-1.0.1/ yasql
[root@localhost html]# vim /etc/nginx/conf.d/yasql.conf
server {
listen 80;
server_name localhost;
charset utf-8;
root /usr/share/nginx/html/yasql/yasql-fe/dist;
index index.html;
access_log /var/log/nginx/yasql.log;
location / {
try_files $uri $uri/ /index.html;
}
location /api {
proxy_read_timeout 650s;
proxy_send_timeout 650s;
proxy_connect_timeout 650s;
proxy_pass http://127.0.0.1:8000;
}
location /api/media {
expires 30d;
alias /usr/share/nginx/html/yasql/yasql/media;
}
location /admin {
proxy_pass http://127.0.0.1:8000;
}
location /static {
expires 30d;
alias /usr/share/nginx/html/yasql/yasql/static;
}
location /ws {
proxy_pass http://127.0.0.1:8001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_read_timeout 36000s;
proxy_send_timeout 36000s;
}
}
[root@localhost html]# systemctl start nginx
[root@localhost html]# systemctl enable nginx
部署后端
部署数据库
安装Django项目依赖包
[root@localhost ~]# cd /usr/share/nginx/html/yasql/yasql
[root@localhost yasql]# /venvyasql/bin/pip3.7 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple
安装UWSGI和GUNICORN服务
[root@localhost yasql]# /venvyasql/bin/pip3.7 install gunicorn -i https://mirrors.aliyun.com/pypi/simple
[root@localhost yasql]# /venvyasql/bin/pip3.7 install uwsgi -i https://mirrors.aliyun.com/pypi/
收集Django静态文件
[root@localhost yasql]# mkdir static
[root@localhost yasql]# mkdir logs
[root@localhost yasql]# /venvyasql/bin/python3.7 manage.py collectstatic
yasql/config.py
# 启用LDAP
# LDAP配置如下,请按照自己公司的LDAP配置进行更正
LDAP_SUPPORT = {
'enable': True, # 为True启用LDAP,为False禁用LDAP
配置完成ldap后,记得重启Django服务。
部署Redis
[root@localhost ~]# tar -xvf redis-7.0.12.tar.gz -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# mv redis-7.0.12/ redis
[root@localhost local]# cd redis
[root@localhost redis]# make install PREFIX=/usr/local/redis/
[root@localhost redis]# vim redis.conf
----------------------------
# 配置改为如下,此处设置密码
requirepass 1234.com
----------------------------
[root@localhost redis]# nohup ./src/redis-server redis.conf &
部署mysql
[root@localhost ~]# groupadd mysql
[root@localhost ~]# useradd -r -g mysql mysql
[root@localhost ~]# cd /usr/local/
[root@localhost local]# tar -xvf /root/mysql-5.7.43-el7-x86_64.tar.gz 解压
[root@localhost local]# mv mysql-5.7.43-el7-x86_64 mysql
[root@localhost local]# mkdir -p /usr/local/mysql/mysql-files 创建数据目录
[root@localhost local]# chown -R mysql:mysql /usr/local/mysql/mysql-files
[root@localhost local]# chmod 750 /usr/local/mysql/mysql-files
[root@localhost local]# cd mysql/
[root@localhost mysql]# bin/mysqld --initialize --user=mysql 初始化
初始化完成后,在最后会生成mysql密码
将mysql服务加入开机启动项
[root@localhost mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@localhost mysql]# chmod +x /etc/init.d/mysql
[root@localhost mysql]# service mysql start 启动mysql服务
启动成功会出现 SUCCESS!
登录mysql
[root@localhost mysql]# cd bin/
[root@localhost bin]# ./mysql -uroot -p'kA/VobLh<6wa'
修改mysql密码
[root@localhost bin]# ./mysqladmin -uroot -p'kA/VobLh<6wa' password 'Liuge666@'
[root@localhost bin]# mysql -uroot -p'Liuge666@'
mysql> create user 'yasql_rw'@'%' identified by '1234.com'
mysql> grant all on *.* to 'yasql_rw'@'%';
mysql> CREATE DATABASE yasql CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
关闭DEBUG
[root@localhost ~]# vim /usr/share/nginx/html/yasql/yasql/config.py
# 关闭debug,本地开发时打开
# 生产环境请务必改为:DEBUG_ENABLED = False
DEBUG_ENABLED = False
初始表结构
[root@localhost ~]# cd /usr/share/nginx/html/yasql/yasql
初始化数据
[root@localhost yasql]# /venvyasql/bin/python3.7 manage.py loaddata initial_data.json
部署supervisor服务
[root@localhost yasql]# /usr/local/bin/pip3.7 install supervisor
[root@localhost yasql]# /usr/local/bin/echo_supervisord_conf > /etc/supervisord.conf
[root@localhost yasql]# vim /etc/supervisord.conf
------------------------------
# 更改为
[include]
files = supervisord.d/*.conf
-----------------------------
mkdir /etc/supervisord.d
cd /etc/supervisord.d
配置supervisor服务
[root@localhost supervisord.d]# vim /etc/supervisord.d/yasql.conf
[program:yasql-server]
user=www
autorestart=true
environment=DJANGO_SETTINGS_MODULE="yasql.settings"
directory=/data/www/yasql/yasql
command=/venvyasql/bin/python3 /venvyasql/bin/gunicorn -w 8 -t 650 -b 127.0.0.1:8000 yasql.wsgi:application
redirect_stderr=true
stdout_logfile=/data/www/yasql/yasql/logs/yasql-server.log
[program:yasql-daphne]
user=www
autorestart=true
environment=DJANGO_SETTINGS_MODULE="yasql.settings"
directory=/data/www/yasql/yasql
numprocs=1
command=/venvyasql/bin/daphne -b 127.0.0.1 -p 8001 --proxy-headers -v2 yasql.asgi:application
redirect_stderr=true
stdout_logfile=/data/www/yasql/yasql/logs/yasql-daphne.log
[program:yasql-celery-beat]
user=www
autorestart=true
environment=DJANGO_SETTINGS_MODULE="yasql.settings"
directory=/data/www/yasql/yasql
command=/venvyasql/bin/celery beat -A yasql
redirect_stderr=true
stdout_logfile=/data/www/yasql/yasql/logs/yasql-celery-beat.log
[program:yasql-celery-default]
user=www
environment=DJANGO_SETTINGS_MODULE="yasql.settings"
directory=/data/www/yasql/yasql
command=/venvyasql/bin/celery worker -A yasql -n localhost -Q default -l info --time-limit=86400 --concurrency=5
redirect_stderr=true
stdout_logfile=/data/www/yasql/yasql/logs/yasql-celery-default.log
numprocs=1
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600
stopasgroup=true
priority=1000
[program:yasql-celery-dbtask]
user=www
environment=DJANGO_SETTINGS_MODULE="yasql.settings"
directory=/data/www/yasql/yasql
command=/venvyasql/bin/celery worker -A yasql -n localhost -Q dbtask -l info --time-limit=86400 --concurrency=20
redirect_stderr=true
stdout_logfile=/data/www/yasql/yasql/logs/yasql-celery-dbtask.log
numprocs=1
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600
stopasgroup=true
priority=1000
[root@localhost supervisord.d]# cd /usr/share/nginx/html/yasql/yasql
[root@localhost yasql]# mkdir -p /usr/share/nginx/html/yasql/yasql/{logs,static}
[root@localhost yasql]# chown -R www. /data/www/yasql/
# 启动supervisor进程
[root@localhost yasql]# /usr/local/bin/supervisord -c /etc/supervisord.conf
[root@localhost yasql]# /usr/local/bin/supervisorctl status #查看服务状态