rsync 客户端 172.17.0.29
rsync 服务端 --daemon 方式运行 172.17.0.31 备份端
以下首先说明服务端的安装情况:
1 检查是否安装rsync
rpm -qa rsync
rsync-3.0.6-12.el6.x86_64 如果没有安装进行yum 安装即可
yum install -y rsync
yum install -y xinetd
/etc/init.d/xinetd status
/etc/init.d/xinetd restart
2 useradd rsync -s /sbin/nologin -M
mkdir /backup
chown rsync.rsync /backup
3 编写rsync daemon 配置文件/etc/rsyncd.conf
##rsyncd.conf start###工作中指定用户(需要指定用户)
uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
【backup】指定模块
path = /backup
read only = false
list = false
hosts allow = 172.17.0.29/32 允许的地址连接
hosts deny = 0.0.0.0/32 拒绝的地址连接
auth users = rsync_backup #虚拟用户名
secrets file = /etc/rsync.password #对应的密码
rsync_config_______________end
[backup01] #注意这里指定模块的方式方法,因为在客户端需要指定这个地方,否则导致同步 失败的奇葩现象
path = /backup01
4 创建上述配置中指定的虚拟账号和密码:
echo "rsync_backup:123456">/etc/rsync.password
chmod 600 /etc/rsync.password # 注意权限
[root@mfsmaster backup01]# cat /etc/rsync.password
rsync_backup:123456
5 启动服务
rsync --daemon
[root@mfsmaster backup01]# cat /etc/rc.local 追加开机启动
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
/usr/local/mfs/sbin/mfsmaster start
rsync --daemon
which rsync
也可以echo "/etc/bin/rsync --daemon" >> /etc/rc.local
[root@mfsmaster ~]# ps -ef |grep rsync
root 1432 1 0 16:57 ? 00:00:00 rsync --daemon
[root@mfsmaster ~]# ss -tnlp | grep rsync 查看873 存在873端口
LISTEN 0 5 :::873 :::* users:(("rsync",1432,5))
LISTEN 0 5 *:873 *:* users:(("rsync",1432,3)
[root@localhost /]# rsync -avz disk.txt [email protected]::backup/ --password-file=/etc/rsync.password
rsync: failed to connect to 172.17.0.16: No route to host (113)
rsync error: error in socket IO (code 10) at clientserver.c(124) [sender=3.0.6]
You have new mail in /var/spool/mail/root
出现错误的方法:
检查服务器的端口netstat –tunlp,远程telnet测试。
可能因为客户端或者服务端的防火墙开启 导致无法通信,可以设置规则放行 rsync(873端口) 或者直接关闭防火墙。
6 客户端的安装方法:
echo "123456" > /etc/rsync.password # 这里只填写密码即可
chmod 600 /etc/rsync.password # 注意权限 (这一步不配置出现password file must not be other-accessible
continuing without password file
Password:
@ERROR: auth failed on module backup
rsync error: error starting client-server protocol (code 5) at main.c(1503) [sender=3.0.6])
rsync -avz moosefs-3.0.81-1.tar.gz [email protected]::backup01 --password-file=/etc/rsync.password # 目录同步并指定相应的密码文件
rsync -avzp --delete /data [email protected]::backup01 --password-file=/etc/rsync.password
注意:这里/data 目录的区别
/data 同步目录
/data/ 同步目录下的文件
/data/* 同步目录下的文件
[root@mqsql29 /]# scp -r /data/ [email protected]:/backup2016/ 复制目录
scp -r /data/* [email protected]:/backup2016/ 复制目录下的文件