上线架构

安装mysql
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
# 下载 mysql5.7 wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
# 安装 mysql5.7 yum -y install mysql57-community-release-el7-10.noarch.rpm yum install mysql-community-server --nogpgcheck
# 启动 mysql5.7 并查看启动状态 systemctl start mysqld.service # 启动mysql服务 systemctl enable mysqld.service # 开机自启动 systemctl status mysqld.service # 查看服务
# 查看默认密码并登录 grep "password" /var/log/mysqld.log mysql -uroot -p
# 修改密码 ALTER USER 'root'@'localhost' IDENTIFIED BY 'Mysql12345?';
|
安装redis
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
# 下载redis-5.0.5 wget http://download.redis.io/releases/redis-5.0.5.tar.gz
# 解压安装包 tar -xf redis-5.0.5.tar.gz
# 进入目标文件 cd redis-5.0.5
# 编译环境 src路径下就有可执行文件 redis-server redis-cli 等 make -j `cat /proc/cpuinfo |grep processor |wc -l`
# 复制环境到指定路径完成安装 cp -rp ~/redis-5.0.5 /usr/local/redis
# 配置redis可以后台启动:修改下方内容 vim /usr/local/redis/redis.conf daemonize yes
# 建立软连接 ln -s /usr/local/redis/src/redis-server /usr/bin/redis-server ln -s /usr/local/redis/src/redis-cli /usr/bin/redis-cli
# 后台运行redis cd /usr/local/redis redis-server ./redis.conf
# 查看服务是否启动 ps aux |grep redis
# 测试redis环境 redis-cli
# 关闭redis服务 pkill -f redis -9
|
安装python3.8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
# 下载依赖 yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make libffi-devel python-devel mariadb-devel gdbm-devel python-setuptools python-devel -y
# 下载源码安装 wget https://registry.npmmirror.com/-/binary/python/3.8.6/Python-3.8.6.tgz tar xf Python-3.8.6.tgz cd Python-3.8.6/ ./configure --prefix=/usr/local/python38 make && make install ln -s /usr/local/python38/bin/python3 /usr/bin/python3.8 ln -s /usr/local/python38/bin/pip3 /usr/bin/pip3.8
# 安装uwsgi pip3.8 install uwsgi ln -s /usr/local/python38/bin/uwsgi /usr/bin/uwsgi
# 配置虚拟环境 python3.8 -m pip install --upgrade pip python3.8 -m pip install --upgrade setuptools pip3.8 install virtualenv pip3.8 install virtualenvwrapper
# 建立软连接 ln -s /usr/local/python38/bin/virtualenv /usr/bin/virtualenv
# 配置环境变量 cat >> ~/.bashrc <<EOF VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3.8 source /usr/local/python38/bin/virtualenvwrapper.sh EOF # 虚拟环境默认根目录:~/.virtualenvs
# 创建虚拟环境 mkvirtualenv luffy
|
安装nginx
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
yum install gcc zlib zlib-devel pcre-devel openssl openssl-devel -y
wget http://nginx.org/download/nginx-1.20.1.tar.gz
tar xf nginx-1.20.1.tar.gz
cd nginx-1.20.1/
./configure --prefix=/usr/local/nginx \ --with-http_stub_status_module \ --with-http_ssl_module --with-pcre
make -j `cat /proc/cpuinfo |grep processor |wc -l` && make install
echo 'export PATH=/usr/local/nginx/sbin:$PATH' >> /etc/profile source /etc/profile
|
上线前端
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
# 修改后端地址 luffycity/src/assets/js/settings.js 改为公网 IP export default {base_url:'http://119.91.117.23:8080/api/v1/'}
# 将 vue 项目 编译为 html css js 等纯静态文件 项目目录下执行 npm run build
# 将 dist 文件夹压缩上传到服务器上 sftp 等工具 # 进入到上传所在的目录 mkdir /web/luffy -p unzip dist.zip -d /web/luffy/
# 修改 nginx 配置文件 cd /usr/local/nginx/ # 修改配置文件,如下
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
nginx.conf worker_processes auto; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; charset UTF-8; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 50m; ##################################### sendfile on; tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; ##################################### fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 256k; ##################################### gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_vary on; gzip_proxied expired no-cache no-store private auth; server_tokens off; include vhost/*.conf; }
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
# 创建目录 mkdir vhost cat > vhost/web.conf <<EOF server { listen 80; server_name localhost; charset utf-8; location / { root /web/luffy/dist; index index.html; try_files $uri $uri/ /index.html; # 解决单页面应用刷新404问题 } } EOF
# 检查 nginx -t
# 启动 nginx
# 检查是否成功启动 netstat -lntup ps -ef |grep nginx
# 访问地址
|
上线后端
上线前准备
setting/pro.py
将luffy_api/setting/dev.py 拷贝过来修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
import os import sys import datetime
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(os.path.join(BASE_DIR, 'apps')) sys.path.append(BASE_DIR)
SECRET_KEY = '-b4z=*^wa1rjc-5a+@+)f%t-%mppmx@vz%8zdps1$rr9r@y&$5'
DEBUG = False
ALLOWED_HOSTS = ['*']
INSTALLED_APPS = [ 'simpleui', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'corsheaders', 'user', 'home', 'course', 'order', 'django_filters', ]
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', 'corsheaders.middleware.CorsMiddleware', ]
ROOT_URLCONF = 'luffy_api.urls'
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', |