网站首页 > 精选教程 正文
准备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-17 搭建Kubernetes集群 kubernetes部署ceph集群
- 2024-10-17 聊聊分布式下的WebSocket解决方案
- 2024-10-17 「SpringCloud」(三十五)Docker+k8s打包部署——集群环境部署
- 2024-10-17 Spring Cloud Alibaba基础教程:Nacos的集群部署
- 2024-10-17 生产环境skywalking集群k8s安装 k8s集群安装 centos7 简书
- 2024-10-17 Nacos集群搭建过程详解 nacos集群启动命令
- 2024-10-17 k8s集群中部署nginx k8s部署consul集群
- 2024-10-17 Kubernetes集群的自动化部署和管理
- 2024-10-17 Spring Cloud笔记02: 在k8s集群中部署Nacos集群
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- nginx反向代理 (57)
- nginx日志 (56)
- nginx限制ip访问 (62)
- mac安装nginx (55)
- java和mysql (59)
- java中final (62)
- win10安装java (72)
- java启动参数 (64)
- java链表反转 (64)
- 字符串反转java (72)
- java逻辑运算符 (59)
- java 请求url (65)
- java信号量 (57)
- java定义枚举 (59)
- java字符串压缩 (56)
- java中的反射 (59)
- java 三维数组 (55)
- java插入排序 (68)
- java线程的状态 (62)
- java异步调用 (55)
- java中的异常处理 (62)
- java锁机制 (54)
- java静态内部类 (55)
- java怎么添加图片 (60)
- java 权限框架 (55)
本文暂时没有评论,来添加一个吧(●'◡'●)