centos6.5 64位上haproxy安装

本文详细介绍了如何在CentOS系统上安装、配置并启动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

 

转载于:https://www.cnblogs.com/zhongnan/p/4026765.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值