网站首页 > 技术教程 正文
准备4台服务器,IP如下:xxx.xxx.xxx.144xxx.xxx.xxx.145xxx.xxx.xxx.146xxx.xxx.xxx.147另外准备一个IP xxx.xxx.xxx.100作为应用的访问地址,避免暴露应用的真实IP。
1、安装keepalive、nginx。2、然后编辑keepalived.conf文件,(包含但不仅限下列内容)
global_defs { router_id ha_master #主机为ha_master,备机为ha_slaver script_user root #enable_script_security}vrrp_script check_nginx { script /keepalived/script/check_nginx.sh #check_nginx.sh的路径,后面需要创建该文件 interval 5}vrrp_instance VI_1 { state MASTER #主机为MASTER,备机为BACKUP interface eth0 #此处修改为ip addr显示的网卡名称 virtual_router_id 100 priority 100 #主机为100,备机为90 advert_int 1 authentication { auth_type PASS auth_pass 1234 } track_script { check_nginx } virtual_ipaddress { xxx.xxx.xxx.100 #集群访问的正式IP }}
3、增加检测nginx脚本,并赋可执行权限mkdir –p /keepalived/scriptvi /keepalived/script/check_nginx.sh,chmod 755 /keepalived/script/check_nginx.sh
修改为以下内容
#!/bin/bashif [ `ps -C nginx --no-header | wc -l` -eq 0 ];then #如果nginx没有启动就启动nginx /etc/nginx/sbin/nginx ## nginx路径 sleep 1 if [ `ps -C nginx --no-header | wc -l` -eq 0 ];then exit 10 fifi
编辑nginx.conf文件,修改http段中的如下内容
```shell
upstream eams { server xxx.xxx.xxx.144:8080; ##8080为应用端口 server xxx.xxx.xxx.145:8080; server xxx.xxx.xxx.146:8080; server xxx.xxx.xxx.147:8080; ip_hash; ##使用hash算法 check interval=3000 rise=2 fall=2 timeout=1000 type=http; check_keepalive_requests 1; check_http_send "HEAD / HTTP/1.1\r\n\r\n"; check_http_expect_alive http_2xx http_3xx http_4xx http_5xx; }
server { listen 80; server_name xxx.xxx.xxx.100; ##集群访问的正式IP #charset koi8-r; #access_log logs/host.access.log main; location /xxx { ##xxx表示应用名称 proxy_set_header Host $host; proxy_set_header X-real-ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://xxx; ##xxx表示应用名称 }
```
启动keepalive、nginx服务。验证是否成功
猜你喜欢
- 2024-10-14 使用keepalived监控tomcat 达到双机热备
- 2024-10-14 keepalived的安装(keepalived安装配置)
- 2024-10-14 15分钟学会nginx+tomcat+keepalived高可用负载均衡
- 2024-10-14 搭建环境tomcat+nginx+keepalived+zabbix
- 2024-10-14 K8s 通过 keepalive+nginx 实现 nginx-ingress-controller 高可用
- 2024-10-14 流量红利下怎么用双机搭建高可用与负载均衡——(上)
- 2024-10-14 快速入门-Keepalived+Nginx-HA高可用-不啰嗦-直接上-边实践边学
- 2024-10-14 Keepalived + Nginx 实现高可用 Web 负载均衡
- 2024-10-14 Keepalived+Nginx架构配置(keepalived nginx配置)
- 2024-10-14 Nginx双机主备(Keepalived实现)(nginx双机负载均衡配置)
你 发表评论:
欢迎- 最近发表
-
- 阿里P8大佬总结的Nacos入门笔记,从安装到进阶小白也能轻松学会
- Linux环境下,Jmeter压力测试的搭建及报错解决方法
- Java 在Word中合并单元格时删除重复值
- 解压缩软件哪个好用?4款大多数人常用的软件~
- Hadoop高可用集群搭建及API调用(hadoop3高可用)
- lombok注解@Data没有toString和getter、setter问题
- Apache Felix介绍(apache fineract)
- Spring Boot官方推荐的Docker镜像编译方式-分层jar包
- Gradle 使用手册(gradle详细教程)
- 字节二面:为什么SpringBoot的 jar可以直接运行?
- 标签列表
-
- 下划线是什么 (87)
- 精美网站 (58)
- qq登录界面 (90)
- nginx 命令 (82)
- nginx .http (73)
- nginx lua (70)
- nginx 重定向 (68)
- Nginx超时 (65)
- nginx 监控 (57)
- odbc (59)
- rar密码破解工具 (62)
- annotation (71)
- 红黑树 (57)
- 智力题 (62)
- php空间申请 (61)
- 按键精灵 注册码 (69)
- 软件测试报告 (59)
- ntcreatefile (64)
- 闪动文字 (56)
- guid (66)
- abap (63)
- mpeg 2 (65)
- column (63)
- dreamweaver教程 (57)
- excel行列转换 (56)
本文暂时没有评论,来添加一个吧(●'◡'●)