环境准备
pip list 导出
pip freeze > ./requirements.txt
pip list 安装
pip install -r ./requirements.txt
更新
更新软件包
$ yum update -y
$ yum -y groupinstall "Development tools"
$ yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel psmisc libffi-devel
python3
在/usr/local下载python3,解压并进入解压目录安装
$ cd /usr/local
$ wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz
$ tar -zxvf Python-3.6.6.tgz
$ cd Python-3.6.6
安装路径
$ ./configure --prefix=/usr/local/python3
$ make
$ make install
链接,全局使用python3和pip3
$ ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
$ ln -s /usr/local/python3/bin/pip3.6 /usr/bin/pip3
查看
virtualenv
pip 安装
$ pip3 install virtualenv
链接
$ ln -s /usr/local/python3/bin/virtualenv /usr/bin/virtualenv
创建夹存放网站文件和指定虚拟环境文件
wwwroot,env
$ mkdir -p /data/env
$ mkdir -p /data/wwwroot
指定虚拟环境
$ virtualenv --python=/usr/bin/python3 pyweb
指定虚拟环境
进入env目录指定虚拟环境python3
$ cd /data/env/
$ virtualenv --python=/usr/bin/python3 pyweb
$ cd /data/env/pyweb/bin
$ source activate
成功配置(对应指定的pyweb名)
虚拟环境安装django
安装django和项目的django版本一致
查看项目的django版本
在虚拟环境安装django和uwsgi,退出虚拟环境再次安装uwsgi
虚拟环境下链接uwsgi
$ pip3 install django==2.1.1
$ pip3 install uwsgi
$ ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi
$ deactivate
部署django
上传
使用fiezilla上传django项目到/data/wwwroot下
migrate、makemigratons
进入虚拟环境的democase下
$ cd /data/env/pyweb/bin
$ source activate
$ cd /data/wwwroot/democase/
$ python3 manage.py migrate
$ python3 manage.py makemigrations
$ python3 manage.py runserver
配置uwsgi
xml配置
项目下创建democase.xml
<uwsgi>
<socket>127.0.0.1:1998</socket>
<chdir>/data/wwwroot/democase/</chdir>
<module>democase.xml</module>
<processes>20</processes>
<daemonize>uwsgi.log</daemonize>
</uwsgi>
启动uwsgi
#启动uwsgl
$ uwsgi -x democase.xml
#uwsgi有没有启动成功,可以用下面的命令查看
$ ps -ef|grep uwsgi
#如果想重启uwsgi,先使用下面的命令杀掉进程,再启动uwsgi
$ killall -9 uwsgi
安装nginx
安装
$ cd /home/
$ wget http://nginx.org/download/nginx-1.13.7.tar.gz
$ tar -zxvf nginx-1.13.7.tar.gz
$ cd nginx-1.13.7
$ ./configure
$ make
$ make install
配置nginx.conf
先备份再修改
$ cp nginx.conf nginx.conf.bak
修改(根据需求修改)
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 80;
server_name 127.0.0.1:80;
charset utf-8;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:1998; #端口要和uwsgi里配置的一样
uwsgi_param UWSGI_SCRIPT democase.wsgi; #wsgi.py所在的目录名
uwsgi_param UWSGI_CHDIR /data/wwwroot/democase/; #项目路径
}
location /static/ {
alias /data/wwwroot/democase/static/; #静态资源路径
}
}
}
进入nginx配置
$ cd /usr/local/nginx/sbin/
$ ./nginx -t
$ ./nginx
加载democase.xml
$ cd /data/wwwroot/democase/
$ uwsgi -x mysite.xml
$ cd /usr/local/nginx/sbin/
$ ./nginx -s reload
访问ip错误问题
$ yum install iptables-services
$ systemctl mask firewalld.service
$ systemctl enable iptables.service
$ systemctl enable ip6tables.service
$ vim /etc/sysconfig/iptables
添加
-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT(vsftpd配置的端口)
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
开放http和80端口
$ systemctl restart iptables.service
$ systemctl start firewalld
$ firewall-cmd --permanent --add-service=http
$ firewall-cmd --permanent --zone=trusted --add-port=80/tcp
完成
ok,完成!
升级sqlite3
改名
软连接
设置临时变量,但是重启之后会失效
# /usr/local/bin/sqlite3 --version
# mv /usr/bin/sqlite3 /usr/bin/sqlite3_old
# ln -s /usr/local/bin/sqlite3 /usr/bin/sqlite3
# export LD_LIBRARY_PATH="/usr/local/lib"
建议/etc/profile之后追加export LD_LIBRARY_PATH="/usr/local/lib"
# vi /etc/profile
# source /etc/profile