keepalived nginx安裝配置

2021-07-04 13:36:21 字數 2871 閱讀 4250

軟體版本:

pcre8.36

keepalived1.2.19

nginx1.8.0

安裝步驟

安裝pcre

tar -zxvf pcre-8.36.tar.gz

cd pcre-8.36

./configure --prefix=/usr/local/pcre

make && make install

安裝keepalived

tar -zxvf keepalived-1.2.19.tar.gz

cd keepalived-1.2.19

./configure --prefix=/usr/local/keepalived

make && make install

cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

mkdir –pv /etc/keepalived

cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/

ln -s /usr/local/keepalived/sbin/keepalived /sbin/

chkconfig keepalived on

安裝nginx

tar -zxvf nginx-1.8.0.tar.gz

cd nginx-1.8.0

./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre/

make && make install

啟動和停止nginx:

啟動:進入到安裝之後$的sbin目錄,執行./nginx

停止:./nginx –s stop

檢查是否安裝成功:進入到安裝之後$的sbin目錄,執行./nginx -t

keepalived

啟動:service keepalived start

停止:service keepalived stop配置配置keepalived

主備keepalived的配置大致相同,不同之處在於state和priority。如下所示:

! configuration file for keepalived

#配置報警郵件

global_defs

notification_email_from [email protected]

smtp_server 192.168.200.1

smtp_connect_timeout 30

router_id lvs_devel

}#配置keepalived伺服器例項

vrrp_instance vi_1

virtual_ipaddress

}

配置nginx

nginx的基本配置如下所示:

#user nobody; #使用者名稱

worker_processes auto; #處理程序個數,一般為自動分配

error_log logs/error.log; #錯誤日誌記錄位置

#error_log logs/error.log notice; #notice/info等為記錄錯誤的級別

#error_log logs/error.log info;

pid logs/nginx.pid; #程序記錄檔案

#配置負載均衡,server為nginx伺服器

upstream nginx

#配置處理請求server

server

location /

#error_page 404 /404.html; #配置錯誤頁面

# redirect server error pages to the static page /50x.html

error_page 500 502 503 504 /50x.html;

location = /50x.html

}server

location /

error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

error_page 500 502 503 504 /50x.html;

location = /50x.html

}}負載均衡nginx 的 upstream目前支援 4 種方式的分配

輪詢(預設)

每個請求按時間順序逐一分配到不同的後端伺服器,如果後端伺服器down掉,能自動剔除。

weight

定輪詢機率,weight和訪問比率成正比,用於後端伺服器效能不均的情況。

ip_hash

每個請求按訪問ip的hash結果分配,這樣每個訪客固定訪問乙個後端伺服器,可以解決session的問題。

fair(第三方)

按後端伺服器的響應時間來分配請求,響應時間短的優先分配。

在http中upstream配置中,clouder是起的負載均衡伺服器或者反向**的名稱。

upstream clouder

keepalived nginx主從切換

五 nginx指令碼,新建nginx check.sh指令碼放到 etc keepalived下 指令碼內容 bin bash a ps c nginx no header wc l if a eq 0 then usr local nginx sbin nginx sleep 2 if ps c ...

keepalived nginx集群部署

192.168.132.130 伺服器1 192.168.132.132 伺服器2 虛擬ip 192.168.132.131 yum install gcc c gcc是gnu的c語言編譯器,至於c 編譯器,它的名字叫做g yum install y pcre pcre devel 在nginx編譯...

keepalived nginx負載安裝

環境 centos7.6 keepalived工具可以生成虛擬浮動ip,繫結到網絡卡上。172.21.210.19 master 172.21.210.20 backup 172.21.210.30 vip 浮動ip 1 兩個節點安裝keepalived yum y install keepaliv...