1.申请云主机
a.阿里云 (注意:阿里云的服务器需要手动添加安全规则使能80端口)
b.腾讯云
2.把网站服务器程序拷贝到云主机
[~/iotServer]$>./venv/bin/pip freeze >requiremtents.txt
[~/iotServer]$>cd ..
[~] mv iotServer/venv/ .
[~]tar -jcvf iotServer.tar.bz2 iotServer/
[~]scp iotServer.tar.bz2 root@140.143.163.129:/root
注意:iotServer.tar.bz2是网站服务器程序压缩包
140.143.163.129是云主机的公网IP地址
3.远程登录云主机
[~] ssh root@140.143.163.129
注意:以下操作均在云主机上操作
4.解压网站服务器程序
[root@VM_0_6_centos ~]# yum install bzip2
[root@VM_0_6_centos ~]# tar -xvf iotServer.tar.bz2
5.安装Python3
[root@VM_0_6_centos ~]# yum list |grep python
[root@VM_0_6_centos ~]# yum install python36.x86_64
6.创建Python虚拟环境
[root@VM_0_6_centos ~]# cd iotServer9
[root@VM_0_6_centos iotServer]# mkdir venv
[root@VM_0_6_centos iotServer]# python36 -m venv ./venv/
7.安装网站服务器需要的包
[root@VM_0_6_centos iotServer]# ./venv/bin/pip install --upgrade pip
[root@VM_0_6_centos iotServer]# ./venv/bin/pip install -r requirements.txt
8.安装mysql
[root@VM_0_6_centos iotServer]# yum list |grep maridb
[root@VM_0_6_centos iotServer]# yum install mariadb.x86_64 mariadb-server.x86_64
[root@VM_0_6_centos iotServer]# systemctl restart mariadb
[root@VM_0_6_centos iotServer]# mysql_secure_installation
[root@VM_0_6_centos iotServer]# systemctl restart mariadb
9.创建数据库
[root@VM_0_6_centos iotServer]# mysql -uroot -p123456
MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS uplooking DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
10.修改网站服务器配置
[root@VM_0_6_centos iotServer]# vim config.py
修改mysql用户名、密码、数据库
11.数据库迁移
[root@VM_0_6_centos iotServer]# ./venv/bin/python run.py db init
[root@VM_0_6_centos iotServer]# ./venv/bin/python run.py db migrate
[root@VM_0_6_centos iotServer]# ./venv/bin/python run.py db upgrade
12.调用网站服务器的init命令
[root@VM_0_6_centos iotServer]# ./env/bin/python run.py init
13.安装gunicorn
[root@VM_0_6_centos iotServer]# ./env/bin/pip install gunicorn
14.修改网站服务器运行文件run.py
[root@VM_0_6_centos iotServer]# vim run.py
去掉manager.run()
15.启动gunicorn
[root@VM_0_6_centos iotServer]# ./venv/bin/gunicorn -w 4 -b 127.0.0.1:8080 --chdir ./ run:app &
16.安装nginx
[root@VM_0_6_centos iotServer]# yum install nginx
17.配置nginx
[root@VM_0_6_centos iotServer]# vim /etc/nginx/nginx.conf
18.重启nginx
[root@VM_0_6_centos iotServer]# service nginx restart6
备份数据库
[root@embsky ~]# mysqldump -uembsky -p uplooking > uplooking20180817.sql
注意:embsky是用户名 uplooking是要备份的数据库的名字 uplooking20180817是数据库备份文件
恢复数据库
[root@embsky ~]# mysql -uembsky -p uplooking
注意:uplooking是要恢复的数据库的名字
网友评论