码迷,mamicode.com
首页 > Web开发 > 详细

HAproxy负载均衡WEB

时间:2016-12-16 23:37:43      阅读:341      评论:0      收藏:0      [点我收藏+]

标签:haproxy   负载均衡   web

HAproxy负载均衡WEB

技术分享

  

26.211和26.212安装apache web服务这里省略

yum install -y httpd 

分部26.211和26.212上创建两个web页面

技术分享

技术分享

 

 

在192.16.26.210上安装HAproxy:1.5.4

Yum install –y haproxy

技术分享

编辑HAproxy配置文件:

vim /etc/haproxy/haproxy.cfg

技术分享

配置文件内容如下:

#---------------------------------------------------------------------

# Example configuration for a possible web application.  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 to the SYSLOGD_OPTIONS in

    #    /etc/sysconfig/syslog

    #

    # 2) configure local2 events to go to the /var/log/haproxy.log

    #   file. A line like the following can be added to

    #   /etc/sysconfig/syslog

    #

    #    local2.*                       /var/log/haproxy.log

    #

    log         127.0.0.1 local2

 

    chroot      /var/lib/haproxy

    pidfile     /var/run/haproxy.pid

    maxconn     4000

    user        haproxy

    group       haproxy

    daemon

 

    # turn on stats unix socket

    stats socket /var/lib/haproxy/stats

 

#---------------------------------------------------------------------

# common defaults that all the ‘listen‘ and ‘backend‘ sections will

# use if not designated in their block

#---------------------------------------------------------------------

defaults

    mode                    http

    log                     global

    option                  httplog

    option                  dontlognull

    option http-server-close

    option forwardfor       except 127.0.0.0/8

    option                  redispatch

    retries                 3

    timeout http-request    10s

    timeout queue           1m

    timeout connect         10s

    timeout client          1m

    timeout server          1m

    timeout http-keep-alive 10s

    timeout check           10s

    maxconn                 3000

 

#---------------------------------------------------------------------

# main frontend which proxys to the backends

#---------------------------------------------------------------------

#frontend  main *:5000

#    acl url_static       path_beg       -i /static /images /javascript /stylesheets

#    acl url_static       path_end       -i .jpg .gif .png .css .js

#

#    use_backend static          if url_static

#    default_backend             app

#

##---------------------------------------------------------------------

## static backend for serving up images, stylesheets and such

##---------------------------------------------------------------------

#backend static

#    balance     roundrobin

#    server      static 127.0.0.1:4331 check

#

##---------------------------------------------------------------------

## round robin balancing between the various backends

##---------------------------------------------------------------------

#backend app

#    balance     roundrobin

#    server  app1 127.0.0.1:5001 check

#    server  app2 127.0.0.1:5002 check

#    server  app3 127.0.0.1:5003 check

#    server  app4 127.0.0.1:5004 check

frontend websrv *:80

   default_backend webservers

backend webservers

     balance  roundrobin

     server node2 192.168.26.211:80 check

     server node3 192.168.26.212:80 check

保存退出:

启动HAproxy服务。

service haproxy start

技术分享

在192.168.26.210上执行:ss  –tnlp   #查看HAproxy是否监听80端口

技术分享

 

打开浏览器:不断刷新访问192.168.26.210观察结果

技术分享

 

技术分享


本文出自 “在路上” 博客,请务必保留此出处http://jdonghong.blog.51cto.com/3473478/1883368

HAproxy负载均衡WEB

标签:haproxy   负载均衡   web

原文地址:http://jdonghong.blog.51cto.com/3473478/1883368

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!