欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

在流復制主備環(huán)境下怎么使用HAProxy搭建負載均衡環(huán)境

這篇文章主要介紹“在流復制主備環(huán)境下怎么使用HAProxy搭建負載均衡環(huán)境”,在日常操作中,相信很多人在在流復制主備環(huán)境下怎么使用HAProxy搭建負載均衡環(huán)境問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”在流復制主備環(huán)境下怎么使用HAProxy搭建負載均衡環(huán)境”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

在玉山等地區(qū),都構建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供成都網站建設、成都網站設計 網站設計制作按需策劃,公司網站建設,企業(yè)網站建設,成都品牌網站建設,全網營銷推廣,成都外貿網站建設公司,玉山網站建設費用合理。

安裝
使用yum安裝相關軟件,在數據庫服務器上安裝xinted和telnet

yum -y install xinetd telnet

配置xinetd
編寫識別主從庫的腳本pgsqlchk

[pg12@localhost ~]$ cat pgsqlchk 
#!/bin/bash
# This script checks if a postgres server is healthy running on localhost. It will return:
# "HTTP/1.x 200 OK\r" (if postgres is running smoothly)
# - OR -
# "HTTP/1.x 500 Internal Server Error\r" (else)
# The purpose of this script is make haproxy capable of monitoring postgres properly
# It is recommended that a low-privileged postgres  user is created to be used by this script.
# For eg. create  user healthchkusr login password 'hc321';
PGBIN=/appdb/pg12/pg12.0/bin
PGSQL_HOST="localhost"
PGSQL_PORT="5432"
PGSQL_DATABASE="testdb"
PGSQL_USERNAME="pg12"
export PGPASSWORD="root"
TMP_FILE="/tmp/pgsqlchk.out"
ERR_FILE="/tmp/pgsqlchk.err"
# We perform a simple query that should return a few results
VALUE=`$PGBIN/psql -qt -h localhost -U pg12 -p 5432 -c "select pg_is_in_recovery()" 2> /dev/null`
# Check the output. If it is not empty then everything is fine and we return something. Else, we just do not return anything.
if [ $VALUE == "t" ]
then
    /bin/echo -e "HTTP/1.1 206 OK\r\n"
    /bin/echo -e "Content-Type: Content-Type: text/plain\r\n"
    /bin/echo -e "\r\n"
    /bin/echo "Standby"
    /bin/echo -e "\r\n"
elif [ $VALUE == "f" ]
then
    /bin/echo -e "HTTP/1.1 200 OK\r\n"
    /bin/echo -e "Content-Type: Content-Type: text/plain\r\n"
    /bin/echo -e "\r\n"
    /bin/echo "Primary"
    /bin/echo -e "\r\n"
else
    /bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n"
    /bin/echo -e "Content-Type: Content-Type: text/plain\r\n"
    /bin/echo -e "\r\n"
    /bin/echo "DB Down"
    /bin/echo -e "\r\n"
fi
[pg12@localhost ~]$

如為主庫,該腳本模擬接收http請求返回http 200響應,如為從庫則返回206,如數據庫不可用則返回503

#主庫
[pg12@localhost ~]$ ifconfig | grep 'inet'
        inet 192.168.26.28  netmask 255.255.0.0  broadcast 192.168.255.255
        ...
[pg12@localhost ~]$ ./pgsqlchk 
HTTP/1.1 200 OK
Content-Type: Content-Type: text/plain
Primary
#從庫
[pg12@localhost ~]$ ifconfig | grep 'inet'
        inet 192.168.26.25  netmask 255.255.0.0  broadcast 192.168.255.255
        ...
[pg12@localhost ~]$ ./pgsqlchk 
HTTP/1.1 206 OK
Content-Type: Content-Type: text/plain
Standby

創(chuàng)建xinetd配置文件,端口使用23267,指向剛才配置的pgsqlchk執(zhí)行文件

[pg12@localhost ~]$ cat /etc/xinetd.d/pgsqlchk
service pgsqlchk
{
        flags           = REUSE
        socket_type     = stream
        port            = 23267
        wait            = no
        user            = nobody
        server          = /home/pg12/pgsqlchk
        log_on_failure  += USERID
        disable         = no
        only_from       = 0.0.0.0/0
        per_source      = UNLIMITED
}

添加服務,并啟動xinetd

[pg12@localhost ~]$ sudo bash -c 'echo "pgsqlchk 23267/tcp # pgsqlchk" >> /etc/services'
[pg12@localhost ~]$ sudo systemctl start xinetd
[pg12@localhost ~]$ systemctl status xinetd
● xinetd.service - Xinetd A Powerful Replacement For Inetd
   Loaded: loaded (/usr/lib/systemd/system/xinetd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-11-14 12:04:37 CST; 23s ago
  Process: 2847 ExecStart=/usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid $EXTRAOPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 2848 (xinetd)
   CGroup: /system.slice/xinetd.service
           └─2848 /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid
[pg12@localhost ~]$

檢查服務和監(jiān)聽,(可通過設置flags=IPv4調整為監(jiān)聽IPv4地址)

[pg12@localhost ~]$ sudo netstat -antup | grep 23267
tcp6       0      0 :::23267                :::*                    LISTEN      6837/xinetd
[pg12@localhost ~]$ sudo systemctl restart xinetd
[pg12@localhost ~]$ sudo systemctl status xinetd -l
● xinetd.service - Xinetd A Powerful Replacement For Inetd
   Loaded: loaded (/usr/lib/systemd/system/xinetd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2019-11-14 15:43:49 CST; 6s ago
  Process: 7461 ExecStart=/usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid $EXTRAOPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 7462 (xinetd)
   CGroup: /system.slice/xinetd.service
           └─7462 /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid
Nov 14 15:43:49 localhost.localdomain xinetd[7462]: START: pgsqlchk pid=7463 from=192.168.26.26
Nov 14 15:43:49 localhost.localdomain xinetd[7462]: EXIT: pgsqlchk status=0 pid=7463 duration=0(sec)
Nov 14 15:43:52 localhost.localdomain xinetd[7462]: START: pgsqlchk pid=7465 from=192.168.26.26
Nov 14 15:43:52 localhost.localdomain xinetd[7462]: EXIT: pgsqlchk status=0 pid=7465 duration=0(sec)
Nov 14 15:43:52 localhost.localdomain xinetd[7462]: START: pgsqlchk pid=7466 from=192.168.26.26
Nov 14 15:43:52 localhost.localdomain xinetd[7462]: EXIT: pgsqlchk status=0 pid=7466 duration=0(sec)
Nov 14 15:43:55 localhost.localdomain xinetd[7462]: START: pgsqlchk pid=7467 from=192.168.26.26
Nov 14 15:43:55 localhost.localdomain xinetd[7462]: EXIT: pgsqlchk status=0 pid=7467 duration=0(sec)
Nov 14 15:43:55 localhost.localdomain xinetd[7462]: START: pgsqlchk pid=7468 from=192.168.26.26
Nov 14 15:43:55 localhost.localdomain xinetd[7462]: EXIT: pgsqlchk status=0 pid=7468 duration=0(sec)
[pg12@localhost ~]$ sudo netstat -antup | grep 23267
tcp        0      0 0.0.0.0:23267           0.0.0.0:*               LISTEN      7462/xinetd         
[pg12@localhost ~]$

配置HAProxy with xinetd
在代理服務器上安裝HAProxy

yum -y install haproxy telnet

配置HAProxy(/etc/haproxy/haproxy.cfg)

[pg12@localhost ~]$ cat /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 http-server-close
    option forwardfor       except 127.0.0.0/8
    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
listen stats
    mode http
    bind *:7000
    stats enable
    stats uri /
listen ReadWrite
    bind *:5000
    option httpchk
    http-check expect status 200
    default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
    server pg0 pg0:5432 maxconn 100 check port 23267
listen ReadOnly
    bind *:5001
    option httpchk
    http-check expect status 206
    default-server inter 3s fall 3 rise 2 on-marked-down shutdown-sessions
    server pg0 pg0:5432 maxconn 100 check port 23267
    server pg1 pg1:5432 maxconn 100 check port 23267
[pg12@localhost ~]$

啟動HAProxy

[pg12@localhost ~]$ sudo systemctl start haproxy
[pg12@localhost ~]$

劃重點:
1.HAProxy使用TCP模式而不是默認的http模式
2.HAProxy監(jiān)聽的端口是5000-5001
3.端口5000用于RW而5001用于Read-only
4.使用http-check(端口為23267)判斷狀態(tài)
5.pg0可用于讀寫,pg1僅用于讀
6.基于http-check,確定服務器狀態(tài)(根據服務響應確定:200/206/503)

驗證haproxy服務是否正常啟動,如出現bind socket的錯誤,則需調整內核參數和SELinux策略

1.設置內核參數:
net.ipv4.ip_nonlocal_bind=1
2.設置SELinux策略
setsebool -P haproxy_connect_any=1
vim /etc/sysconfig/selinux
SELINUX=enforcing
-->
SELINUX=permissive

正常啟動HAProxy的日志

[root@localhost ~]# systemctl status haproxy -l
● haproxy.service - HAProxy Load Balancer
   Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2019-11-14 14:41:09 CST; 12min ago
 Main PID: 1963 (haproxy-systemd)
   CGroup: /system.slice/haproxy.service
           ├─1963 /usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
           ├─1964 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
           └─1965 /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
Nov 14 14:41:09 localhost.localdomain systemd[1]: Started HAProxy Load Balancer.
Nov 14 14:41:09 localhost.localdomain haproxy-systemd-wrapper[1963]: haproxy-systemd-wrapper: executing /usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -Ds
[root@localhost ~]#

到此,關于“在流復制主備環(huán)境下怎么使用HAProxy搭建負載均衡環(huán)境”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注創(chuàng)新互聯網站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

本文題目:在流復制主備環(huán)境下怎么使用HAProxy搭建負載均衡環(huán)境
文章位置:http://aaarwkj.com/article42/iihjec.html

成都網站建設公司_創(chuàng)新互聯,為您提供外貿網站建設、定制網站、網站導航、網站營銷、網站改版、營銷型網站建設

廣告

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

綿陽服務器托管
国产情侣自拍在线观看| 少妇视频资源一区二区三区| 亚洲国产精品一区一区| 国产成人短视频在线播放| 91精品蜜臀国产综合久久久久久| 国产一区二区欧美精品| 国产激情久久久久久影院| 国产精品一区二区啪啪| 国产精品一区二区精品| 欧美精品一区二区三区色| 国产一区二区三区高潮爽| 国产一区二区成人精品| 少妇高潮在线观看免费| 色婷婷精品二区久久蜜臀av| 日韩欧美 高清一区| 日韩欧美精品另类在线| 久久亚洲精品国产精品黑人| 亚洲成人av在线蜜桃| 国产精品午夜福利天堂| 日本乱码一区二区三区在线观看| 国产日产精品久久一区| 日韩精品一区二区三区中文| 91色综合久久久久婷婷| 中文字幕日韩欧美一区| 人妻熟女一区二区视频| 亚洲女人淫片在线观看| 国产美女冒白浆免费网站| 欧美国内日本一区二区| 午夜情色视频在线观看| 永久免费成人在线视频| 欧美日韩另类激情免费| 91九色中文视频在线观看 | 精品久久久久久久久极品| 欧美另类精品一区二区三区| 国产精品亚洲在钱视频| 日韩在线观看精品亚洲| 国产一区二区三区在线看片| 久久伊人亚洲精品中文字幕| 欧美另类精品一区二区| 国产成人综合亚洲国产| 精品国产一区=区三区乱码|