双机热备之 Rsync 文件主主同步

1.安装软件

yum -y install rsync xinetd 

2.配置文件

A服务器中设置    #ip  本机

编辑配置文件 vi /etc/rsyncd.conf 

motd file = /etc/rsyncd.motd

transfer logging = yes

log file = /var/log/rsyncd.log

port = 873

address = 192.168.77.134 

uid = nobody

gid = nobody

use chroot = no

read only = no

max connections = 10

[common]

comment = rsync info

path = /home/www                            #路径

ignore errors

auth users = sync                     #账号

secrets file = /etc/rsyncd.secrets

hosts allow = 192.168.77.0/255.255.255.0

hosts deny = *

list = false

 

2、创建用户密码文件

echo "sync:123456" > /etc/rsyncd.secrets

chmod 600 /etc/rsyncd.secrets

3、创建提示信息文件:

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

4、启动服务:

rsync  --daemon

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

 

5、客户端配置(由于是主主同步,所以不需要区分客户端):

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

echo  "123456"  >  /root/passwd

chmod  600  /root/passwd

 

6、添加定时任务

vi /home/rsync.sh

rsync -avz --password-file=/root/passwd  sync@192.168.77.134common /home/www  >/dev/null 2>&1

 

* * * * * /home/rsync.sh

 

测试(对方ip) B服务器中设置同A服务器,只是区分IP地址

 

#拉取

rsync -avz --password-file=/root/passwd  sync@192.168.4.220::common /home/www

#推送

rsync -avz --password-file=/root/passwd /home/www/ sync@192.168.77.128::common

 

 

 

添加开放端口

firewall-cmd --add-port=873/tcp --permanent

9.重启防火墙

systemctl restart firewalld

文件同步推送需要修改文件 用户  为root   ,

(1) vi /etc/rsyncd.conf   

(2) Gid,uid   都改为root

  1. 重启服务   
    service xinetd restart

 

posted @ 2020-12-29 15:52  夫子张  阅读(492)  评论(0)    收藏  举报