centos7中rsync安装和配置

环境:centos7 64位
目的:实现服务器之间的文件同步(可以配置crontab定时任务用)

安装rsync 服务端

  1. 下载yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
cd /etc/yum.repos.d/
wget http://mirrors.aliyun.com/repo/Centos-7.repo
  1. yum安装rsync最新版本
yum install rsync -y

4.启动
systemctl enable rsyncd #设置开机启动
systemctl start rsyncd #启动rsync
启动端口为:873

配置文件
cat <<‘EOF’>/etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = no
max connections = 10
strict modes = yes
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log

[iot02]
path = /data/ftp/file/royole
comment = log file
ignore errors
read only = no
write only = no
hosts allow = 0.0.0.0
hosts deny = 0.0.0.0/32
list = false
uid = root
gid = root
vauth users = loguser
secrets file = /etc/server.pass
EOF

secrets file:
cat <<‘EOF’> /etc/server.pass
loguser:66xxP@
EOF

测试:
安装rsync 客户端

yum install rsync -y
/usr/bin/rsync -vzrtopg --progress --include *.log --include *.gz --exclude-from=/script/rsync-exclude.txt /deploy/ loguser@172.18.24.92::iot02 --password-file=/etc/server.pass

–exclude-from=/script/rsync-exclude.txt文件样例:

cat /script/rsync-exclude.txt
*.jar
*/tmp
*.sh
web
jenkinsRemoteDir
*.txt

参数说明:
-r 子目录递归同步
-v 输出详情
-t 保持文件时间
-p --perms 保持文件权限
-o --owner 保持文件属主信息
-g --group 保持文件属组信息
-z 压缩传输
–include 包含文件
–exclude-from 排除文件列表

另一种rsync传输的方法:

利用ssh的22端口,公钥免密
rsync -avz --progress --include *.log --include *.gz  --exclude tmp --exclude tomcat* --exclude *.jar deploy@192.144.135.220:/home/dyyu/rowrite/ucenter /data/ftp/file/royole/rowrite
解析:
把远程目标服务器192.144.135.220:/home/dyyu/rowrite/ucenter目录,同步到本地/data/ftp/file/royole/rowrite;远端用户deploy做免密就不需要输入密码。
  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值