haproxy install

haproxy 安装

  1. haproxy 安装

    1
    2
    3
    4
    5
    6
    [root@localhost app]# useradd -s /sbin/nologin haproxy

    [root@localhost app]# tar xzf haproxy-1.7.2.tar.gz
    [root@localhost app]# cd haproxy-1.7.2
    [root@localhost haproxy-1.7.2]# make TARGET=generic PREFIX=/mnt/app/haproxy
    [root@localhost haproxy-1.7.2]# make install PREFIX=/mnt/app/haproxy
  2. haproxy 环境变量

    1
    2
    3
    4
    [root@localhost haproxy-1.7.2]# echo 'export HAPROXY_HOME=/mnt/app/haproxy' | tee /etc/profile.d/haproxy.sh   
    [root@localhost haproxy-1.7.2]# echo 'export HAPROXY_BIN=${HAPROXY_HOME}/sbin' | tee -a /etc/profile.d/haproxy.sh
    [root@localhost haproxy-1.7.2]# echo 'export PATH=${HAPROXY_BIN}:$PATH' | tee -a /etc/profile.d/haproxy.sh
    [root@localhost haproxy-1.7.2]# source /etc/profile
  3. haproxy 创建配置文件

    1
    2
    [root@localhost haproxy-1.7.2]# mkdir -p /mnt/app/haproxy/conf
    [root@localhost haproxy-1.7.2]# touch /mnt/app/haproxy/conf/haproxy.cfg
  4. haproxy 配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    [root@localhost app]# vim /mnt/app/haproxy/conf/haproxy.cfg
    global
    log /mnt/log/haproxy 127.0.0.1 local0
    log /mnt/log/haproxy 127.0.0.1 local1 notice
    stats socket /mnt/log/haproxy/haproxy.socket mode 770 level admin
    pidfile /mnt/log/haproxy/haproxy.pid
    maxconn 5000
    user haproxy
    group haproxy
    deamon

    defaults
    log global
    mode tcp
    option tcplog
    option dontlognull
    retries 3
    option redispatch
    timeout connect 5s
    timeout client 120s
    timeout server 120s

    listen haproxy_stats
    bind 0.0.0.0:8080
    stats refresh 30s
    stats uri /haproxy?stats
    stats realm Haproxy Manager
    stats auth admin:admin
    stats hide-version

    listen rabbitmq_admin
    bind 0.0.0.0:8090
    server rabbit228 192.168.18.228:15672
    server rabbit229 192.168.18.229:15672
    server rabbit230 192.168.18.230:15672

    listen rabbitmq_cluster
    bind 0.0.0.0:5672
    mode tcp
    option tcplog
    option clitcpka
    timeout client 3h
    timeout server 3h
    balance roundrobin
    server rabbit228 192.168.18.228:15672 check inter 5s rise 2 fall 3
    server rabbit229 192.168.18.229:15672 check inter 5s rise 2 fall 3
    server rabbit230 192.168.18.230:15672 check inter 5s rise 2 fall 3
  5. haproxy 启动

    1
    [root@localhost haproxy-1.7.2]# /mnt/app/haproxy/sbin/haproxy -f /mnt/app/haproxy/conf/haproxy.cfg
  6. 查看haproxy状态

    1
    2
    在浏览器中打开:
    http://192.168.18.223:8080/haproxy?stats