阿里云服务器安装后-天扬建筑业财税网校迁移过程

01/18/2016

由于业务需要对天扬建筑业财税网校的服务器进行了迁移工作,本篇日志详细记录了迁移过程

1.打包备份系统数据,包括NGINX配置文件、数据文件、MYSQL数据库数据3个部分。利用阿里云内网SSH进行数据传输,速度还是很好的

tianyangtax@iZ25xrwbim5Z:~$ mkdir edusoho
tianyangtax@iZ25xrwbim5Z:~$ cd edusoho
tianyangtax@iZ25xrwbim5Z:~$ cp /etc/nginx/sites-available/www.tianyangtax.com ./
tianyangtax@iZ25xrwbim5Z:~/edusoho$  mysqldump -u root -p edusoho | gzip > edusoho-database.sql.gz
Enter password: 
tianyangtax@iZ25xrwbim5Z:~$ cd /mnt/wwwroot
tianyangtax@iZ25xrwbim5Z:/mnt/wwwroot$ sudo tar -zcvf edusoho-site.tar.gz ./edusoho
tianyangtax@iZ25xrwbim5Z:/mnt/wwwroot$ sudo mv edusoho-site.tar.gz ~/edusoho
tianyangtax@iZ25xrwbim5Z:/mnt/wwwroot$ cd ~/edusoho
tianyangtax@iZ25xrwbim5Z:~/edusoho$ ls -l
total 510520
-rw-rw-r-- 1 tianyangtax tianyangtax 201114105 Jan 16 00:19 edusoho-database.sql.gz
-rw-r--r-- 1 root        root        321644242 Jan 16 00:24 edusoho-site.tar.gz
-rw-r--r-- 1 root        root             2304 Jan 15 23:54 www.tianyangtax.com
tianyangtax@iZ25xrwbim5Z:~/edusoho$ cd ..
tianyangtax@iZ25xrwbim5Z:~$ sudo tar -zcvf edusoho-archive.tar.gz ./edusoho
./edusoho/
./edusoho/edusoho-site.tar.gz
./edusoho/edusoho-database.sql.gz
./edusoho/www.tianyangtax.com
tianyangtax@iZ25xrwbim5Z:~$ scp -P 2002 edusoho-archive.tar.gz tianyangtax@10.44.29.234:/home/tianyangtax/edusoho-archive.tar.gz
tianyangtax@10.44.29.234's password: 
edusoho-archive.tar.gz                             100%  494MB  61.8MB/s   00:08

2.新服务器解压缩,打开MYSQL为网校系统建立数据库及用户,并导入备份数据

tianyangtax@iZ25tc8mln7Z:/mnt/backup$ sudo mkdir 20160116-site-move
tianyangtax@iZ25tc8mln7Z:/mnt/backup$ cd 20160116-site-move
tianyangtax@iZ25tc8mln7Z:/mnt/backup/20160116-site-move$ sudo mv ~/* ./
tianyangtax@iZ25tc8mln7Z:/mnt/backup/20160116-site-move$ sudo tar -zxvf edusoho-archive.tar.gz
tianyangtax@iZ25tc8mln7Z:/mnt/backup/20160116-site-move$ cd edusoho
tianyangtax@iZ25tc8mln7Z:/mnt/backup/20160116-site-move/edusoho$ ls -l
total 1949160
-rw-rw-r-- 1 tianyangtax tianyangtax 1674277524 Jan 16 00:19 edusoho-database.sql.gz
-rw-r--r-- 1 root        root         321644242 Jan 16 00:24 edusoho-site.tar.gz
-rw-r--r-- 1 root        root              2304 Jan 15 23:54 www.tianyangtax.com
tianyangtax@iZ25tc8mln7Z:/mnt/backup/20160116-site-move/edusoho$ sudo gunzip edusoho-database.sql.gz
tianyangtax@iZ25tc8mln7Z:/mnt/backup/20160116-site-move/edusoho$ mysql -u esuser -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 39
Server version: 5.5.46-0ubuntu0.14.04.2 (Ubuntu)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database `edusoho` default character set utf8;
Query OK, 1 row affected (0.08 sec)

mysql> grant all privileges on `edusoho`.* to 'esuser'@'localhost' identified by 'edusoho';
Query OK, 0 rows affected (0.08 sec)

mysql> use edusoho;
Database changed

mysql> source /mnt/backup/20160116-site-move/edusoho/edusoho-database.sql
mysql> quit
Bye

3.解包网站数据文件,更新配置文件中数据库相关信息

tianyangtax@iZ25tc8mln7Z:/mnt/backup/20160116-site-move/edusoho$ ls -l
total 1949160
-rw-rw-r-- 1 tianyangtax tianyangtax 1674277524 Jan 16 00:19 edusoho-database.sql
-rw-r--r-- 1 root        root         321644242 Jan 16 00:24 edusoho-site.tar.gz
-rw-r--r-- 1 root        root              2304 Jan 15 23:54 www.tianyangtax.com
tianyangtax@iZ25tc8mln7Z:/mnt/backup/20160116-site-move/edusoho$ sudo mkdir /mnt/wwwroot
tianyangtax@iZ25tc8mln7Z:/mnt/backup/20160116-site-move/edusoho$ sudo cp edusoho-site.tar.gz /mnt/wwwroot/
tianyangtax@iZ25tc8mln7Z:/mnt/backup/20160116-site-move/edusoho$ cd /mnt/wwwroot
tianyangtax@iZ25tc8mln7Z:/mnt/wwwroot$ sudo tar -zxvf edusoho-site.tar.gz
tianyangtax@iZ25tc8mln7Z:/mnt/wwwroot$ sudo chown -R www-data:www-data edusoho
tianyangtax@iZ25tc8mln7Z:/mnt/wwwroot$ cd edusoho/app/config
tianyangtax@iZ25tc8mln7Z:/mnt/wwwroot/edusoho/app/config$ sudo vim parameters.yml
tianyangtax@iZ25tc8mln7Z:/mnt/wwwroot/edusoho/app/config$ cat parameters.yml
parameters:
    database_driver: pdo_mysql
    database_host: ********
    database_port: ****
    database_name: ********
    database_user: ******** 
    database_password: '********'
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    locale: zh_CN
    secret: ********************************
    user_partner: none
    smvpToken: ******************************************************8

4.解包NGINX配置文件,重启NGINX服务

tianyangtax@iZ25tc8mln7Z:/mnt/wwwroot/edusoho/app/config$ cd /etc/nginx/sites-available
tianyangtax@iZ25tc8mln7Z:/etc/nginx/sites-available$ ls /mnt/backup/20160116-site-move/edusoho
edusoho-database.sql  edusoho-site.tar.gz  www.tianyangtax.com
tianyangtax@iZ25tc8mln7Z:/etc/nginx/sites-available$ sudo cp  /mnt/backup/20160116-site-move/edusoho/www.tianyangtax.com ./
tianyangtax@iZ25tc8mln7Z:/etc/nginx/sites-available$ cd ../sites-enabled
tianyangtax@iZ25tc8mln7Z:/etc/nginx/sites-enabled$ sudo ln -s /etc/nginx/sites-available/www.tianyangtax.com www.tianyangtax.com
tianyangtax@iZ25tc8mln7Z:/etc/nginx/sites-enabled$ ls -l
total 0
lrwxrwxrwx 1 root root 34 Jan 12 20:01 default -> /etc/nginx/sites-available/default
lrwxrwxrwx 1 root root 46 Jan 16 01:08 www.tianyangtax.com -> /etc/nginx/sites-available/www.tianyangtax.com
tianyangtax@iZ25tc8mln7Z:/etc/nginx/sites-enabled$ sudo service nginx restart
* Restarting nginx nginx                                                 [ OK ]  

2016-01-18 21:34:58屏幕截图