关闭防火墙和seliunx
防火墙关闭:
systemctl stop firewalld.service
关闭seliunx
输入:
vi /etc/seliunx/config
将
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
改为:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
源服务器配置
在226上配置
uid = 0 #进行备份的用户
gid = 0 #进行备份的组
use chroot = no #不使用chroot
max connections = 10 #最大连接数
log file = /var/log/rsyncd.log #日志文件
[rsyncd] #这里是认证的模块名
path = /home/tests #参与同步的目录,配置的时候把这个注释删了,不然会提示错误
ignore errors #可以忽略一些无关的IO错误
read only = yes #只读
list = no #不允许列清单
anth users = root #认证的用户名
secrets file = /etc/rsync.passwd #密码文件存放地址
配置时最好去掉注释
添加密码文件:
vi /etc/rsyncd.passwd
在打开的文件中添加用户名和密码
用户名和rsyncd.conf文件配置的一样
root:zp@123789
创建好后授权
chmod 600 /etc/rsync.passwd
重启rsync
systemctl restart rsyncd
备份服务器配置
创建密码文件
vi /etc/rsync.passwd
在打开的文件里面填写密码:
zp@123789
创建好后授权
chmod 600 /etc/rsync.passwd
重启rsync
systemctl restart rsyncd
同步操作测试
首先分别在两个服务器创建一个新的同步的文件夹,或者使用已经创建好的文件夹,不管是哪个路径下的文件夹,要和 rsyncd.conf 文件配置的路径一致。我两个服务器的文件同步路径都是一样的,都是 /home/tests,一点要安装源服务器.conf配置文件里的路径创建文件夹。
创建好后,备份服务器输入以下命令
rsync -vzurtopg --progress --delete root@192.168.1.226::rsyncd /home/tests --password-file=/etc/rsync.passwd
注:root@192.168.1.226:root就是192.168.1.226源文件服务器 rsyncd.conf 文件配置的用户名 ::rsyncd rsyncd.conf 文件配置的模块名 /home/tests 同步的目录 –password-file=/etc/rsync.passwd 表示加载配置文件 需要加载密码才能访问
出现以下文字既说明成功
receiving incremental file list
./
11.txt
0 100% 0.00kB/s 0:00:00 (xfr#1, to-chk=3/5)
sent 46 bytes received 160 bytes 412.00 bytes/sec
total size is 0 speedup is 0.00
自动备份
注意:本文归作者所有,未经作者允许,不得转载