標籤:
【轉】CentOS5.6下配置rsync內網同步資料到外網
本文轉自:http://www.linuxidc.com/Linux/2012-06/64070.htm
一、需求
衛士那邊有一個需求,就是要把一台內網伺服器的資料同步到外網的一台伺服器上,之前我用的是rsync+intify-tool+ssh實現的即時同步更新,前幾天我還在東莞出差,開發的人給我打電話說這兩台伺服器的資料不同步了,我上去檢查一遍,原來是用來同步資料的這個系統帳號被北京的同事修改,ssh免密碼登陸失敗了,所以資料同步不了,後來想想這樣在系統開著個單使用者用來同步資料確實是存在安全風險,我有具體和開發的溝通了一下,這個項目的資料同步也不是那麼的需要即時同步,所以現在我要改成單用rsync同步,具體步驟如下:
二、環境
內網:10.20.220.247
同步目錄1:/data/appsdata/softmgr-v3/static-file/update
同步目錄2:/data/appsdata/softmgr-v3/static-file/v1_0
外網:114.112.36.X
同步目錄1:/data/apps/ksoftmgr/ksafe/client/update
同步目錄2:/data/apps/ksoftmgr/ksafe/client/v1_0
三、安裝配置
1.伺服器端(114.112.36.69)
A、[[email protected] ~]# yum -y install rsync xinetd
B、[[email protected] ~]# vi /etc/xinetd.d/rsync
將 disable = no 改成yes
[[email protected] ~]# /etc/init.d/xinetd start
C、撰寫rsync的設定檔http://www.linuxidc.com
[[email protected] ~]# vi /etc/rsyncd.conf
uid = root
gid = root
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
[update]
path = /data/apps/ksoftmgr/ksafe/client/update
comment = update file
ignore errors
read only = no
write only = no
hosts allow = 125.89.65.194
hosts deny = *
uid = root
auth users = wcm
secrets file = /etc/web.pass
[v1_0]
path = /data/apps/ksoftmgr/ksafe/client/v1_0
comment = v1_0 file
ignore errors
read only = no
write only = no
hosts allow = 125.89.65.194
hosts deny = *
uid = root
auth users = wcm
secrets file = /etc/web.pass
D、撰寫密碼檔案
[[email protected] ~]# vi /etc/web.pass (格式 帳號:密碼)
wcm:8888888
[[email protected] ~]# chown root:root /etc/web.pass
[[email protected] ~]# chmod 600 /etc/web.pass
E、啟動rsync
[[email protected] ~]# rsync --daemon
[[email protected] ~]# echo "rsync --daemon" >> /etc/rc.local
2、用戶端(10.20.220.247)
A、[[email protected] ~]# yum -y install rsync
B、撰寫密碼檔案
[[email protected] ~]# vi /etc/web.pass (主要:唯寫用來同步的帳號的密碼)
8888888
[[email protected] ~]# chown root:root /etc/web.pass
[[email protected] ~]# chmod 600 /etc/web.pass
C、撰寫crontab,沒一分鐘同步一次
[[email protected] v1_0]# crontab -e
*/1 * * * * /usr/bin/rsync -avz --progress --delete /data/appsdata/softmgr-v3/static-file/update/ [email protected]::update --password-file=/etc/web.pass
*/1 * * * * /usr/bin/rsync -avz --progress --delete /data/appsdata/softmgr-v3/static-file/v1_0/ [email protected]::v1_0 --password-file=/etc/web.pass
四、測試
在內網的update和v1_0下面刪除或者建立檔案,看對應外網的機器上是否也是做了相應的操作,如果是,說明OK,我的肯定是撒,線上的不同步就悲劇了。
【轉】CentOS5.6下配置rsync內網同步資料到外網