# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
下载python3
Python下载源1.下载软件包
#wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
2.解压
#tar -xzvf Python-3.6.1.tgz3.创建目录
#mkdir -p /usr/local/python3.6
4.把Python3.6安装到 /usr/local/python3.6目录
# ./configure --prefix=/usr/local/python3.6#make && make install
5.创建软连接ln -s /usr/local/python3.6/bin/python3.6 /usr/bin/python3ln -s /usr/local/python3.6/bin/pip3 /usr/bin/pip36.查看Python版本
#python--version
Python3.6.1
CentOS删除编译安装的Python3
卸载Python3
通过安装日志可知Python3被安装在如下目录了
/usr/local/lib/python3.6 /usr/local/bin/2to3-3.6 to /usr/local/bin/pyvenv-3.6 /usr/local/bin/pydoc3.6 /usr/local/bin/idle3.6
#删除上述文件
rm -rf /usr/local/lib/python3.6rm-rf /usr/local/bin/2to3-3.6to
rm-rf /usr/local/bin/pyvenv-3.6rm-rf /usr/local/bin/pydoc3.6rm-rf /usr/local/bin/idle3.6
给python3安装django和uwsgi,pymysql以及配置启动项目的xml文件
pip3 install pymysql
pip3 install django==1.11
pip3 install uwsgi
为了在终端中使用uwsgi命令,执行以下命令
ln -s /usr/local/python3.6/bin/uwsgi /usr/bin/uwsgi3
专门用来放我们的django项目
mkdir /www/
将你的django项目放到你想放的路径下,例如/www/,假设我们的Django项目名为"myproject"
在你的django项目下新建 myproject.xml,内容如下:
[root@mysql myproject]# vim myproject.xml
127.0.0.1:8002
/www/myproject
myproject.wsgi
4
uwsgi.log
wq保存
安装nginx和配置nginx.conf文件
下载nginx,执行解压命令
wget http://nginx.org/download/nginx-1.13.7.tar.gz
tar -zxvf nginx-1.13.7.tar.gz
进入解压后的nginx-1.13.7文件夹,编译安装nginx
[root@mysql myproject]# cd /soft/[root@mysql soft]# cd nginx-1.13.7./configure --prefix=/usr/local/nginx --with-http_ssl_modulemake && make install
nginx一般默认安装好的路径为/usr/local/nginx
在/usr/local/nginx/conf/中打开nginx.conf,加入以下内容,先备份nginx.conf文件
[root@mysql nginx-1.13.7]# cd /usr/local/nginx/conf/[root@mysql conf]#cp nginx.conf nginx.conf.bak
vim nginx.conf
server {
listen8001; # 暴露给外部访问的端口
server_name localhost;
charset utf-8;
#access_log logs/host.access.log main;
location/{
include uwsgi_params;
uwsgi_pass127.0.0.1:8002; # 外部访问8001就转发到内部8002
}
location/static/{
alias/www/myproject/statics/; #项目静态路径设置
}
关闭 selinux
vim /etc/selinux/config
SELINUX=enforcing
改为disabled
SELINUX=disabled
iptables加上允许8001,8002,3306,80端口
vim /etc/sysconfig/iptables
配置文件配置
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 8001 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT-A INPUT -m state --state NEW -m tcp -p tcp --dport 8002 -j ACCEPT
配置好重启iptables
[root@mysql myproject]# service iptables restart
启动nginx
[root@mysql conf]# /usr/local/nginx/sbin/nginx
访问项目页面
进入你的django项目路径,执行以下命令:
uwsgi3 -x myproject.xml
注:执行该xml后django就算是启动了,内部的nginx服务也将被启动,uwsgi将能够连接到nginx的服务了,此时网络应该是通畅的了。
以上步骤都没有出错的话,打开你的浏览器,输入以下链接,http://192.168.0.110:8001 (请将该ip替换成你的服务器ip)
网站访问成功!
部署完成之后发现django后台admin访问时无样式
解决方法如下:
1.先打开django项目中settings.py文件(/www/myproject/myproject/settings.py),添加如下配置
[root@mysql myproject]# vim settings.py
STATIC_ROOT = os.path.join(BASE_DIR, "statics")
2.然后在django项目下 执行 python3 manage.py collectstatic 此命令是搜集静态文件的命令,
[root@mysql myproject]# python3 manage.py collectstatic
You have requested to collect static files at the destination
location as specifiedinyour settings:/www/myproject/statics
This will overwrite existing files!Are you sure you want todo this?Type'yes' to continue, or 'no' to cancel: yes
搜集后的静态文件存放在/home/myproject/statics/中
3.重新启动uwsgi和nginx
[root@mysql myproject]# /usr/local/nginx/sbin/nginx -s reload
[root@mysql myproject]# pkill uwsgi
[root@mysql myproject]# uwsgi3-x myproject.xml
[uWSGI] parsing configfile myproject.xml
可以看到admin样式