Keepalived+LVS/DR服务器 基础搭建
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Keepalived+LVS/DR服务器 基础搭建相关的知识,希望对你有一定的参考价值。
【使用Keepalived为LVS调度器提供高可用功能,防止调度器单点故障,为用户提供Web服务】
使用5台虚拟机 1台作为Linux路由器
2台作为LVS调度器 1台作为Real Server 物理机作为客户端
一、配置网络环境
真实Web服务器地址1、192.168.4.52
真实Web服务器地址2、192.168.4.53
服务器VIP地址设置为 192.168.4.252
1、配置Realserver >52
[[email protected] html]# ifconfig lo:1 192.168.4.252/32
[[email protected] conf]#cd /proc/sys/net/ipv4/conf
[[email protected] conf]# echo 1 > lo/arp_ignore
[[email protected] conf]# echo 2 > lo/arp_announce
[[email protected] conf]# echo 1 > all/arp_ignore
[[email protected] conf]# echo 2 > all/arp_announce
>53
[[email protected] html]# ifconfig lo:1 192.168.4.252/32
[[email protected] html]# cd /proc/sys/net/ipv4/conf/
[[email protected] conf]# echo 1 > lo/arp_ignore
[[email protected] conf]# echo 2 > lo/arp_announce
[[email protected] conf]# echo 1 > all/arp_ignore
[[email protected] conf]# echo 2 > all/arp_announce
2、配置调度器
LVS1调度器真实IP地址为192.168.4.50
LVS2调度器真实IP地址为192.168.4.51
安装ipvsadm、 keepalived
[[email protected] ~]# yum -y install ipvsadm
[[email protected] ~]# yum -y install ipvsadm
[[email protected] ~]# yum -y install keepalived
[[email protected] ~]# yum -y install keepalived
3、编写网页文件(52,53)
[[email protected] ~]#yum -y install httpd
[[email protected] ~]#yum -y install httpd
[[email protected] ~]#echo 192.168.4.52 > /var/www/html/test.html
[[email protected] ~]#echo 192.168.4.53 > /var/www/html/test.html
二、 修改配置文件
[[email protected] ~]# vim /etc/keepalived/keepalived.conf
15 vrrp_instance VI_1 {
16 state MASTER 主服务器为MASTER
17 interface eth0
18 virtual_router_id 51
19 priority 150 优先级
20 advert_int 1
21 authentication {
22 auth_type PASS
23 auth_pass 1111 主辅服务器密码一致
24 }
25 virtual_ipaddress { 虚拟IP
26 192.168.4.252
27 }
28 }
29
30 virtual_server 192.168.4.252 80 { 设置VIP为192.168.4.252
31 delay_loop 6
32 lb_algo rr 设置LVS的调度算法为RR
33 lb_kind DR 设置LVS的模式为DR
34 nat_mask 255.255.255.0
35 persistence_timeout 50
36 protocol TCP
37 connect_timeout 3
38 nb_get_retry 3
39 delay_before_retry 3
40 real_server 192.168.4.52 80 {
41 weight 1 设置权重为1
42 }
43 real_server 192.168.4.53. 80 {
44 weight 2 设置权重为2
45 }
46 }
2.1 LVS2调度器设置大致一样,修改以下两样
[[email protected] ~]# scp /etc/keepalived/keepalived.conf 192.168.4.51:/etc/keepalived/
[[email protected] ~]# vim /etc/keepalived/keepalived.conf
16 state DACKUP从服务器
19 priority 100 优先级
三、测试
[[email protected] ~]# service keepalived start 开启服务
[[email protected] ~]# ip addr show | grep 192.168.4.*
inet 192.168.4.50/24 brd 192.168.4.255 scope global eth0
inet 192.168.4.252/32 scope global eth0 虚拟ip地址
[[email protected] ~]# ipvsadm -Ln 查看信息
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.4.252:80 rr persistent 50
-> 192.168.4.52:80 Route 1 0 0
-> 192.168.4.53:80 Route 1 0 0
3.1 访问
[[email protected] ~]# elinks -dump http://192.168.4.252/test.html
192.168.4.52
[[email protected] ~]# elinks -dump http://192.168.4.252/test.html
192.168.4.53
[[email protected] ~]# ipvsadm -Ln --stats
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Conns InPkts OutPkts InBytes OutBytes
-> RemoteAddress:Port
TCP 192.168.4.252:80 2 10 0 848 0
-> 192.168.4.52:80 1 5 0 424 0
-> 192.168.4.53:80 1 5 0 424 0
【把50的服务关闭】
[[email protected] ~]# service keepalived stop
[[email protected] ~]# elinks -dump http://192.168.4.252/test.html
192.168.4.52
[[email protected] ~]# elinks -dump http://192.168.4.252/test.html
192.168.4.53
【VIP会在51上面】
[[email protected] ~]# ipvsadm -Ln --stats
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Conns InPkts OutPkts InBytes OutBytes
-> RemoteAddress:Port
TCP 192.168.4.252:80 2 10 0 848 0
-> 192.168.4.52:80 1 5 0 424 0
-> 192.168.4.53:80 1 5 0 424 0
以上是关于Keepalived+LVS/DR服务器 基础搭建的主要内容,如果未能解决你的问题,请参考以下文章
搭建LVS(DR模式)+Keepalived高可用群集,可跟做!!!