当前位置:网站首页>微服务架构从0到1,搭建全过程记录,手把手教学,连载中...
微服务架构从0到1,搭建全过程记录,手把手教学,连载中...
2022-04-22 20:06:00 【mildness丶】
准备Linux主机
架构设计
安装Keepalived
Keepalived可以虚拟出一个ip,多台主机都配置Keepalived,当前主机挂了可以选举出另一台接管这个ip。这样只需要一个ip就可以连接主备机,无需关注主备切换。
如需关闭防火墙(不建议):
# 关闭
systemctl stop firewalld
# 禁止开机启动防火墙
systemctl disable firewalld
用yum的方式安装
yum install keepalived
配置主主机
使用yum安装后配置文件在
/etc/keepalived/keepalived.conf
配置文件内容很多,全部删掉替换成下面的,看注释做对应修改
! Configuration File for keepalived
global_defs {
# 给当前主机起个名字
router_id NGINX1
}
# vrrp是Keepalived在内网中通讯的协议,VI_1是实例名称,可改
vrrp_instance VI_1 {
state MASTER
# ens33是本机网卡名称,可以ip addr查看
interface ens33
virtual_router_id 51
# 主备竞选时的优先级 数字越大越高
priority 100
# 间隔检测时间
advert_int 1
# 同一组的认证配置,防止同一个内网中多个Keepalived组错乱
authentication {
auth_type PASS
auth_pass 1111
}
# 虚拟ip地址,用户访问下面的ip,会映射到本机,可配多个
virtual_ipaddress {
192.168.25.211
}
}
启动Keepalived
systemctl start keepalived
查看当前ip
[root@nginx1 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:24:8c:bb brd ff:ff:ff:ff:ff:ff
inet 192.168.25.125/24 brd 192.168.25.255 scope global noprefixroute dynamic ens33
valid_lft 5358sec preferred_lft 5358sec
# 多了这个192.168.25.211的vip
inet 192.168.25.211/32 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::575:23df:be65:edbf/64 scope link noprefixroute
valid_lft forever preferred_lft forever
配置副主机
操作同主主机,配置文件与主主机不同的地方:
- router_id 改名字
- state BACKUP
- priority 50
启动Keepalived
测试主主机宕机后,ip能否漂移
关机
init 0
关闭主主机依然能ping通即可。
ping 192.168.25.211
副主机ip addr发现192.168.25.211已经跑到副主机上。
Keepalived安装完成!
Keepalived只会检测自己的进程,假设主机没宕机,nginx宕机了,Keepalived是不会漂移ip的。此时可以写一个sh脚本,一直在服务器上跑,查看nginx状态,如果发现nginx挂了,则干掉Keepalived的进程。其他redis集群,mysql集群等,都是同理。
版权声明
本文为[mildness丶]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_41720396/article/details/124345063
边栏推荐
- Jmeter:一文2000字接口测试基础知识介绍
- Connection method of Jincang database kingbasees
- 面试千万不要这么说,“不喜欢开发,所以选择测试”
- [Chongqing Guangdong education] reference materials of management principles of Sichuan Agricultural University
- [program source code] graduation project - second-hand trading website
- 2022-01-12 wechat applet debugging
- Solve the problem of log printing when kingbasees inserts data into PG mode stand-alone database
- How can I apply for convertible bonds? Is it safe to purchase convertible bonds?
- DBUS client user guide
- Which brand of sports headphones is better and recommended for easy-to-use sports headphones
猜你喜欢

Internet News: Lenovo announced the new progress of ESG; Excellent sound and painting of Jimi h3s and z6x Pro were highly praised; Little red book responded to "layoffs of 20%"
![【无标题】LeetCode 396 旋转函数[数学 找规律] HERODING的LeetCode之路](/img/7a/c365daf5a61f02cb3cc8d7ec044283.png)
【无标题】LeetCode 396 旋转函数[数学 找规律] HERODING的LeetCode之路

DNS resource records detailed explanation & authority | recursive resolution difference (super detailed)

为什么说PuddingSwap或许为成为GameFi领域的一匹强势黑马?

嵌入式Web项目(一)——Web服务器的引入

面试千万不要这么说,“不喜欢开发,所以选择测试”

海康内置4G卡的摄像头设备无法注册EasyCVR平台是什么原因?

顶测科技整理转行过程中一定要避免的问题

From functional test to automatic test, the salary doubled. I sorted out this 3000 word super complete learning guide

DNS解析流程&基础知识
随机推荐
让模型训练速度提升2到4倍,「彩票假设」作者的这个全新PyTorch库火了
树的那些破事~模板小结
顶测科技整理转行过程中一定要避免的问题
金仓数据库KingbaseES服务启动方法
Detailed tutorial on installing MySQL 8.0 + eclipse configuration under Linux
[Chongqing Guangdong education] reference materials of management principles of Sichuan Agricultural University
FPGA SEU问题与SEM Core
See how big websites play the secret of website acceleration (CDN)
Hard work alone is not enough! And this
Quarkus dependency injection 9: bean read / write lock
KingbaseES中数据库启动安装程序方法
Which futures company is safer to open a domestic futures account?
启动kingbase单机服务时报错:invalid value for parmeter “bindcpulist”:”0-95”
【无标题】LeetCode 396 旋转函数[数学 找规律] HERODING的LeetCode之路
CVPR 2022: is smile recognition also sexist? Zhejiang University and Wuhan University jointly set up a fairness improvement framework
envoy代理后获取客户端真实IP
Method of database startup installer in kingbasees
2022-01-12 wechat applet debugging
Biography: Ali Dharma Institute layoffs 30%! Internal staff: rumors! Netizen: why not cut 29.99%...
[program source code] graduation project - second-hand trading website