centos6.5 64位上haproxy安装
haproxy提供高可用性、负载均衡以及基于TCP和HTTP应用的代 理,支持虚拟主机,它是免费、快速并且可靠的一种解决方案。
下载:目前来看官网是没法下载了只能通过baidu来找寻(nn的google也不能访问了)
[root@centos-test ~]# cd haproxy-1.4.17
[root@centos-test ~]# make TARGET=linux26 CPU=x86_64 PREFIX=/usr/local/haprpxy
[root@centos-test ~]# make install PREFIX=/usr/local/haproxy
[root@centos-test ~]# mkdir -p /usr/local/haproxy/conf
[root@centos-test ~]# mkdir -p /etc/haproxy
[root@centos-test ~]# cp ~/haproxy-1.4.17/examples/haproxy.cfg /usr/local/haproxy/conf/haproxy.cfg
[root@centos-test ~]# ln -s /usr/local/haproxy/conf/haproxy.cfg /etc/haproxy/haproxy.cfg
[root@centos-test ~]# cp -r ~/haproxy-1.4.17/examples/errorfiles /usr/local/haproxy/errorfiles
[root@centos-test ~]# ln -s /usr/local/haproxy/errorfiles /etc/haproxy/errorfiles
[root@centos-test ~]# mkdir -p /usr/local/haproxy/log
[root@centos-test ~]# touch /usr/local/haproxy/log/haproxy.log
[root@centos-test ~]# ln -s /usr/local/haproxy/log/haproxy.log /var/log/haproxy.log
[root@centos-test ~]# cp ~/haproxy-1.4.17/examples/haproxy.init /etc/rc.d/init.d/haproxy
[root@centos-test ~]# chmod +x /etc/rc.d/init.d/haproxy
[root@centos-test ~]# chkconfig haproxy on
[root@centos-test ~]# ln -s /usr/local/haproxy/sbin/haproxy /usr/sbin
[root@centos-test ~]# cp /usr/local/haproxy/conf/haproxy.cfg /usr/local/haproxy/conf/haproxy.cfg-bak
[root@centos-test ~]# service haproxy restart
配置文件
[root@centos-test ~]#vi /usr/local/haproxy/conf/haproxy.cfg
global
log 127.0.0.1 local0
maxconn 65536 #最大连接数
chroot /usr/local/haproxy
uid 501
gid 501
daemon
nbproc 1
pidfile /usr/local/haproxy/logs/haproxy.pid
#debug
defaults
log global
log 127.0.0.1 local3
#mode http #如果不单单是http服务在defaults中mode就可以不用http
retries 2
maxconn 65536
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen web_proxy
bind :80
mode http
option httplog
option httpclose
option dontlognull
option forwardfor
option redispatch
stats refresh 30s #统计页面自动刷新时间
stats uri /stats #统计页面url
stats realm baison-test-Haproxy #统计页面密码框上提示文本
stats auth admin:admin123 #统计页面用户名和密码设置
stats hide-version
acl is_a hdr_beg(host) -i www.example2.com #判断域名是不是www.example2.com,是则给与a服务器集群服务
acl is_b hdr_beg(host) -i www.example3.com #判断域名是不是www.example3.com,是则给与a服务器集群服务
acl is_c hdr_beg(host) -i www.example4.com #判断域名是不是www.example4.com,是则给与a服务器集群服务
use_backend a_server if is_a
use_backend b_server if is_b
use_backend b_server if is_c
backend a_server
mode http #http 模式
stats uri /haproxy
balance roundrobin
cookie JSESSIONID prefix
stats hide-version
option httpclose
server web1_192.168.200.148 192.168.200.148:80 cookie app1inst1 check inter 2000 rise 2 fall 5
server web1_192.168.200.149 192.168.200.149:80 cookie app1inst1 check inter 2000 rise 2 fall 5
backend b_server
mode http #http 模式
stats uri /haproxy
balance source
cookie JSESSIONID prefix
stats hide-version
option httpclose
server tomcat1_192.168.200.148 192.168.200.148:8081 #cookie app1inst1 check #inter 2000 rise 2 fall 5
server tomcat1_192.168.200.149 192.168.200.149:8081 #cookie app1inst1 check #inter 2000 rise 2 fall 5
listen monitor_proxy
bind :10000
mode tcp
server monitor1_192.168.200.148 192.168.200.148:10000 check inter 2000 rise 2 fall 5
server monitor1_192.168.200.149 192.168.200.149:10000 check inter 2000 rise 2 fall 5