1. 程式人生 > >Ceph RGW負載均衡和高可用配置

Ceph RGW負載均衡和高可用配置

配置主要參考

(配置負載均衡有多種方法,這裡是使用keepalived 用於高可用,haproxy 用於負載均衡)

注意:負載均衡節點不能與任何RGW節點重合。

架構示意圖如下:

閘道器高可用和負載均衡架構圖

我的三個RGW分別為

R3S25:172.16.50.25

R3S43:172.16.50.43

R3S44:172.16.50.44

兩個LB伺服器

R3S24:172.16.50.24

R3S42:172.16.50.42

VIP

虛擬ip:172.16.50.100

1.安裝keepalived haproxy -y

yum install keepalived haproxy -y

選取兩個均衡節點(均衡節點不能和rgw節點重合),下面在均衡節點(LB)執行。

開啟linux ip轉發功能

echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf

sysctl -p

允許繫結到非本地ip

echo "net.ipv4.ip_nonlocal_bind = 1" >> /etc/sysctl.conf

sysctl -p

檢查 :

/usr/sbin/sysctl net.ipv4.ip_nonlocal_bind

/usr/sbin/sysctl net.ipv4.ip_forward

cat /proc/sys/net/ipv4/ip_forward

檢視是否看起了ip轉發功能

如果上述檔案中的值為0,說明禁止進行IP轉發;如果是1,則說明IP轉發功能已經開啟。

2.修改keepalived + Haproxy配置檔案

下面所有操作均只需在LB(負載均衡器)節點執行

vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived
vrrp_script chk_haproxy {
    script "killall -0 haproxy" # 檢查haproxy程序
    interval 2
    weight 2
}
vrrp_instance VI_1 {
    state BACKUP
    interface enp175s0f1    # 似情況修改
    virtual_router_id 1      # id號區域網唯一
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        172.16.50.100        # VIP,配好了,客戶端連線該ip即可高可用
    }
    track_script {
        chk_haproxy
    }
}

haproxy 的配置檔案

#---------------------------------------------------------------------
# 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
    stats refresh           30s
    stats uri /stats #統計頁面url
    stats realm baison-test-Haproxy #統計頁面密碼框上提示文字
    stats auth admin:admin123 #統計頁面使用者名稱和密碼設定
    stats hide-version #隱藏統計頁面上HAProxy的版本資訊

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend rgw *:80     # 偵聽埠
    mode http
    default_backend    rgw
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend rgw
    mode http
    balance    roundrobin     # 均衡模式,當前為輪循
    server R4S43 172.16.50.43:7480 check   # 填寫真實閘道器IP和埠
    server R4S44 172.16.50.44:7480 check
    server R3S25 172.16.50.25:7480 check

3. 啟動服務

systemctl start keepalived

systemctl enable keepalived

systemctl start haproxy

systemctl enable haproxy

關閉防火牆

systemctl stop firewalld

檢視狀態

systemctl status keepalived

systemctl status haproxy

關閉電腦的防火牆

在瀏覽器中開啟http://ip:80/stats

輸入賬號/密碼:admin/admin123

即可在web頁面中看到當前負載均衡的狀態