下载安装haproxy-1.8.2.tar.gz
官网下载地址:https://www.haproxy.org/
解压haproxy-1.8.2.tar.gz
![](https://i-blog.csdnimg.cn/blog_migrate/e4db5d3da6bc8fdc0019b03105f715a2.png)
查看系统内核版本
![](https://i-blog.csdnimg.cn/blog_migrate/20d26f78a47f9e907c25eebcb33a304d.png)
![](https://i-blog.csdnimg.cn/blog_migrate/4967cf4d9f028a7ce47d523878c64bd3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/345abbfe20d8df63a3d66b312d92ad36.png)
![](https://i-blog.csdnimg.cn/blog_migrate/0588700dee2a17c288bcb4f643df0d2f.png)
查看安装的haproxy版本
![](https://i-blog.csdnimg.cn/blog_migrate/572c116407e7ab0dac1dbbe5e338beab.png)
创建系统服务启动方式(在源码包中的examples文件夹下拷贝,并相应修改内容)
![](https://i-blog.csdnimg.cn/blog_migrate/7e5db6cfb65097487d66bd1ceab968b8.png)
vim /etc/init.d/haproxy修改相应的内容与之匹配
![](https://i-blog.csdnimg.cn/blog_migrate/205680cc029e25bc287e4fc3b8f3a430.png)
创建haproxy配置文件vim /etc/haproxy/haproxy.cfg
![](https://i-blog.csdnimg.cn/blog_migrate/aa620cf79ba174b312e4357e7f269ce3.png)
查看haproxy监控状态
![](https://i-blog.csdnimg.cn/blog_migrate/5457e8365acc7c5313449963ba764ad9.png)
官网下载地址:https://www.haproxy.org/
解压haproxy-1.8.2.tar.gz
tar -zxvf haproxy-1.8.2
![](https://i-blog.csdnimg.cn/blog_migrate/e4db5d3da6bc8fdc0019b03105f715a2.png)
查看系统内核版本
uname -r
![](https://i-blog.csdnimg.cn/blog_migrate/20d26f78a47f9e907c25eebcb33a304d.png)
make TARGET=linux2632 PREFIX=/usr/local/haproxy18
![](https://i-blog.csdnimg.cn/blog_migrate/4967cf4d9f028a7ce47d523878c64bd3.png)
make install PREFIX=/usr/local/haproxy18
![](https://i-blog.csdnimg.cn/blog_migrate/345abbfe20d8df63a3d66b312d92ad36.png)
cp -rf /usr/local/haproxy18/sbin/haproxy /usr/sbin/
![](https://i-blog.csdnimg.cn/blog_migrate/0588700dee2a17c288bcb4f643df0d2f.png)
查看安装的haproxy版本
![](https://i-blog.csdnimg.cn/blog_migrate/572c116407e7ab0dac1dbbe5e338beab.png)
创建系统服务启动方式(在源码包中的examples文件夹下拷贝,并相应修改内容)
![](https://i-blog.csdnimg.cn/blog_migrate/7e5db6cfb65097487d66bd1ceab968b8.png)
vim /etc/init.d/haproxy修改相应的内容与之匹配
![](https://i-blog.csdnimg.cn/blog_migrate/205680cc029e25bc287e4fc3b8f3a430.png)
创建haproxy配置文件vim /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local0
maxconn 4000
ulimit-n 80170
#uid 500
#gid 500
user xiaofeng #使用uid也可以
group xiaofeng
#chroot /usr/local/haproxy
nbproc 1
daemon
pidfile /usr/local/haproxy18/haproxy.pid
stats socket /var/run/haproxy.sock
# debug
# quiet
defaults
log 127.0.0.1 local3
mode http
option httplog
option httpclose
option dontlognull
option abortonclose
option forwardfor
option redispatch
retries 2
maxconn 2000
balance roundrobin
timeout connect 5000
timeout check 20000
timeout client 150000
timeout server 150000
listen stats
bind 0.0.0.0:10081
mode http
log 127.0.0.1 local0 err
stats uri /hastats
stats auth admin:admin
stats refresh 30s
stats hide-version
#option httpchk GET /Login.d
frontend http_80
option forwardfor
bind :80
mode http
maxconn 1500
log global
option httplog
# log the name of the virtual server
capture request header Host len 30
# log the beginning of the referrer
capture request header Referer len 50
acl test hdr_beg(host) -i test.proxy.com
use_backend zone_test if test
backend zone_test
mode http
option forwardfor
option httpchk GET / HTTP/1.1\r\nHost:test.proxy.com
server web01 192.168.0.103:80 check inter 9000 rise 3 fall 3
server web02 192.168.0.104:80 check inter 9000 rise 3 fall 3
启动haproxy服务service haproxy start![](https://i-blog.csdnimg.cn/blog_migrate/aa620cf79ba174b312e4357e7f269ce3.png)
查看haproxy监控状态
![](https://i-blog.csdnimg.cn/blog_migrate/5457e8365acc7c5313449963ba764ad9.png)
写的较好的haproxy博客和文档:
http://www.ttlsa.com/linux/haproxy-study-tutorial/
https://www.cnblogs.com/heiye123/articles/7928292.html
https://www.cnblogs.com/shanyou/archive/2012/10/16/2726768.html
http://blog.51cto.com/freeloda/1294094
https://www.cnblogs.com/zhangs1986/p/6517788.html