












利用Rsync服务让SLB下多台centos服务器文件同步更新
因为易淘帮使用了SLB负载均衡,为了保证SLB下两台服务器下面的网站文件同步,易淘帮采用了rsync服务进行同步,并进行了每三分钟同步一次。根据这样操作可以完美的使用slb服务,实现负载均衡、容灾恢复。
一. 介绍
rsync – remote synchronize是类unix系统下的数据镜像备份工具,它的特性如下:
检测是否安装rsync服务rpm -qa|grep rsync
服务端和客户端安装rsyncyum -y install rsync
也可以源码安装
rsync下载地址:http://rsync.samba.org/
`./configure
make && make install`
我们将SLB下面两台服务器分为服务器A与服务器B,服务器A为主服务器,但是需要注意的是必须在服务器A(100.xxx.xxx.1)和 B(100.xxx.xxx.2)上都安装rsync,其中A服务器上是以服务器模式运行rsync,而B上则以客户端方式运行rsync。这样在web 服务器A上运行rsync守护进程,在B上定时运行客户程序来备份web服务器A上需要备份的内容。
三. 服务器A配置
vi /etc/rsyncd.conf #根据你自己的rsyncd.conf文件所以目录而定
#[globale]
strict modes = yes
port = 873
uid = root
gid = root
user chroot = no
max connections = 5 #同时的最大连接数
timeout = 600
pid file = /var/run/rsyncd.pid #进程的pid存放文件位置
lock file = /var/run/rsyncd.lock #lock文件位置
log file = /var/log/rsyncd.log #日志文件位置
[eeetb.com-rsyncd] #建立一个备份名,服务器B通过该名称指定具体的备份位置,可自定义
path=/home/wwwroot #备份文件存放的目录位置
ignore errors
read only = no
list = no
hosts allow = 100.xxx.xxx.2 #允许服务器B地址,如果是内网可以使用内网IP
auth users = root #允许那些用户,这里的用户test的信息存放在/etc/rsyncd.password
secrets file = /etc/rsyncd.password #指定允许的用户和用户密码
建立用户密码文件:
`vi /etc/rsyncd.password
root:123456 #允许的用户和密码`
修改防火墙策略,允许873端口(tcp/udp)
`vi /etc/sysconfig/iptables #加入下面的规则
-A INPUT -s 100.xxx.xxx.2 -p tcp -m state --state NEW -m tcp --dport 873 -j ACCEPT #授权B服务器访问A服务器873端口`
启动服务器端
`/usr/bin/rsync --daemon --config=/etc/rsyncd.conf
添加rsyncd开机自启动
echo '/usr/bin/rsync --daemon --config=/etc/rsyncd.conf' >> /etc/rc.local`
四. 服务器B配置
vi /etc/rsyncd.password
123456 #服务器A设置的密码
chmod 600 /etc/rsyncd.password
设置每天自动同步任务
crontab -e #(可以定时每三分钟同步一次文件)加入下方内容
*/3 * * * * /usr/bin/rsync -avzP --delete --progress --exclude=排除的不需同步目录 --password-file=/etc/rsyncd.password root@100.xxx.xxx.1::eeetb-rsync /home/wwwroot > /dev/null 2>&1
重新修改一下每天同步任务,修复原任务无法同步问题
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。