RabbitMQ install

Java 安装

1
2
3
4
5
6
7
8
[root@localhost app]# tar xzf jdk-8u111-linux-x64.tar.gz
[root@localhost app]# mv jdk1.8.0_111 /mnt/app/java
[root@localhost app]# echo 'JAVA_HOME=/mnt/app/java' | tee /etc/profile.d/java.sh
[root@localhost app]# echo 'JRE_HOME=${JAVA_HOME}/jre' | tee -a /etc/profile.d/java.sh
[root@localhost app]# echo 'CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib' | tee -a /etc/profile.d/java.sh
[root@localhost app]# echo 'export PATH=${JAVA_HOME}/bin:$PATH' | tee -a /etc/profile.d/java.sh
[root@localhost app]# source /etc/profile
[root@localhost app]# java -version

Erlang 安装

1
2
3
4
5
6
7
8
9
10
[root@localhost app]# tar xzf otp_src_19.2.tar.gz
[root@localhost app]# cd otp_src_19.2
[root@localhost otp_src_19.2]# ./configure --prefix=/mnt/app/erlang
[root@localhost otp_src_19.2]# make
[root@localhost otp_src_19.2]# make install

[root@localhost otp_src_19.2]# echo 'export ERLANG_HOME=/mnt/app/erlang' | tee /etc/profile.d/erlang.sh
[root@localhost otp_src_19.2]# echo 'export ERLANG_BIN=${ERLANG_HOME}/bin' | tee -a /etc/profile.d/erlang.sh
[root@localhost otp_src_19.2]# echo 'export PATH=${ERLANG_BIN}:$PATH' | tee -a /etc/profile.d/erlang.sh
[root@localhost otp_src_19.2]# source /etc/profile

RabbitMQ standard install

  1. RabbitMQ 设置主机名

    1
    2
    3
    4
    [root@localhost app]# echo rabbitmq188 | tee /etc/hostname
    [root@localhost app]# echo '192.168.13.188 rabbitmq188' |tee -a /etc/hosts
    [root@localhost app]# hostname rabbitmq188
    [root@localhost app]# $SHELL
  2. RabbitMQ 安装

    1
    2
    3
    4
    [root@localhost app]# xz -d rabbitmq-server-generic-unix-3.6.10.tar.xz
    [root@localhost app]# tar xf rabbitmq-server-generic-unix-3.6.10.tar
    [root@localhost app]# mv rabbitmq_server-3.6.10 /mnt/app/rabbitmq
    [root@localhost app]# chown -R wisdom.wisdom /mnt/app/rabbitmq
  3. RabbitMQ 环境变量

    1
    2
    3
    4
    [root@localhost app]# echo 'export RABBITMQ_HOME=/mnt/app/rabbitmq' |tee /etc/profile.d/rabbitmq.sh
    [root@localhost app]# echo 'export RABBITMQ_BIN=$RABBITMQ_HOME/sbin' |tee -a /etc/profile.d/rabbitmq.sh
    [root@localhost app]# echo 'export PATH=$RABBITMQ_BIN:$PATH' |tee -a /etc/profile.d/rabbitmq.sh
    [root@localhost app]# source /etc/profile
  4. RabbitMQ 配置文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    [wisdom@localhost ~]$ cat > /mnt/app/rabbitmq/etc/rabbitmq/rabbitmq-env.conf <<EOF
    RABBITMQ_MNESIA_BASE=/mnt/data/rabbitmq/mnesia
    RABBITMQ_LOG_BASE=/mnt/log/rabbitmq
    EOF

    [wisdom@localhost ~]$ cat > /mnt/app/rabbitmq/etc/rabbitmq/rabbitmq.config <<EOF
    [
    {rabbit,
    [
    {vm_memory_high_watermark, 0.6},
    {vm_memory_high_watermark_paging_ratio, 0.3},
    {disk_free_limit, "10GB"},
    {hipe_compile, true},
    {queue_index_embed_msgs_below, 4096}
    ]
    }
    ].
    EOF

    [root@localhost app]# mkdir -p /mnt/data/rabbitmq/mnesia
    [root@localhost app]# mkdir -p /mnt/log/rabbitmq
    [root@localhost app]# chown -R wisdom.wisdom /mnt/data/rabbitmq
    [root@localhost app]# chown -R wisdom.wisdom /mnt/log/rabbitmq
  5. RabbitMQ 启动

    1
    2
    3
    4
    5
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmq-server -detached
    or:
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmq-server &

    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl stop
  6. RabbitMQ 安装插件rabbitmq_management(web控制台)

    1
    2
    3
    [root@localhost app]# su - wisdom
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmq-plugins list
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmq-plugins enable rabbitmq_management
  7. RabbitMQ 创建vhost

    1
    2
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl list_vhosts
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl add_vhost /zabbix
  8. RabbitMQ 高可用方案

    1
    2
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl set_policy -p /zabbix ha-all "^" '{"ha-mode":"all"}'
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl list_policies -p /zabbix
  9. RabbitMQ 用户创建

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl list_users
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl delete_user guest

    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl add_user zabbix zabbix123

    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl set_user_tags zabbix administrator monitoring

    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl list_permissions
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl list_user_permissions zabbix
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl set_permissions -p /zabbix zabbix '.*' '.*' '.*'
  10. RabbitMQ 用户操作

    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
    48
    49
    50
    51
    52
    53
    * vhost管理
    //查看vhost
    [wisdom@rabbitmq188 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl list_vhosts

    //创建vhost
    [wisdom@rabbitmq188 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl add_vhost /zabbix

    //删除vhost
    [wisdom@rabbitmq188 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl delete_vhost /zabbix


    * 用户管理
    //创建用户
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl add_user xroot xroot123

    //删除用户
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl delete_user guest

    //修改密码
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl change_password Username Newpassword

    //查看用户列表
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl list_users


    * 用户角色管理
    1. 超级管理员(administrator)
    可登陆管理控制台(启用management plugin的情况下),可查看所有的信息,并且可以对用户,策略(policy)进行操作
    2. 监控者(monitoring)
    可登陆管理控制台(启用management plugin的情况下),同时可以查看rabbitmq节点的相关信息(进程数,内存使用情况,磁盘使用情况等)
    3. 策略制定者(policymaker)
    可登陆管理控制台(启用management plugin的情况下),同时可以对policy进行管理.但无法查看节点的相关信息(上图红框标识的部分)
    4. 普通管理者(management)
    仅可登陆管理控制台(启用management plugin的情况下),无法看到节点信息,也无法对策略进行管理
    5. 其他
    无法登陆管理控制台,通常就是普通的生产者和消费者

    //修改用户角色
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl set_user_tags xroot administrator


    * 用户权限
    //查看指定vhost权限
    [wisdom@rabbitmq188 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl list_permissions -p /

    //查看指定用户权限
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl list_user_permissions xroot

    //为用户设置权限
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl set_permissions -p / xnroot '.*' '.*' '.*'

    //清空所有权限
    [wisdom@localhost ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl clear_permissions
  11. rabbitmq 优化

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    [wisdom@localhost ~]$ cat /mnt/app/rabbitmq/etc/rabbitmq/rabbitmq.config
    [
    {rabbit,
    [
    {vm_memory_high_watermark, 0.6},
    {vm_memory_high_watermark_paging_ratio, 0.3},
    {disk_free_limit, "10GB"},
    {hipe_compile, true},
    {queue_index_embed_msgs_below, 4096}
    ]
    }
    ].

    [wisdom@localhost ~]$ cat /mnt/app/rabbitmq/sbin/rabbitmq-defaults
    PLUGINS_DIR="${RABBITMQ_HOME}/plugins"
    IO_THREAD_POOL_SIZE=16
  12. RabbitMQ 启动脚本

    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
    [wisdom@rabbit67 ~]$ cat /etc/init.d/rabbitmq
    #!/bin/bash
    STATUS=$1
    ROLE='rabbitmq'
    RBSERVER="/mnt/app/${ROLE}/sbin/rabbitmq-server "
    RBCTL="/mnt/app/${ROLE}/sbin/rabbitmqctl "

    if [ $STATUS == "start" ];then
    $RBSERVER &
    fi

    if [ $STATUS == "stop" ];then
    NUM=$(ps -ef|grep -w rabbitmq-server|grep -v grep|awk '{print $2}'|wc -l)
    if [ $NUM != 1 ];then
    echo "Please check $ROLE, There are $NUM processes."
    exit 0
    fi

    $RBCTL stop
    if [ $? == 0 ];then
    echo "$ROLE stoped success."
    else
    echo "$ROLE stoped fail."
    fi
    fi

    if [ $STATUS == "status" ];then
    NUM=$(ps -ef|grep -w rabbitmq-server|grep -v grep|awk '{print $2}'|wc -l)

    if [ $NUM == 0 ];then
    echo "$ROLE is stopped."
    exit 0
    fi

    if [ $NUM != 1 ];then
    echo "Please check $ROLE, There are $NUM processes."
    fi

    PID=$(ps -ef|grep -w rabbitmq-server|grep -v grep|awk '{print $2}')
    echo "$ROLE is running. PID: $PID"
    fi

RabbitMQ cluster install

  1. RabbitMQ 安装

    1
    2
    3
    4
    [root@localhost app]# xz -d rabbitmq-server-generic-unix-3.6.6.tar.xz
    [root@localhost app]# tar xf rabbitmq-server-generic-unix-3.6.6.tar
    [root@localhost app]# mv rabbitmq_server-3.6.6 /mnt/app/rabbitmq
    [root@localhost app]# chown -R root.root /mnt/app/rabbitmq
  2. RabbitMQ 安装rabbitmq_management插件

    1
    [root@localhost app]# /mnt/app/rabbitmq/sbin/rabbitmq-plugins enable rabbitmq_management
  3. RabbitMQ 环境变量

    1
    2
    3
    4
    [root@localhost app]# echo 'export RABBITMQ_HOME=/mnt/app/rabbitmq' | tee /etc/profile.d/rabbitmq.sh
    [root@localhost app]# echo 'export RABBITMQ_BIN=${RABBITMQ_HOME}/sbin' | tee -a /etc/profile.d/rabbitmq.sh
    [root@localhost app]# echo 'export PATH=${RABBITMQ_BIN}:$PATH' | tee -a /etc/profile.d/rabbitmq.sh
    [root@localhost app]# source /etc/profile
  4. RabbitMQ 创建配置文件和目录(数据+日志)

    1
    2
    3
    4
    5
    6
    7
    [root@localhost app]# touch /mnt/app/rabbitmq/etc/rabbitmq/rabbitmq-env.conf
    [root@localhost app]# touch /mnt/app/rabbitmq/etc/rabbitmq/rabbitmq.config
    [root@localhost app]# chown -R wisdom.wisdom /mnt/app/rabbitmq/etc/

    [root@localhost app]# mkdir -p /mnt/{data,log}/rabbitmq
    [root@localhost app]# mkdir -p /mnt/data/rabbitmq/mnesia
    [root@localhost app]# chown -R wisdom.wisdom /mnt/{data,log}/rabbitmq
  5. RabbitMQ 集群主机名设置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    RabbitMQ cluster-1:
    [root@localhost app]# hostname rabbit228
    [root@localhost app]# echo 'rabbit228' |tee /etc/hostname
    [root@localhost app]# echo '192.168.18.228 rabbit228' |tee -a /etc/hosts
    [root@localhost app]# echo '192.168.18.229 rabbit229' |tee -a /etc/hosts
    [root@localhost app]# echo '192.168.18.230 rabbit230' |tee -a /etc/hosts

    RabbitMQ cluster-2:
    [root@localhost app]# hostname rabbit229
    [root@localhost app]# echo 'rabbit229' |tee /etc/hostname
    [root@localhost app]# echo '192.168.18.228 rabbit228' |tee -a /etc/hosts
    [root@localhost app]# echo '192.168.18.229 rabbit229' |tee -a /etc/hosts
    [root@localhost app]# echo '192.168.18.230 rabbit230' |tee -a /etc/hosts

    RabbitMQ cluster-3:
    [root@localhost app]# hostname rabbit230
    [root@localhost app]# echo 'rabbit230' |tee /etc/hostname
    [root@localhost app]# echo '192.168.18.228 rabbit228' |tee -a /etc/hosts
    [root@localhost app]# echo '192.168.18.229 rabbit229' |tee -a /etc/hosts
    [root@localhost app]# echo '192.168.18.230 rabbit230' |tee -a /etc/hosts
  6. RabbitMQ 集群配置

    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
    //cluster-X:(三台机器都要执行)
    [root@localhost app]# su - wisdom
    [wisdom@localhost ~]$ cat > /mnt/app/rabbitmq/etc/rabbitmq/rabbitmq-env.conf <<EOF
    > RABBITMQ_NODE_IP_ADDRESS=
    > RABBITMQ_NODE_PORT=5672
    > RABBITMQ_DIST_PORT=25672
    > RABBITMQ_NODENAME=rabbit@\$HOSTNAME
    > RABBITMQ_MNESIA_BASE=/mnt/data/rabbitmq/mnesia
    > RABBITMQ_LOG_BASE=/mnt/log/rabbitmq
    > EOF

    [wisdom@rabbitX ~]$ cat > /mnt/app/rabbitmq/etc/rabbitmq/rabbitmq.config <<EOF
    > [
    > {rabbit,
    > [
    > ]},
    > {kernel,
    > [
    > ]},
    > {rabbitmq_management,
    > [
    > ]},
    > {rabbitmq_shovel,
    > [{shovels,
    > [
    > ]}
    > ]},
    > {rabbitmq_stomp,
    > [
    > ]},
    > {rabbitmq_mqtt,
    > [
    > ]},
    > {rabbitmq_amqp1_0,
    > [
    > ]},
    > {rabbitmq_auth_backend_ldap,
    > [
    > ]}
    > ].
    > EOF
  7. RabbitMQ 启动所有服务

    1
    2
    3
    [wisdom@rabbitX ~]$ /mnt/app/rabbitmq/sbin/rabbitmq-server &
    [wisdom@rabbitX ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl stop
    [wisdom@rabbitX ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl status
  8. RabbitMQ 集群操作:将要加入集群的机器都使用一个cookie(在三台机器中任选一台)

    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
    48
    49
    50
    //在228上找到elang.cookie
    [wisdom@rabbit228 ~]$ cat ~/.erlang.cookie
    HBSJBDVPUCEITCQZQQDB

    //将.erlang.cookie内容copy到229和230这两台机器的~/.erlang.cookie文件中
    [wisdom@rabbit229 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl stop
    [wisdom@rabbit229 ~]$ chmod 600 ~/.erlang.cookie
    [wisdom@rabbit229 ~]$ echo HBSJBDVPUCEITCQZQQDB | tee ~/.erlang.cookie
    [wisdom@rabbit229 ~]$ chmod 400 ~/.erlang.cookie

    [wisdom@rabbit230 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl stop
    [wisdom@rabbit230 ~]$ chmod 600 ~/.erlang.cookie
    [wisdom@rabbit230 ~]$ echo HBSJBDVPUCEITCQZQQDB | tee ~/.erlang.cookie
    [wisdom@rabbit230 ~]$ chmod 400 ~/.erlang.cookie

    //修改完~/.erlang.cookie后,启动RabbitMQ服务
    [wisdom@rabbit229 ~]$ /mnt/app/rabbitmq/sbin/rabbitmq-server &
    [wisdom@rabbit230 ~]$ /mnt/app/rabbitmq/sbin/rabbitmq-server &

    9. RabbitMQ 集群操作: 将229节点加入到228 RabbitMQ集群中(磁盘存储)
    ```bash
    //查看228节点的集群状态
    [wisdom@rabbit229 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl -n rabbit@rabbit228 cluster_status
    Cluster status of node rabbit@rabbit228 ...
    [{nodes,[{disc,[rabbit@rabbit228,rabbit@rabbit229]}]},
    {running_nodes,[rabbit@rabbit228]},
    {cluster_name,<<"rabbit@rabbit228">>},
    {partitions,[]},
    {alarms,[{rabbit@rabbit228,[]}]}]

    //停止229节点的Rabbitmq服务
    [wisdom@rabbit229 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl stop_app

    //清空229 Rabbit元数据
    [wisdom@rabbit229 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl -n rabbit@rabbit229 reset

    //将229 Rabbit加入到228集群中
    [wisdom@rabbit229 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl join_cluster rabbit@rabbit228

    //启动229 Rabbit服务
    [wisdom@rabbit229 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl start_app

    //查看集群状态
    [wisdom@rabbit229 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl -n rabbit@rabbit228 cluster_status
    Cluster status of node rabbit@rabbit228 ...
    [{nodes,[{disc,[rabbit@rabbit228,rabbit@rabbit229]}]},
    {running_nodes,[rabbit@rabbit228]},
    {cluster_name,<<"rabbit@rabbit228">>},
    {partitions,[]},
    {alarms,[{rabbit@rabbit228,[]}]}]
  9. RabbitMQ 集群操作: 将230 RabbitMQ加入到228 RabbitMQ集群中(内存存储)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    //停止230节点的Rabbitmq服务
    [wisdom@rabbit230 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl stop_app

    //清空230 Rabbit元数据
    [wisdom@rabbit230 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl -n rabbit@rabbit230 reset

    //将230 Rabbit加入到228集群中,内存存储
    [wisdom@rabbit230 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl join_cluster rabbit@rabbit228 --ram

    //启动230 Rabbit服务
    [wisdom@rabbit230 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl start_app

    ////查看集群状态
    [wisdom@rabbit229 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl -n rabbit@rabbit228 cluster_status
    Cluster status of node rabbit@rabbit228 ...
    [{nodes,[{disc,[rabbit@rabbit228,rabbit@rabbit229]},{ram,[rabbit@rabbit230]}]},
    {running_nodes,[rabbit@rabbit230,rabbit@rabbit229,rabbit@rabbit228]},
    {cluster_name,<<"rabbit@rabbit228">>},
    {partitions,[]},
    {alarms,[{rabbit@rabbit230,[]},{rabbit@rabbit229,[]},{rabbit@rabbit228,[]}]}]
  10. 设置集群中所有的队列为镜像队列(任意一台机器上执行)

    1
    [wisdom@rabbit228 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl set_policy ha-all "^" '{"ha-mode":"all"}'
  11. 设置用户权限

    1
    2
    3
    [wisdom@rabbit228 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl add_user test test123  
    [wisdom@rabbit229 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl set_user_tags test administrator
    [wisdom@rabbit228 ~]$ /mnt/app/rabbitmq/sbin/rabbitmqctl set_permissions -p / test ".\*" ".\*" ".\*"
  12. 安装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
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    //haproxy 安装
    [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

    //haproxy 环境变量设置
    [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

    //haproxy 创建配置文件
    [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

    //haproxy 配置
    [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

    //haproxy 启动
    [root@localhost haproxy-1.7.2]# /mnt/app/haproxy/sbin/haproxy -f /mnt/app/haproxy/conf/haproxy.cfg

    //通过haproxy查看RabbitMQ状态
    在浏览器中打开:
    http://192.168.18.223:8090