Nginx專題 八 Nginx配置高可用的集群

2021-10-04 22:28:36 字數 3653 閱讀 8160

4 .完成高可用配置(主從配置)

5.最終測試

集群架構圖:

(1)需要兩台 nginx  伺服器

(2)需要 keepalived

(3)需要虛擬 ip

(1)需要兩台伺服器 192.168.70.128  和 192.168.70.130

(2)在兩台伺服器安裝 nginx

(3)在兩台伺服器安裝 keepalived

(1)使用 yum 命令進行安裝

yum install keepalived –y
(2)安裝之後,在etc 裡面生成目錄 keepalived,有檔案 keepalived.conf

[root@centos2 init.d]

# cd /etc/

[root@centos2 etc]

# ls keep*

keepalived.conf

(1)修改/etc/keepalived/keepalived.conf192.168.70.128

}

(2 )在/usr/local/src新增指令碼

192.168.70.128

#!/bin/basha=`

ps -c nginx –no-header |

wc -l`if[

$a -eq 0 ]

;then

sleep 2if[

`ps -c nginx --no-header |

wc -l`

-eq 0 ]

;then

killall keepalived

fifi

[root@centos2 src]

# ls

nginx_check.sh

[root@centos2 src]

# chmod +755 nginx_check.sh

[root@centos2 src]

# ls

nginx_check.sh

192.168.70.130

#!/bin/basha=`

ps -c nginx –no-header |

wc -l`if[

$a -eq 0 ]

;then

sleep 2if[

`ps -c nginx --no-header |

wc -l`

-eq 0 ]

;then

killall keepalived

fifi

[root@centos3 sbin]

# cd /usr/local/src

[root@centos3 src]

# ls

[root@centos3 src]

# vi nginx_check.sh

[root@centos3 src]

# ls

nginx_check.sh

[root@centos3 src]

# chmod +755 nginx_check.sh

[root@centos3 src]

# ll

total 4

-rwxr-xr-x. 1 root root 194 apr 13 01:04 nginx_check.sh

(3 )把兩台伺服器上 nginx 和 和 keepalived 啟動

啟動 nginx :

service nginx reload

啟動 keepalived :

(1)在瀏覽器位址列輸入 虛擬 ip 位址

(2)把主伺服器(192.168.70.128 )nginx 和 和 keepalived 停止,再輸入

至此為止,nginx的高可用搭建完畢!

Nginx系列(八 nginx日誌)

remote addr,http x forwarded for 記錄客戶端ip位址 remote user 記錄客戶端使用者名稱 request 記錄請求的url和http協議 status 記錄請求狀態 body bytes sent 傳送給客戶端的位元組數,不包括響應頭的大小 該變數與apac...

Nginx配置分析 nginx 二

基於網域名稱配置 在 conf nginx.conf中新增兩個虛擬主機配置 server server 配置host檔案,dns本地化 192.168.1.103 www.host1.com 192.168.1.103 www.host2.com 測試成功 埠配置在 conf nginx.conf中...

nginx 配置nginx集群(7)

1.準備兩台伺服器 且都安裝nginx 和keepalived 安裝keepalived yum install keepalived y安裝好後linux 的etc 資料夾下面會有keepalived資料夾以及配置檔案 2.修改keepalived的配置問價 virtual ipaddress3....