专注Java教育14年 全国咨询/投诉热线:444-1124-454
星辉LOGO图
始于2009,口口相传的Java黄埔军校
首页 hot资讯 构建高可用Nginx集群的方法

构建高可用Nginx集群的方法

更新时间:2021-12-17 13:15:30 来源:星辉 浏览1648次

实验目的:

构建一个高可用的Nginx集群。

实验要求:

1.基于nat结构实现;

2.实现高可用;

实验拓扑图形:

实验步骤:

1.按图配置各个网卡地址;

2.设置Nginx主机(下面带#的部分为从所需要的配置,其他则一样)

        Yum install httpd nginx    
        Vim /etc/httpd/conf/httpd.conf    
        Listen 80 àListen
8080    
        Vim /etc/nginx/nginx.conf    
        http{                  
upstream websrvs {                  
server 172.18.24.3:80;                  
server 172.18.24.5:80;                  
server 127.0.0.1:8080 backup;    
            }    
        }    
        vim /etc/nginx/conf.d/default.conf               
location / {                   
proxy_pass http://websrvs;    
        }    
        vim /etc/keepalived/keepalived.conf    
        global_defs {             
notification_email {                   
root@localhost    
           }              
notification_email_from keeplived@localhost             
smtp_server 127.0.0.1              
smtp_connect_timeout 30             
router_id tes1t             
vrrp_mcast_group4 224.0.100.24    
        }    
        vrrp_script ‘ngxstatus’ {                  
script “killall -0 nginx && exit 0 || exit 1”                 
interval 1                  
weight -5    
        }    
        vrrp_instance myr1 {               
state MASTER                
#BACKUP             
interface eth0                
#ens38              
virtual_router_id 67               
priority 100                   #98              
advert_int 1             
authentication {                 
auth_type PASS                
auth_pass UIpYPPDI    
            }               
track_script {                  
 ngxstatus    
            }               
virtual_ipaddress {                  
172.18.24.13/16 dev eth0       
#ens38    
            }              
notify_master “/etc/keepalived/notify.sh master”               
notify_backup “/etc/keepalived/notify.sh backup”              
notify_fault “/etc/keepalived/notify.sh fault”    
        }    
        Systemctl start httpd    
        Systemctl start nginx    
        Systemctl start keepalived    

3.配置RS主机

Yum install httpd

Vim /var/www/html/index.html

4.检测:curl http://172.18.24.13

检测结果:实现高可用Nginx集群。

如果您想了解更相关知识,不妨来关注一下星辉的Java星辉在线学习,里面的课程内容全面细致,从入门到精通,很适合没有基础的小伙伴学习,相信对大家会有所帮助的。

提交申请后,顾问老师会电话与您沟通安排学习

免费课程推荐 >>
技术文档推荐 >>