CentOS 7 安装配置 Rsync 实现数据同步

安装环境

服务端:192.168.1.113
客户端:192.168.1.114
需求:114主机上 /opt/image/ 自动同步113主机上 /home/image/

服务端 192.168.1.113

1、安装 rsync 

yum install rsync –y

systemctl start rsyncd    # 启动
systemctl enable rsyncd   # 增加开机启动

2、配置文件 

vi /etc/rsyncd.conf

uid = root
gid = root
use chroot = no
read only = no
max connections = 200
transfer logging = yes
log file =/var/log/rsyncd.log
timeout = 900

[image]
path = /home/image/
ignore erros
auth users = rsync
secrets file = /etc/rsyncd.secrets
hosts allow = 192.168.1.0/255.255.255.0
hosts deny = *
list = false

rsyncd.conf 配置文件说明

# 设置服务器信息提示文件名称,在该文件中编写提示信息 
motd file = /etc/rsyncd.motd

# 开启Rsync数据传输日志功能 
transfer logging = yes

# 设置日志文件名称,可以通过log format参数设置日志格式 
log file =/var/log/rsyncd.log 

# 设置Rsync进程号保存文件名称 
pid file =/var/run/rsyncd.pid 

# 设置锁文件名称 
lock file =/var/run/rsync.lock 

# 设置服务器监听的端口号,默认为873 
port = 873

# 设置服务器所监听网卡接口的IP地址,这里服务器IP地址为192.168.0.254 
address = 192.168.0.254

# 设置进行数据传输时所使用的账户名称或ID号,默认使用nobody 
uid = nobody

# 设置进行数据传输时所使用的组名称或GID号,默认使用nobody 
gid = nobody

# 设置user chroot为yes后,rsync会首先进行chroot设置,将根映射到path参数路径下,对客户 
# 端而言,系统的根就是path参数所指定的路径。但这样做需要root权限,并且在同步符号 
# 连接资料时仅会同步名称,而内容将不会同步。 
use chroot = no 

# 是否允许客户端上传数据,这里设置为只读。 
read only = yes

# 设置并发连接数,0代表无限制。超出并发数后,则将会收到稍后重试的提示消息 
max connections = 10 

# 模块,Rsync通过模块定义同步的目录,模块以[name]的形式定义,这与Samba定义共享目录是一样的效果。
[common]

# comment定义注释说明字串 
comment = Web content 

# 同步目录的真实路径通过path指定 
path = /common

# 忽略一些IO错误 
ignore errors 

# exclude可以指定例外的目录,即将common目录下的某个目录设置为不同步数据 
exclude = test/

# 设置允许连接服务器的账户,账户可以是系统中不存在的用户 
auth users = tom,jerry

# 设置密码验证文件名称,注意该文件的权限要求为只读,建议权限为600,仅在设置auth users 参数后有效
secrets file = /etc/rsyncd.secrets

# 设置允许哪些主机可以同步数据,可以是单个IP,也可以是网段,多个IP与网段之间使用空格分隔
hosts allow=192.168.0.0/255.255.255.0 

# 设置拒绝所有(除hosts allow定义的主机外) 
hosts deny=* 

# 客户端请求显示模块列表时,本模块名称是否显示,默认为true 
list= false

3、创建密码

echo "rsync:123456" > /etc/rsyncd.secrets
chmod 600 /etc/rsyncd.secrets

4、创建同步目录

mkdir -p /home/image

5、配置防火墙

-A INPUT -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT

客户端 192.168.1.114

1、安装 rsync

yum install rsync –y

systemctl start rsyncd    # 启动
systemctl enable rsyncd   # 增加开机启动

2、客户端 创建同步目录

mkdir -p /opt/image

3、创建 客户端 密码

echo "123456" > /root/passwd    # 同步时免密码
chmod 600 /root/passwd          # 修改权限

4、拉取同步 本例采用

# 192.168.1.114 拉取192.168.1.113 的数据 
rsync -avz --password-file=/root/passwd rsync@192.168.1.113::image /opt/image/

推送同步

#192.168.1.114 推送数据至 192.168.1.113
rsync -avz --password-file=/root/passwd /opt/image/ rsync@192.168.1.113::image

错误相关

@ERROR: auth failed on module image

rsync error: error starting client-server protocol (code 5) at main.c(1503) [receiver=3.0.6]

1、客户端没有 /root/passwd 这个文件或密码不对,或服务器端 用户名和密码不对

2、/etc/rsyncd.secrets, /root/passwd 文件权限要 改成 600

Centos 6.8 安装 rsync

  1. 安装(xinetd 与rsync)
  2. chkconfig rsync on 与 service xinetd restart
  3. 配置文件 rsyncd.conf
  4. mkdir /etc/rsyncd
  5. touch /etc/rsyncd/{rsyncd.conf,rsyncd.secrets}
  6. vim /etc/xinetd.d/rsync
# 指定配置文件
vim /etc/xinetd.d/rsync

{
        disable = no
        flags           = IPv6
        socket_type     = stream
        wait            = no
        user            = root
        server          = /usr/bin/rsync
        server_args     = --daemon --config=/etc/rsyncd/rsyncd.conf
        log_on_failure  += USERID
}
  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值