天天看點

在國産處理器伺服器上做HAProxy負載均衡

環境

硬體平台:國産 arm64 3399cpu海之舟伺服器

作業系統:海之舟伺服器作業系統1.0A

在國産處理器伺服器上做HAProxy負載均衡

使用者通路192.168.125位址時,haproxy配置設定至二台伺服器,192.168.1.7,192.168.1.8。實作負載分擔。

[email protected]:/home/zs# apt-get install haproxy //安裝軟體

[email protected]:/home/zs# nano /etc/haproxy/haproxy.cfg

#---------------------------------------------------------------------

#main frontend which proxys to the backends

#---------------------------------------------------------------------

frontend main

bind :80 //偵測端口80

default_backend webserver

#---------------------------------------------------------------------

#static backend for serving up images, stylesheets and such

#---------------------------------------------------------------------

backend webserver

balance roundrobin //輪詢方式

server web1 192.168.1.7:80 check //預設每2000ms檢查一次伺服器,192.168.1.7是否正常.

server web2 192.168.1.8:80 check

[email protected]:/home/zs# /etc/init.d/haproxy stop //重新開機伺服器,使配置生效

[ ok ] Stopping haproxy (via systemctl): haproxy.service.

[email protected]:/home/zs# /etc/init.d/haproxy start

[ ok ] Starting haproxy (via systemctl): haproxy.service.

[email protected]:/home/zs# netstat -an |more //檢視端口是否啟用

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 0.0.0.0:80 0.0.0.0: LISTEN //顯示80端口啟用

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN

tcp 0 64 192.168.1.125:22 192.168.1.6:1524 ESTABLISHED

tcp6 0 0 :::8080 ::? LISTEN

tcp6 0 0 :::22 ::? LISTEN

tcp6 0 0 127.0.0.1:8005 ::? LISTEN

tcp6 0 0 :::8009 ::? LISTEN

Active UNIX domain sockets (servers and established)

[email protected]:/home/zs#

在用戶端浏覽器中輸入位址http://192.168.1.125,即可通路到輪詢的網頁.

繼續閱讀