haproxy安装配置介绍
来源:互联网 发布:淘宝网户外刀 编辑:程序博客网 时间:2024/06/03 02:27
haproxy利用单进程来接受请求,可以作为反向代理服务器来使用。代理的程序包括httpd和tcp程序,下面简单的介绍下安装使用。
环境描述:
client 访问的是web服务,地址为192.168.1.1,client的地址为192.168.1.100,后端的两个服务器的IP地址分别为172.16.1.10/11,haproxy连接服务器的地址为172.16.1.1。情况交代完毕。开始配置。
haproxy在红帽6.4版本上可以直接的进行安装。
rpm –ivh haproxy***.rpm
开始配置:
vi /etc/haproxy/haproxy.cfg
#---------------------------------------------------------------------
# Example configuration for a possible webapplication. See the
# full configuration options online.
#
# http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------
#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
#to have these messages end up in /var/log/haproxy.log you will
#need to:
#
#1) configure syslog to accept network log events. This is done
# by adding the '-r' option tothe SYSLOGD_OPTIONS in
# /etc/sysconfig/syslog
#
#2) configure local2 events to go to the /var/log/haproxy.log
# file. A line like thefollowing can be added to
# /etc/sysconfig/syslog
#
# local2.* /var/log/haproxy.log
#
log 127.0.0.1 local2
打开配置文件会有这样的提示,我们需要做的是,按照提示修改syslog的配置文件,
vi/etc/sysconfig/rsyslog
# Options forrsyslogd
# Syslogdoptions are deprecated since rsyslog v3.
# If you want touse them, switch to compatibility mode 2 by "-c 2"
# Seersyslogd(8) for more details
SYSLOGD_OPTIONS="-c 2 -r"
然后定义local2
vi /etc/rsyslog.conf
添加这样的一行就OK了。
local2.* /var/log/haproxy.log
而后重启rsyslog服务。
service rsyslogrestart
下面开始定义haproxy的正文内容。
defaults
mode http //mode可以有http和tcp两种。
log global //日志用的是全局的日志
option httplog //日志格式按照http的格式来记录
option dontlognull //对于上级负载发过来的监测心跳的信息不予以记录,就是不是web请求的不记录到日志中去。
option http-server-close // HAProxy工作于隧道模式,其仅检查每一个连接的第一个请求,因此,仅第一个请求报文被附加此首部。如果想为每一个请求都附加此首部,请确保同时使用了“option httpclose”、“option forceclose”和“option http-server-close”几个option。
option forwardfor except 127.0.0.0/8 //记录真实的访问地址,除了127.0.0.1
option redispatch
retries 3
timeout http-request 10s //http请求超时时间为10s
timeout queue 1m //超时的队列
timeout connect 10s //连接超时为10s
timeout client 1m //客户端连接超时1m
timeout server 1m //服务器超时时间 1m
timeout http-keep-alive 10s //http-keep-alive超时时间为10s
timeout check 10s //检查的超时时间为10s
maxconn 3000 //最大的连接数为3000
listen stats
mode http //模式为http
bind *:1080 //监听在1080端口上
stats enable //开启状态查看
stats hide-version //查看haproxy的时候隐藏版本号
stats uri /haproxyadmin //查看状态的时候uri为根目录下的/haproxyadmin
stats realm Haproxy\ Statistics //查看的时候的提示
stats auth admin:admin //登录查看界面的时候的用户名和密码
stats admin if TRUE //如果验证通过则允许登录
frontend web
bind *:80 //监听在80 端口上
mode http //模式为http
log global //日志采用的是全局日志
option httpclose //当访问结束自动关闭http连接
option logasap
option dontlognull //不将空请求记录到日志中去
capture request header Host len 40 //抓取请求报文头部Host的前40个byte
capture request header Referer len 200 //抓取请求报文头部Referer的前200个byte
default_backend servers //接受到的请求转到到servers上面去
option forwardfor //记录真实的访问地址
backend servers
balance roundrobin //后端服务器提供服务时采用加权轮询的方法
server web1 192.168.5.150:80 check maxconn 4000 //web1 检查方式和最大的连接数量
server web2 192.168.5.200:80 check maxconn 4000 //web2 检查方式和最大的连接数量
在check中可以使用 inter=2fall=2 rise=1 //当服务器down的时候需要检查两次,每次的间隔为2S,如果有服务器上线的话,只需要检查一次就好了。
另外在配置提供服务的Apache上面。我们需要修改配置文件中的日志的记录格式,从而使Apache记录真实的IP地址。如果有疑问可以参照本人的另外一篇博客又讲到。今天就到这了,后面是keepalived+Haproxy,敬请期待…………………..
- haproxy安装配置介绍
- haproxy安装配置介绍
- haproxy安装与配置
- haproxy安装与配置
- Haproxy安装配置
- Haproxy安装和配置
- Haproxy安装与配置
- haproxy安装与配置
- Haproxy+keepalived安装配置
- haproxy 安装和配置
- Haproxy 安装 配置
- haproxy安装配置
- Haproxy安装及配置
- HAProxy 安装与配置
- Haproxy安装与配置
- haproxy 安装配置
- haproxy安装配置
- HAProxy安装及配置
- 蛇形矩阵
- java 数组中的最大值
- Intel Threading Building Blocks 编程指南:简单循环的并行化
- (java)Power of Two
- 数据库交换表的名称
- haproxy安装配置介绍
- Java中的方法覆盖
- js常用事件总结
- android 设置textview中划线效果
- Android Studio中代码混淆
- OSGCopy例子解析
- Intel Threading Building Blocks 编程指南 : 内存分配
- 计算机术语 blob
- PE总结2---PE文件结构