Linux中安装rsync同步工具步骤详解

07-29

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软件是分服务器端与客户端两种,也就是主从服务器了,所以安装版本是不一样的哦.