LVS+Keepalived高可用群集
一、配置主调度器
1) LVS配置:[root@localhost~]# vim /etc/stsctl.conf添加以下参数: net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.send_redirects= 0 net.ipv4.conf.eth0.send_redirects= 0[root@localhost~]# sysctl -p[root@localhost~]# modprobe ip_vs[root@localhost~]# echo “modprobe ip_vs” > /etc/rc.local2)安装支持软件在编译前,必须安装内核开发包kernel-devel openssl-devel popt-devel ipvsadm[root@localhost~]# yum -y install kernel-devel openssl-devel popt-devel[root@localhost~]# rpm –ivh /misc/cd/Server/Packages/ipvsadm-1.25-9.e16.i686.rpm3) 编译安装keepalived[root@localhost~]# tar zxf keepalived-1.2.2.tar.gz[root@localhost~]# cd keepalived-1.2.2[root@localhost~]# ./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-131 .0.15.e16.i686[root@localhost~]# make && make install4) 使用keepalived 服务[root@localhost~]# ls -l /etc/init.d/keepalived-rwxr-xr-x 1 root root 1288 11月 8 16.23 /etc/init.d/keepalived[root@localhost~]# chkconfig --add keepalived [root@localhost~]# chkconfig keepalived on5)配置keepalived文件的全局配置,热备配置等[root@localhost~]# vim /etc/keepalived/keepalived.conf
a)b) 服务器池配置
启动keepalived服务 [root@localhost~]# service keepalived restart
二、配置从调度器
1) LVS配置:[root@localhost~]# vim /etc/stsctl.conf添加以下参数: net.ipv4.conf.all.send_redirects = 0 net.ipv4.conf.default.send_redirects= 0 net.ipv4.conf.eth0.send_redirects= 0[root@localhost~]# sysctl -p[root@localhost~]# modprobe ip_vs[root@localhost~]# echo “modprobe ip_vs” > /etc/rc.local2)安装支持软件在编译前,必须安装内核开发包kernel-devel openssl-devel popt-devel ipvsadm[root@localhost~]# yum -y install kernel-devel openssl-devel popt-devel[root@localhost~]# rpm –ivh /misc/cd/Server/Packages/ipvsadm-1.25-9.e16.i686.rpm3) 编译安装keepalived[root@localhost~]# tar zxf keepalived-1.2.2.tar.gz[root@localhost~]# cd keepalived-1.2.2[root@localhost~]# ./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-131 .0.15.e16.i686[root@localhost~]# make && make install4) 使用keepalived 服务[root@localhost~]# ls -l /etc/init.d/keepalived-rwxr-xr-x 1 root root 1288 11月 8 16.23 /etc/init.d/keepalived[root@localhost~]# chkconfig --add keepalived [root@localhost~]# chkconfig keepalived on5)配置keepalived文件的全局配置,热备配置等[root@localhost~]# vim /etc/keepalived/keepalived.conf
启动keepalived服务[root@localhost~]# service keepalived restart三、配置web节点服务器 (web1 web2)
1)配置虚拟Ip地址(VIP)漂浮地址
[root@localhost~]# cd /etc/sysconfig/network-scripts/
[root@localhost~]# cp ifcfgh-lo ifcfg-lo:0
[root@localhost~]# ifup lo:0
[root@localhost~]# vim /etc/rc.local
/sbin/route add -host 200.0.0.254 dev lo:0 //添加路由记录[root@localhost~]# route add -host 200.0.0.254 dev lo:0
2)调整、proc响应参数 sysctl.conf
[root@localhost~]# vim etc/sysctl.conf
添加以下参数: net.ipv4.conf.all.arp_ignore = 1net.ipv4.conf.all.arp_announce= 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce= 2
net.ipv4.conf.lo.arp_ignore= 1
net.ipv4.conf.lo.arp_announce= 2
[root@localhost~]# sysctl -p
[root@localhost~]# service httpd start
[root@localhost~]# chkconfig httpd on
3)测试LVS群集
[root@localhost~]# ipvsadm -Ln
邮件服务器注:在调度器上安装sendmail邮件服务器,每当web节点down,up时,都会发送邮件到调度器指定邮箱里。
1)在主调度器上安装sendmail服务[root@localhost~]# yum -y install sendmail
[root@localhost~]# service sendmail start
[root@localhost~]# chkconfig sendmail on
[root@localhost~]# useradd u1
[root@localhost~]# vim /etc/keepalived/keepalived.conf
[root@localhost~]# vim /etc/resolv.conf
Servicename dns1.beent.com
[root@localhost~]# vim /etc/hosts
127.0.0.1 dns1.benet.com
[root@localhost~]# cat /var/mail/u1 //查看邮件