centos7实现rsync实现同步

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/diyiday/article/details/83306053

两台服务器

192.168.1.10
192.168.1.20

前期准备

两台服务器关闭防火墙

查看防火墙状态

firewall-cmd --state

停止firewall

systemctl stop firewalld.service

禁止firewall开机启动

systemctl disable firewalld.service 

关闭selinux(非必须)
进入到/etc/selinux/config文件

vi /etc/selinux/config

将SELINUX=enforcing改为SELINUX=disabled

安装软件

添加rsync源

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum update
yum install inotify-tools-devel -y
yum install inotify-tools -y
yum -y install rsync
yum -y install xinetd   # 非必要安装

配置192.168.1.10

在192.168.1.10服务器上如下配置:

vi  /etc/rsyncd.conf

添加如下内容

uid = nobody #进行备份的用户nobody为任何用户

gid = nobody #进行备份的组 nobody为任何组

use chroot = no #不使用chroot

max connections = 10 #最大连接数

log file = /var/log/rsyncd.log #日志文件


[rsyncd] # 这里是认证的模块名

path = /home/test/ #参与同步的目录

ignore errors # 可以忽略一些无关的IO错误

read only = yes #只读

list = no #不允许列清单

anth users = test #认证的用户名

secrets file = /etc/rsyncd.passwd #密码文件存放地址

添加密码文件

vi  /etc/rsyncd.passwd

test:123456

配置完毕后,启动rsync,启动命令如下,启动会自动查找etc目录下rsyncd.conf加载启动

rsync –daemon

配置192.168.1.20

192.168.1.20同样安装 上面的软件,但是只需要编辑一个配置文件

vi /etc/rsyncd.passwd

内容只需要存放密码即可
123456

之后输入如下命令,即可同步 192.168.1.10指定目录的文件到 192.168.1.20服务器

rsync -vzurtopg --progress --delete [email protected]::rsyncd /data/test --password-file=/etc/rsync.passwd

上面命令详解

  • -vzurtopg --progress --delete 这些参数可以参考rsync详细介绍
  • test 这个表示用户名,就是192.168.1.10中 /etc/rsyncd.conf配置的用户,还有rsyncd.passwd配置的用户名
  • ::rsyncd这个表示/etc/rsyncd.conf配置的模块名字
  • /data/test 表示同步的目录
  • –password-file=/etc/rsync.passwd 表示加载配置文件 需要加载密码才能访问

于是这样,就初步完成一个简单的rsync 同步文件的操作。

猜你喜欢

转载自blog.csdn.net/diyiday/article/details/83306053