一、实验环境

LVS+keepalived高可用群集_第1张图片

wKiom1mYgaGRvG_RAAAN7Ztjkus803.png

二、实验步骤

LVS-keepalived  1配置(主)

实验步骤:

加载ip_vs模块

安装ipvsadm管理工具

安装keepalived源码包。

修改内核参数( /etc/sysctl.conf)文件,关闭ICMP重定向

IP:vmnet2192.168.1.2 网关:192.168.1.1

#modprobe  ip_vs

#yum install  -y  kernel-devel  popt-devel  openssl-devel

#yum install -y  ipvsadm  gcc gcc-c++

#tar  zxf  keepalived-1.2.13.tar.gz

#cd keepalived-1.2.13

#./configure   --prefix=/

--with-kernel-dir=/usr/src/kernels/2.6.32-431.e16.x86_64

#make && make install

#chkconfig  --add   keepalived

#chkconfig   keepalived   on

#vim /etc/sysctl.conf

wKioL1mYga-TxiN_AAAUPcx7-ZU562.png

#sysctl  -p                       使配置生效

#cd   /etc/keepalived/

#cp   keepalived.conf    keepalived.conf.bak   备份一份以防配错

#vim   keepalived.conf

LVS+keepalived高可用群集_第2张图片

LVS+keepalived高可用群集_第3张图片

#service   keepalived  start

LVS+keepalived高可用群集_第4张图片LVS-keepalived  2配置(备份)

IP:vmnet 2192.168.1.3 网关:192.168.1.1

#modprobe  ip_vs

#yum install  -y  kernel-devel  popt-devel  openssl-devel

#yum install -y  ipvsadm  gcc gcc-c++

#tar  zxf  keepalived-1.2.13.tar.gz

#cd keepalived-1.2.13

#./configure   --prefix=/

--with-kernel-dir=/usr/src/kernels/2.6.32-431.e16.x86_64

#make && make install

#chkconfig  --add   keepalived

#chkconfig   keepalived   on

#scp  [email protected]:/etc/sysctl.conf     /etc/

#sysctl    -p

#scp  [email protected]:/etc/keepalived/keepalived.conf   /etc/keepalived/

#vim /etc/keepalived/keepalived.conf

LVS+keepalived高可用群集_第5张图片

#service  keepalived  start

#ip  addr  show   eth0

LVS+keepalived高可用群集_第6张图片

NFS共享存储配置

Ip192.168.2.1

#yum  install  rpcbind  nfs-utils

#chkconfig   rpcbind  on

#chkconfig   nfs      on

#mkdir  -p  /opt/wwwroot

#vim   /etc/exports

/opt/wwwroot     192.168.3.0/24(rw,sync,no_root_squash)

#echo  www.itdby.com  > /opt/wwwroot/index.html

#service   rpcbind  start

#service    nfs     start

#netstat    -anpt   | grep  rpcbind

wKiom1mYglSQwxvWAAAkGNEGqKU417.png

WEB 1节点服务器配置

Ipwmnet 2:192.168.1.4    vmnet 8:192.168.2.2

配置步骤: 

ifcfg-lo:0配置群集ip地址192.168.1.254,子网掩码为255.255.255.255

修改内核参数( /etc/sysctl.conf)文件,关闭ARP应答。

#cd  /etc/sysconfig/network-scripts/      配置虚拟VIP

#cp ifcfg-lo   ifcfg-lo:0

#vim  ifcfg-lo:0

LVS+keepalived高可用群集_第7张图片

#ifconfig  lo:0;ifup lo:0

wKiom1mYgu-Alm9XAAAqbdC_TnM406.png

#echo  /sbin/route  add  -host   192.168.1.254  dev  lo:0  >>  /etc/rc.local                        重启后生效

#route add  -host   192.168.1.254   dev  lo:0  临时添加VIP本地访问路由,即时生效。

#vim  /etc/sysctl.conf    修改内核参数( /etc/sysctl.conf)文件,关闭ARP应答。

LVS+keepalived高可用群集_第8张图片

#sysctl   -p                          使配置生效

#yum  install   -y  httpd   rpcbind  nfs-utils

#service httpd  start

#chkconfig   httpd   on

#echo 11111 > /var/www/html/index.html

WEB  2节点服务器配置

Ipwmnet 2:192.168.1.5   vmnet 3:192.168.2.3

配置步骤:

ifcfg-lo:0配置群集ip地址192.168.1.254,子网掩码为255.255.255.255

修改内核参数( /etc/sysctl.conf)文件,关闭ARP应答。

#scp   [email protected]:/etc/sysconfig/network-scripts/ifcfg-lo:0

/etc/sysconfig/network-scripts/

#cat  /etc/sysconfig/network-scripts/ifcfg-lo:0

LVS+keepalived高可用群集_第9张图片

#ifconfig  lo:0;ifup lo:0

wKioL1mYgxzzePT3AAAqbdC_TnM832.png

#echo  /sbin/route  add  -host   192.168.1.254  dev  lo:0  >>  /etc/rc.local                        重启后生效

#route  add  -host   192.168.1.254   dev  lo:0  临时添加VIP本地访问路由,即时生效。

#scp  [email protected]:/etc/sysctl.conf   /etc/

#sysctl   -p                          使配置生效

#cat   /etc/sysctl.conf    修改内核参数( /etc/sysctl.conf)文件,关闭ARP应答。

LVS+keepalived高可用群集_第10张图片

#yum  install   -y  httpd   rpcbind  nfs-utils

#service  httpd  start

#chkconfig   httpd   on

#echo 22222 >  /var/www/html/index.html

Windwos  7客户机测试http//192.168.1.254

wKioL1mYgzLjtAPkAAAcPCIob5U400.png

wKioL1mYgz6RmfQWAAAc87eD5ng010.png

把主调度器宕掉

LVS+keepalived高可用群集_第11张图片

再次测试http://192.168.1.254

wKiom1mYg2STia0jAAAc7OVUoEI148.png

LVS+keepalived高可用群集_第12张图片

查看从服务器

LVS+keepalived高可用群集_第13张图片

再次配置各节点服务器

#service  rpcbind   start

#service   nfs    start

#mount   192.168.2.1:/opt/wwwroot     /var/www/html

Windows  7客户端测试http://192.168.1.254
wKioL1mYg4qSRurQAAAeUUnlxUk201.png