rsync+sersync+nfs高可用
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rsync+sersync+nfs高可用相关的知识,希望对你有一定的参考价值。
环境:
HOST | IP | OS | |
主机1 | 100011 | 10.0.0.11 | CentOS6.6 |
主机2 | 100012 | 10.0.0.12 | CentOS6.6 |
为了省事,直接关闭iptables,selinux,以下配置都为10.0.0.11上的配置,10.0.0.12也要做相同配置(个别地方须修改,如ip等)
一、安装配置rsync
1、安装
[[email protected] /]# yum install -y rsync xinetd
[[email protected] /]# service xinetd start&&chkconfig xinetd onfont
2、创建配置文件
[[email protected] /]# mkdir /var/log/rsyncd ##存放日志文件
[[email protected] /]# vi /etc/rsyncd.conf
######内容######
uid=root
gid=root
use chroot=no
max connections=10
strict modes=yes
port=873
address=10.0.0.11 ##本地要监听的IP地址
[data] ##数据同步模块名,可自定义名字
path=/nfs-storage
comment=nfs mirror
ignore errors
read only=no
list=no
secrets file=/etc/rsync.pas
hosts allow=*
pid file=/var/run/rsyncd.pid
lock file=/var/run/rsync.lock
log file=/var/log/rsyncd/rsyncd.log
3、配置认证文件
[[email protected] /]# echo "abcd,.1234">/etc/rsync.pas
[[email protected] /]# chmod 600 /etc/rsync.pas
rsync配置结束,不要添加开机启动,通过keepalived启动
二、安装配置sersync
1、下载安装
wget http://sersync.googlecode.com/files/sersync2.5.4_64bit_binary_stable_final.tar.gz
或
[[email protected] ~]#tar -zxvf sersync2.5.4_64bit_binary_stable_final.tar.gz
cd GNU-lINUX-x86/
mkdir /usr/local/sersync
mkdir /usr/local/sersync/conf
mkdir /usr/local/sersync/bin
mkdir /usr/local/sersync/log
cp confxml.xml /usr/local/sersync/conf
cp sersync2 /usr/local/sersync/bin/
ln -s /usr/local/sersync/bin/sersync2 /usr/bin/sersync2
2、配置
vi /usr/local/sersync/conf/confxml.xml
红色标注为我个人添加或修改部份
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
<host hostip="localhost" port="8008"></host>
<debug start="false"/>
<fileSystem xfs="false"/>
<filter start="true">
<exclude expression="^(.*)/Runtime/*"></exclude> 这是缓存目录,忽略掉,不监控
<exclude expression="^\.(.*)"></exclude>
<exclude expression="(.*)\.tmp"></exclude>
<exclude expression="(.*)\.svn"></exclude>
<exclude expression="(.*)\.gz"></exclude>
<exclude expression="^info/*"></exclude>
<exclude expression="^static/*"></exclude>
</filter>
<inotify>
<delete start="true"/>
<createFolder start="true"/>
<createFile start="false"/>
<closeWrite start="true"/>
<moveFrom start="false"/>
<moveTo start="false"/>
<attrib start="false"/>
<modify start="false"/>
</inotify>
<sersync>
<localpath watch="/nfs-storage"> 本地监控目录
<remote ip="10.0.0.12" name="data"/> 对端ip及rsync里面数据同步模块名
<!--<remote ip="192.168.8.39" name="tongbu"/>-->
<!--<remote ip="192.168.8.40" name="tongbu"/>-->
</localpath>
<rsync>
<commonParams params="-artuz"/>
<auth start="false" users="root" passwordfile="/etc/rsync.pas"/>
<userDefinedPort start="false" port="874"/><!-- port=874 -->
<timeout start="false" time="100"/><!-- timeout=100 -->
<ssh start="false"/>
</rsync>
<failLog path="/tmp/rsync_fail_log.sh" timeToExecute="5"/><!--default every 60mins execute once-->
<crontab start="false" schedule="600"><!--600mins-->
<crontabfilter start="false">
<exclude expression="*.php"></exclude>
<exclude expression="info/*"></exclude>
</crontabfilter>
</crontab>
<plugin start="false" name="command"/>
</sersync>
<plugin name="command">
<param prefix="/bin/sh" suffix="" ignoreError="true"/> <!--prefix /opt/tongbu/mmm.sh suffix-->
<filter start="false">
<include expression="(.*)\.php"/>
<include expression="(.*)\.sh"/>
</filter>
</plugin>
<plugin name="socket">
<localpath watch="/opt/tongbu">
<deshost ip="192.168.138.20" port="8009"/>
</localpath>
</plugin>
<plugin name="refreshCDN">
<localpath watch="/data0/htdocs/cms.xoyo.com/site/">
<cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
<sendurl base="http://pic.xoyo.com/cms"/>
<regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
</localpath>
</plugin>
</head>
sersync配置结束,不要添加开机启动 ,通过keepalived启动
三、安装本置keepalived
1、安装
[[email protected] /]# yum install -y keepalived
2、配置
[[email protected] /]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
}
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id 100011 不能重复,我用的ip地址作为标识
}
vrrp_instance VI_1 {
state BACKUP 两台都配置BACKUP
interface eth0
virtual_router_id 248 同一vrrp组要一样,我用的vip
# use_vmac uvmac 开始想整vmac没成功
# vmac_xmit_base
priority 100 另一台上配置小于100
advert_int 1
nopreempt 另一台不需要
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.248/24
}
notify_master /usr/local/sersync/tomaster.sh
notify_backup /usr/local/sersync/tobackup.sh
}
}
四、安装配置nfs
1、服务器端,100012也要做相同配置
[[email protected] /]#yum install -y nfs-utils rpcbind
[[email protected] /]#vi /etc/exports
/nfs-storage/webdata 10.0.0.0/24(rw,no_root_squash)
[[email protected] /]service rpcbind start&&service nfs start
[[email protected] /]chkconfig nfs on&&chkconfig rpcbind on
[[email protected] /]#exportfs
/nfs-storage/webdata
10.0.0.0/24
2、客户端通过autofs挂载
[[email protected] /]vi /etc/auto.nfs 假定100010为其中一台apache服务器
webdata -rw,bg,soft,udp,rsize=524288,wsize=524288 10.0.0.248:/nfs-storage/webdata
[[email protected] /]vi /etc/auto.master
#
# Sample auto.master file
# This is a ‘master‘ automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/misc /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
# "nosuid" and "nodev" options unless the "suid" and "dev"
# options are explicitly given.
#
/net -hosts
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master
/mydata /etc/auto.nfs --timeout=20 新加内容
service autofs restart
在/mydata下执行ls 发现为空,因通过autofs自动挂载配置,要有访问才会挂载,如执行cd webdata 便可发现挂载成功。上同的配置--timeout=20是说20秒空闲,就umount.
后记:过上一段时间,发现rsync的日志较大,通过logrotate分割rsync的日志,具体怎样使用,百度!!!
[[email protected] /]#vi /etc/logrotate.d/rsyncd
/var/log/rsyncd/rsyncd.log {
notifempty
daily
rotate 7
}
部署过多次后后,我咋觉得要把这简单的事描述清楚,咋就这么困难呢,唉,语文没学好,。我的疑惑:比如挂载的时候通过udp(默认是tcp,我把它改成udp和把vmac固定,是为了看服务器端故障转移,看是不是要快些)。
重要东东在附件。checktb是根据官方脚本简单修改的,另也尝试rsync+sersync双向同步,但发现有点问题。(有兴趣自行测试吧)
脚本执行
[[email protected] /]crontab -e
* * * * * /usr/local/sersync/checktb.sh
* * * * * sleep 10; /usr/local/sersync/checktb.sh
* * * * * sleep 20; /usr/local/sersync/checktb.sh
* * * * * sleep 30; /usr/local/sersync/checktb.sh
* * * * * sleep 40; /usr/local/sersync/checktb.sh
* * * * * sleep 50; /usr/local/sersync/checktb.sh
第一次写,由于我是菜鸟,简单的都还不懂,跟别说深层次的。肯定有疏漏不当之处,欢迎拍砖,拍了后但也请指正。
本文出自 “铠哥” 博客,请务必保留此出处http://kaixulucky.blog.51cto.com/1585007/1758017
以上是关于rsync+sersync+nfs高可用的主要内容,如果未能解决你的问题,请参考以下文章