python基于centos云服务器的简单高并发部署

使用nginx的简单云服务器部署

1.申请云主机:
a.阿里云 (注意:阿里云的服务器需要手动添加安全规则使能80端口)
b.腾讯云

2.把网站服务器程序拷贝到云主机:
lzy@lzy-ThinkPad-E460:~/uplooking$ scp 03IotServer.tar.bz2 [email protected]:/root
注意:03IotServer.tar.bz2是网站服务器程序压缩包”
39.106.179.20是云主机的公网IP地址

3.远程登录云主机:
lzy@lzy-ThinkPad-E460:~/uplooking$ ssh [email protected]
注意:以下操作均在云主机上操作

4.解压网站服务器程序:
[root@iz2zei12ill6tpuwou81fiz ~]# yum install bzip2
[root@iz2zei12ill6tpuwou81fiz ~]# tar -xvf 03IotServer.tar.bz2

5.安装Python3:
[root@iz2zei12ill6tpuwou81fiz ~]# yum list |grep python
[root@iz2zei12ill6tpuwou81fiz ~]# yum install python36.x86_64

6.创建Python虚拟环境”:
[root@iz2zei12ill6tpuwou81fiz ~]# cd 03IotServer
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# mkdir env
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# python36 -m venv ./env/

7.安装网站服务器需要的包:
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# ./env/bin/pip install –upgrade pip
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# ./env/bin/pip install -r requirements.txt

8.安装mysql:
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# yum list |grep maridb
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# yum install mariadb.x86_64 mariadb-server.x86_64
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# systemctl restart mariadb
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# mysql_secure_installation

9.创建数据库:
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# mysql -uroot -pLzy123456
MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS uplooking DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

10.修改网站服务器配置:
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# vim config.py
修改mysql用户名、密码、数据库

11.数据库迁移:
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# ./env/bin/python run.py db init
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# ./env/bin/python run.py db migrate
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# ./env/bin/python run.py db upgrade

12.调用网站服务器的init命令:
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# ./env/bin/python run.py init

13.安装gunicorn:
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# ./env/bin/pip install gunicorn

14.修改网站服务器运行文件run.py:
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# vim run.py
去掉manager.run()

15.启动gunicorn:
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# ./env/bin/gunicorn -w 4 -b 127.0.0.1:8080 –chdir ./ run:app &

16.安装nginx:
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# yum install nginx

17.配置nginx:
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# vim /etc/nginx/nginx.conf

18.重启nginx:
[root@iz2zei12ill6tpuwou81fiz 03IotServer]# service nginx restart

猜你喜欢

转载自blog.csdn.net/huang_yong_peng/article/details/81844187