keepalived是一个类似于layer3, 4 & 7交换机制的软件,也就是我们平时说的第3层、第4层和第7层交换。Keepalived是自动完成,不需人工干涉。
调度服务器:
需要在LVS的基础上面做。
参考上两节:
负载均衡群集之一LVS-DR:http://blog.51cto.com/13572519/2084197
负载均衡群集之—LVS-NAT:http://blog.51cto.com/13572519/2084181
一块网卡:
Vmnet1:192.168.80.100
主与从调度器上都做下面的3步的:加载、安装ipvsadm包
下载地址:http://www.keepalived.org/download.html
[[email protected] ~]# modprobe ip_vs
[[email protected] ~]# rpm -ivh /mnt/Packages/ipvsadm-1.27-7.el7.x86_64.rpm
---------keepalived安装配置(主、从都要配置的)----
[[email protected] ~]# yum -y install popt-devel kernel-devel openssl-devel
WinSCP上传keepalived到主从服务器
[[email protected] ~]# tar fx keepalived-1.4.2.tar.gz -C /opt
[[email protected] opt]# cd /opt/keepalived-1.4.2/
[[email protected] keepalived-1.4.2]# yum -y install \
gcc \
gcc-c++ \
make
[[email protected] keepalived-1.4.2]# ./configure --prefix=/
[[email protected] keepalived-1.4.2]# make && make install
[[email protected] keepalived]# cp -r /opt/keepalived-1.4.2/keepalived/etc/keepalived/ /etc/init.d
[[email protected] keepalived]# systemctl enable keepalived
--------------------------------修改配置文件(主调度器)-------------
[[email protected] keepalived]# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {br/>[email protected]
[email protected]br/>[email protected]
}
notification_email_from [email protected]
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_01
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 110
advert_int 1
authentication {
auth_type PASS
auth_pass 6666
}
virtual_ipaddress {
192.168.80.188
}
}
virtual_server 192.168.80.188 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 192.168.80.101 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.80.102 80 {
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
[[email protected] keepalived]# service keepalived start
[[email protected] keepalived]# ip addr show dev ens33 //验证绑定了虚拟地址
inet 192.168.80.188/32 scope global ens33
[[email protected] keepalived]# ipvsadm -L
[[email protected] keepalived]# tail -f /var/log/messages //对业务服务器和主调度器进行关闭验证热备及健康检查效果。
MASTER STATE代表主服务器
BACKUP STATE代表备用服务器
---------------------------------修改配置文件(从调度器)-----------------
[[email protected] ~]# modprobe ip_vs
[[email protected] ~]# rpm -ivh /mnt/Packages/ipvsadm-1.27-7.el7.x86_64.rpm
[[email protected] ~]# yum -y install \
gcc \
gcc-c++ \
make
[[email protected] ~]# tar fx keepalived-1.4.2.tar.gz -C /opt
[[email protected] ~]# cd /opt/keepalived-1.4.2/
[[email protected] keepalived-1.4.2]# ./configure --prefix=/
[[email protected] keepalived-1.4.2]# make && make install
[[email protected] keepalived-1.4.2]# cp -r keepalived/etc/init.d/keepalived /etc/init.d/
[[email protected] keepalived-1.4.2]# systemctl enable keepalived
[[email protected] keepalived-1.4.2]# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from benet [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_02 //主从要不相同
}
vrrp_instance VI_1 {
state BACKUP //从调度器的热备状态
interface ens33
virtual_router_id 51 //编号主与从的两边要一样的
priority 105 //从调度器的优先级
advert_int 1
authentication { //主、从热备认证信息
auth_type PASS
auth_pass 6666
}
virtual_ipaddress { //指定群集VIP地址(虚拟服务器地址),可以指定多个的
192.168.80.188
}
}
virtual_server 192.168.80.188 80 { //虚拟服务器地址(VIP)、端口
delay_loop 6 //健康检查的间隔时间(秒)正常情况下。
lb_algo rr //轮询(rr)调度算法
lb_kind DR //直接路由(DR)群集工作模式
persistence_timeout 60 //连接保持时间,(秒),若注释掉加个"!"在这个时间内同一客户端的请求被同一服务器处理
protocol TCP //应用服务采用的是TCP协议
real_server 192.168.80.101 80 { //第一个web节点的地址、端口
weight 1 //节点的权重
TCP_CHECK { //健康检查方式
connect_port 80 //检查的目标端口
connect_timeout 3 //连接超时(秒)
nb_get_retry 3 //重试次数
delay_before_retry 3 //重试间隔(秒)
}
}
real_server 192.168.80.102 80 { //第二个web节点的地址、端口
weight 1
TCP_CHECK {
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
[[email protected] keepalived-1.4.2]# service keepalived start
[[email protected] keepalived-1.4.2]# ip addr show dev ens33
[[email protected] keepalived-1.4.2]# tail -f /var/log/messages
MASTER STATE代表主服务器
BACKUP STATE代表备用服务器
以下是WEB服务器:
192.168.80.101服务器:
[[email protected] ~]# yum install -y httpd
[[email protected] ~]# vi /etc/httpd/conf/httpd.confServerName www.aa.com
[[email protected] ~]# vi /var/www/html/index.html
<h1>Server aa </h1>
192.168.80.102服务器:
[[email protected] ~]# yum install -y httpd
[[email protected] ~]# vi /etc/httpd/conf/httpd.conf
ServerName www.bb.com
[[email protected] ~]# vi /var/www/html/index.html
<h1>Server bb </h1>
原文地址:http://blog.51cto.com/13572519/2084295