centos7 安装python3.5和pip和uwsgi和nginx以及简单部署

准备编译环境

yum groupinstall 'Development Tools'
yum install zlib-devel bzip2-devel  openssl-devel ncurses-devel

环境如果错误,可能遇到各种问题,如wget无法下载https链接的文件  

下载Python3.5代码包

wget  https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz
【注意大小写】

  

解压编译

tar Jxvf  Python-3.5.0.tar.xz
cd Python-3.5.0
./configure --prefix=/usr/local/python3  【记住路径】
make && make install

 

做软链[python3 和pip3]  

ln -s /usr/local/python3/bin/python3.5 /usr/local/bin/python3

  

提示同时成功安装pip-7.12与setuptools就成功了!

做pip软连接:ln -s /usr/local/python3/bin/pip3.5     /usr/local/bin/pip3

升级pip: pip install --upgrade pip

 

Error:Ignoring ensurepip failure: pip 7.1.2 requires SSL/TLS

这是原因没有安装或升级oenssl:
yum install openssl-devel


然后重装下python3(一定要重编译安装,家常便饭)
# cd Python-3.5
# ./configure --prefix=/usr/local/python3
# make && make install

  

Error: no module namd "_sqlite3" 

yum install sqlite-devel -y
或者要安装pymysql等其他 然后重装下python3(一定要重编译安装,家常便饭) # cd Python-3.5 # ./configure --prefix=/usr/local/python3 # make && make install 测试:python3解释器下import sqlite3,即没问题

  

 

uwsgi 安装和部署

pip3 install uwsgi


find / -name "uwsgi":
结果是:/usr/local/python3/bin/uwsgi
做软连接:ln -s  /usr/local/python3/bin/uwsgi     /usr/local/bin/uwsgi

uwsgi+django简单部署
我把工程文件blog放在/opt
cd /opt
cd /blog
uwsgi --http 192.168.34.128:8008 --wsgi-file blog/wsgi.py
不成功会报错,成功会提示已经绑定到IP地址和端口


这样打开客户端浏览器输入192.168.34.128:8008即可访问

  

 安装nginx

下载对应当前系统版本的nginx包(package)
wget  http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

建立nginx的yum仓库
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

下载并安装nginx
yum install nginx

启动nginx服务
systemctl start nginx

配置
默认的配置文件在 /etc/nginx 路径下,使用该配置已经可以正确地运行nginx;
如需要自定义,根据文档修改添加响应参数nginx.conf 文件即可。
修改完毕,nginx  -t,查看配置文件的语法什么的有没有写错
如果nginx已经运行,重新载入nginx -s reload

  

django静态文件的配置:

                        STATICFILES_DIRS = (
				os.path.join(BASE_DIR,'static'),
			)
			STATIC_ROOT = os.path.join(BASE_DIR,'uuuuuu')
			
			python manage.py collectstatic                    

  

简单的uwsgi_socket.ini配置文件:

[uwsgi]
socket = 127.0.0.1:8001
chdir = /opt/blog     #django项目的启动路径
wsgi-file = blog/wsgi.py     #django项目文件夹blog的里面blog的wsgi文件
# processes = 4
# threads = 2
static-map = /static=/opt/blog/sdata    #静态文件的配置目录

  

简单的nginx配置文件:

# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user root;
worker_processes 4;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
    worker_connections  1024;
}


http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    #types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    
    upstream django {
        # server unix:///path/to/your/mysite/mysite.sock; # for a file socket
        server 127.0.0.1:8001; # for a web port socket (we'll use this first)
    }
    server {
        listen      80;

        #server_name ; 
        charset     utf-8;

        
        # max upload size
        client_max_body_size 75M;   # adjust to taste

        location /static {
            alias  /opt/s4blog/sdata; # your Django project's static files - amend as required
        }

        # Finally, send all non-media requests to the Django server.
        location / {
            uwsgi_pass  django;
            include     uwsgi_params; # the uwsgi_params file you installed
        }
    }
}

 

默认80端口,客户端dns域名解析成ip地址网络访问,80端口server里uwsgi_pass到upstream django转发到127.0.0.0:8001 ==》uwsgi_socket.ini==》Django程序

 

记得启动uwsgi uwsgi_socket.ini 和systemctl start nginx

 

posted @ 2017-10-30 21:10  Adamanter  阅读(261)  评论(0编辑  收藏  举报