1安装编译工具
yum install zlib-devel bzip2-devel openssl-devel python-devel kernel-devel libffi-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
2官网下载安装
wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz tar -xvJf Python-3.5.0.tar.xz #注意解压方式和.tar.gz结尾的区别 cd Python-3.5.0 ./configure prefix=/usr/local/python3 make && make install ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
3安装pip3(python3以上都自带pip和setuptools)
1.首先安装setuptools
小伙伴们可以通过官方模块库来下载:https://pypi.python.org/pypi
这里我就直接用wget到服务器上下载了版本为19.6
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26 tar -zxvf setuptools-19.6.tar.gz cd setuptools-19.6 /usr/local/python3/bin/python3 setup.py build /usr/local/python3/bin/python3 setup.py install
2.然后直接安装pip就搞定了。。
同样先下载然后在执行命令搞定!!
wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb tar -zxvf pip-8.0.2.tar.gz cd pip-8.0.2 /usr/local/python3/bin/python3 setup.py build /usr/local/python3/bin/python3 setup.py install ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
3用pip安装模块
/usr/local/python3/bin/pip3 install Django==2.1.1
4用pip安装uwsgi
/usr/local/python3/bin/pip3 install uwsgi
ln -s /usr/local/python3/bin/uwsgi /usr/local/bin/uwsgi
测试文件test.py def app(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"] 运行 uwsgi --http :8000 --wsgi-file test.py 用uwsgi 启动django uwsgi --http :8000 --module projectName.wsgi
可以把参数写到配置文件里面uwsgi.ini
[uwsgi] #生产环境不需要此项 http = :9000 # 取决于nginx配置 upstream socket = 127.0.0.1:9090 socket = 127.0.0.1:9091 # 项目根目录 chdir = /home/user/projectName# Django的wsgi文件 module = projectName.wsgi # Python虚拟环境的路径 #home = /home/user/.virtualenvs/envname/bin/python # 进程相关的设置 # 主进程 master = true # 最大数量的工作进程 processes = 4 #每个进程开启的线程数 threads = 2 # 设置socket的权限 chmod-socket = 666 # 退出的时候是否清理环境 vacuum = true #用户和组,没有权限是改为root试试,nginx.conf的user配置也改为root uid = nginx gid = nginx stats = 127.0.0.1:9191 # 静态文件 绝对地址 static-map = /static=/home/user/projectName/static
启动uwsgi
uwsgi --ini uwsgi.ini
以www用户启动
uwsgi --uid www --gid www uwsgi.ini
停止uwsgi
uwsgi --stop uwsgi.pid
或者
killall -9 uwsgi
重启uwsgi
uwsgi --reload uwsgi.ini
5安装nginx
安装略过........
配置支持uwsgi的nginx.conf文件
upstream django { server 127.0.0.1:9090; } server { listen 80; server_name localhost; charset utf-8; access_log /var/log/nginx/nginx_access.log main; error_log /var/log/nginx/nginx_error.log; client_max_body_size 75M; location /static { alias /djproject/mysite/static; #指定django的静态文件 } location / { include /etc/nginx/uwsgi_params; #加载uwsgi模块 uwsgi_pass 127.0.0.1:9090; #所有请求转到9090端口交给uwsgi处理 } # location / { # uwsgi_pass django; # include /path/to/your/mysite/uwsgi_params; # } }
django静态文件加载
在settings.py设置此项 STATIC_ROOT = os.path.join(BASE_DIR, "static/") 收集静态文件操作 python3 manage.py collectstatic