当前位置:网站首页>【集群】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#223 (Div. 2)】A. Sereja and Dima
- 【NOIP2016 D1T3】换教室(期望DP+Floyd)(究极思维陷阱!)
- Nosqlzoo question brushing-1
- C language volatile
- 【AtCoder2304】Cleaning
- Rabin-Miller素数测试
- [STL source code analysis] summary notes (9): set/multiset and map/multimap
- Qstring to hexadecimal qstring
- Raspberry pie builds a full-featured NAS server (07): manage your library & read as you please
- Several transaction modes of Seata
猜你喜欢

【CodeForces1019E】Raining season(边分治+斜率优化)

二、用户登录和注册

Sdl-2 thread logic

Seata的几种事务模式

May 30-June 5, 2022 AI industry weekly (issue 100): three years

【LeetCode】-- 17. Letter combination of telephone number

No response from win10 explorer when dragging files

软件测试周刊(第75期):唯有平视,才能看见真实的自己。

10 advanced concepts that must be understood in learning SQL

big.js--使用/实例
随机推荐
Adventure of small X
C language to write a calculator MVC (very interesting code architecture callback and constructor mode and the use of pointer functions)
[STL source code analysis] summary notes (9): set/multiset and map/multimap
模线性方程组(中国剩余定理+通用解法)
QT interface nested movement based on qscrollarea
[STL source code analysis] summary note (2): overview of containers
2022.5.30-6.5 AI行业周刊(第100期):三年时光
Gobang interface of mobile console (C language)
big. Js-- use / instance
Compound ratemodel contract analysis
Mobile console Gobang (first draft of detailed design)
Compound RateModel合约解析
【Oracle 数据库】奶妈式教程day04 排序查询
【编译原理】05-语法制导的语义计算——基于翻译模式的语义计算
[STL source code analysis] summary notes (7): ingenious deque
[Oracle database] mammy tutorial day02 use of database management tool sqlplus
【AtCoder1984】Wide Swap (拓扑排序转化)
2022低压电工考题及在线模拟考试
JVM tuning
CRMEB/V4.4标准版打通版商城源码小程序公众号H5+App商城源码