zoukankan      html  css  js  c++  java
  • HAProxy负载均衡安装配置

    1.下载HAProxy
       http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.22.tar.gz
     
    2. 安装haproxy
       #tar zxvf haproxy-1.4.22.tar.gz
       #cd haproxy-1.4.22
       #make TARGET=linux26
       #make install   
       
    3. 创建haproxy用户和组
       #groupadd haproxy
       #useradd haproxy(useradd -g haproxy haproxy)
      
    4、haproxy配置文件(/etc/haproxy.cfg)
    ----------------------------------------------------------------------------------------------------------
    global
            log 127.0.0.1   local0
            maxconn 4096
            chroot /usr/local
            uid 99
            gid 99
            daemon
            nbproc 1
            pidfile /usr/local/run/haproxy.pid
            #debug  
            #quiet  
     
    defaults
            log     127.0.0.1       local3
            mode    http
            option  dontlognull  
            retries 2
            maxconn 2000
            balance roundrobin
            contimeout      5000
            clitimeout      50000
            srvtimeout      50000
     
    listen  web_proxy 0.0.0.0:1080
            option  httpchk GET /ping.jsp
            stats   uri     /haproxy-stats
     
    listen  postgres
            bind    0.0.0.0:5433
            mode    tcp
            balance roundrobin
            server  db1 192.168.111.151:5432 weight 1 maxconn 10000 check inter 10s
            server  db2 192.168.111.152:5432 weight 1 maxconn 10000 check inter 10s
            server  db3 192.168.111.153:5432 weight 1 maxconn 10000 check inter 10s
            server  db4 192.168.111.154:5432 weight 1 maxconn 10000 check inter 10s
            server  db5 192.168.111.155:5432 weight 1 maxconn 10000 check inter 10s
            server  db6 192.168.111.156:5432 weight 1 maxconn 10000 check inter 10s
            server  db7 192.168.111.157:5432 weight 1 maxconn 10000 check inter 10s
            server  db8  192.168.111.158:5432 weight 1 maxconn 10000 check inter 10s
    ----------------------------------------------------------------------------------------------------------
    5. 创建haproxy服务
    1)创建haproxy启动脚本
    #/etc/init.d/haproxy
    文件内容如下
    ----------------------------------------------------------------------------------------------------------
    #! /bin/sh
     
    PROGDIR=/usr/local
    PROGNAME=haproxy
    DAEMON=$PROGDIR/sbin/$PROGNAME
    CONFIG=/etc/$PROGNAME.cfg
    PIDFILE=$PROGDIR/run/$PROGNAME.pid
    DESC="HAProxy daemon"
    SCRIPTNAME=/etc/init.d/$PROGNAME
     
    # Gracefully exit if the package has been removed.
    test -x $DAEMON || exit 0
    start()
    {
        echo -n "Starting $DESC: $PROGNAME"
        $DAEMON -f $CONFIG
        echo "."
    }
    stop()
    {
        echo -n "Stopping $DESC: $PROGNAME"
        cat $PIDFILE | xargs kill
        echo "."
    }
    case "$1" in
      start)
        start
        ;;
      stop)
        stop
        ;;
    *)
        echo "Usage: $SCRIPTNAME {start|stop}" >&2
        exit 1
        ;;
    esac
    exit 0
    ----------------------------------------------------------------------------------------------------------
    启动服务
    service haproxy start 
    可能问题:
    创建run目录
    2)创建haxproxy服务
    #chkconfig --add haproxy
    #chkconfig haproxy on
     
    六、测试
     
    在浏览器里面输入:http://192.168.111.150:1080/haproxy-stats,可以看到haproxy的监控界面。
  • 相关阅读:
    商品翻牌效果(纯css)
    3D旋转相册(纯css)
    3D旋转
    前端搜索js
    js打字的效果
    淡入淡出,类似于轮播图
    返回顶部
    java设计模式--状态模式
    java设计模式--抽象工厂模式
    java设计模式--观察者模式
  • 原文地址:https://www.cnblogs.com/marsprj/p/4550584.html
Copyright © 2011-2022 走看看