環(huán)境
系統(tǒng):CentOS 7.4
軟件:haproxy-1.8.7.tar.gz
準(zhǔn)備
- 安裝依賴包
# yum install gcc
安裝
下載源碼包
地址:http://www.haproxy.org/#down-
編譯安裝
# tar -xzvf haproxy-1.8.7.tar.gz # cd haproxy-1.8.7 # make PREFIX=/usr/local/haproxy TARGET=linux2628 # make install PREFIX=/usr/local/haproxy
-
配置環(huán)境變量
# vim /etc/profile export PATH=/usr/local/haproxy/sbin:$PATH # source /etc/profile
配置
- 創(chuàng)建配置文件
# mkdir /usr/local/haproxy/conf
# vim /usr/local/haproxy/conf/haproxy.cfg
global
daemon
maxconn 4000
pidfile /usr/local/haproxy/haproxy.pid
defaults
timeout connect 10s
timeout client 1m
timeout server 1m
listen app
bind 0.0.0.0:8080
mode tcp
server app001 app001.domain.com:8080 check
server app002 app002.domain.com:8080 check
listen haproxy_statistics
bind 0.0.0.0:9000
mode http
stats enable
stats uri /haproxy_statistics
stats realm HAProxy\ Statistics
stats auth admin:Password
啟動
-
添加啟動服務(wù)
# vim /usr/lib/systemd/system/haproxy.service [Unit] Description=HAProxy After=network.target [Service] User=root Type=forking ExecStart=/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg ExecStop=/usr/bin/kill `/usr/bin/cat /usr/local/haproxy/haproxy.pid` [Install] WantedBy=multi-user.target
-
啟動
# systemctl enable haproxy.service # systemctl start haproxy.service
其他
- 查看HAProxy狀態(tài)
Web地址:http://ip:9000/haproxy_statistics