如何进行LVS-DR+Keepalived网站服务器双机热备配置,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
keepalived是一个类似于layer3, 4 & 7交换机制的软件,也就是我们平时说的第3层、第4层和第7层交换。Keepalived是自动完成,不需人工干涉。
调度服务器:
需要在LVS的基础上面做。
参考上两节:
负载均衡群集之一LVS-DR:https://blog.51cto.com/13572519/2084197
负载均衡群集之—LVS-NAT:https://blog.51cto.com/13572519/2084181
一块网卡:
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到主从服务器
[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 {acassen@firewall.loc
br/>sysadmin@firewall.loc<br/}
notification_email_from Alexandre.Cassen@firewall.loc
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 {
root@localhost.localdomain
}
notification_email_from benet root@localhost.localdomain
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代表备用服务器
以下是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
<h2>Server aa </h2>
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
<h2>Server bb </h2>
看完上述内容,你们掌握如何进行LVS-DR+Keepalived网站服务器双机热备配置的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。