Keepalived 是一个基于VRRP协议来实现的LVS服务高可用方案,可以利用其来避免单点故障。一个mysql或lvs或nginx服务会有2台服务器运行Keepalived,一台为主服务器(MASTER),一台为备份服务器(BACKUP),但是对外表现为一个虚拟IP,主服务器会发送特定的消息给备份服务器,当备份服务器收不到这个消息的时候,即主服务器宕机的时候,备份服务器就会接管虚拟IP,继续提供服务,从而保证了高可用性。
以下简图为例,当服务调用mysql的时候,直接调用vip,这样即使master上宕机,依旧可访问从数据库。
Keepalive的安装:
1、 安装环境包
[root@jacken ~]# yum -y install kernel-devel openssl-devel popt-devel1.
2、 安装keepalive
[root@jacken ~]# wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
[root@jacken ~]# tar -zxf keepalived-1.1.15.tar.gz
[root@jacken ~]# cd keepalived-1.1.15
[root@jacken keepalived-1.1.15]#./configure --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/
[root@jacken ~]# make && make install1.2.3.4.5.
在编译选项中,“--sysconf”指定了Keepalived配置文件的安装路径.“--with-kernel-dir”是个很重要的参数,但这个参数并不是要把Keepalived编译进内核,而是指定使用内核源码中的头文件,即include目录。只有在使用LVS时,才需要用到“--with-kernel-dir”参数,其他时候是不需要的。
3、 设置keepalive
[root@jacken ~]# DIR=/usr/local/ ; cp$DIR/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
[root@jacken ~]# cp $DIR/etc/sysconfig/keepalived /etc/sysconfig/ && mkdir -p /etc/keepalived
[root@jacken ~]# cp $DIR/sbin/keepalived /usr/sbin/
[root@jacken ~]# cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
[root@jacken ~]# /etc/init.d/keepalivedrestart
Stopping keepalived: [FAILED]
Starting keepalived: [ OK ]
[root@jacken ~]#modprobe ip_vs
[root@jacken ~]#modprobe ip_vs_rr
[root@jacken ~]#modprobe ip_vs_wrr1.2.3.4.5.6.7.8.9.10.
Other
脚本配置文件:
[root@jacken ~]# chmod +xinstall_keepalive.sh
[root@jacken ~]# cat install_keepalive.sh
#!/bin/bash
yum -y install kernel-devel openssl-devel popt-devel &&
wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz &&
tar -zxf keepalived-1.1.15.tar.gz &&
cd keepalived-1.1.15 &&
./configure --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/ &&
make && make install &&
DIR=/usr/local/
cp $DIR/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/ &&
cp $DIR/etc/sysconfig/keepalived /etc/sysconfig/ && mkdir -p /etc/keepalived &&
cp $DIR/sbin/keepalived /usr/sbin/&&
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/ &&
/etc/init.d/keepalived restart
if [ $? -eq 0 ];then
echo -e '\e[32mInstall Keepalive Successfully!\e[0m'
else
echo -e '\e[31mInstall Keepalive Failure!\e[0m'
fi
[root@jacken ~]#1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.
其实这个不算是什么脚本,方便安装而已,一定要注意内核版本号要对应。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。
本文系转载,前往查看
如有侵权,请联系 cloudcommunity@tencent.com 删除。