rsync是一款服務器與服務器這間的同步工具了,通常我們可以利用rsync來實時數據同步操作了,下面我一起來看看安裝rsync同步軟件的教程.
安裝
rsync-3.1.0.tar.gz
#tar zxvf rsync-3.1.0.tar.gz
#cd rsync-3.1.0
#./configure --prefix=/home/work/rsync
#make
#make install
rsync服務端的配置;
環境:192.168.11.11為生產機;192.168.11.12為備份機;
那麼需要192.168.11.11需要作為rsync的client;
192.168.11.12作為rsync的service端;
1、192.168.11.12_service端的配置;
1)[root@cmmailapp2 data]# touch /etc/rsyncd.conf //此文件為rsync的主配置問題,默認不存在需要手動創建;
2)定義同步的配置;
[root@cmmailapp2 data]# cat /etc/rsyncd.conf
[data]
path = /data/
auth users = coremail
uid = root
gid = root
secrets file = /etc/rsyncd.secrets
read only = no
[mysql]
Path = /home/coremail/var/mysql
auth users = coremail
uid = root
gid = root
secrets file = /etc/rsyncd.secrets
read only = no
[cmxt]
Path = /home/coremail/
auth users = coremail
uid = root
gid = root
secrets file = /etc/rsyncd.secrets
read only = no
3)定義密碼文件/etc/rsyncd.secrets
[root@cmmailapp2 data]# cat /etc/rsyncd.secrets
coremail:coremail
4)啟動rsync啟動服務
[root@cmmailapp2 data]# cat /etc/xinetd.d/rsync
# default: off
# description: The rsync server is a good addition to an ftp server, as it
# allows crc checksumming etc.
service rsync
{
disable = yes //需要修改為no;
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
[root@cmmailapp2 data]# chkconfig --level 2345 rsync on
[root@cmmailapp2 data]# chkconfig rsync on
[root@cmmailapp2 data]# chkconfig --level 2345 xinetd on
[root@cmmailapp2 data]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
2、192.168.11.11_client端的配置;
[root@cmmailapp1 /]# cat /etc/rsyncd.secrets
coremail
[root@cmmailapp1 /]# rsync -aSvH --password-file=/etc/rsyncd.secrets /home/coremail/[email protected]::data
[root@cmmailapp1 /]# rsync -aSvH --password-file=/etc/rsyncd.secrets /home/coremail/[email protected]::mysql
[root@cmmailapp1 /]# rsync -aSvH --password-file=/etc/rsyncd.secrets /home/coremail/[email protected]::cmxt
五、定義定時自行rsync同步,指定同步的日志所在的路徑/var/log/rsync/下;
[root@cmmailapp1 log]# cat /root/rsync.sh
DATE=`date +%Y%m%d%H%M`
rsync -aSvH --password-file=/etc/rsyncd.secrets /home/coremail/ [email protected]::data >/var/log/rsync.date.$DATE
rsync -aSvH --password-file=/etc/rsyncd.secrets /home/coremail/ [email protected]::mysql >/var/log/rsync.mysql.$DATE
rsync -aSvH --password-file=/etc/rsyncd.secrets /home/coremail/ [email protected]::cmxt >/var/log/rsync.cmxt.$DATE
chmod u+x /root/rsync.sh
[root@cmmailapp1 log]# crontab -l
0 3 * * * /root/rsync.sh
執行時候的日子記錄文件:
[root@cmmailapp1 log]# ls |grep 'rsync'
rsync.cmxt.201110180915
rsync.date.201110180915
rsync.mysql.201110180915
啟動
rsync --daemon --port 3334 --config=/home/work/rsync/conf/rsyncd.conf
錯誤1
@ERROR: setgroups failed
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6]
這個錯我是由於 起服務的 rsync 和 傳輸的rsync的版本不用。後來換成一個版本後就好了。
ps大家要注意一點的時rsync軟件是分服務器端與客戶端兩種,也就是主從服務器了,所以安裝版本是不一樣的哦.