Haproxy安装:
useradd haproxy
#wget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.25.tar.gz
# tar zxvf haproxy-1.4.25.tar.gz
# cd haproxy-1.4.25
# make TARGET=linux26 PREFIX=/usr/local/haproxy ARCH=x86_64
# make install PREFIX=/usr/local/haproxy
#cd /usr/local/haproxy
#chown -R haproxy.haproxy *
配置文件:
#cd /usr/local/haproxy
#vi/usr/local/haproxy/haproxy.cfg
globallog /dev/log local0log /dev/log local1 noticechroot /usr/local/haproxystats socket /run/haproxy/admin.sock mode 660 level adminstats timeout 30suser haproxygroup haproxydaemon# Default SSL material locations#ca-base /etc/ssl/certs#crt-base /etc/ssl/private# Default ciphers to use on SSL-enabled listening sockets.# For more information, see ciphers(1SSL). This list is from:# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/#ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS#ssl-default-bind-options no-sslv3defaultslog globalmode http #默认的模式mode { tcp|http|health },tcp是4层,http是7层,health只会返回OKoption tcplogoption dontlognulltimeout connect 5000timeout client 50000timeout server 50000#errorfile 400 /etc/haproxy/errors/400.http#errorfile 403 /etc/haproxy/errors/403.http#errorfile 408 /etc/haproxy/errors/408.http#errorfile 500 /etc/haproxy/errors/500.http#errorfile 502 /etc/haproxy/errors/502.http#errorfile 503 /etc/haproxy/errors/503.http#errorfile 504 /etc/haproxy/errors/504.http########统计页面配置########
listen admin_stats
bind 0.0.0.0:9080 #监听端口
mode http #http的7层模式
option httplog #采用http日志格式
#log 127.0.0.1 local0 err
maxconn 10
stats refresh 30s #统计页面自动刷新时间
stats uri /stats #统计页面url
stats realm XingCloud\ Haproxy #统计页面密码框上提示文本
stats auth admin:admin #统计页面用户名和密码设置
stats hide-version #隐藏统计页面上HAProxy的版本信息########test配置#################
listen test
bind 0.0.0.0:8080 #注意端口号要不低于1024
mode http
#maxconn 4086
#log 127.0.0.1 local0 debug
server s1 192.168.1.189:80
server s2 192.168.1.189:81
其中:
192.168.1.189:80
192.168.1.189:81
为部署好的web网站。
运行:
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg