LVS+Keeplived

LVS+keeplived主:

Eth0:

 

Eth1:

 

重启网卡 

service network restart

修改配置文件(在最后添加):

vim /etc/sysctl.conf

让配置文件生效:sysctl -p

添加ipvs模块

[root@lhy network-scripts]# modprobe ip_vs

root@lhy network-scripts]# rpm -ivh /media/cdrom/Packages/ipvsadm-1.26-2.el6.x86_64.rpm

warning: /media/cdrom/Packages/ipvsadm-1.26-2.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY

Preparing...                ########################################### [100%]

   1:ipvsadm                ########################################### [100%]

先停止该服务:service ipvsadm stop

安装keeplived

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

tar -zxvf keepalived-1.2.13.tar.gz -C /usr/src/

cd /usr/src/keepalived-1.2.13/

./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/

make && make install

/etc/init.d/keepalived start

 chkconfig --add keepalived

chkconfig keepalived on

cd /etc/keepalived/

cp keepalived.conf keepalived.conf.bak

安装完成以后修改配置文件:

vim keepalived.conf

eth0和eth1对应同网段下的漂移IP

Lvs+keeplived备:

Eth0:

Eth1:

重启网卡:service network restart

开启路由转发(同主)

添加IP_vs模块并安装keeplived(同主)

安装完成之后,修改配置文件:

vim keepalived.conf

网页随便写点东西

web1:

[root@lhy 桌面]# ifconfig eth0 192.168.10.11

[root@lhy 桌面]# vim /usr/local/nginx/html/index.html

[root@lhy 桌面]# service nginx start

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] still could not bind()

start nginx......

[root@lhy 桌面]# route add default gw 192.168.10.10

 

Web2

[root@lhy 桌面]# ifconfig eth0 192.168.10.12

[root@lhy 桌面]# vim /usr/local/nginx/html/index.html

[root@lhy 桌面]# service nginx start

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] still could not bind()

start nginx......

[root@lhy 桌面]# route add default gw 192.168.10.10

Lvs+keepalived主:

IP a

虚拟IP在主上面

 

 

Client

[root@lhy 桌面]# ifconfig eth0 192.168.11.11

route add default gw 192.168.11.9

 

[root@lhy 桌面]# curl 192.168.11.9

nihao

[root@lhy 桌面]# curl 192.168.11.9

hello

验证成功

 

Lvs+keepalived主:

 

Lvs+keepalived备:

IP a

虚拟IP飘到备上面

Client

[root@lhy 桌面]# ifconfig eth0 192.168.11.11

 

[root@lhy 桌面]# curl 192.168.11.9

nihao

[root@lhy 桌面]# curl 192.168.11.9

hello

OK

 

Web1和web2关闭 nginx

[root@lhy 桌面]# curl 192.168.11.9

I'm so so  sorry

 

重启主的keepalived

 

[root@lhy 桌面]# curl 192.168.11.9

 I'm sorry

 

Client端调到桥接模式  lvs+keepalived主和备两端连接外网的网卡也调到桥接模式。

也可以都在nat 模式下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值