最近rsync这部分吃了不少亏,有些细节部分需要记住


检测rsync是否安装

rpm -qa | grep rsync


安装rsync

yum install -y rsync



rsync主配置文件rsync.conf

pid file = /var/run/rsyncd.pid    #会在/var/run下产生进程文件
port = 873
address = 192.168.18.27    #ip配置成本机的,不然rsync起不来
#uid = nobody
#gid = nobody
uid = root
gid = root

use chroot = yes
read only = no

#limit access to private LANs
#hosts allow=101.226.1.186/255.255.0.0
hosts allow=192.168.18.88/255.255.255.0 192.168.18.91/255.255.255.0 #公司需要限定内网ip
hosts deny=*

max connections = 5
motd file = /etc/rsyncd/rsyncd.motd

#This will give you a separate log file
#log file = /var/log/rsync.log

#This will log every file transferred - up to 85,000+ per user, per sync
#transfer logging = yes

log format = %t %a %m %f %b  #日志格式
syslog facility = local3
timeout = 300

[logdir]
path = /opt/nowtel/     #需要同步的目录
list=yes     #允许列表
ignore errors    #忽略错误
auth users = logserver    #这个用户就是密码文件里的用户
secrets file = /etc/rsyncd/rsyncd.secrets   #加密文件的位置
comment = log message


在/etc/rsyncd.secrets文件下面需要这样定义
  logserver:log8273192

  1.前一个为用户名,后一个为密码
  2.该文件必须置为600权限


客户端也要的密码文件需要创建

eg:rsync.password

创建目录在/opt/rsync/rsync.password

而且权限是600


服务器端

启动rsync服务

/usr/bin/rsync --daemon --config=/etc/rsync/rsync.conf



客户端

nohup /usr/bin/rsync -avzP --password-file=/opt/rsync/rsync.password logserver@192.168.18.27::logdir /opt/message &

~