lvs+keepalived安装

一、 LVS简介

LVS是Linux Virtual Server的简称,即Linux虚拟服务器。使用LVS技术要达到的目标是:通过LVS提供的负载均衡技术和Linux操作系统实现一个高性能、高可用的服务器群集,它具有良好可靠性、可扩展性和可操作性。从而以低廉的成本实现最优的服务性能。

二、网络拓扑

三、接口IP及属性配置

1,在Master配置接口IP如下:

[[email protected] network-scripts]# ifconfig

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

inet 192.168.230.10  netmask255.255.255.0  broadcast 192.168.230.255

inet6 fe80::250:56ff:fe9a:55c5 prefixlen 64  scopeid0x20<link>

ether 00:50:56:9a:55:c5 txqueuelen 1000  (Ethernet)

RX packets 1201  bytes 94251 (92.0KiB)

RX errors 0  dropped 0  overruns 0 frame 0

TX packets 5964  bytes 390181(381.0 KiB)

TX errors 0  dropped 0 overruns0  carrier 0  collisions 0

ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

inet 192.168.230.100  netmask255.255.255.255  broadcast192.168.230.100

ether 00:50:56:9a:55:c5 txqueuelen 1000  (Ethernet)

2,在Slave配置接口IP如下:

[[email protected] ~]# ifconfig

ens33:flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

inet 192.168.230.11  netmask255.255.255.0  broadcast 192.168.230.255

inet6 fe80::250:56ff:fe9a:62e8 prefixlen 64  scopeid0x20<link>

ether 00:50:56:9a:62:e8 txqueuelen 1000  (Ethernet)

RX packets 3  bytes 620 (620.0 B)

RX errors 0  dropped 0  overruns 0 frame 0

TX packets 50  bytes 7844 (7.6KiB)

TX errors 0  dropped 0 overruns0  carrier 0  collisions 0

ens33:0:flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

inet 192.168.230.100  netmask255.255.255.255  broadcast192.168.230.100

ether 00:50:56:9a:62:e8 txqueuelen 1000  (Ethernet)

3,在rs1上配置接口IP如下:

[[email protected]]# ifconfig

ens33:flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

inet 192.168.230.12  netmask255.255.255.0  broadcast 192.168.230.255

inet6 fe80::250:56ff:fe9a:daa prefixlen 64  scopeid0x20<link>

ether 00:50:56:9a:0d:aa txqueuelen 1000  (Ethernet)

RX packets 162543  bytes 11199233(10.6 MiB)

RX errors 0  dropped 66  overruns 0 frame 0

TX packets 74236  bytes 9216209(8.7 MiB)

TX errors 0  dropped 0 overruns0  carrier 0  collisions 0

lo:0:flags=73<UP,LOOPBACK,RUNNING>  mtu65536

inet 192.168.230.100  netmask 255.255.255.255

loop  txqueuelen 0  (Local Loopback)

4,在rs2上配置接口IP如下:

[[email protected]]# ifconfig

ens33:flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

inet 192.168.230.13  netmask255.255.255.0  broadcast 192.168.230.255

inet6 fe80::250:56ff:fe9a:2be1 prefixlen 64  scopeid0x20<link>

ether 00:50:56:9a:2b:e1 txqueuelen 1000  (Ethernet)

RX packets 161840  bytes 11150452(10.6 MiB)

RX errors 0  dropped 44  overruns 0 frame 0

TX packets 73427  bytes 7893814(7.5 MiB)

TX errors 0  dropped 0 overruns0  carrier 0  collisions 0

lo:0:flags=73<UP,LOOPBACK,RUNNING>  mtu65536

inet 192.168.230.100  netmask255.255.255.255

loop  txqueuelen 0  (Local Loopback)

5,在Master和Slave上开启转发功能

[[email protected] ~]# echo "1">/proc/sys/net/ipv4/ip_forward

6,在rs1和rs2配置接口属性

[[email protected] ~]# echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore

[[email protected] ~]# echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce

[[email protected] ~]# echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore

[[email protected] ~]# echo "2">/proc/sys/net/ipv4/conf/all/arp_announce

[[email protected] ~]# sysctl -p

net.ipv4.conf.ens33.arp_announce = 2

net.ipv4.conf.ens33.arp_ignore = 1

net.ipv4.conf.lo.arp_announce = 2

net.ipv4.conf.lo.arp_ignore = 1

四、软件安装

1,在Master上安装ipvsadm和keepalived

[[email protected] ~]# yum install -ykeepalived ipvsadm

2,同样在Slave上安装ipvsadm和keepalived

[[email protected] ~]# yum install -ykeepalived ipvsadm

3,在rs1和rs2安装测试服务,这里安装httpd服务,具体服务配置请参考官方配置文档。

[[email protected] htdocs]# yum install -yhttpd

访问192.168.230.12服务:

访问192.168.230.13服务:

五、keepalived配置

1,在Master配置如下:

[[email protected] keepalived]# cat/etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

notification_email {

[email protected]        #全局配置,邮件通知配置。

[email protected]

[email protected]

test.com

}

notification_email_from [email protected]

smtp_server 192.168.200.1

smtp_connect_timeout 30

router_id LVS_DEVEL

}

vrrp_instance VI_1 {         #配置vrrp实例

state MASTER          #配置vrrp状态,Mater配置为MASTER,Slave配置为SLAVE

interface ens33        #关联端口,根据实际修改

virtual_router_id 55         #vrrpid,Master和Slave需配置一致

priority 100      #vrrp优先级,Mater配置100,Slave应该配置小于100就行

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.230.100     #与vip对应

}

}

virtual_server 192.168.230.100 80 { #配置虚拟服务属性

delay_loop 6

lb_algo rr          #配置算法,默认rr(轮询算法)

lb_kind DR        #配置lvs模式

#persistence_timeout 50         #会话保持时间

protocol TCP    #协议

real_server 192.168.230.12 80 {     #真实服务器属性

weight 1            #权重

}

real_server 192.168.230.13 80 {

weight 1

}

}

2,在Slave上配置如下:

[[email protected] keepalived]# cat/etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

notification_email {

[email protected]

[email protected]

[email protected]

}

notification_email_from [email protected]

smtp_server 192.168.200.1

smtp_connect_timeout 30

router_id LVS_DEVEL

}

vrrp_instance VI_1 {

state BACKUP         #vrrp状态slave配置为BACKUP

interface ens33

virtual_router_id 55

priority 90         #Slave优先级低于Mater的优先级

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.230.100

}

}

virtual_server 192.168.230.100 80 {

delay_loop 6

lb_algo rr

lb_kind DR

#persistence_timeout 50

protocol TCP

real_server 192.168.230.12 80 {

weight 1

}

real_server 192.168.230.13 80 {

weight 1

}

}

3,在Master和Slave上配置开机自启动服务

[[email protected] ~]# chkconfig keepalived on

4,配置完在Master和Slave上重启keepalived服务

[[email protected] keepalived]# servicekeepalived restart

六、测试

1,客户端通过vip访问

2,清除浏览器缓存再次访问

3,将Mater关闭,再次通过vip依然可以正常访问

4,丢包测试,重启Master过程丢1个ping包。

时间: 2024-10-11 03:48:09

lvs+keepalived安装的相关文章

Lvs+keepalived安装配置(v1.0)

测试环境 系统:centos6.5_x86_64 主DR IP:192.168.1.216 备DR IP:192.168.1.218 VIP:192.168.1.253/254 real_server1:192.168.1.220 real_server2:192.168.1.219 一.安装ipvsadm 1.1 安装依赖包 yum -y install  libnl-devel  libnl popt popt-static 1.2 下载并安装ipvsadm wget http://www.

nginx+lvs+keepalived安装

安装nginx 配置文件和之前的一样 user nobody nobody;    #定义Nginx运行的用户和用户组 worker_processes 4;    #nginx进程数,建议设置为等于CPU总核心数. error_log logs/error.log    info;    #全局错误日志定义类型,[ debug | info | notice | warn | error | crit ] worker_rlimit_nofile 1024;    #一个nginx进程打开的最

(2)LVS+Keepalived高可用负载均衡架构原理及配置

1.keepalived 介绍2.keepalived 优缺点3.keepalived 应用场景4.keepalived 安装配置5.keepalived+lvs 高可用6.keepalived+nginx 高可用7.keepalived 切换原理8.性能优化9.常见故障 一.keepalived 介绍 1.keepalived 定义keepalived是一个基于VRRP(virtual route redundent protocol)协议来实现的LVS服务高可用方案,可以利用其来避免单点故障

LVS+Nginx(LVS + Keepalived + Nginx安装及配置)

(也可以每个nginx都挂在上所有的应用服务器) nginx大家都在用,估计也很熟悉了,在做负载均衡时很好用,安装简单.配置简单.相关材料也特别多. lvs是国内的章文嵩博士的大作,比nginx被广泛接受还要早7年,并且已经被红帽作为了系统内置软件,可谓很牛了.lvs相对于nginx来说配置上就要相对复杂一些. 但是,有时候我们会看到大牛们分享的经验里面是lvs+nginx作为负载均衡了,一直想不明白这是个什么道理. 为什么会出现两者被同时使用呢?其实,这要从两者的各自优势来说了. nginx用

架构设计:负载均衡层设计方案(7)——LVS + Keepalived + Nginx安装及配置

1.概述 上篇文章<架构设计:负载均衡层设计方案(6)--Nginx + Keepalived构建高可用的负载层>(http://blog.csdn.net/yinwenjie/article/details/47130609) 我们解说了Nginx的故障切换.而且承诺各位读者会尽快解说 LVS + Keepalived + Nginx的安装和配置.在中间由于工作的原因.我又插写了三篇关于zookeeper的原理使用的文章.今天这边文章我们回归主题.为各位读者解说LVS + Keepalive

Centos安装LVS+Keepalived

Centos安装LVS+Keepalived LVS Keepalived 主机IP配置如下 #LVS-DR-Master 172.16.1.191 #LVS-DR-Backup 172.16.1.192 #LVS-DR-VIP 172.16.1.196 #Web_1-RealServer 172.16.1.193 #Web_2-RealServer 172.16.1.194 在DS1 DS2上执行以下命令 yum -y install ipvsadm wget http://www.keepa

LVS + Keepalived + Nginx安装及配置

1.概述 上篇文章<架构设计:负载均衡层设计方案(6)——Nginx + Keepalived构建高可用的负载层>(http://blog.csdn.net/yinwenjie/article/details/47130609) 我们讲解了Nginx的故障切换,并且承诺各位读者会尽快讲解 LVS + Keepalived + Nginx的安装和配置.在中间由于工作的原因,我又插写了三篇关于zookeeper的原理使用的文章.今天这边文章我们回归主题,为各位读者讲解 LVS + Keepaliv

centos 7 LVS+keepalived实现nginx的高可用以及负载均衡

一.准备工作:关闭防火墙,selinux以免对实验结果造成影响,准备虚机,设置IP地址.主机名 hostname:Nginx01 IP:192.168.1.87 Role:Nginx Server hostname:Nginx02 IP: 192.168.1.88 Role:Nginx Server hostname:LVS01 IP: 192.168.1.89 Role:LVS+Keepalived hostname:LVS02 IP: 192.168.1.90 Role:LVS+Keepal

LVS+Keepalived实现负载均衡

一.负载均衡:必不可少的基础手段 1.1 找更多的牛来拉车吧 当前大多数的互联网系统都使用了服务器集群技术,集群即将相同服务部署在多台服务器上构成一个集群整体对外提供服务,这些集群可以是Web应用服务器集群,也可以是数据库服务器集群,还可以是分布式缓存服务器集群等等. 古人有云:当一头牛拉不动车的时候,不要去寻找一头更强壮的牛,而是用两头牛来拉车. 在实际应用中,在Web服务器集群之前总会有一台负载均衡服务器,负载均衡设备的任务就是作为Web服务器流量的入口,挑选最合适的一台Web服务器,将客户