Haproxy 安裝配置詳解-端口映射

Haproxylinux

簡介:web

HAProxy提供高可用性、負載均衡以及基於TCP和HTTP應用的代理,支持虛擬主機,它是免費、快速而且可靠的一種解決方案。安全

HAProxy特別適用於那些負載特大的web站點,這些站點一般又須要會話保持或七層處理。bash

HAProxy運行在當前的硬件上,徹底能夠支持數以萬計的併發鏈接。而且它的運行模式使得它能夠很簡單安全的整合進您當前的架構中, 同時能夠保護你的web服務器不被暴露到網絡上。服務器

HAProxy實現了一種事件驅動, 單一進程模型,此模型支持很是大的併發鏈接數。多進程或多線程模型受內存限制 、系統調度器限制以及無處不在的鎖限制,不多能處理數千併發鏈接。事件驅動模型由於在有更好的資源和時間管理的用戶空間(User-Space) 實現全部這網絡

些任務,因此沒有這些問題。此模型的弊端是,在多核系統上,這些程序一般擴展性較差。這就是爲何他們必須進行優化以 使每一個CPU時間片(Cycle)作更多的工做。多線程

 

安裝:架構

#下載
wget http://fossies.org/linux/misc/haproxy-1.6.9.tar.gz
#解壓
tar -zxvf haproxy-1.6.9.tar.gz
cd haproxy-1.6.9
#安裝
make TARGET=linux2628 ARCH=x86_64 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy

#參數說明
TARGET=linux26   #內核版本,使用uname -r查看內核,如:2.6.18-371.el5,此時該參數就爲linux26;kernel 大於2.6.28的用:TARGET=linux2628
ARCH=x86_64      #系統位數
PREFIX=/usr/local/haprpxy  #/usr/local/haprpxy爲haprpxy安裝路徑

 

配置:併發

【/usr/local/haproxy/haproxy.conf】負載均衡

global
        daemon
        log 127.0.0.1 local3 info
        maxconn 1000
        ulimit-n 4000
        uid     1001                               #普通用戶的uid和gid
        gid     1001
        quiet
        quiet
        nbproc  1
        pidfile /home/work/env/haproxy/haproxy.pid  #普通用戶路徑權限
defaults
        mode tcp                                    #協議
        timeout connect 5000ms
        timeout client 50000ms
        timeout server 50000ms
frontend http-in-unstable                           #名字
        bind 43.243.130.89:1115                     #本地端口 ,注本地端口防火牆也要放開
        default_backend httpunstable
backend httpunstable
        server proxy00 192.168.122.173:1115 check inter 2000 fall 3 weight 30 maxconn 1000
                                                    #外部端口(虛擬機)端口
frontend http-in-unstable_1443
        bind 43.243.130.89:1443
        default_backend httpunstable_1443
backend httpunstable_1443
        server proxy00 192.168.122.173:1443 check inter 2000 fall 3 weight 30 maxconn 1000

 啓動腳本:

/home/work/env/haproxy/check_haproxy.sh  #注意路徑權限

#!/bin/sh
dir=`dirname $(realpath $0)`
selfname=`basename $0`
cd $dir
PID=`ps aux | grep '/usr/local/haproxy/sbin/haproxy' | grep -v grep | grep -v "$selfname" |  awk '{ print $2 }'`
if [ -z "$PID" ]; then
    /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.conf
fi
相關文章
相關標籤/搜索