nics 发表于 2019-1-1 12:46:03

linux运维之Haproxy

  Haproxy负载均衡搭建
  1、搭建环境
      3台基于Glassfish的Web服务器IP地址为:192.168.100.22, 192.168.100.23 ,192.168.100.24
      1台Haproxy服务器的外网IP为:192.168.1.31 ,内网IP为:192.168.100.31
      服务器OS均为Centos5.5 X86 64
  2、Haproxy的安装和配置
      从http://haproxy.1wt.eu/上下载其最新版本,通过FileZilla软件上传到192.168.1.31服务器上,进入上传的目录后
  # tar -zxvf haproxy-1.4.15
  # make TARGET=linux26 PREFIX=/home/haproxy install(编译文件到/home/haproxy文件夹下)
  # cd /home/haproxy
  # mkdir conf(创建conf目录)
  # cd conf
  # vi haproxy.cfg(创建haproxy.cfg配置文件)
  global
      log 127.0.0.1   local0
      #log 127.0.0.1local1 notice
      #log loghost    local0 info
      maxconn 65535
      # maxpipes 4096
      #chroot /home/haproxy
      uid 501
      gid 501
      daemon
      nbproc 3
      #pidfile /home/haproxy/logs/haproxy.pid
      #debug
      quiet
  defaults
      log   127.0.0.1       local3
      mode    http
      optionhttplog
      optionhttpclose
      optiondontlognull
      optionforwardfor
      optionredispatch
      retries 3
      maxconn 4096
      balance roundrobin
      stats refresh 30s
      stats   uri   /haproxy-stats
      stats realm Haproxy\ statistics
      stats auth admin:passwd
      contimeout      5000
      clitimeout      50000
      srvtimeout      50000
  listenhttp-in
      bind 0.0.0.0:80
      optionhttpchk GET /ping.jsp
      servers1 192.168.100.22:81 weight 3 check inter 40000 rise 2 fall 3
      servers2 192.168.100.23:81 weight 3 check inter 40000 rise 2 fall 3
      servers3 192.168.100.24:81 weight 3 check inter 40000 rise 2 fall 3

  # /home/haproxy/sbin/haproxy -f /home/haproxy/conf/haproxy.cfg   (启动Haproxy服务,可以设置成开机自启动,这里并不做配置,主要是因为Haproxy双机热备是要做,在文档的最后会补上自启动的方法)
  如果没有启动没有报错的话,在浏览器上输入http://192.168.1.31/haproxy-stats 就会看到

http://blog.运维网.com/attachment/201109/171250482.jpg
  补:开机自启动
  # echo "/home/haproxy/sbin/haproxy -f /home/haproxy/conf/haproxy.cfg" >> /etc/rc.local
  接下来是"linux运维之Glassfish"



页: [1]
查看完整版本: linux运维之Haproxy