MooseFS分布式文件系统+keepalived高可用+unison和intoify实时双机器同步
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MooseFS分布式文件系统+keepalived高可用+unison和intoify实时双机器同步相关的知识,希望对你有一定的参考价值。
、moosefs+keepalived双机高可用
2.1、部署环境及思路
2.1.1、环境
192.168.1.237 keepalived (MASTER) mfsmaster mfscgiserv
192.168.1.236 keepalived (Slave) mfschuckserver mfsclient
192.168.1.239 虚拟VIP
2.1.2、原理
mfsmaster的故障恢复在1.6.5版本后可以由mfsmetalogger产生的日志文件 changelog.*.mfs和metadata.mfs.back由命令mfsmetarestore恢复,在1.7版本后命令mfsmetarestore不可用,改为mfsmaster –a
192.168.1.237 keepalivedmaster 定时运行检测 mfsmaster 进程的脚本check_master.sh,(如果有必要,定时从mfsmaster 获取 metadata.mfs.back 做备份文件用于master恢复)
如果检测到 mfsmaster 故障的时候,192.168.1.237 keepalived会将虚拟IP漂移到备机。
192.168.1.236keepalived 自动绑定从主机上漂移过来的虚拟IP,同时状态从backup转换为master 并触发脚本notify_master事件,执行恢复并启动keepalived_notify.sh脚本,(根据条件判断)此时备机变为管理服务器
整个切换在2~10秒内完成根据检测时间间隔
当元管理服务器mfsmaster恢复后,192.168.1.236 keepalived 状态从master转到backup 并触发 notify_backup事件执行恢复并启动keepalived_notify.sh(根据条件判断)脚本,此时由管理服务器恢复为备机,同时192.168.1.236自动关闭mfsmaster服务。
、keepalived安装配置
Keepalived安装:版本为1.2.7
./configure--prefix=/usr/local/keepalived
make&&make install
keeplived配置
在主机mfsmaster 192.168.1.237上的keeplived配置:
vim/usr/local/keepalived/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
}
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_scriptcheck_run {
script "/usr/local/mfs/check_master.sh"
interval 2
}
vrrp_sync_groupVG1 {
group {
VI_1
}
}
vrrp_instanceVI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script{
check_run
}
virtual_ipaddress {
192.168.1.239
# 192.168.200.17
# 192.168.200.18
}
}
#配置说明:interval 2配置项,KEEPALIVED MASTER 每2秒检测一次 mfsmaster状态
接下我们编辑vim /usr/local/mfs/check_master.sh脚本。编辑完赋权755
#!/bin/bash
MFS_HOME=/usr/local/mfs
#$MFS_HOME/sbin/mfsmasterstart
ps-ef|grep mfsmaster|grep -v ‘grep‘
RETVAL=$?
if[ $RETVAL -eq 0 ];then
exit 0
else
exit 1
fi
在备机mfsmaster 192.168.1.236上的keeplived配置:
vim/usr/local/keepalived/etc/keepalived/keepalived.conf
!Configuration File for keepalived
global_defs{
notification_email {
}
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_sync_groupVG1 {
group {
VI_1
}
notify_master"/usr/local/mfs/keepalived_notify.sh master"
notify_backup"/usr/local/mfs/keepalived_notify.sh backup"
}
vrrp_instanceVI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.239
#192.168.200.17
#192.168.200.18
}
}
需要注意的是主备机上priority优先级不能设置为一样的。
接下我们编辑vim/usr/local/mfs/keepalived_notify.sh脚本,记得赋权755
#!/bin/bash
MFS_HOME=/usr/local/mfs
MFSMARSTER=${MFS_HOME}/sbin/mfsmaster
MFSMETARESTORE=${MFS_HOME}/sbin/mfsmetarestore
MFS_DATA_PATH=${MFS_HOME}/var/mfs
functionbackup2master(){
$MFSMARSTERstart
}
functionmaster2backup(){
$MFSMARSTERstop
}
functionERROR(){
echo"usage: keepalived_notify.sh master|backup "
}
case$1 in
master)
backup2master
;;
backup)
master2backup
;;
*)
ERROR
;;
esac
2.3、keepalived开机自启
1. 建立服务启动脚本,以便使用service命令控制之
cp/usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/keepalived
chmod+x /etc/init.d/keepalived
2.修改/etc/init.d/keepalived,寻找大约15行左右的. /etc/sysconfig/keepalived, 修改为:
. /usr/local/keepalived/etc/sysconfig/keepalived, 即指向正确的文件位置
同时在上述行下添加以下内容(将keepavlied主程序所在路径导入到环境变量PATH中):
PATH="$PATH:/usr/local/keepalived/sbin"
exportPATH
3.修改/usr/local/keepalived/etc/sysconfig/keepalived文件,设置正确的服务启动参数
KEEPALIVED_OPTIONS="-D-f /usr/local/keepalived/etc/keepalived/keepalived.conf"
4.经过以上修改,keepalived基本安装即可完成,启动测试之:
servicekeepalived restart
5.切勿忘记将此服务设置为开机启动
chkconfigkeepalived on
2.4、故障切换测试
1,挂接客户端,注意一定要挂接虚拟IP地址192.168.1.239。
rz或者touch文件
2,关闭192.168.1.237上的mfsmaster,观察192.168.1.236是否已经启动了mfsmaster,查看
/var/log/messages,同时观察mfsclient文件读写,删除,上传是否正常。
3,恢复启动192.168.1.237上的mfsmaster,观察192.168.1.236是否已经关闭了mfsmaster,查看/var/log/messages,同时观察mfsclient文件是否正常。来回切换后,mfsclient正常。说明moosefs+keeplived实现高可用。
注意事项:
一、对于/usr/local/mfs/sbin/mfscgiserv这个服务,因为只在192.168.1.237上启动了该服务,在主备切换完成后,是不能访问的,所以建议把192.168.1.236上的mfscgiserv也启动,这样弄,只不过后面同步的时候会跳过mfscgiserv的.lock文件,没有多大影响,那么我们访问的时候输入虚拟IP就可以管理了。http://192.168.1.239:9425
经过测试,发现以下问题:
1, 因为metalogger服务器存在数据丢失的问题,现在最好的解决方法就是把主备机做成镜像服务器,备机不依靠上述提到的用metalogger的方式启动,metalogger另外单独选择一台服务器做备份或者不用metalogger,单独备份mfsmaster下的数据路径数据。那么最终就是主备机做双向同步才能保证数据不丢失。双向同步工具我们选择unison!
本文出自 “LawLer” 博客,谢绝转载!
以上是关于MooseFS分布式文件系统+keepalived高可用+unison和intoify实时双机器同步的主要内容,如果未能解决你的问题,请参考以下文章