【运维记录】利用nginx对clickhouse做负载均衡

背景

如题,想对自己三节点的clickhouse做负载均衡。

步骤

1、下载nginx

yum install nginx

2、修改nginx配置

vim /etc/nginx/nginx.conf

3、配置文件内容

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;
events {
    worker_connections 1024;
}
http {

    upstream clickhouse {
        server xxx.xxx.xxx.xxx:8123;
        server xxx.xxx.xxx.xxx:8123;
        server xxx.xxx.xxx.xxx:8123;
    }

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
    server {
        listen 8000;
        server_name smartck.com;

        location / {
            proxy_pass http://clickhouse;
        }
    }

}

4、检测配置文件

cd /etc/nginx/ && /usr/sbin/nginx -t

如下,则代表配置文件格式没问题。
在这里插入图片描述
5、启动nginx

systemctl start nginx.service
systemctl status nginx.service

以下,则代表nginx启动成功
在这里插入图片描述

6、clickhouse链接测试
链接后查看链接节点,在hadoop002节点上。
在这里插入图片描述
断开后重新链接,连接到hadoop001节点上。
在这里插入图片描述
至此,收工。

踩坑记录

报错:Code: 102. DB::NetException: Unexpected packet from server localhost:8123 (expected Hello or Exception, got Unknown packet). (UNEXPECTED_PACKET_FROM_SERVER)

个人认为是因为8123是http访问端口,而通过「clickhouse-client -m」访问是tcp的访问类型,所以clickhouse-client -m -port 8123链接不上。

思考: 个人认为是因为8123是http访问端口,而通过「clickhouse-client -m」访问是属于tcp的访问类型,所以无法通过clickhouse-client -m -port 8123链接不上。

报错:Code: 210. DB::NetException: Connection refused (localhost:9000). (NETWORK_ERROR)
在这里插入图片描述
思考: 思考了一下,原因是因为9000端口之前被hadoop平台占用、所以将端口修改为19000。如果有相关的报错,这是一个排查方向。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值