当前位置:网站首页>【集群】LVS+keepalived高可用集群
【集群】LVS+keepalived高可用集群
2022-06-11 07:29:00 【雪碧不要气】
前言
本博客内容仅为记录博主思路,仅供参考,一切以自己实践结果为准。
一、LVS+keepalived
1.0 架构概况
| 作用 | IP地址 | 安装服务 |
|---|---|---|
| 主负载均衡器 | 192.168.13.10 | ipvsadm/keepalived |
| 节点服务器1 | 192.168.13.20 | httpd |
| 节点服务器2 | 192.168.13.30 | httpd |
| 备用负载均衡器 | 192.168.13.40 | ipvsadm/keepalived |
1.2 节点服务器
yum install -y httpd
cd /etc/sysconfig/network-scripts/
cp ifcfg-lo ifcfg-lo:0
vim ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.13.100
NETMASK=255.255.255.255
ONBOOT=yes
vim /etc/rc.local
route add -host 192.168.13.100 dev lo:0
chmod +x /etc/rc.d/rc.local
vim /etc/sysctl.conf
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
sysctl -p
echo '<h1>This is the first test web1!</h1>' > /var/www/html/index.html
systemctl start httpd
#另一个节点服务器重复此操作
1.2 主负载均衡服务器
yum install -y ipvsadm keepalived
cd /etc/keepalived
vim keepalived.conf
10行:smtp_server 127.0.0.1
12行:router_id LVS_01
13-16行:删除
#vrrp热备份模块#
17行:interface ens33
19行(priority 100上方插入):nopreempt
27行:192.168.13.100
28-29行:删除
#virtual虚拟服务器模块#
31行:192.168.13.100 80
34行:lb_kind DR
35行:persistence_timeout 0
36行:protocol TCP
38行:real_server 192.168.13.20 80 {
39行:weight 1
40行:TCP_CHECK {
41行:connect_port 80
42行:connect_timeout 3
43行:nb_get_retry 3
44行:delay_before_retry 3
45行:}
46行:}
47-55行:38,46 co 46
#将上面9行节点服务器配置复制下来,改一下节点服务器IP地址即可
56行:}
56行以下:全部删除
systemctl start keepalived
scp keepalived.conf 192.168.13.40:`pwd`
ipvsadm-save > /etc/sysconfig/ipvsadm
systemctl restart keepalived
ipvsadm -ln
1.3 备负载均衡服务器
yum install -y ipvsadm keepalived
cd /etc/keepalived/
vim keepalived.conf
12行:router_id LVS_02
16行:state BACKUP
20行:priority 90
systemctl start keepalived
ipvsadm-save > /etc/sysconfig/ipvsadm
systemctl start ipvsadm
systemctl restart keepalived
ipvsadm -ln
1.4 测试
- 1、网页访问192.168.13.100,产生负载均衡效果
- 2、主负载:systemctl stop keepalived,VIP地址跳到备用负载均衡器(ip addr查看)
二、负载均衡器配置文件模板
! Configuration File for keepalived
global_defs {
notification_email {
[email protected].loc
[email protected].loc
[email protected].loc
}
notification_email_from Alexandre.[email protected].loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_01
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
nopreempt
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.13.100
}
}
virtual_server 192.168.13.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 0
protocol TCP
real_server 192.168.13.20 80 {
weight 1
TCP_CHECK{
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.13.30 80 {
weight 1
TCP_CHECK{
connect_port 80
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
三、结语
- 心态要好
边栏推荐
- 【CF#693 (Div. 3)】B. Fair Division
- 【CF#223 (Div. 2)】A. Sereja and Dima
- Building a full-featured NAS server with raspberry pie (06): built-in file synchronization tool for penetration
- 【CF #277.5 (Div. 2)】B. BerSU Ball
- C language inherits memory management mechanism (unfinished)
- Leetcode-9. Palindrome Numbber
- 2022低压电工考题及在线模拟考试
- Ffmpeg extraction package format extracts AAC and customizes adtc header to realize arbitrary frame decoding
- [analysis of STL source code] summary note (4): behind the scenes hero allocator
- Building a full-featured NAS server with raspberry pie (05): playing with video and audio & sorting out movies
猜你喜欢

JVM学习记录(七)——类加载过程与双亲委派模型

2022.5.30-6.5 AI行业周刊(第100期):三年时光

2022低压电工考题及在线模拟考试

Outer margin collapse

2、 User login and registration

The gap between the parent box and the child box

The rotation of the earth and the moon (II)

2022年熔化焊接与热切割考试练习题及答案
![[STL source code analysis] summary notes (12): functors and adapters](/img/6d/a3a9cde2c8792579af7505c2226914.jpg)
[STL source code analysis] summary notes (12): functors and adapters
![[Oracle database] mammy tutorial day04 Sorting Query](/img/79/9db26aa2d9dbb5514427edf03004f4.png)
[Oracle database] mammy tutorial day04 Sorting Query
随机推荐
[analysis of STL source code] summary notes (3): vector introduction
SQLZOO刷题记录-3
Post-processing of ffmpeg miscellaneous notes
【AtCoder1981】Shorten Diameter(图论思维)
A case in which the MySQL administrator password cannot take effect
【AtCoder2387】+/- Rectangle
学 SQL 必须了解的10个高级概念
big. Js-- use / instance
RTMP protocol
2022 melting welding and thermal cutting exam exercises and answers
Mistakes in Niuke JS exercise
Several transaction modes of Seata
Regular Expression Matching
Crmeb/v4.4 Standard Version open version mall source code applet official account h5+app mall source code
QT table display data
Gobang interface of mobile console (C language)
【Oracle 数据库】奶妈式教程day03 排序查询
P1390 sum of common divisors (Mobius inversion)
Miscellany C language
自动化测试的生命周期是什么?