由于测试环境只有内网,所以在外网同系统上安装python.
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tar.xz
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ zlib* sqlite-devel
mkdir /home/python3
xz –d Python-3.6.5.tgz.xz
tar -zxvf Python-3.6.5.tgzcd Python-3.6.5
./configure --prefix=/home/python3
make && make install
/home/python3/bin/pip3 install -r requirements.txt #该文件一般放在项目目录上
request pymysql paramiko pymongo==3.7.0 django==1.11.10 django-celery==3.2.1 celery==3.1.20 redis用django 新建个项目测试测试,有少库的,就装上
/home/python3/bin/django-admin startproject newtest
/home/python3/bin/python3 manage.py runserver 0.0.0.0:8087 运行没错就下一步,有错就根据错误信息解决,一般少库就装库。
如报这个错:
File "/home/python3/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 198, in get_new_connection conn = Database.connect(**conn_params) django.db.utils.NotSupportedError: URIs not supported ^Z [1]+ Stopped /home/python3/bin/python3 manage.py runserver 0.0.0.0:8087原因分析,这是sqlite3版本3.7的通病,安装3.8的就可以,这里我采用修改源码的方式,直接打开
"/home/python3/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py"这个文件,修改修改大概198行,通过搜索uri查找。 # between multiple threads. The safe-guarding will be handled at a # higher level by the `BaseDatabaseWrapper.allow_thread_sharing` # property. This is necessary as the shareability is disabled by # default in pysqlite and it cannot be changed once a connection is # opened. if 'check_same_thread' in kwargs and kwargs['check_same_thread']: warnings.warn( 'The `check_same_thread` option was provided and set to ' 'True. It will be overridden with False. Use the ' '`DatabaseWrapper.allow_thread_sharing` property instead ' 'for controlling thread shareability.', RuntimeWarning ) kwargs.update({'check_same_thread': False}) if self.features.can_share_in_memory_db: kwargs.update({'uri': False}) #这里原来是True,修改为False就可以了 return kwargs修改mysql的登录密码
>mysql set password=password('root');
>mysql grant all privileges on *.* to root@'%' identified by 'root';
>mysql flush privileges;
yum install mariadb-server mariadb #有做离线源的也可以这么做
拷贝nops这个项目的文件到服务器上,例如 /home/www 这个目录
添加权限:chomd +x /home
视情况可将 /home 修改为nginx用户: chown -r nginx:nginx /home
修改配置: \home\www\nops\nops\settings.py
把里面数据库配置都修改为我们创建的
因为我们的项目用了celery 所以先要启动这个
后台启动celery:
/home/python3/bin/python3 /home/www/nops/manage.py celery worker --loglevel=info >/dev/null 2>&1 & 有定时任务的话,还需要启动心跳: /home/python3/bin/python3 /home/www/nops/manage.py celery beat >> /home/www/nops/celery.log 2>&1 &启动项目: 先
/home/python3/bin/python3 /home/www/nops/manage.py runserver 0.0.0.0:8087测试没问题就可以配置uwsgi
安装 uwsgi
sudo pip install uwsgi --upgrade
使用 uwsgi 运行项目
uwsgi --http :8001 --chdir /home/www/nops --module nops.wsgi
这样就可以跑了,project.wsgi 指的是 /home/www/nops/wsgi.py 文件
这样只是测试,正式环境下:
先编写uwsgi.ini文件:
[uwsgi] #home=/home/qitanl/pyenv/soms chdir=/home/www/nops # Django项目根目录 (绝对路径) module=nops.wsgi:application master=True # process-related settings # master pidfile=/home/www/nops/vm.pid vacuum=True # clear environment on exit max-requests=1000 daemonize=/home/www/nops/v_uwsgi.log socket = 0.0.0.0:10000 #真实服务的端口 #http = 0.0.0.0:8082其中soms 改为只能项目名字就行。#是注释掉的,这里保留做学习助于理解。
启动:uwsgi --ini uwsgi.ini
启动成功后uwsgi会占用10000端口运行该项目,但要注意这里没配http,所以不能直接用http访问。
yum install nginx
安装nginx
然后添加配置文件:
server { listen 8082; server_name nops.com; index index.html; location / { root /home/www/nops; ##uwsgi uwsgi_pass 127.0.0.1:10000; include uwsgi_params; uwsgi_param UWSGI_CHDIR /home/www/nops; uwsgi_param UWSGI_SCRIPT wsgi; } location ~ .*\.(log|php|pl|py|sh|cgi)$ { return 403; } location /static/ { alias /home/www/nops/static; autoindex on; } location ~ .*\.(gif|jpg|png|htm|html|css|js|flv|ico|swf)(.*) { root /home/www/nops; expires 30d; } location ~ .*\.(js|css)?(.*) { root /home/www/nops; expires 12h; } }重启:
cd /etc/rc.d/init.d# ./nginx stopStopping nginx: [ OK ]# ./nginx startStarting nginx: [ OK ]
到此访问: ip:8082端口即可看到项目
转载于:https://www.cnblogs.com/CGCong/p/9399298.html
相关资源:一个经典内网上线方法 一个经典内网上线方法