- 浏览: 550111 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (267)
- 随笔 (4)
- Spring (13)
- Java (61)
- HTTP (3)
- Windows (1)
- CI(Continuous Integration) (3)
- Dozer (1)
- Apache (11)
- DB (7)
- Architecture (41)
- Design Patterns (11)
- Test (5)
- Agile (1)
- ORM (3)
- PMP (2)
- ESB (2)
- Maven (5)
- IDE (1)
- Camel (1)
- Webservice (3)
- MySQL (6)
- CentOS (14)
- Linux (19)
- BI (3)
- RPC (2)
- Cluster (9)
- NoSQL (7)
- Oracle (25)
- Loadbalance (7)
- Web (5)
- tomcat (1)
- freemarker (1)
- 制造 (0)
最新评论
-
panamera:
如果设置了连接需要密码,Dynamic Broker-Clus ...
ActiveMQ 集群配置 -
panamera:
请问你的最后一种模式Broker-C节点是不是应该也要修改持久 ...
ActiveMQ 集群配置 -
maosheng:
longshao_feng 写道楼主使用 文件共享 模式的ma ...
ActiveMQ 集群配置 -
longshao_feng:
楼主使用 文件共享 模式的master-slave,produ ...
ActiveMQ 集群配置 -
tanglanwen:
感触很深,必定谨记!
少走弯路的十条忠告
HAProxy是一款开源的高性能的代理转发软件,提供高可用性、负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费、快速并且可靠的一种解决方案。用途最多的还是将它用着前端的负载均衡器,他可以提供第4层和第7层的负载,用的最多还是第7层(mode http),HAProxy特别适用于那些负载特大的web站点, 这些站点通常又需要会话保持或七层处理。HAProxy运行在当前的硬件上,完全可以支持数以万计的并发连接。并且它的运行模式使得它可以很简单安全的整合进您当前的架构中, 同时可以保护你的web服务器不被暴露到网络上。
关于性能方面,haproxy 官方说同等条件下lvs>haproxy>nginx 原因lvs的转发直接在内核空间完成,haproxy 和nginx 还需要使用用户空间的资源,而相对于nginx haproxy调用的资源比较少而已
HAProxy实现了一种事件驱动, 单一进程模型,此模型支持非常大的并发连接数。多进程或多线程模型受内存限制 、系统调度器限制以及无处不在的锁限制,很少能处理数千并发连接。事件驱动模型因为在有更好的资源和时间管理的用户端(User-Space) 实现所有这些任务,所以没有这些问题。此模型的弊端是,在多核系统上,这些程序通常扩展性较差。这就是为什么他们必须进行优化以使每个CPU时间片(Cycle)做更多的工作。
软件负载均衡一般通过两种方式来实现:基于操作系统的软负载实现和基于第三方应用的软负载实现。LVS就是基于Linux操作系统实现的一种软负载,HAProxy就是开源的并且基于第三应用实现的软负载。HAProxy相比LVS的使用要简单很多,功能方面也很丰富。当前,HAProxy支持两种主要的代理模式:"tcp"也即4层(大多用于邮件服务器、内部协议通信服务器等),和7层(HTTP)。在4层模式 下,HAProxy仅在客户端和服务器之间转发双向流量。7层模式下,HAProxy会分析协议,并且能通过允许、拒绝、交换、增加、修改或者删除请求 (request)或者回应(response)里指定内容来控制协议,这种操作要基于特定规则。
HAProxy支持双机热备支持虚拟主机,但其配置简单,拥有非常不错的服务器健康检查功能,当其代理的后端服务器出现故障, HAProxy会自动将该服务器摘除,故障恢复后再自动将该服务器加入。新的1.3引入了frontend,backend;frontend根据任意 HTTP请求头内容做规则匹配,然后把请求定向到相关的backend.
软件下载:
下载地址:http://www.haproxy.org/download/1.5/src/haproxy-1.5.5.tar.gz
依赖包安装:
# yum install gcc gcc-c++ make zlib-devel bzip2-devel openssl-devel
haproxy安装:
# tar -zvxf haproxy-1.5.5.tar.gz
# cd haproxy-1.5.5
# uname -a ## 查看linux内核版本
# make TARGET=linux26 PREFIX=/usr/local/haproxy-1.5.5
# make install PREFIX=/usr/local/haproxy-1.5.5
编辑启动文件:
# touch /etc/init.d/haproxy
# vi /etc/init.d/haproxy --添加以下内容
#!/bin/sh
#
# haproxy
#
# haproxy starting and stopping the haproxy load balancer
#
# chkconfig: 345 55 45
# description: HAProxy is a free, very fast and reliable solution
# offering high availability, load balancing, and
# proxying for TCP and HTTP-based applications
# config: /etc/haproxy/haproxy.cfg
# pidfile: /var/run/haproxy.pid
# probe: true
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -f /usr/local/haproxy-1.5.5/sbin/haproxy ] || exit 0
[ -f /etc/haproxy/haproxy.conf ] || exit 0
# Define our actions
checkconfig() {
# Check the config file for errors
/usr/local/haproxy-1.5.5/sbin/haproxy -c -q -f /etc/haproxy/haproxy.conf
if [ $? -ne 0 ]; then
echo "Errors found in configuration file."
return 1
fi
# We're OK!
return 0
}
start() {
# Check config
/usr/local/haproxy-1.5.5/sbin/haproxy -c -q -f /etc/haproxy/haproxy.conf
if [ $? -ne 0 ]; then
echo "Errors found in configuration file."
return 1
fi
echo -n "Starting HAProxy: "
daemon /usr/local/haproxy-1.5.5/sbin/haproxy -D -f /etc/haproxy/haproxy.conf -p /var/run/haproxy.pid
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/haproxy
return $RETVAL
}
stop() {
echo -n "Shutting down HAProxy: "
killproc haproxy -USR1
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/haproxy
[ $RETVAL -eq 0 ] && rm -f /var/run/haproxy.pid
return $RETVAL
}
restart() {
/usr/local/haproxy-1.5.5/sbin/haproxy -c -q -f /etc/haproxy/haproxy.conf
if [ $? -ne 0 ]; then
echo "Errors found in configuration file."
return 1
fi
stop
start
}
check() {
/usr/local/haproxy-1.5.5/sbin/haproxy -c -q -V -f /etc/haproxy/haproxy.conf
}
rhstatus() {
status haproxy
}
reload() {
/usr/local/haproxy-1.5.5/sbin/haproxy -c -q -f /etc/haproxy/haproxy.conf
if [ $? -ne 0 ]; then
echo "Errors found in configuration file."
return 1
fi
echo -n "Reloading HAProxy config: "
/usr/local/haproxy-1.5.5/sbin/haproxy -f /etc/haproxy/haproxy.conf -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid)
success $"Reloading HAProxy config: "
echo
}
# Possible parameters
case "$1" in
start)
start
;;
stop)
stop
;;
status)
rhstatus
;;
restart)
restart
;;
reload)
reload
;;
checkconfig)
check
;;
*)
echo "Usage: haproxy {start|stop|status|restart|reload|checkconfig}"
exit 1
esac
exit 0
授权:
# chmod +x /etc/init.d/haproxy
编辑haproxy配置文件:
# mkdir /etc/haproxy
# touch /etc/haproxy/haproxy.conf
# vi /etc/haproxy/haproxy.conf
global
maxconn 4096 #默认最大连接数
pidfile /var/run/haproxy.pid #haproxy的pid存放路径
daemon #以后台形式运行haproxy
nbproc 1 #进程数量
defaults
log global
mode http #所处理的类别 (#7层 http;4层tcp )
retries 3 #三次连接失败就认为是服务器不可用
option httplog
option httpclose
option redispatch #serverId对应的服务器挂掉后,强制定向到其他健康的服务器
option abortonclose #当服务器负载很高的时候,自动结束掉当前队列处理比较久的连接
maxconn 4096 #最大连接数
timeout connect 50000 #连接超时
timeout client 50000 #客户端超时
timeout server 50000 #服务器超时
balance roundrobin #默认的负载均衡的方式,轮询方式
listen mysql_proxy
bind *:3366 #监听端口
mode tcp #tcp的4层模式
balance roundrobin
option tcpka
option httpchk
server mysqldb1 172.16.10.70:3306 weight 1 #weight代表权重
server mysqldb1 172.16.10.71:3306 weight 1 #weight代表权重
listen stats
bind *:8888
mode http
option httplog
option httpclose
balance roundrobin
stats refresh 5s
stats uri / #网站健康检测URL,用来检测HAProxy管理的网站是否可以用,正常返回200,不正常返回503
stats realm Haproxy\ Statistics
stats auth admin:admin #账号密码
启动并检查:
# service haproxy start
# netstat -plantu | grep 3366
tcp 0 0 0.0.0.0:3366 0.0.0.0:* LISTEN 23626/haproxy
关于性能方面,haproxy 官方说同等条件下lvs>haproxy>nginx 原因lvs的转发直接在内核空间完成,haproxy 和nginx 还需要使用用户空间的资源,而相对于nginx haproxy调用的资源比较少而已
HAProxy实现了一种事件驱动, 单一进程模型,此模型支持非常大的并发连接数。多进程或多线程模型受内存限制 、系统调度器限制以及无处不在的锁限制,很少能处理数千并发连接。事件驱动模型因为在有更好的资源和时间管理的用户端(User-Space) 实现所有这些任务,所以没有这些问题。此模型的弊端是,在多核系统上,这些程序通常扩展性较差。这就是为什么他们必须进行优化以使每个CPU时间片(Cycle)做更多的工作。
软件负载均衡一般通过两种方式来实现:基于操作系统的软负载实现和基于第三方应用的软负载实现。LVS就是基于Linux操作系统实现的一种软负载,HAProxy就是开源的并且基于第三应用实现的软负载。HAProxy相比LVS的使用要简单很多,功能方面也很丰富。当前,HAProxy支持两种主要的代理模式:"tcp"也即4层(大多用于邮件服务器、内部协议通信服务器等),和7层(HTTP)。在4层模式 下,HAProxy仅在客户端和服务器之间转发双向流量。7层模式下,HAProxy会分析协议,并且能通过允许、拒绝、交换、增加、修改或者删除请求 (request)或者回应(response)里指定内容来控制协议,这种操作要基于特定规则。
HAProxy支持双机热备支持虚拟主机,但其配置简单,拥有非常不错的服务器健康检查功能,当其代理的后端服务器出现故障, HAProxy会自动将该服务器摘除,故障恢复后再自动将该服务器加入。新的1.3引入了frontend,backend;frontend根据任意 HTTP请求头内容做规则匹配,然后把请求定向到相关的backend.
软件下载:
下载地址:http://www.haproxy.org/download/1.5/src/haproxy-1.5.5.tar.gz
依赖包安装:
# yum install gcc gcc-c++ make zlib-devel bzip2-devel openssl-devel
haproxy安装:
# tar -zvxf haproxy-1.5.5.tar.gz
# cd haproxy-1.5.5
# uname -a ## 查看linux内核版本
# make TARGET=linux26 PREFIX=/usr/local/haproxy-1.5.5
# make install PREFIX=/usr/local/haproxy-1.5.5
编辑启动文件:
# touch /etc/init.d/haproxy
# vi /etc/init.d/haproxy --添加以下内容
#!/bin/sh
#
# haproxy
#
# haproxy starting and stopping the haproxy load balancer
#
# chkconfig: 345 55 45
# description: HAProxy is a free, very fast and reliable solution
# offering high availability, load balancing, and
# proxying for TCP and HTTP-based applications
# config: /etc/haproxy/haproxy.cfg
# pidfile: /var/run/haproxy.pid
# probe: true
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -f /usr/local/haproxy-1.5.5/sbin/haproxy ] || exit 0
[ -f /etc/haproxy/haproxy.conf ] || exit 0
# Define our actions
checkconfig() {
# Check the config file for errors
/usr/local/haproxy-1.5.5/sbin/haproxy -c -q -f /etc/haproxy/haproxy.conf
if [ $? -ne 0 ]; then
echo "Errors found in configuration file."
return 1
fi
# We're OK!
return 0
}
start() {
# Check config
/usr/local/haproxy-1.5.5/sbin/haproxy -c -q -f /etc/haproxy/haproxy.conf
if [ $? -ne 0 ]; then
echo "Errors found in configuration file."
return 1
fi
echo -n "Starting HAProxy: "
daemon /usr/local/haproxy-1.5.5/sbin/haproxy -D -f /etc/haproxy/haproxy.conf -p /var/run/haproxy.pid
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/haproxy
return $RETVAL
}
stop() {
echo -n "Shutting down HAProxy: "
killproc haproxy -USR1
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/haproxy
[ $RETVAL -eq 0 ] && rm -f /var/run/haproxy.pid
return $RETVAL
}
restart() {
/usr/local/haproxy-1.5.5/sbin/haproxy -c -q -f /etc/haproxy/haproxy.conf
if [ $? -ne 0 ]; then
echo "Errors found in configuration file."
return 1
fi
stop
start
}
check() {
/usr/local/haproxy-1.5.5/sbin/haproxy -c -q -V -f /etc/haproxy/haproxy.conf
}
rhstatus() {
status haproxy
}
reload() {
/usr/local/haproxy-1.5.5/sbin/haproxy -c -q -f /etc/haproxy/haproxy.conf
if [ $? -ne 0 ]; then
echo "Errors found in configuration file."
return 1
fi
echo -n "Reloading HAProxy config: "
/usr/local/haproxy-1.5.5/sbin/haproxy -f /etc/haproxy/haproxy.conf -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid)
success $"Reloading HAProxy config: "
echo
}
# Possible parameters
case "$1" in
start)
start
;;
stop)
stop
;;
status)
rhstatus
;;
restart)
restart
;;
reload)
reload
;;
checkconfig)
check
;;
*)
echo "Usage: haproxy {start|stop|status|restart|reload|checkconfig}"
exit 1
esac
exit 0
授权:
# chmod +x /etc/init.d/haproxy
编辑haproxy配置文件:
# mkdir /etc/haproxy
# touch /etc/haproxy/haproxy.conf
# vi /etc/haproxy/haproxy.conf
global
maxconn 4096 #默认最大连接数
pidfile /var/run/haproxy.pid #haproxy的pid存放路径
daemon #以后台形式运行haproxy
nbproc 1 #进程数量
defaults
log global
mode http #所处理的类别 (#7层 http;4层tcp )
retries 3 #三次连接失败就认为是服务器不可用
option httplog
option httpclose
option redispatch #serverId对应的服务器挂掉后,强制定向到其他健康的服务器
option abortonclose #当服务器负载很高的时候,自动结束掉当前队列处理比较久的连接
maxconn 4096 #最大连接数
timeout connect 50000 #连接超时
timeout client 50000 #客户端超时
timeout server 50000 #服务器超时
balance roundrobin #默认的负载均衡的方式,轮询方式
listen mysql_proxy
bind *:3366 #监听端口
mode tcp #tcp的4层模式
balance roundrobin
option tcpka
option httpchk
server mysqldb1 172.16.10.70:3306 weight 1 #weight代表权重
server mysqldb1 172.16.10.71:3306 weight 1 #weight代表权重
listen stats
bind *:8888
mode http
option httplog
option httpclose
balance roundrobin
stats refresh 5s
stats uri / #网站健康检测URL,用来检测HAProxy管理的网站是否可以用,正常返回200,不正常返回503
stats realm Haproxy\ Statistics
stats auth admin:admin #账号密码
启动并检查:
# service haproxy start
# netstat -plantu | grep 3366
tcp 0 0 0.0.0.0:3366 0.0.0.0:* LISTEN 23626/haproxy
发表评论
-
Centos7 部署 Prometheus、Grafana、Cadvisor
2020-06-03 10:41 1119概述 Prometheus (中文名:普罗米修斯)是由 Sou ... -
CentOS7 部署 K8S 过程及问题处理
2020-06-03 10:35 1824前提 前提:VirtualBox CentOS7 物理机IP ... -
阿里云服务器ESC Centos下安装配置svn服务器
2017-05-16 13:35 9071.检查是否已安装 rpm -qa subversion ... -
Centos7 部署 Kafka 集群
2016-06-06 15:08 910概述 Kafka特性: 1、高吞吐量、低延迟:Kafka每 ... -
CentOS 6.3 安装 Zabbix
2015-11-05 10:36 882Linux下常用的系统监控软件有Nagios、Cacti、Za ... -
CentOS 6.3 安装 mysql-cluster-gpl-7.4.7
2015-10-14 15:32 4287什么是MySQL集群 MySQL集 ... -
CentOS 6.3 安装 Keepalived
2015-08-28 16:43 1500Keepalived is a routing softwar ... -
Linux的IO模型介绍
2015-08-26 15:09 1250阻塞:用户进程访问数据时,如果未完成IO,等待IO操作完成 ... -
CentOS 6.3 安装 ActiveMQ
2015-08-25 14:36 20561. tar -zvxf apache-activemq-5. ... -
CentOS 6.3 启动\停止Oracle
2015-08-14 13:46 1131在CentOS 6.3下安装完Oracle Database ... -
CentOS 6.3 安装 Redis
2015-08-03 15:13 8571. tar -zvxf redis-3.0.0.tar.gz ... -
CentOS下SSH免密码登录的配置
2015-07-31 09:44 2674整体流程: 1.在客户机 ... -
CentOS下service zookeeper does not support chkconfig的解决办法
2015-07-07 15:46 8016最初的zookeeper执行脚本 ... -
CentOS 6.3 安装 JDK
2015-05-12 11:19 542好久没写点东西了,今天简单的介绍CentOS下安装JDK 首 ...
相关推荐
CentOS 6.3 安装VMTools 本篇为大家介绍如何在CentOS 6.3中安装VMTools
CentOS 6.3安装(超级详细图解教程) 相当齐全
CentOS6.3安装(超级详细图解教程)。具体软件安装步骤与方法。
Centos6.3 yum安装lamp架构
CentOS 6.3安装文档 word版
Centos6.3安装教您如何按照centos,已经出现的常见问题的解决
主要是针对配置centos6.3版本的安装、python26的安装、python26模块的安装、nginx服务的安装、hg安装、解决乱码问题及ftp问题,centos6.3版本的安装与配置,安装过程中的配置,安装包选择
NULL 博文链接:https://love-66521.iteye.com/blog/1622449
解决红帽linux下载yum源问题,或其他linux系统yum源
Oracle 11gR2 For Centos6.3数据库安装文档 Oracle 11gR2 For Centos6.3数据库安装文档
CentOS6.3源码安装mysql5.6方法.pdf
还不错的,很实用。希望大家能够喜欢,以后多多交流。
详细讲解安装CentOS6.3操作系统,非常详细的安装步骤。
CentOS6.3 Linux操作系统图文安装教程
elfutils-libelf-devel-0.152-1.el6.i686.rpm
CentOS6.3安装TimesTen.docx
CentOS 6.3安装(超级详细图解教程) ,最新的CentOS,操作系统安装教程。
Centos 6.3最小化安装桌面脚本 在最小化系统安装桌面
CentOS6.3安装和配置KVM的详细教程