日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網(wǎng)為廣大站長提供免費收錄網(wǎng)站服務(wù),提交前請做好本站友鏈:【 網(wǎng)站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(wù)(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

眾所周知,Nginx 是一個廣受好評的 web 服務(wù)器,也可以用作反向代理,負載均衡器和 HTTP 緩存。keepalive 工作在虛擬路由器冗余協(xié)議 vrrp (Virtual Router Redundancy Protocol) 上,它允許一個靜態(tài) IP 在兩個 linux 系統(tǒng)之間進行故障轉(zhuǎn)移。

在本文中,我們將演示如何在 Linux 中使用 keepalive 設(shè)置高可用 (HA) NGINX web 服務(wù)器。

實驗準(zhǔn)備

  • Node 1 – 192.168.1.130 – nginx1.example.com – minimal centos 8 / RHEL 8
  • Node 2 – 192.168.1.140 – nginx2.example.com – minimal CentOS 8 / RHEL 8
  • Virtual IP (VIP) – 192.168.1.150
  • sudo user pkumar
  • firewalld enbled
  • SELinux Running

 

廢話不多說,讓我們直接進入安裝和配置步驟。

1) 安裝 NGINX Web Server

For CentOS 8 / RHEL 8

NGINX 軟件包在 CentOS 8 / RHEL 8 存儲庫默認可用,在兩個節(jié)點上運行如下命令

$ sudo dnf install -y nginx

For CentOS 7 / RHEL 7

NGINX 軟件包在 CentOS 7 / RHEL 7 存儲庫中默認不可用,我們必須啟用 epel 存儲庫,在兩個節(jié)點上運行以下命令

$ sudo yum install epel-release -y$ sudo yum install -y nginx

For Ubuntu / Debian

基于 Debian 的發(fā)行版,nginx 軟件包在存儲庫中默認可用,在兩個節(jié)點上運行如下命令

$ sudo apt update$ sudo apt install -y nginx2) 為兩個節(jié)點自定義 index.html

讓我們?yōu)檫@兩個節(jié)點創(chuàng)建自定義 index.html,這樣我們就可以很容易地識別哪個服務(wù)器在通過虛擬 IP 訪問網(wǎng)站。

在 node 1 上,執(zhí)行如下命令

[pkumar@nginx1 ~]$ echo "This is NGINX Web Server from Node 1" | sudo tee /usr/share/nginx/html/index.html

在 node 2 上,執(zhí)行如下命令

[pkumar@nginx2 ~]$ echo "This is NGINX Web Server from Node 2" | sudo tee /usr/share/nginx/html/index.html3) 放行 NGINX 端口并啟動其服務(wù)

如果防火墻已啟用,通過以下命令放行 80 端口

For CentOS / RHEL System

$ sudo firewall-cmd --permanent --add-service=http$ sudo firewall-cmd –reload

For Ubuntu / Debian System

$ sudo ufw allow 'Nginx HTTP'

啟動并啟用 nginx 服務(wù)

$ sudo systemctl start nginx$ sudo systemctl enable nginx

在外部運行 curl 命令測試兩個節(jié)點的 NGINX 服務(wù)器

$ curl http://192.168.1.130This is NGINX Web Server from Node 1$ curl http://192.168.1.140This is NGINX Web Server from Node 2

以上輸出確認 NGINX 正在運行,并且可以從外部通過系統(tǒng)的 IP 地址訪問。

4) 安裝配置 Keepalived

在兩個節(jié)點上安裝配置 Keepalived

For CentOS / RHEL systems

$ sudo dnf install -y keepalived // CentOS 8/ RHEL 8$ sudo yum install -y keepalived // CentOS 7 / RHEL 7

For Ubuntu / Debian System

$ apt install -y keepalived

本文中,Node 1 作為主節(jié)點,Node 2 作為從節(jié)點。

備份配置文件

[pkumar@nginx1 ~]$ sudo cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf-org

編輯配置文件

[pkumar@nginx1 ~]$ echo -n | sudo tee /etc/keepalived/keepalived.conf[pkumar@nginx1 ~]$ sudo vi /etc/keepalived/keepalived.conf

復(fù)制如下內(nèi)容:

global_defs {# Keepalived process identifierRouter_id nginx# script to check whether Nginx is running or notVRRP_script check_nginx {script "/bin/check_nginx.sh"interval 2weight 50# Virtual interface - The priority specifies the order in which the assigned interface to take over in a failovervrrp_instance VI_01 {state MASTERinterface enp0s3virtual_router_id 151priority 110# The virtual ip address shared between the two NGINX Web Server which will floatvirtual_ipaddress {192.168.1.150/24track_script {check_nginxauthentication {auth_type AHauth_pass secret


 

現(xiàn)在創(chuàng)建一個帶有以下內(nèi)容的腳本,它將檢查 nginx 服務(wù)是否正在運行。keepalive 將始終檢查 check_nginx.sh 腳本的輸出,如果它發(fā)現(xiàn) nginx 服務(wù)停止或沒有響應(yīng),那么它將虛擬 ip 地址指向備份節(jié)點。

[pkumar@nginx1 ~]$ sudo vi /bin/check_nginx.sh#!/bin/shif [ -z "`pidof nginx`" ]; thenexit 1fi

保存并關(guān)閉文件,設(shè)置所需權(quán)限

[pkumar@nginx1 ~]$ sudo chmod 755 /bin/check_nginx.sh

使用 scp 命令把 keepalive .conf 和 check_nginx.sh 文件從 Node 1 復(fù)制到 Node 2

[pkumar@nginx1 ~]$ scp /etc/keepalived/keepalived.conf [email protected]:/etc/keepalived/[pkumar@nginx1 ~]$ scp /bin/check_nginx.sh [email protected]:/bin/

復(fù)制完成后,登錄到 Node 2,并在 keepalive .conf 文件中做一些更改。將 state 從 MASTER 更改為 BACKUP,并將 priority 設(shè)置為 100 降低優(yōu)先級。


 

如果開啟防火墻,執(zhí)行以下命令放行 VRRP(兩個節(jié)點都要執(zhí)行)

For CentOS / RHEL Systems

$ sudo firewall-cmd --add-rich-rule='rule protocol value="vrrp" accept' --permanent$ sudo firewall-cmd --reload

For Ubuntu / Debian Systems

在主節(jié)點 (Node 1) 上執(zhí)行

$ sudo ufw allow to 224.0.0.18 comment 'VRRP Broadcast'$ sudo ufw allow from 192.168.1.140 comment 'VRRP Router'

在從節(jié)點 (Node 2) 上執(zhí)行

$ sudo ufw allow to 224.0.0.18 comment 'VRRP Broadcast'$ sudo ufw allow from 192.168.1.130 comment 'VRRP Router'

啟動和開啟 keepalived 服務(wù)

$ sudo systemctl start keepalived$ sudo systemctl enable keepalived

驗證 keepalived 服務(wù)狀態(tài)

$ sudo systemctl status keepalived


 

驗證主節(jié)點上的 VIP (虛擬 ip 地址) 狀態(tài),本例中 VIP 是 192.168.1.130

$ ip add show


 

以上輸出確認在主節(jié)點的 enp0s3 接口上配置了 VIP

5) Keepalive 和 NGINX 測試

使用虛擬 IP (192.168.1.150) 訪問 nginx 服務(wù)器,目前它應(yīng)該會顯示 Node 1 頁面。


 

停止 Node 1 上的 NGINX 服務(wù),看看虛擬 IP 是否從 Node 1 切換到 Node 2,這次它應(yīng)該會顯示 Node 1 頁面。

[pkumar@nginx1 ~]$ sudo systemctl stop nginx[pkumar@nginx1 ~]$ ip add show


 

登錄到 Node 2,查看虛擬 IP 是否正確

[pkumar@nginx2 ~]$ ip add show


 

使用虛擬 IP (192.168.1.150) 訪問 nginx 服務(wù)器


 

漂亮,以上證實我們已經(jīng)成功地設(shè)置了高可用的 NGINX Web 服務(wù)器。

分享到:
標(biāo)簽:Nginx
用戶無頭像

網(wǎng)友整理

注冊時間:

網(wǎng)站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨大挑戰(zhàn)2018-06-03

數(shù)獨一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學(xué)四六

運動步數(shù)有氧達人2018-06-03

記錄運動步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績評定2018-06-03

通用課目體育訓(xùn)練成績評定