liangsw  

一、安装HAProxy

在NNA和NNS安装

采用yum安装:

yum -y install haproxy

验证安装:

# 版本信息
haproxy -vv

涉及的目录:

/etc/haproxy
/etc/haproxy/haproxy.cfg                --haproxy的配置文件
/etc/logrotate.d/haproxy
/etc/sysconfig/haproxy
/usr/bin/halog
/usr/bin/iprange
/usr/lib/systemd/system/haproxy.service  --haproxy的服务启动脚本
/usr/sbin/haproxy
/usr/sbin/haproxy-systemd-wrapper
...
/usr/share/haproxy
/usr/share/haproxy/400.http             --以下为HTTP访问的错误状态码页面
/usr/share/haproxy/403.http
/usr/share/haproxy/408.http
/usr/share/haproxy/500.http
/usr/share/haproxy/502.http
/usr/share/haproxy/503.http
/usr/share/haproxy/504.http
/usr/share/haproxy/README
/usr/share/man/man1/halog.1.gz         --可以直接使用man halog查看命令的使用语法
/usr/share/man/man1/haproxy.1.gz       --使用man haproxy查看命令的使用语法

配置文件编辑:

cd /etc/haproxy
ls haproxy.cfg
cp haproxy.cfg  config.cfg
vi config.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
    daemon
    nbproc	1

    # 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                    tcp
    option                  redispatch
    option                  abortonclose
    retries                 3
    timeout connect         1d
    timeout client          1d
    timeout server          1d
    timeout check           2000
    log 127.0.0.1 local0    err
    maxconn                 1024

listen  admin_stats                     #定义管理界面
        bind 0.0.0.0:1090               #管理界面访问IP和端口
        mode http                       #管理界面所使用的协议
        maxconn 10          #最大连接数
        stats refresh 30s               #30秒自动刷新
        stats uri /                     #访问url
        stats realm Hive\ Haproxy       #验证窗口提示
        stats auth admin:123456         #401验证用户名密码

listen hive             #hive后端定义
        bind 0.0.0.0:10001              #ha作为proxy所绑定的IP和端口
        mode tcp                        #以4层方式代理,重要
        balance leastconn               #调度算法 'leastconn' 最少连接数分配,或者 'roundrobin',轮询分配
        maxconn 1024                    #最大连接数
        server hive_1 slave01:10000 check inter 180000 rise 1 fall 2
        server hive_2 slave02:10000 check inter 180000 rise 1 fall 2
        server hive_3 slave03:10000 check inter 180000 rise 1 fall 2
mkdir /var/lib/haproxy/
touch stats

NNA、NNS机器操作暂时完成;

二、启动

hive启动:在slave01、slave02、slave03分别启动hive:

hive --service hiveserver2 &

haproxy启动:在nna、nns分别启动

haproxy -f config.cfg

三、网页端验证

登录网址:http://master:1090/ 或者 http://standby:1090/(本人的master是nna,standby是nns,没配置wondows的hosts,请使用自己对应的IP);用户名/密码:admin/123456

 

posted on 2019-07-10 01:58  liangsw  阅读(179)  评论(0编辑  收藏  举报