nginx安装与impala的负载均衡配置

操作系统:小红帽6.7

下载

nginx 下载地址

直接下载最新版的包即可

编译

#安装前置的依赖包,可以挂在系统镜像后使用yum命令安装即可
yum install -y gc gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel ncurses-devel perl

#编译
./configure --user=root --group=root --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-stream

make && make install

使用

启动

启动代码格式:nginx安装目录地址 -c nginx配置文件地址

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

停止

正常停止

方法1.命令停止

/usr/local/nginx/sbin/nginx -s stop

方法2.杀进程停止

#查看进程号
ps -ef|grep nginx
#杀死进程
kill -QUIT xxxxxxx

强制停止

pkill -9 nginx

重启

/usr/local/nginx/sbin/nginx -s reload

验证nginx配置文件是否正确

/usr/local/nginx/sbin/nginx -t

看到下面的返回值说明配置文件正确:

nginx.conf test is successful

将nginx服务加如系统自启动服务

在/etc/init.d目录下创建nginx脚本

#!/bin/sh
#description: Http server daemon

DESC="nginx daemon"
NAME=nginx

#写入nginx的安装目录
DAEMON=/usr/local/nginx/sbin/nginx

set -e
[ -x "$DAEMON" ] || exit 0

do_start() {
$DAEMON || echo -n "nginx is already running";
}

do_stop() {
$DAEMON -s stop || echo -n "nginx stop failed"
}

do_reload() {
$DAEMON -s reload || echo -n "nginx reload failed"
}

case "$1" in
start)
do_start
;;
stop)
do_stop
;;
reload|graceful)
do_reload
;;
restart)
do_stop
sleep 2
do_start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
exit 3
;;
esac

exit 0

设置自启动脚本执行权限,并设置开机启动

chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig nginx on

测试Nginx是否正常访问

在浏览器输入http://hostname

配置Impala负载均衡策略

修改/usr/local/nginx/conf/nginx.conf文件

# ***在文件末尾增加如下配置***

stream{

  #impala-shell 负载均衡算法声明与服务器配置
  upstream impala-shell {

    #路由策略:最少连接
    least_conn;

    #down 表示单前的server暂时不参与负载
    server bigdata-poc-shtz-1:21000 down;

    #weight 默认为1.weight越大,负载的权重就越大。
    server bigdata-poc-shtz-3:21000 weight=2;
    server bigdata-poc-shtz-4:21000 weight=2;

    #其它所有的非backup机器down或者忙的时候,请求backup机器,所以这台机器压力会最轻。
    server bigdata-poc-shtz-5:21000 backup;
  }

  #impala-jdbc 负载均衡算法声明与服务器配置
  upstream impala-jdbc {

    #路由策略:当在upstream配置块中没有指定使用的负载均衡算法时,默认使用的是加权轮询。

    #down 表示单前的server暂时不参与负载
    server bigdata-poc-shtz-1:21050 down;

    #weight 默认为1.weight越大,负载的权重就越大。
    #Nginx每收到6个客户端的请求,会把其中的3个转发给bigdata-poc-shtz-3,把其中的2个转发给bigdata-poc-shtz-4:21050,把其中的1个转发给bigdata-poc-shtz-5。
    server bigdata-poc-shtz-3:21050 weight=3;
    server bigdata-poc-shtz-4:21050 weight=2;
    server bigdata-poc-shtz-5:21050 weight=1;
  }

  #impala-shell 负载均衡
  server{
    listen 25003;
    proxy_pass impala-shell;
  }

  #impala-jdbc 负载均衡
  server{
    listen 25004;
    proxy_pass impala-jdbc;
    
    #通过页面访问http://127.0.0.1/stats查看状态
    location /stats {
      stub_status on;
      access_log off;
      allow bigdata-poc-shtz-4;
    }
  
  }
}



重启nginx服务

#停止
/usr/local/nginx/sbin/nginx -s stop
#启动
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

测试impala-shell是否可用

impala-shell -i bigdata-poc-shtz-4:25003

设置HUE配置,使用nginx的负载均衡

在HUE配置 -> 高级 -> hue_safety_valve.ini 的 Hue 服务高级配置代码段(安全阀) 填入如下内容:

[impala]
server_host=bigdata-poc-shtz-4
server_port=25004

重启HUE组件,并使用sql测试

猜你喜欢

转载自blog.csdn.net/abyslll/article/details/88019310