LVS-DR+Keepalived网站服务器双机热备配置

Keepalived是一个类似于layer3, 4 & 7交换机制的软件,也就是我们平时说的第3层、第4层和第7层交换。Keepalived是自动完成,不需人工干涉。

调度服务器:
需要在LVS的基础上面做。

一块网卡:
Vmnet1:192.168.80.100
主与从调度器上都做下面的3步的:加载、安装ipvsadm包
下载地址:http://www.keepalived.org/download.html
[root@lss ~]# modprobe ip_vs
[root@lss ~]# rpm -ivh /mnt/Packages/ipvsadm-1.27-7.el7.x86_64.rpm
---------keepalived安装配置(主、从都要配置的)----
[root@lss ~]# yum -y install popt-devel kernel-devel openssl-devel
WinSCP上传keepalived到主从服务器

LVS-DR+Keepalived网站服务器双机热备配置

[root@lss ~]# tar fx keepalived-1.4.2.tar.gz -C /opt
[root@lss opt]# cd /opt/keepalived-1.4.2/
[root@lss keepalived-1.4.2]# yum -y install \
gcc \
gcc-c++ \
make
[root@lss keepalived-1.4.2]# ./configure --prefix=/
[root@lss keepalived-1.4.2]# make && make install
[root@lss keepalived]# cp -r /opt/keepalived-1.4.2/keepalived/etc/keepalived/ /etc/init.d
[root@lss keepalived]# systemctl enable keepalived
--------------------------------修改配置文件(主调度器)-------------
[root@lss keepalived]# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {br/>[email protected]
[email protected]/>[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
}
}
}
[root@lss keepalived]# service keepalived start
[root@lss keepalived]# ip addr show dev ens33 //验证绑定了虚拟地址
inet 192.168.80.188/32 scope global ens33
[root@lss keepalived]# ipvsadm -L
[root@lss keepalived]# tail -f /var/log/messages //对业务服务器和主调度器进行关闭验证热备及健康检查效果。
MASTER STATE代表主服务器
BACKUP STATE代表备用服务器

---------------------------------修改配置文件(从调度器)-----------------
[root@LSS03 ~]# modprobe ip_vs
[root@LSS03 ~]# rpm -ivh /mnt/Packages/ipvsadm-1.27-7.el7.x86_64.rpm
[root@LSS03 ~]# yum -y install \
gcc \
gcc-c++ \
make
[root@LSS03 ~]# tar fx keepalived-1.4.2.tar.gz -C /opt
[root@LSS03 ~]# cd /opt/keepalived-1.4.2/
[root@LSS03 keepalived-1.4.2]# ./configure --prefix=/
[root@LSS03 keepalived-1.4.2]# make && make install
[root@LSS03 keepalived-1.4.2]# cp -r keepalived/etc/init.d/keepalived /etc/init.d/
[root@LSS03 keepalived-1.4.2]# systemctl enable keepalived
[root@LSS03 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
}
}
}
[root@LSS03 keepalived-1.4.2]# service keepalived start
[root@LSS03 keepalived-1.4.2]# ip addr show dev ens33
[root@LSS03 keepalived-1.4.2]# tail -f /var/log/messages
MASTER STATE代表主服务器
BACKUP STATE代表备用服务器

LVS-DR+Keepalived网站服务器双机热备配置

以下是WEB服务器:
192.168.80.101服务器:
[root@lss01 ~]# yum install -y httpd
[root@lss01 ~]# vi /etc/httpd/conf/httpd.confServerName www.aa.com
[root@lss01 ~]# vi /var/www/html/index.html
<h1>Server aa </h1>

192.168.80.102服务器:
[root@lss02 ~]# yum install -y httpd
[root@lss02 ~]# vi /etc/httpd/conf/httpd.conf
ServerName www.bb.com
[root@lss02 ~]# vi /var/www/html/index.html
<h1>Server bb </h1>

相关推荐