一、实验环境

wKioL1mYgY3w_-ByAADFddYHUrQ523.png-wh_50

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

wKioL1mYgbrAYL3nAACy_cS-0ds528.png

wKiom1mYgcqjWzuCAAEHWuZg0N4355.png

#service   keepalived  start

wKioL1mYgdGx5BFWAACI42j4gV4620.pngLVS-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  root@192.168.1.3:/etc/sysctl.conf     /etc/

#sysctl    -p

#scp  root@192.168.1.3:/etc/keepalived/keepalived.conf   /etc/keepalived/

#vim /etc/keepalived/keepalived.conf

wKiom1mYgiLQXZQCAABytDUXZvk144.png

#service  keepalived  start

#ip  addr  show   eth0

wKioL1mYgjbCMsZ1AABwSurJsdY311.png

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

wKioL1mYgt7hveYFAAAh_uyzOT4966.png

#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应答。

wKioL1mYgvaQ6ekPAAAfSWTf6HA391.png

#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   root@192.168.1.4:/etc/sysconfig/network-scripts/ifcfg-lo:0

/etc/sysconfig/network-scripts/

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

wKiom1mYgwjAvbUXAAAh_uyzOT4345.png

#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  root@192.168.1.4:/etc/sysctl.conf   /etc/

#sysctl   -p                          使配置生效

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

wKiom1mYgyzz5bpXAAAfSWTf6HA478.png

#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

把主调度器宕掉

wKiom1mYg1HiXKQfAACizV3cQKw570.png

再次测试http://192.168.1.254

wKiom1mYg2STia0jAAAc7OVUoEI148.png

wKioL1mYg2mTcXxkAAAdU4quiP4798.png

查看从服务器

wKiom1mYg37wKEHbAACDCtolyR4887.png

再次配置各节点服务器

#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