1.申請云主機
????????a.阿里云 (注意:阿里云的服務器需要手動添加安全規(guī)則使能80端口)?
? ?? ???b.騰訊云
2.把網(wǎng)站服務器程序拷貝到云主機
? ? ? ? [~/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是網(wǎng)站服務器程序壓縮包
? ? ? ? ? ? ? ? ? ? 140.143.163.129是云主機的公網(wǎng)IP地址
3.遠程登錄云主機
????????[~] ssh?root@140.143.163.129
注意:以下操作均在云主機上操作
4.解壓網(wǎng)站服務器程序
? ?? ???[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.創(chuàng)建Python虛擬環(huán)境?
? ?? ???[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.安裝網(wǎng)站服務器需要的包
? ?? ???[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.創(chuàng)建數(shù)據(jù)庫
? ?? ???[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.修改網(wǎng)站服務器配置
? ?? ???[root@VM_0_6_centos iotServer]# vim config.py
? ?? ?? ?? ?? ? 修改mysql用戶名钳宪、密碼翼抠、數(shù)據(jù)庫
11.數(shù)據(jù)庫遷移
? ?? ???[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.調(diào)用網(wǎng)站服務器的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.修改網(wǎng)站服務器運行文件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?
備份數(shù)據(jù)庫
[root@embsky ~]# mysqldump -uembsky -p uplooking > uplooking20180817.sql
注意:embsky是用戶名??uplooking是要備份的數(shù)據(jù)庫的名字??uplooking20180817是數(shù)據(jù)庫備份文件
恢復數(shù)據(jù)庫
[root@embsky ~]# mysql -uembsky -p uplooking
注意:uplooking是要恢復的數(shù)據(jù)庫的名字