奥德赛F9 发表于 2019-1-1 12:08:18

haproxy安装配置

  1.安装

  # wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.20.tar.gz
  #tar zxvf haproxy-1.3.20.tar.gz
  #cdhaproxy-1.3.20
  #make TARTGET=linux26 PREFIX=/data/haproxy
  #make install PREFIX=/data/haproxy
      说明:

  

TARGET:
指定对目标操作系统在编译的时候进行优化,可选择如下值之一:
linux22 for Linux 2.2
linux24 for Linux 2.4 and above (default)
linux24e for Linux 2.4 with support for a working epoll (> 0.21)
linux26 for Linux 2.6 and above
solaris for Solaris 8 or 10 (others untested)
freebsd for FreeBSD 5 to 8.0 (others untested)
openbsd for OpenBSD 3.1 to 4.6 (others untested)
cygwin for Cygwin
generic for any other OS.
custom to manually adjust every setting
如果目标系统不确定,则保持默认值generic即可。
  2.配置
  安装完毕后进入安装目录
  #cd /data/haproxy
  默认是没有.cfg文件的,新建之
  haproxy:配置分几部分

  global :参数是进程级的,主要是系统相关
  default :配置默认参数,可用到frontend,backend
  frontend:接受请求的前端
  backend:后端集群的配置
  vim haproxy.cfg:
  
  
global
log 127.0.0.1 local0#日志输出配置
maxconn 4096    #最大连接
chroot /data/haproxy
uid 500      #运行用户
gid 500      #运行组
daemon       #以后台进程方式运行
nbproc 2   #开启2个实例
pidfile /data/haproxy/haproxy.pid#pid位置
defaults
log 127.0.0.1 local3#日志文件的输出定向
mode http             #所处理的类别,默认采用http模式,可配置成tcp作4层消息转发
option httplog      #日志类别,采用httplog
option dontlognull   
option forwardfor   #如果后端服务器需要获得客户端真实ip需要配置的参数,可以从Http Header中获得客户端ip
option httpclose      #每次请求完毕后主动关闭http通道,haproxy不支持keep-alive,只能模拟这种模式的实现
retries 3             #3次连接失败就认为服务器不可用,主要通过后面的check检查
option redispatch   #当serverid对应的服务器挂掉后,强制定向到其他健康服务器
maxconn 4000          #最大连接数
stats uri /haproxy-admin#haproxy 监控页面的访问地址
contimeout      5000            #连接超时时间
clitimeout      50000         #客户端连接超时时间
srvtimeout      50000         #服务器端连接超时时间
stats auth www:www          #设置监控页面的用户和密码 www
stats hide-version          #隐藏统计页面的HAproxy版本信息
frontend http-in             #前台
bind *:8000
mode http
option httplog
log global
default_backend htmpool#服务器池
backend htmpool            #后端
balance leastconn      #负载均衡算法
option httpchk HEAD /index.html HTTP/1.0#健康检查
server web1 122.225.98.82:80 cookie 1 weight 5 check inter 2000 rise 2 fall 3
server web2 122.225.98.83:80 cookie 1 weight 5 check inter 2000 rise 2 fall 3  
3.日志
# vim /etc/syslog.conf
在最下边增加
local3.*         /var/log/haproxy.log
local0.*         /var/log/haproxy.log
service syslog restart
  

  4.启动
启动服务:
# /data/haproxy/sbin/haproxy -f /data/haproxy/haproxy.cfg
重启服务:
#/data/haproxy/sbin/haproxy -f /data/haproxy/haproxy.cfg -st `cat /data/haproxy/haproxy.pid`
  5.访问
http://s3.运维网.com/wyfs02/M02/23/9B/wKiom1M7z16iF9rTAAW_0HNifGE708.jpg



页: [1]
查看完整版本: haproxy安装配置