博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LVS-Keepalived高可用集群(NAT)
阅读量:5072 次
发布时间:2019-06-12

本文共 4121 字,大约阅读时间需要 13 分钟。

LEA-6-LVS-NAT+Keepalived高可用集群

-------client-----------------主LVS-----------------从LVS--------------------WEB1--------------------WEB2-------------
2.2.2.250 2.2.2.10 2.2.2.20
192.168.1.10 192.168.1.20 192.168.1.101 192.168.1.102
外网漂移IP:2.2.2.2
内网漂移IP:192.168.1.1

一、配置LVS服务器(主-从两台)

1、配置IP
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
[root@localhost ~]# service network restart

2、调整响应参数(主-从配置一样)

[root@localhost ~]# vim /etc/sysctl.conf
修改:
net.ipv4.ip_forward = 1
添加:
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

3、安装并配置ipvsadm(主-从配置一样)

[root@localhost ~]# rpm -ihv /mnt/Packages/ipvsadm-1.26-2.el6.x86_64.rpm
[root@localhost ~]# service ipvsadm stop
[root@localhost ~]# ipvsadm -A -t 2.2.2.2:80 -s rr
[root@localhost ~]# ipvsadm -a -t 2.2.2.2:80 -r 192.168.1.101:80 -m -w 1
[root@localhost ~]# ipvsadm -a -t 2.2.2.2:80 -r 192.168.1.102:80 -m -w 1
[root@localhost ~]# service ipvsadm save
[root@localhost ~]# chkconfig ipvsadm on
[root@localhost ~]# service ipvsadm start

二、配置Keepalived服务器

4、安装keepalived软件(主-从配置一样)

[root@localhost ~]# yum -y install kernel-devel openssl-devel popt-devel
[root@localhost ~]# tar -zxvf keepalived-1.2.13.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/keepalived-1.2.13/
[root@localhost keepalived-1.2.13]# ./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64
[root@localhost keepalived-1.2.13]# make && make install
[root@localhost ~]# /etc/init.d/keepalived start
[root@localhost ~]# netstat -anp | grep keepalived
[root@localhost ~]# chkconfig --add keepalived
[root@localhost ~]# chkconfig keepalived on

4.1、主服务器配置

[root@localhost ~]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf_bak
[root@localhost ~]# vim /etc/keepalived/keepalived.conf
修改:
global_defs {
router_id LVS_DEVEL_R1
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 1
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
2.2.2.2
}
}
vrrp_instance VI_1 {
state MASTER
interface eth1
virtual_router_id 1
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.1
}
}
virtual_server 2.2.2.2 80 {
delay_loop 15
lb_algo rr
lb_kind NAT
protocol TCP
real_server 192.168.1.101 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
real_server 192.168.1.102 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 4
}
}
}
[root@localhost ~]# service keepalived restart
[root@localhost ~]# ip add show dev eth0

4.2、从服务器配置

[root@localhost ~]# cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf_bak
[root@localhost ~]# vim /etc/keepalived/keepalived.conf
修改:
global_defs {
router_id LVS_DEVEL_R2
}
vrrp_instance VI_1 {
state BACKUP
priority 99
......
---其他参数与主服务器保持一致----
}
[root@localhost ~]# service keepalived restart
[root@localhost ~]# ip add show dev eth0

三、配置WEB节点服务器

1、配置IP地址

1)设置IP
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
2、配置http服务
WEB-1:
[root@localhost ~]# echo "welcome to 192.168.1.101 web server" > /var/www/html/index.html
[root@localhost ~]# service httpd restart
[root@localhost ~]# chkconfig --add httpd
[root@localhost ~]# chkconfig httpd on
WEB-2:
[root@localhost ~]# echo "welcome to 192.168.1.102 web server" > /var/www/html/index.html
[root@localhost ~]# service httpd restart
[root@localhost ~]# chkconfig --add httpd
[root@localhost ~]# chkconfig httpd on

三、验证:

一)使用ping命令
客户端:ping -t 2.2.2.2
断开主LVS的网卡,查看客户端的ping情况。
重启主LVS的网卡,查看客户端的ping情况。
二)客户端
1、访问:
http://2.2.2.2/
在主LVS上查看:
[root@localhost ~]# ipvsadm -Lnc
2、断开主LVS的网卡
客户端访问:http://2.2.2.2/
在主-从LVS上查看:
[root@localhost ~]# ipvsadm -Lnc
在主-从LVS上查看:
[root@localhost ~]# ip addr show dev eth0
3、重启主LVS的网卡
客户端访问:http://2.2.2.2/
在主-从LVS上查看:
[root@localhost ~]# ipvsadm -Lnc
在主-从LVS上查看:
[root@localhost ~]# ip addr show dev eth0

转载于:https://www.cnblogs.com/luoyan01/p/9734173.html

你可能感兴趣的文章
web服务器
查看>>
网卡流量检测.py
查看>>
ajax
查看>>
poj1981 Circle and Points 单位圆覆盖问题
查看>>
POP的Stroke动画
查看>>
SQL语句在查询分析器中可以执行,代码中不能执行
查看>>
yii 1.x 添加 rules 验证url数组
查看>>
html+css 布局篇
查看>>
SQL优化
查看>>
用C语言操纵Mysql
查看>>
轻松学MVC4.0–6 MVC的执行流程
查看>>
redis集群如何清理前缀相同的key
查看>>
Python 集合(Set)、字典(Dictionary)
查看>>
获取元素
查看>>
proxy写监听方法,实现响应式
查看>>
第一阶段冲刺06
查看>>
十个免费的 Web 压力测试工具
查看>>
EOS生产区块:解析插件producer_plugin
查看>>
mysql重置密码
查看>>
jQuery轮 播的封装
查看>>