實驗目的:
構建一個高可用的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集群。
原創文章,作者:chenxu@magedu.com,如若轉載,請注明出處:http://www.www58058.com/75798