一、官方網站:HAProxy
二、下載處三、可直接使用yum install haproxy,但會安裝1.5 版
其指令如下:
$sudo yum install haproxy
以下,目前測試有錯。目前正在除錯中。
四、shell安裝2.3 版Ha Proxy
檔案名稱:HaProxy23Install.sh
檔案內容:
#!/bin/bash
yum install -y make gcc wget
wget http://www.haproxy.org/download/2.3/src/haproxy-2.3.2.tar.gz
tar zxvf haproxy-2.3.2.tar.gz
cd ~/haproxy-2.3.2
make TARGET=linux310 ARCH=x86_64 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
cp /usr/local/haproxy/sbin/haproxy /usr/sbin/
cp examples/haproxy.init /etc/init.d/haproxy
chmod 755 /etc/init.d/haproxy
useradd -r haproxy
mkdir /etc/haproxy
echo "global" > /etc/haproxy/haproxy.cfg
echo " log 127.0.0.1 local2" >> /etc/haproxy/haproxy.cfg
echo " chroot /var/lib/haproxy" >> /etc/haproxy/haproxy.cfg
echo " pidfile /var/run/haproxy.pid" >> /etc/haproxy/haproxy.cfg
echo " maxconn 4000" >> /etc/haproxy/haproxy.cfg
echo " user haproxy" >> /etc/haproxy/haproxy.cfg
echo " group haproxy" >> /etc/haproxy/haproxy.cfg
echo " daemon" >> /etc/haproxy/haproxy.cfg
echo " stats socket /var/lib/haproxy/stats" >> /etc/haproxy/haproxy.cfg
echo "defaults" >> /etc/haproxy/haproxy.cfg
echo " mode http" >> /etc/haproxy/haproxy.cfg
echo " log global" >> /etc/haproxy/haproxy.cfg
echo " option httplog" >> /etc/haproxy/haproxy.cfg
echo " option dontlognull" >> /etc/haproxy/haproxy.cfg
echo " option http-server-close" >> /etc/haproxy/haproxy.cfg
echo " option forwardfor except 127.0.0.0/8" >> /etc/haproxy/haproxy.cfg
echo " option redispatch" >> /etc/haproxy/haproxy.cfg
echo " retries 3" >> /etc/haproxy/haproxy.cfg
echo " timeout http-request 10s" >> /etc/haproxy/haproxy.cfg
echo " timeout queue 1m" >> /etc/haproxy/haproxy.cfg
echo " timeout connect 10s" >> /etc/haproxy/haproxy.cfg
echo " timeout client 1m" >> /etc/haproxy/haproxy.cfg
echo " timeout server 1m" >> /etc/haproxy/haproxy.cfg
echo " timeout http-keep-alive 10s" >> /etc/haproxy/haproxy.cfg
echo " timeout check 10s" >> /etc/haproxy/haproxy.cfg
echo " maxconn 3000" >> /etc/haproxy/haproxy.cfg
echo "frontend main *:5000" >> /etc/haproxy/haproxy.cfg
echo " acl url_static path_beg -i /static /images /javascript /stylesheets" >> /etc/haproxy/haproxy.cfg
echo " acl url_static path_end -i .jpg .gif .png .css .js" >> /etc/haproxy/haproxy.cfg
echo " use_backend static if url_static" >> /etc/haproxy/haproxy.cfg
echo " default_backend app" >> /etc/haproxy/haproxy.cfg
echo "backend static" >> /etc/haproxy/haproxy.cfg
echo " balance roundrobin" >> /etc/haproxy/haproxy.cfg
echo " server static 127.0.0.1:4331 check" >> /etc/haproxy/haproxy.cfg
echo "backend app" >> /etc/haproxy/haproxy.cfg
echo " balance roundrobin" >> /etc/haproxy/haproxy.cfg
echo " server app1 127.0.0.1:5001 check" >> /etc/haproxy/haproxy.cfg
echo " server app2 127.0.0.1:5002 check" >> /etc/haproxy/haproxy.cfg
echo " server app3 127.0.0.1:5003 check" >> /etc/haproxy/haproxy.cfg
echo " server app4 127.0.0.1:5004 check" >> /etc/haproxy/haproxy.cfg
service haproxy start
五、安裝2.3 版Ha Proxy的相關步驟
01.安裝make、gcc、wget$sudo yum install -y make gcc wget
02.wget Ha Proxy 2.3
$sudo wget http://www.haproxy.org/download/2.3/src/haproxy-2.3.2.tar.gz
03.解壓縮haproxy-2.3.2.tar.gz
$sudo tar zxvf haproxy-2.3.2.tar.gz
04.進入haproxy-2.3.2
$cd haproxy-2.3.2
05.編譯
$sudo make TARGET=linux310 ARCH=x86_64 PREFIX=/usr/local/haproxy
06.安裝Ha Proxy,並將執行檔指定到/usr/local
$sudo make install PREFIX=/usr/local/haproxy
07.將執行檔複製到/usr/sbin/底下
$sudo cp /usr/local/haproxy/sbin/haproxy /usr/sbin/
08.複製啟動腳本檔案到系統中,並調整權限,確保系統可以正常將Haproxy啟動
$sudo cp examples/haproxy.init /etc/init.d/haproxy
$sudo chmod 755 /etc/init.d/haproxy
09.新增使用者帳號haproxy給Haproxy使用
$sudo useradd -r haproxy
10.在/etc/下新增一個haproxy的資料夾,並放入設定檔,檔名為:haproxy.cfg
$mkdir /etc/haproxy
$vi /etc/haproxy/haproxy.cfg
檔案名稱:haproxy.cfg
檔案內容:
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats
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
frontend main *:5000
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js
use_backend static if url_static
default_backend app
backend static
balance roundrobin
server static 127.0.0.1:4331 check
backend app
balance roundrobin
server app1 127.0.0.1:5001 check
server app2 127.0.0.1:5002 check
server app3 127.0.0.1:5003 check
server app4 127.0.0.1:5004 check
11.啟動Ha Proxy服務
$service haproxy start
12.啟動、重啟、關閉Ha Proxy服務
#啟動服務
$sudo systemctl start haproxy.service
#重新啟動服務
$sudo systemctl restart haproxy.service
#關閉服務
$sudo systemctl stop haproxy.service
沒有留言:
張貼留言