yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
项目python版本为3.8.5, django版本为3.1.1
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
cd Python-3.8.5/./configure --prefix=/usr/local/python3makemake install
ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3
# 从开发环境中导出所安装的库到requirements.txt文件中
pip freeze > requirements.txt
pip install -r requirements.txt
pip install uwsgi
wget http://tel.mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.34-el7-x86_64.tar.gz
# 重命名压缩包
mv mysql-5.7.34-el7-x86_64.tar.gz mysql.tar.gztar zxf mysql.tar.gz
# 进入mysql目录
cd mysql
cd mysqlmkdir data
useradd mysql -s /sbin/nologin -M
# 回到/usr/local目录cd ..
# 设置mysql目录权限
chown -R mysql.mysql mysql
cd mysql
# 执行后,屏幕会提示root临时密码,需要记录下来
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
yum install libaio
wget https://www.python.org/ftp/python/3.8.5/Python-3.8.5.tgztar zvxf Python-3.8.5.tgz
cd Python-3.8.5/./configure --prefix=/usr/local/python3makemake install
ln -s /usr/local/python3/bin/python3.8 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.8 /usr/bin/pip3
# vim /etc/init.d/mysqld
# 修改basedir和datadir
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
/etc/init.d/mysqld start
ln -s /usr/local/mysql/mysql.sock /tmp/mysql.sock
cd /usr/local/mysql
# 回车后会提示输入密码,输入临时密码回车即可
bin/mysql -uroot -p
# 登录之后修改密码
mysql> set password = password('123456');
mysql> alter user 'root'@'localhost' password expire never;
mysql> flush privileges;
wget http://nginx.org/download/nginx-1.17.7.tar.gz
yum install -y pcre pcre-devel openssl openssl-devel gcc
useradd nginx -s /sbin/nologin -M
tar zxf nginx-1.17.7.tar.gz
cd nginx-1.17.7
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
wget http://download.redis.io/releases/redis-2.8.17.tar.gz
tar xzf redis-2.8.17.tar.gz
mv redis-2.8.17 redis
cd redis
make
cd src
./redis.server
cd src
./redis.server
# 在项目根目录下创建uwsgi.ini文件
[uwsgi]
# 配置nginx连接的socket连接 /data/web/project为项目目录
socket=/data/web/project/project.sock
# 配置uwsgi.pid所在的目录
pidfile=/data/web/project/uwsgi.pid
# 进程数
processes=8
# 每个进程的线程数
threads=2
# 项目路径,项目所在的目录
chdir=/data/web/project
# wsgi接口模块文件路径
module=project.wsgi
# 启动管理主进程
master=true
enable-threads=true
logdate=true
limit-as=6048
# 日志文件
daemonize=/data/web/project/run.log
# -d表示后台启动
uwsgi -d --ini uwsgi.ini
# 停止
uwsgi --stop uwsgi.pid
# 重启
uwsgi --reload uwsgi.pid
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type Application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include vhost/*.conf;
}
mkdir vhost
cd vhost
# vim www.xxx.com.conf
server {
listen 80;
server_name www.xxx.com;
charset utf-8;
client_max_body_size 50M;
location / {
uwsgi_pass unix:/data/web/project/project.sock;
include uwsgi_params;
}
location /static {
alias /data/web/project/static;
}
location /media {
alias /data/web/project/media;
}
}
代码迁移至服务器前,使用命令 python manage.py collectstatic 收集静态文件
python manage.py collectstatic