安装rsync
#yum install rsync
# yum -y install xinetd
# vi /etc/xinetd.d/rsync
将如下代码
service rsync
{
disable = yes
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = �Cdaemon
log_on_failure += USERID
}
中的 disable = yes 改成 disable = no
然后启动 xinetd
# /etc/init.d/xinetd start 或 service xinetd restart
注意:如果服务器上装有防火墙记得要打开端口,默认端口是873
# vi /etc/rsyncd.conf (这个文件如果不存在自己创建)
uid = root
gid = root
use chroot = no
max connections = 5
secrets file = /etc/rsyncd.secrets rsyncd.pass
log file = /var/log/rsyncd.log
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
commen= hello world
[web]
path = /user/web/webroot /usr/wenjian/web /home/data/htdocs 注这个是要同步的目录
auth users = rsync 用户名
read only = no
hosts allow = 192.168.1.182
hosts deny = *
list = true
ignore errors
[root@dianxin149 webserver]# vim /etc/server.pas rsyncd.pass
rsync149:tongBu tongbu
给文件正确的权限
# chown root:root /etc/server.pas
# chmod 600 /etc/server.pas #(必须是600)
#service xinetd restart
#chkconfig xinetd on
镜像备份到dianxin182上的/mydata/bak目录下
电信182上的设置如下
tar xvzf rsync-2.6.7.tar.gz
cd rsync-2.6.7
./configure --prefix=/usr/local/rsync
make
make install
#vim /etc/server.pas
tongBu
# chown root:root /etc/server.pas
# chmod 600 /etc/server.pas
#crontable -e
* * * * * /user/rsync/bin/rsync 这是在客户端的路径 -avz --progress --password-file=/etc/rsyncd.secrets [email protected]::149182 /mydata/bak/ >/dev/null
# which rsync 查看rsync 安装路径
# vim /etc/rc.local
/user/rsync/bin/rsync �Cdaemon
# echo "* * * * * /user/rsync/bin/rsync -avz --progress --password-file=/etc/rsyncd.secrets [email protected]::149182 /mydata/bak/ >/dev/null" >> /var/spool/cron/root
测试 在被同步端 rsync -vzrtopg --progress --delete --password-file=/etc/rsyncd.pass.pass [email protected]::web /usr/wenjian
4. 使用 --execlude= 排除不需要同步的文件后缀名
rsync -vzrtopg --progress --delete --password-file=/etc/rsync_client.pass --exclude="*.tmp" [email protected]::web /opt/web
1)备份本地
rsync -r --progress --delete /root/test /root/test1
5. 使用 --execlude-from= 排除不需要同步的目录
[root@ASB opt]# rsync -vzrtopg --progress --delete --password-file=/etc/rsync_client.pass --exclude-from=/opt/pcdir [email protected]::web /opt/web
如果出现错误
@ERROR: auth failed on module web1
rsync error: error starting client-server protocol (code 5) at main.c(1503) [receiver=3.0.6]
检查 用户名和密码在检查权限在检查secrets file = /etc/rsyncd.secrets etc后边的文件要对应