[转帖]HAProxy 7层 负载均衡
HAProxy 7层 负载均衡
https://www.cnblogs.com/jicki/p/5546902.html HAProxy
系统 CentOS 5.8 x64
wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.26.tar.gz
cd haproxy-1.3.26
make TARGET=linux26 PREFIX=/opt/local/haproxy
make install PREFIX=/opt/local/haproxy
mkdir /opt/local/haproxy/conf
cd /opt/local/haproxy/conf/
vim haproxy.cfg
后台配置模式
------------------------------------------------------------------------------------------------
global
log 127.0.0.1 local0
maxconn 65535
chroot /opt/local/haproxy
uid 502
gid 502
daemon
nbproc 8
pidfile /opt/local/haproxy/haproxy.pid
defaults
log 127.0.0.1 local3
mode http
option httplog
option httpclose
option dontlognull
option forwardfor
option redispatch
retries 2
maxconn 2000
balance roundrobin
stats uri /haproxy-stats
timeout connect 5000
timeout client 50000
timeout server 50000
listen 172.24.0.100
bind *:80
mode http
option httplog
log global
option httpchk HEAD /index.jsp HTTP/1.0
server web1 172.24.0.101:8080 weight 2 check inter 2000 rise 2 fall 3
server web2 172.24.0.102:8080 weight 2 check inter 2000 rise 2 fall 3
添加 日志
vi /etc/syslog.conf (centos 5.X版本)
vi /etc/rsyslog.conf (centos 6.X版本)
local3.* /var/log/haproxy.log
local0.* /var/log/haproxy.log
vi /etc/sysconfig/syslog (centos 5.X版本)
vi /etc/sysconfig/rsyslog (centos 6.X版本)
SYSLOGD_OPTIONS="-m 0"
修改为
SYSLOGD_OPTIONS="-r -m 0"
重启日志服务
service syslog restart
/opt/local/haproxy/sbin/haproxy -f /opt/local/haproxy/haproxy.cfg 启动haproxy
或者用 脚本 来做启动 重启 关闭
vi /etc/init.d/haproxy
-----------------------------------------------------------------------------------------
#!/bin/bash
BASE_DIR="/opt/local/haproxy"
ARGV="$@"
start()
{
echo "START HAPoxy SERVERS"
$BASE_DIR/sbin/haproxy -f $BASE_DIR/conf/haproxy.cfg
}
stop()
{
echo "STOP HAPoxy Listen"
kill -TTOU $(cat $BASE_DIR/haproxy.pid)
echo "STOP HAPoxy process"
kill -USR1 $(cat $BASE_DIR/haproxy.pid)
}
case $ARGV in
start)
start
ERROR=$?
;;
stop)
stop
ERROR=$?
;;
restart)
stop
start
ERROR=$?
;;
*)
echo "hactl.sh [start|restart|stop]"
esac
exit $ERROR
--------------------------------------------------------------------------------------
chmod +x /etc/init.d/haproxy
1.4版本以后的 启动 出现
--------------------------------------------------------------------------------------------------
[WARNING] 022/092301 (26090) : Proxy 'www.xxx.com': in multi-process mode, stats will be limited to process assigned to the current request.
那是因为配置文件 nbproc > 1 所导致的...可将 配置文件 nbproc 设置为 1 或者修改编译文件..
在源码配置src/cfgparse.c找到如下行
if (nbproc > 1) {
if (curproxy->uri_auth) {
Warning("Proxy '%s': in multi-process mode, stats will be limited to process assigned to the current request.\n", curproxy->id);
if (!LIST_ISEMPTY(&curproxy->uri_auth->admin_rules)) {
Warning("Proxy '%s': stats admin will not work correctly in multi-process mode.\n", curproxy->id);
}
修改 nbproc > 1 这个数值就可以...
----------------------------------------------------------------------------------------------------
option httpchk HEAD /index.php HTTP/1.0 这个为监控页面..在跟目录增加index.php文件,否则报503错误.
web监控 页面 http://www.xxxx.com/haproxy-stats
IP数据转发设置
-------------------------------------------------------------------------------
global maxconn 65535 #最大连接数,HAProxy是数据转发,每条数据链路占用两个连接。
daemon #daemon方式运行
nbproc 1
group nobody
user nobody
defaults
timeout server 86400s
timeout client 86400s
timeout connect 8640s
#log 127.0.0.1 local7.* warning
listen xxxxx_80
bind 本机IP:80
mode tcp #tcp模式,只转发,不分析
option tcpka
option srvtcpka
option clitcpka
server xxxxxx_80_src 目标IP:80 check inter 1000 rise 1 fall 2 #目标服务器定义
-------------------------------------------------------------------------------------
[转帖]HAProxy 7层 负载均衡的更多相关文章
- HAProxy 7层 负载均衡
系统 CentOS 5.8 x64 wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.26.tar.gz cd haproxy-1.3.2 ...
- 大型网站系统架构实践(四)http层负载均衡之haproxy实践篇(一)
方案 上篇文章讲到了负载均衡的相关理论知识,这篇文章我打算讲讲实践方法以及实践中遇到的问题 方案:haproxy http层负载均衡 安装一个haproxy服务,两个web服务 haproxy:192 ...
- http层负载均衡之haproxy
http层负载均衡之haproxy实践篇(一) 方案 上篇文章讲到了负载均衡的相关理论知识,这篇文章我打算讲讲实践方法以及实践中遇到的问题 方案:haproxy http层负载均衡 安装一个hapro ...
- http层负载均衡之 haproxy实践篇
方案 上篇文章讲到了负载均衡的相关理论知识,这篇文章我打算讲讲实践方法以及实践中遇到的问题 方案:haproxy http层负载均衡 安装一个haproxy服务,两个web服务 haproxy:192 ...
- 四层和七层负载均衡的特点及常用负载均衡Nginx、Haproxy、LVS对比
一.四层与七层负载均衡在原理上的区别 图示: 四层负载均衡与七层负载均衡在工作原理上的简单区别如下图: 概述: 1.四层负载均衡工作在OSI模型中的四层,即传输层.四层负载均衡只能根据报文中目标地址和 ...
- Windows Azure支持七层负载均衡--Application Gateway
一直以来Windows Azure的负载均衡(Loadbalancer)功能一直被客户诟病,无法其竞争对手(特别是国内的云厂商)匹敌. Windows Azure的负载均衡器是四层的,前期的版本不支持 ...
- 项目实战4—HAProxy实现高级负载均衡实战和ACL控制
haproxy实现高级负载均衡实战 环境:随着公司业务的发展,公司负载均衡服务已经实现四层负载均衡,但业务的复杂程度提升,公司要求把mobile手机站点作为单独的服务提供,不在和pc站点一起提供服务 ...
- 项目详解4—haproxy 反向代理负载均衡
一.企业服务架构图及负载均衡的要求 1.场景说明 在企业生产环境中,每天会有很多的需求变更,比如增加服务器.新业务上线.url路由修改.域名配置等等,对于前端负载均衡设备来说,容易维护,复杂度低,是首 ...
- Web负载均衡学习笔记之四层和七层负载均衡的区别
0x00 简介 简单理解四层和七层负载均衡: ① 所谓四层就是基于IP+端口的负载均衡:七层就是基于URL等应用层信息的负载均衡:同理,还有基于MAC地址的二层负载均衡和基于IP地址的三层负载均衡. ...
随机推荐
- CF1203F2 Complete the Projects (hard version)(结论+背包+贪心)
题目 做法 对于加分的直接贪心 而掉分的用排序后的背包动规 假设有两个物品\((a_1,b_1)(a_2,b_2)\) 选第一个物品后无法选择第二个物品,假设开始值为\(r\):\(r>a_1, ...
- ZR#989
ZR#989 先吐槽一下这个ZZ出题人,卡哈希表. 我就不写那个能过的类高精了,直接写哈希的题解 解法: 判断两个数相加结果是否等于第三个数, 可以直接用 hash判断. #include<io ...
- spark-shell启动错误
18/06/24 16:41:40 ERROR spark.SparkContext: Error initializing SparkContext.java.net.BindException: ...
- js函数运行方式一览
定义对象然后调用 j = {} j["delete"]=function () { console.log("ok") } j["delete&quo ...
- VUE导入Excel
import FilenameOption from './components/FilenameOption' import AutoWidthOption from './components/A ...
- Microsoft OA
Given a string S consisting of N lowercase letters, return the minimum number of letters that must b ...
- Leetcode: Most Stones Removed with Same Row or Column
On a 2D plane, we place stones at some integer coordinate points. Each coordinate point may have at ...
- ModSecurity:一款优秀的开源WAF
一.ModSecurity3.0介绍 ModSecurity是一个开源的跨平台Web应用程序防火墙(WAF)引擎,用于Apache,IIS和Nginx,由Trustwave的SpiderLabs开发. ...
- Java 有双引号的字符串处理
public class Test{ public static void main(String[] args){ String str1 = "\"name\"&qu ...
- 013-docker-安装-Centos7
1.搜索镜像 docker search centos 2.拉取合适镜像 选择合适tag:https://hub.docker.com/,下载合适版本 docker pull centos:6.6 d ...