更新:管理服務器(主機shenxiang62) 使用rsync推送數據到(主機shenxiang61)便可
備份:管理服務器(主機shenxiang62) 使用rsync從主機(shenxiang61)拉入數據到本地
對此,shenxiang61 爲rsync服務端 shenxiang62爲客戶端php
[root@shenxiang61 ~]# yum install -y xinetd [root@shenxiang61 ~]# vim /etc/xinetd.d/rsync service rsync { disable = no #把yes改成no flags = IPv6 socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = –daemon log_on_failure += USERID }
[root@shenxiang61 ~]# vim /etc/rsyncd.conf [root@shenxiang61 ~]# cat !$ Ø 由於這裏文件都是apache服務來使用;因此讀寫用戶設爲apache cat /etc/rsyncd.conf uid = apache gid = apache use chroot = no max conections = 200 timeout = 300 pid file = /var/run/rsyncd.pid lock file = /var/run/rsync.lock log file = /var/log/rsync.log [webdata] path = /www/web/ ignore errors read only = no list = yes hosts allow = 192.168.1.62 auth users = xuegod secrets file = /etc/rsync.password
注意:
#文件格式:[用戶:密碼]
#認證文件權限要爲600mysql
[root@shenxiang61 ~]# vim /etc/rsync.password [root@shenxiang61 ~]# cat !$ cat /etc/rsync.password xuegod:xg123456 [root@shenxiang61 ~]# chmod 600 !$ chmod 600 /etc/rsync.password [root@shenxiang61 ~]# ll !$ ll /etc/rsync.password –rw——- 1 root root 16 Feb 18 00:12 /etc/rsync.password
[root@shenxiang61 ~]# /etc/init.d/xinetd restart [root@shenxiang61 ~]# lsof -i :873 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME xinetd 26469 root 6u IPv6 54207 0t0 TCP *:rsync (LISTEN)
[root@shenxiang62 ~]# yum install -y rsync
[root@shenxiang62 ~]# vim /etc/rsync.webpwd [root@shenxiang62 ~]# cat !$ cat /etc/rsync.webpwd xg123456 [root@shenxiang62 ~]# chmod 600 !$ chmod 600 /etc/rsync.webpwd [root@shenxiang62 ~]# ll !$ ll /etc/rsync.webpwd -rw——- 1 root root 9 Feb 18 11:46 /etc/rsync.webpwd
Ø 原理:使用rsync拉pull數據同步方式
Ø 執行動做:主機shenxiang62web
[root@shenxiang62 ~]# mkdir /data/webdata
[root@shenxiang62 ~]# rsync -avz xuegod@192.168.1.61::webdata –password-file=/etc/rsync.webpwd /data/webdata/ ......省略 uc_server/view/default/pm_send.htm uc_server/view/default/pm_view.htm uc_server/view/default/templates.lang.php uc_server/view/default/user_avatar.htm sent 80375 bytes received 12036146 bytes 4846608.40 bytes/sec total size is 28106599 speedup is 2.32
[root@shenxiang62 ~]# ll /data/webdata/ total 116 -rw-r–r– 1 apache apache 2739 Feb 17 22:08 admin.php drwxr-xr-x 11 apache apache 4096 Feb 17 22:08 api -rw-r–r– 1 apache apache 727 Feb 17 22:08 api.php drwxr-xr-x 2 apache apache 4096 Feb 17 22:08 archiver drwxr-xr-x 2 apache apache 4096 Feb 17 22:45 config ......省略
[root@shenxiang62 ~]# cd /data_bak/ [root@shenxiang62 data_bak]# vim webbak.sh [root@shenxiang62 data_bak]# cat !$ cat webbak.sh #!/bin/bash export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin webdata='/data_bak/webdata/' webdaemon=webdata webuser=xuegod webhost='192.168.1.61' mysqlhost='192.168.1.222' webpwd='/etc/rsync.webpwd' time=$(date +"%Y%m%d") rsync -avz $webuser@$webhost::$webdaemon --password-file=$webpwd /data/webdata/$time_bak \ && echo "NFS server webdata ${time} backup success!!" >>/data_bak/bak.log && find /data/webdata -mtime +8 |xargs rm -rf
[root@shenxiang62 data_bak]# echo 「30 3 * * * root /bin/bash /data_bak/webbak.sh」 >> /etc/crontab [root@shenxiang62 data_bak]# tail /etc/crontab # .—————- minute (0 – 59) # | .————- hour (0 – 23) # | | .———- day of month (1 – 31) # | | | .——- month (1 – 12) OR jan,feb,mar,apr … # | | | | .—- day of week (0 – 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed 30 4 * * * root /bin/bash /data_bak/webbak.sh
Ø 原理:rsync使用推push數據同步方式
Ø 執行動做:主機shenxiang62sql
[root@shenxiang61 ~]# cp -r /www/web/ /www/web.bak [root@shenxiang61 ~]# rm -rf /www/web/* [root@shenxiang61 ~]# ll /www/web total 0
[root@shenxiang62 ~]# rsync -avz –delete /data/webdata/ xuegod@192.168.1.61::webdata –password-file=/etc/rsync.webpwd ......省略 uc_server/view/default/pm_nav.htm uc_server/view/default/pm_send.htm uc_server/view/default/pm_view.htm uc_server/view/default/templates.lang.php uc_server/view/default/user_avatar.htm sent 12036078 bytes received 80324 bytes 1615520.27 bytes/sec total size is 28106599 speedup is 2.32
[root@shenxiang61 ~]# ll /www/web total 116 -rw-r–r– 1 apache apache 2739 Feb 17 22:08 admin.php drwxr-xr-x 11 apache apache 4096 Feb 17 22:08 api -rw-r–r– 1 apache apache 727 Feb 17 22:08 api.php drwxr-xr-x 2 apache apache 4096 Feb 17 22:08 archiver drwxr-xr-x 2 apache apache 4096 Feb 17 22:45 config -rw-r–r– 1 apache apache 922 Feb 17 22:08 connect.php -rw-r–r– 1 apache apache 253 Feb 17 22:08 cp.php ......省略