中文字幕日韩精品一区二区免费_精品一区二区三区国产精品无卡在_国精品无码专区一区二区三区_国产αv三级中文在线

haproxy+keepalived實現(xiàn)網站高可靠-創(chuàng)新互聯(lián)

10年積累的做網站、網站建設經驗,可以快速應對客戶對網站的新想法和需求。提供各種問題對應的解決方案。讓選擇我們的客戶得到更好、更有力的網絡服務。我雖然不認識你,你也不認識我。但先網站制作后付款的網站建設流程,更有五指山免費網站建設讓你可以放心的選擇與我們合作。

haproxy 1的配置文件,包括 keepalived 和 haproxy 的配置,分別如下:

 【haproxy 1的keepalived 配置文件】  /etc/keepalived/keepalived.conf

global_defs {
router_id NodeB
}
vrrp_instance VI_1 {
state BACKUP #設置為主服務器
interface ens33 #監(jiān)測網絡接口
virtual_router_id 51 #主、備必須一樣
priority 90 #(主、備機取不同的優(yōu)先級,主機值較大,備份機值較小,值越大優(yōu)先級越高)
advert_int 1 #VRRP Multicast廣播周期秒數(shù)
authentication {
auth_type PASS #VRRP認證方式,主備必須一致
auth_pass 1111 #(密碼)
}
virtual_ipaddress {
192.168.248.200
}

 【haproxy 1的haproxy.conf 配置文件】  /etc/haproxy/haproxy.cfg

#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2

chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon

# turn on stats unix socket
stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------

frontend web *:80
frontend web1 192.168.248.200:80
# bind 192.168.248.200:80
mode http
use_backend app

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static 127.0.0.1:4331 check

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
balance roundrobin
server app1 192.168.248.144:80 check
server app2 192.168.248.146:80 check

【haproxy 2的keepalived 配置文件】

global_defs {
router_id NodeB
}
vrrp_instance VI_1 {
state BACKUP #設置為主服務器
interface ens33 #監(jiān)測網絡接口
virtual_router_id 51 #主、備必須一樣
priority 90 #(主、備機取不同的優(yōu)先級,主機值較大,備份機值較小,值越大優(yōu)先級越高)
advert_int 1 #VRRP Multicast廣播周期秒數(shù)
authentication {
auth_type PASS #VRRP認證方式,主備必須一致
auth_pass 1111 #(密碼)
}
virtual_ipaddress {
192.168.248.200
}

【haproxy 2的haproxy.cfg】 /etc/haproxy/haproxy.cfg

#---------------------------------------------------------------------
# Example configuration for a possible web application. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
# to have these messages end up in /var/log/haproxy.log you will
# need to:
#
# 1) configure syslog to accept network log events. This is done
# by adding the '-r' option to the SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
# 2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like the following can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2

chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon

# turn on stats unix socket
stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------

frontend web *:80
frontend web1 192.168.248.200:80
# bind 192.168.248.200:80
mode http
use_backend app

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static 127.0.0.1:4331 check

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend app
balance roundrobin
server app1 192.168.248.144:80 check
server app2 192.168.248.146:80 check

【web 服務器1 的http index文件內容】

[root@localhost zhou]# yum install -y httpd

[root@localhost zhou]# echo "Hello I am nginx-backend 1. " > /var/www/html/index.html
[root@localhost zhou]# service httpd start
Redirecting to /bin/systemctl start httpd.service
[root@localhost zhou]# firewall-cmd --permanent --add-port=80/tcp
success
[root@localhost zhou]# firewall-cmd --reload
success
[root@localhost zhou]#

【web 服務器2 的http index文件內容】

[root@localhost zhou]# yum install -y httpd

[root@localhost zhou]# echo "Hello I am nginx-backend 2. " > /var/www/html/index.html
[root@localhost zhou]# service httpd start
Redirecting to /bin/systemctl start httpd.service
[root@localhost zhou]# firewall-cmd --permanent --add-port=80/tcp
success
[root@localhost zhou]# firewall-cmd --reload
success
[root@localhost zhou]#

 【haproxy 1的服務啟動】 haproxy 2與之相同。

keepalived -f /etc/keepalived/keepalived.conf

haproxy  -f  /etc/haproxy/haproxy.cfg

firewall-cmd --permenant --add-port=80/tcp

firewall-cmd --reload

【驗證結果】

如果關閉掉一個haproxy ,則不影響系統(tǒng)的正常工作,web網站還是可以正常訪問,并且是輪詢的結果。

標題名稱:haproxy+keepalived實現(xiàn)網站高可靠-創(chuàng)新互聯(lián)
網頁地址:http://www.rwnh.cn/article30/dgsepo.html

成都網站建設公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、網站策劃、用戶體驗、面包屑導航、動態(tài)網站企業(yè)網站制作

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

外貿網站制作
安图县| 封开县| 高淳县| 商南县| 高密市| 麻城市| 阜城县| 武威市| 永修县| 柳林县| 高淳县| 宁津县| 深泽县| 宣武区| 旅游| 洛扎县| 珲春市| 那曲县| 上高县| 白玉县| 三穗县| 合肥市| 利津县| 万年县| 治多县| 天津市| 巩留县| 罗城| 湖北省| 都江堰市| 湖口县| 石首市| 册亨县| 壶关县| 青铜峡市| 榆林市| 临泉县| 南部县| 子洲县| 桑日县| 哈密市|