服务端配置
一、添加配置文件
备份
cp /etc/rsyncd.conf{,.ori}
添加内容
cat > /etc/rsyncd.conf<配置文件查帮助
man rsyncd.conf
二、创建目录和添加用户[root@backup ~]$mkdir -p /backup [root@backup ~]$ls -d /backup [root@backup ~]useradd -s /sbin/nologin -M rsync [root@backup ~]$id rsync [root@backup ~]$chown -R rsync.rsync /backup/ [root@backup ~]$ll -d /backup/ drwxr-xr-x 2 rsync rsync 6 Nov 4 06:57 /backup/三、添加密码文件
[root@backup ~]$echo "rsync_backup:shnne123" >/etc/rsync.password [root@backup ~]$cat /etc/rsync.password rsync_backup:shnne123 [root@backup ~]$chmod 600 /etc/rsync.password [root@backup ~]$ll /etc/rsync.password -rw------- 1 root root 23 Nov 4 07:01 /etc/rsync.password四、启动服务
rsync --daemon (CentOS 6启动方式) CentOS 7启动方式 [root@backup ~]$systemctl start rsyncd [root@backup ~]$systemctl enable rsyncd [root@backup ~]$systemctl status rsyncd [root@backup ~]$netstat -lntup|grep 873 [root@backup ~]$lsof -i :873客户端配置
第一种方法[root@nfs01 ~]$echo "shnne123" > /etc/rsync.password [root@nfs01 ~]$cat /etc/rsync.password oldboy123 [root@nfs01 ~]$chmod 600 /etc/rsync.password [root@nfs01 ~]$ll /etc/rsync.password -rw------- 1 root root 10 Nov 4 07:09 /etc/rsync.password第二种方法
[root@nfs01 ~]$echo 'export RSYNC_PASSWORD=shnne123' >> /etc/bashrc [root@nfs01 ~]$tail -1 /etc/bashrc export RSYNC_PASSWORD=shnne123 [root@nfs01 ~]$. /etc/bashrc [root@nfs01 ~]$echo $RSYNC_PASSWORD shnne123测试结果
拉取实践[root@nfs01 ~]$rsync -avz rsync_backup@172.16.1.41::backup /data --password-file=/etc/rsync.password [root@nfs01 ~]$rsync -avz rsync://rsync_backup@172.16.1.41/backup /data --password-file=/etc/rsync.password推送实践
[root@nfs01 ~]$rsync -avz /data rsync_backup@172.16.1.41::backup --password-file=/etc/rsync.password [root@nfs01 ~]$rsync -avz /data rsync://rsync_backup@172.16.1.41/backup --password-file=/etc/rsync.password