centos7安装配置rsync以及遇到问题

安装

服务端

安装软件:

yum  -y  install  rsync

创建需同步的目录:

mkdir  -p  /data

编辑配置文件:vim /etc/rsyncd.conf

motd file = /etc/rsyncd.motd
transfer logging = yes
log file = /var/log/rsyncd.log #日志存放路径
port = 873  #端口号
address = 192.168.0.37  #IP地址
uid = root #使用的用户名
gid = root  #使用的密码
use chroot = no
read only = no
max connections = 10
[common]
comment = rsync lee
path = /data
ignore errors
auth users = simops
secrets file = /etc/rsyncd.secrets
hosts allow = 192.168.0.0/255.255.255.0 #允许访问的地址段
hosts deny = *
list = false

UID = 0
GID = 0

创建用户密码:

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

创建提示信息文件:

echo  "rsync simops"  >  /etc/rsyncd.motd

配置防火墙规则和关闭SElinux:

iptables  -I  INPUT  -p  tcp  --dport  873  -j  ACCEPT
setenforce 0 #临时关闭SElinux

启动服务:

rsync  --daemon
echo  "rsync  --daemon"  >>  /etc/rc.local

二、客户端(192.168.0.17):

安装软件:

yum  -y  install  rsync

创建需同步的目录:

mkdir  -p  /data

创建密码文件(免输入密码):

echo  "123456"  >  /root/passwd
chmod  600  /root/passwd

拉取:

rsync  -avz  --password-file=/root/passwd  simops@192.168.0.37::common  /data/

推送

rsync  -avz  --password-file=/root/passwd  /data  simops@192.168.0.37::common

遇到问题

1、执行推送命令之后报错

rsync  -avz  --password-file=/root/passwd  lee@192.168.0.37::common  /home/lee/rsync/
rsync  lee

@ERROR: invalid uid root #使用的用户名
rsync error: error starting client-server protocol (code 5) at main.c(1648) [Receiver=3.1.2]

解决方案在rsyncd.conf文件中添加下面两行即可解决问题

UID = 0 
GID = 0 

2、服务器端同步目录没有权限

rsync  -avz  --password-file=/root/passwd  simops@192.168.0.37::common  /home/lee/rsync/
rsync  lee

@ERROR: chdir failed
rsync error: error starting client-server protocol (code 5) at main.c(1648) [Receiver=3.1.2]

解决方案:服务器端同步目录没有权限,cwrsync默认用户是Svcwrsync。为同步目录添加用户Svcwrsync权限

3、没有关闭selinux

rsync  -avz  --password-file=/root/passwd simops@192.168.0.37::common  /data/
rsync  lee

receiving incremental file list
rsync: opendir "." (in common) failed: Permission denied (13)

sent 20 bytes  received 108 bytes  256.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1650) [generator=3.1.2]

这个问题看似已经同步可是去查看的时候没有同步过来
细细的检查了一下是selinux问题,关闭之后就可以了

上一篇:vuex中store.commit和store.dispatch的用法区别


下一篇:居然之家采用云原生数据库支撑核心业务全面上云