为了方便测试,禁掉防火墙和Selinux
(1) 禁掉防火墙
chkconfig iptables off
(2) 禁掉Selinux
vi /etc/selinux/config
SELINUX=disabled
(3) 必须重新启动系统
shutdown -r now
一.检查lvs模块是否已经安装
1)modprobe -l | grep ipvs
2)cd /boot
cat config-2.6.32-358.el6.x86_64 | grep -i ipvs
二.yum安装ipvsadm
yum -y install ipvsadm
三.安装keepalived
1.先安装所需的环境
1)gcc
yum install gcc gcc-c++
2)openssl-devel, openssl
yum install openssl-devel openssl
3)源码内核
yum install kernel-devel kernel
建立软连接
ln -s /usr/src/kernels/内核名称/ /usr/src/linux
4)popt-devel , libnl-devel
yum install popt-devel libnl-devel
5)libnfnetlink-devel
yum install -y libnfnetlink-devel
2.源码安装keepalived
1)cd /usr/local/src 下载keepalived
wget http://www.keepalived.org/software/keepalived-版本号.tar.gz
http://www.keepalived.org/software/keepalived-1.2.20.tar.gz
2)解压缩
tar -zxvf keepalived-版本号.tar.gz
cd keepalived-版本号
3)配置安装,依次执行
./configure
确保以下3个信息都为YES
Use IPVS Framework YES
IPVS sync daemon support YES
Use VRRP Framework YES
make
make install
4)创建软连接
ln -s /usr/local/sbin/keepalived /sbin/
5)检查是否安装成功
keepalived --help
6)启动设置
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalilved
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/sbin/keepalived /usr/sbin/
7) 配置keepalived.conf
vi /etc/keepalived/keepalived.conf
8) 启动keepalived服务并查看进程
service keepalived start (或者/etc/init.d/keepalived start)
ps -ef | grep keepalived
ipvsadm -L -n
重启 service keepalived restart
9) 设置开机自启动
chkconfig keepalived on
======================keepalived.conf配置文件=========================