部署项目《下课说》APP时,总结出的一些命令和方法细节Linux、ubuntu、django、uwsgi、nginx、mysql里面有些是查找的资料,我也不大懂【手动笑哭】,这还是部署到一台服务器上,看分布式、集群服务器的技术贴时,都感觉好厉害?,还需努力!不过确实部署成功了,项目可以正常运行,期间还修改过几次代码,运行都很稳定。 【真没少费劲,装了好几遍,从刚开始装第一遍的时候装了一天,装到第三四次的时候一个小时就搞定了】
1.安装python3.6 python tab tab # 两次tab键,查看python版本[一般只有python2.7和3.5,需要寄几装3.6] apt-get update # 更新数据源 apt-get install software-properties-common add-apt-repository ppa:jonathonf/python-3.6 apt-get update apt-get install python3.62.创建软链接 which python3 #查看python位置 /usr/bin/python3 cd /usr/bin rm python #[把python绑成python3.6版本,可以不写] ln -s python3.6 python rm python3 #[把python3绑成python3.6版本,这个要写不然是python3.5] ln -s python3.6 python3 可以移除python3.5 apt autoremove python3.53.安装pip3 对应python3.6 apt-get install python3-pip pip3 install --upgrade pip #把pip3更新到最新 退出重新登 [python3.7目前还没有pip版本可用,亲测,不要用python3.7]4.安装虚拟环境 pip3 install virtualenv #在python3.6下创建 创建虚拟环境: virtualenv pro_wait_env #[找个目录进入,我放在了home目录下] cd pro_wait_env source pro_wait_env/bin/activate # 激活虚拟环境进入 python -V # 查看环境 pip -V pip list deactivate # 退出5.安装git apt-get install git #[也可以在虚拟环境部分安装]clone代码 git clone 克隆地址 # clone github上面的代码6.安装mysql #wget https://dev.mysql.com/get/mysql-apt-config_0.8.10-1_all.deb #dpkg -i mysql-apt-config_0.8.10-1_all.deb # 选择8.0 ok #apt-get update apt-get install mysql-server # 两次密码 默认5.7版本 ps aux|grep mysql # 查看进程 mysql -uroot -p # 进入数据库 cd /etc/mysql/mysql.conf.d sudo vim mysqld.cnf bind-address = 0.0.0.0 # 这样在Win可以远程连接 sudo service mysql restart # 重启 mysql -uroot -p # 进入数据库 # 修改密码 root@xks:/etc/mysql# cat debian.cnf user = debian-sys-maint password = a5iXwkeENbRNXkd5 user = debian-sys-maint password = 57QwMAShmXlmSYdy update user set authentication_string=PASSWORD("Xks201314") where user='root';7.同步数据 pip freeze > requirments.txt # 在本机项目中 生成Python环境下的所有类库到requirments.txt pip install -r requirements.txt # 在服务器虚拟环境中 安装django需要的库8.上传settings.py用于测试 ALLOWED_HOSTS = ['*']9.安装mysqlclient wget https://dev.mysql.com/get/libmysqlclient-dev_8.0.11-1ubuntu16.04_amd64.deb dpkg -i libmysqlclient-dev_8.0.11-1ubuntu16.04_amd64.deb # 执行上一句,若提示没有按照libmysqlclient21,则执行apt-get install libmysqlclient21 apt-get update apt-get install libmysqlclient-dev apt-get install python3.6-dev apt-get install openssl apt-get install libssl-dev 主要的:其实可以直接装pymysql pip3 install pymysql10.测试启动 python manage.py runserver 0.0.0.0:80============================================== nginx和uwsgi ================================测试:pip install uwsgiuwsgi --http :8000 --wsgi-file test.pyuwsgi --chdir /home/pro_test --home /home/dj20_env/ --http :8000 --module pro_test.wsgi:applicationuwsgi --chdir /www/pro_test --www /www/pro_xks_env/ --http :8000 --module pro_test.wsgi:application配置:apt install nginxcd /etc/nginxcd sites-available/可以把sites-available和sites-enabled 中的default都删掉,软连接引用默认在sites-available/目录下: vim pro_test.conf内容:# mysite_nginx.confupstream django { server 127.0.0.1:8001; }# configuration of the serverserver { listen 8000; server_name 47.100.206.78; charset utf-8; client_max_body_size 75M; # adjust to taste location /media { alias /home/pro_wait/media; } location /static { alias /home/pro_wait/static; } location / { uwsgi_pass django; include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed }}//# mysite_nginx.confupstream django { server 127.0.0.1:8001; }# configuration of the serverserver { listen 8000; server_name 47.100.206.78; charset utf-8; client_max_body_size 75M; # adjust to taste location /media { alias /www/pro_wait/media; } location /static { alias /www/pro_wait/static; } location / { uwsgi_pass django; include /etc/nginx/uwsgi_params; # the uwsgi_params file you installed }}进入项目vim pro_test.ini内容:====第一次部署=====# mysite_uwsgi.ini file[uwsgi]# Django-related settingschdir = /home/pro_waitmodule = pro_wait.wsgi:applicationhome = /home/dj20_env# process-related settingsmaster = true# maximum number of worker processesprocesses = 10harakiri = 60max-requests = 5000# the socket (use the full path to be safesocket = 127.0.0.1:8001uid = 1000gid = 2000pidfile = /home/pro_wait/master.piddaemonize = /home/pro_wait/pro_wait.logvacuum = true//====第二次部署=====//# mysite_uwsgi.ini file[uwsgi]# Django-related settingschdir = /www/pro_waitmodule = pro_wait.wsgi:applicationhome = /www/pro_xks_env# process-related settingsmaster = true# maximum number of worker processesprocesses = 10harakiri = 60max-requests = 5000# the socket (use the full path to be safesocket = 127.0.0.1:8001uid = 1000gid = 2000pidfile = /www/pro_wait/master.piddaemonize = /www/pro_wait/pro_wait.logvacuum = true先在setting.py中加入 STATIC_ROOT = os.path.join(BASE_DIR, 'static/') STATIC_URL = '/static/'收集静态文件 python manage.py collectstatic启动django uwsgi --ini /home/pro_wait/pro_wait.ini #通过这个ini文件启动 uwsgi --ini /www/pro_wait/pro_wait.ini #通过这个ini文件启动查看进程 ps -aux | grep uwsgi软连接到执行 ln -s /etc/nginx/sites-available/pro_wait.conf /etc/nginx/sites-enabled/pro_wait.conf查看nginx状态: nginx -t重启nginx服务: service nginx restartnginx -s stopuwsgi --stop master.piduwsgi --reload master.pidps -aux | grep uwsgipip freeze > requeirment.txtchmod 777 mediachmod -R 777 medianginx的启动和停止: sudo service nginx start / stop / status / restart;修改代码重启 killall -9 uwsgi uwsgi --ini /www/pro_wait/pro_wait.ini service nginx restart .
.