关于作者

My baby
☑阅读控 ☑80后 ☑看电影 ☑打篮球
#java #jquery #ubuntu #wordpress #php #mysql
来自天朝!
不大不小,而立之年!
不喜政治,但愿意关注时事!
我爱天朝,但天朝不爱我们!
PS:我就是希望她能回到我小时候那样子——上下学自己去,走几条马路就到学校,遇见陌生人也不害怕,不用家长去接,路上没那么多汽车,汽车知道避让行人,不用给老师送礼拍马屁,就这么简单。

蜘蛛网间

蜘蛛网与您分享网络间的爬行轨迹

阿里云服务器安装后-网站自动备份

01/23/2016

网站服务器为了安全的需要,配置CRON进行每日的备份任务.

1.编写自动备份网站的脚本.包括了备份网站文件及数据库文件,删除30天以前的备份数据.

tianyangtax@iZ25tc8mln7Z:~$ sudo vim /usr/sbin/site-backup-script
tianyangtax@iZ25tc8mln7Z:~$ sudo cat /usr/sbin/site-backup-script
#!/bin/sh                                                                                                                                   
rq=`date +%Y%m%d`
tar zcf /mnt/backup/www.tianyangtax.com/site/SiteFile-$rq.tar.gz /mnt/wwwroot/edusoho
mysqldump -u dbuser -pdbpwd edusoho | gzip > /mnt/backup/www.tianyangtax.com/mysql/MySql-$rq.gz
find /mnt/backup/www.tianyangtax.com/site/ -mtime +30 -name "*.tar.gz" -exec rm -rf {} \;
find /mnt/backup/www.tianyangtax.com/mysql/ -mtime +30 -name "*.gz" -exec rm -rf {} \;
tianyangtax@iZ25tc8mln7Z:~$ sudo chmod +x /usr/sbin/site-backup-script

2.添加CRON任务,每日04:27执行备份操作

tianyangtax@iZ25tc8mln7Z:~$ sudo vim /etc/cron.d/site-backup-cron
tianyangtax@iZ25tc8mln7Z:~$ sudo cat /etc/cron.d/site-backup-cron
27  4   *   *   *   root    /usr/sbin/site-backup-script

3.打开ubuntu的cron日志功能,可以看到我们的备份脚本正常执行了.

tianyangtax@iZ25tc8mln7Z:~$ sudo vim /etc/rsyslog.d/50-default.conf
tianyangtax@iZ25tc8mln7Z:~$ sudo cat /etc/rsyslog.d/50-default.conf
...
cron.*              /var/log/cron.log
...
tianyangtax@iZ25tc8mln7Z:~$ sudo service rsyslog restart
rsyslog stop/waiting
rsyslog start/running, process 3130
tianyangtax@iZ25tc8mln7Z:~$ sudo service cron restart
cron stop/waiting
cron start/running, process 3145
tianyangtax@iZ25tc8mln7Z:~$ sudo tail /var/log/cron.log
...
Jan 22 04:27:01 iZ25tc8mln7Z CRON[6231]: (root) CMD (/usr/sbin/site-backup-script)
...

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

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屏幕截图

阿里云服务器安装后-转移大体积备份数据

01/16/2016

阿里云更换ECS主机后,需要对网站数据在不同主机间迁移,由于数据量相对还比较大,因此配置阿里云安全组选项后利用ECS云主机内网进行数据转移.

1.安全组设置

分别在源服务器以及目标服务器的安全组配置处增加内网入方向策略规则,允许另一方服务器的内网访问.授权对象填写另一服务器的内网地址.

2016-01-16 03:12:44屏幕截图

2.源服务器将备份目录进行打包压缩

利用SSH工具的SCP进行文件传输,由于阿里云系统盘默认的大小为20G,备份目录有17G空间有些不足,因此对打包文件进行了分割,每10G分割一份.

tianyangtax@iZ25xrwbim5Z:/mnt$ sudo tar -zcvf backup.tar.gz ./backup
tianyangtax@iZ25xrwbim5Z:/mnt$ sudo split -b 10G  backup.tar.gz backup.tar.gz.
tianyangtax@iZ25xrwbim5Z:/mnt$ ls -l
total 33179748
drwxr-xr-x 9 root     root            4096 Nov 28 23:39 backup
-rw-r--r-- 1 root     root     16988007291 Jan 15 22:23 backup.tar.gz
-rw-r--r-- 1 root     root     10737418240 Jan 15 22:59 backup.tar.gz.aa
-rw-r--r-- 1 root     root      6250589051 Jan 15 23:03 backup.tar.gz.ab

3.利用SSH工具scp进行文件传输

我们可以看到阿里云ECS内网见传输速度能够达到30-40MB/s 速度还是很快的

tianyangtax@iZ25xrwbim5Z:/mnt$ scp -P 2002 backup.tar.gz.aa tianyangtax@10.44.29.234:/home/tianyangtax/backup.tar.gz.aa
backup.tar.gz.aa                                  79% 8410MB 33.7MB/s 00:26 ETA

4.将传输完毕的文件,先移动到单独的数据盘挂载点 /mnt

tianyangtax@iZ25tc8mln7Z:~$ sudo mv backup.tar.gz.aa /mnt
tianyangtax@iZ25tc8mln7Z:~$ cd /mnt
tianyangtax@iZ25tc8mln7Z:/mnt$ ls -l
total 10485784
-rw-r--r-- 1 tianyangtax tianyangtax 10737418240 Jan 15 23:12 backup.tar.gz.aa
drwxr-xr-x 3 root        root               4096 Jan 15 21:38 database
drwx------ 2 root        root              16384 Jan 11 20:29 lost+found

5.继续传输分卷压缩包的第二部分

tianyangtax@iZ25xrwbim5Z:/mnt$ scp -P 2002 backup.tar.gz.ab tianyangtax@10.44.29.234:/home/tianyangtax/backup.tar.gz.ab
backup.tar.gz.ab                                  79% 6410MB 33.7MB/s 00:26 ETA

6.依旧移动第二个分卷至数据盘挂载点

tianyangtax@iZ25tc8mln7Z:~$ sudo mv backup.tar.gz.ab /mnt
tianyangtax@iZ25tc8mln7Z:~$ cd /mnt
tianyangtax@iZ25tc8mln7Z:/mnt$ ls -l
total 16589880
-rw-r--r-- 1 tianyangtax tianyangtax 10737418240 Jan 15 23:12 backup.tar.gz.aa
-rw-r--r-- 1 tianyangtax tianyangtax  6250589051 Jan 15 23:20 backup.tar.gz.ab
drwxr-xr-x 3 root        root               4096 Jan 15 21:38 database
drwx------ 2 root        root              16384 Jan 11 20:29 lost+found

7.将分卷合并为一个完整压缩包并解压缩,完成后删除压缩包,完成整个备份数据迁移过程.

tianyangtax@iZ25tc8mln7Z:/mnt$ sudo bash -c "cat backup.tar.gz.* > backup.tar.gz"
tianyangtax@iZ25tc8mln7Z:/mnt$ ls -l
total 33179736
-rw-r--r-- 1 root        root        16988007291 Jan 15 23:34 backup.tar.gz
-rw-r--r-- 1 tianyangtax tianyangtax 10737418240 Jan 15 23:12 backup.tar.gz.aa
-rw-r--r-- 1 tianyangtax tianyangtax  6250589051 Jan 15 23:20 backup.tar.gz.ab
drwxr-xr-x 3 root        root               4096 Jan 15 21:38 database
drwx------ 2 root        root              16384 Jan 11 20:29 lost+found
tianyangtax@iZ25tc8mln7Z:/mnt$ sduo tar -zxvf backup.tar.gz ./
tianyangtax@iZ25tc8mln7Z:/mnt$ sudo rm -rf backup.tar.*
tianyangtax@iZ25tc8mln7Z:/mnt$ ls -l
total 24
drwxr-xr-x 9 root root  4096 Nov 28 23:39 backup
drwxr-xr-x 3 root root  4096 Jan 15 21:38 database
drwx------ 2 root root 16384 Jan 11 20:29 lost+found

阿里云服务器安装后-移动MYSQL数据库文件位置

01/15/2016

1.停止MYSQL服务,移动默认数据目录 /var/lib/mysql 至指定位置.

tianyangtax@iZ25tc8mln7Z:~$ sudo service mysql stop
mysql stop/waiting
tianyangtax@iZ25tc8mln7Z:~$ cd /mnt
tianyangtax@iZ25tc8mln7Z:/mnt$ sudo mkdir database
tianyangtax@iZ25tc8mln7Z:/mnt$ cd database
tianyangtax@iZ25tc8mln7Z:/mnt/database$ sudo mv /var/lib/mysql ./
tianyangtax@iZ25tc8mln7Z:/mnt/database$ ls -l
total 4
drwx------ 4 mysql mysql 4096 Jan 15 21:31 mysql

2.更改配置文件

tianyangtax@iZ25tc8mln7Z:/mnt/database$ sudo vim /etc/apparmor.d/usr.sbin.mysqld
tianyangtax@iZ25tc8mln7Z:/mnt/database$ sudo cat /etc/apparmor.d/usr.sbin.mysqld
...
  #edit by royakon for move datadir to /mnt on 20160115
  #/var/lib/mysql/ r,
  #/var/lib/mysql/** rwk,
  /mnt/database/mysql/ r,
  /mnt/database/mysql/** rwk,
  #end edit
...
tianyangtax@iZ25tc8mln7Z:/mnt/database$ sudo vim /etc/mysql/my.cnf
tianyangtax@iZ25tc8mln7Z:/mnt/database$ sudo cat /etc/mysql/my.cnf
...
datadir         = /mnt/database/mysql
...

3.重新启动MYSQL服务,并测试

tianyangtax@iZ25tc8mln7Z:/mnt/database$ sudo service mysql start
mysql start/running, process 1718
tianyangtax@iZ25tc8mln7Z:/mnt/database$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 38
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> quit
Bye

阿里云服务器安装后-安装配置PHP-FPM

01/12/2016

1.更新缓存,安装PHP-FPM

tianyangtax@iZ25tc8mln7Z:~$ sudo apt-get update
tianyangtax@iZ25tc8mln7Z:~$ sudo apt-get upgrade
tianyangtax@iZ25tc8mln7Z:~$ sudo apt-get install php5 php5-cli php5-curl php5-fpm php5-intl php5-mcrypt php5-mysqlnd php5-gd

2.更新PHP-FPM配置文件

tianyangtax@iZ25tc8mln7Z:~$ sudo vim /etc/php5/fpm/php.ini
tianyangtax@iZ25tc8mln7Z:~$ sudo cat /etc/php5/fpm/php.ini
...
post_max_size = 1024M 
memory_limit = 2048M
upload_max_filesize = 1024M
...
tianyangtax@iZ25tc8mln7Z:~$ sudo vim /etc/php5/fpm/pool.d/www.conf
tianyangtax@iZ25tc8mln7Z:~$ sudo cat /etc/php5/fpm/pool.d/www.conf
...
listen = /var/run/php5-fpm.sock
...
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
...
tianyangtax@iZ25tc8mln7Z:~$ sudo service php5-fpm restart
php5-fpm stop/waiting
php5-fpm start/running, process 11930

3.更新NGINX站点配置文件以支持PHP

tianyangtax@iZ25tc8mln7Z:~$ sudo vim /etc/nginx/sites-available/default
tianyangtax@iZ25tc8mln7Z:~$ sudo cat /etc/nginx/sites-available/default
...
server {
...
    	index index.html index.htm index.php;
...
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
	#
	location ~ \.php$ {
		fastcgi_split_path_info ^(.+\.php)(/.+)$;
		# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
	
		# With php5-cgi alone:
		# fastcgi_pass 127.0.0.1:9000;
		# With php5-fpm:
		fastcgi_pass unix:/var/run/php5-fpm.sock;
		fastcgi_index index.php;
		include fastcgi_params;
	}

	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	location ~ /\.ht {
		deny all;
	}
...
tianyangtax@iZ25tc8mln7Z:~$ sudo service nginx restart
 * Restarting nginx nginx                     [ OK ]

4.测试服务器及PHP是否正常

 
tianyangtax@iZ25tc8mln7Z:~$ sudo vim /usr/share/nginx/html/phpinfo.php
tianyangtax@iZ25tc8mln7Z:~$ sudo cat /usr/share/nginx/html/phpinfo.php
< ?php
    phpinfo();

2016-01-12 20:58:31屏幕截图

Older Posts