Clickhouse 集群部署安装

ClickHouse 集群部署安装

1、环境准备

(1)、阿里云服务器两台 集群节点信息

192.168.5.13 ch01

192.168.5.14 ch02

(2)、修改 /etc/cloud/cloud.cfg ( 所有节点 )

[root@iZbp1fsk0p3opmtlo52u91Z ~]# vim /etc/cloud/cloud.cfg
注释掉 # manage_etc_hosts: localhost

(3)、文件打开数调整 ( 所有节点 )

在 /etc/security/limits.conf和/etc/security/limits.d/20-nproc.conf 这两个文件的末尾加入以下内容:
注意:没有20-nproc.conf 该文件就创建一个

[root@ch01 conf]# vim /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
* soft nproc 131072
* hard nproc 131072

[root@ch01 conf]# vim /etc/security/limits.d/20-nproc.conf
* soft nofile 65535
* hard nofile 65535
* soft nproc 131072
* hard nproc 131072

(4)、取消selinux ( 所有节点 )

修改 /etc/selinux/config 中的 SELINUX=disabled 后重启

vim /etc/selinux/config
SELINUX=disabled

(5)、关闭防火墙 ( 所有节点 )

systemctl status firewalld.service
systemctl stop firewalld.service

(6)、安装依赖 ( 所有节点 )

root用户执行:
yum install -y libtool
yum install -y *unixODBC*

(7)、验证是否支持sse 4.2指令集 ( 所有节点 )

需要验证当前服务器的CPU是否支持SSE 4.2指令集,因为向量化执行需要用到这项特性

[root@ch02 ~]# grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
SSE 4.2 supported


(8)、修改 hostname ( 所有节点 )

192.168.5.13
[root@iZbp1fsk0p3opmtlo52u91Z ~]# hostnamectl set-hostname ch01
[root@iZbp1fsk0p3opmtlo52u91Z ~]# exit
登出

连接断开
连接主机...
连接主机成功
Last login: Wed Jun 29 09:53:30 2022 from 117.64.249.192

Welcome to Alibaba Cloud Elastic Compute Service !

[root@ch01 ~]# 
192.168.5.14
[root@iZbp1fsk0p3opmtlo52u92Z ~]# hostnamectl set-hostname ch02
[root@iZbp1fsk0p3opmtlo52u92Z ~]# exit
登出

连接断开
连接主机...
连接主机成功
Last login: Wed Jun 29 09:53:28 2022 from 117.64.249.192

Welcome to Alibaba Cloud Elastic Compute Service !

[root@ch02 ~]# 

(9)、配置hosts ( 所有节点 )

[root@ch01 ~]# vim /etc/hosts
# 192.168.5.13  iZbp1fsk0p3opmtlo52u91Z iZbp1fsk0p3opmtlo52u91Z
192.168.5.13  ch01
192.168.5.14  ch02

[root@ch02 ~]# vim /etc/hosts
# 192.168.5.14  iZbp1fsk0p3opmtlo52u92Z iZbp1fsk0p3opmtlo52u92Z
192.168.5.13  ch01
192.168.5.14  ch02

(10) 上面步骤完成后重启服务器 reboot

2、JDK安装

(1)、上传jdk压缩包至 服务器/opt 目录下

[root@ch01 opt]# ls
Clickhouse21.3.4.25  jdk-8u241-linux-x64.tar.gz  zookeeper-3.4.13.tar.gz

(2)、解压安装包 ,配置环境变量

[root@ch01 opt]# tar -zxvf jdk-8u241-linux-x64.tar.gz
[root@ch01 opt]# vim /etc/profile
export JAVA_HOME=/usr/java/jdk1.8.0_181-cloudera
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin

(3)、source环境变量 ,验证是否成功

[root@ch01 opt]# source /etc/profile
[root@ch01 opt]# java -version
java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)

3、Zookeeper 集群安装

使用kafka上的Zookeeper ,此处安装省略

在 clickhouse 集群上 hosts 上新增

192.168.5.5 zk01
192.168.5.6 zk02
192.168.5.8 zk03

4、安装部署ClickHouse

(1)、上传安装包至服务器上 /opt/Clickhouse21.3.4.25 目录下

[root@ch01 /]# cd /opt/Clickhouse21.3.4.25/
[root@ch01 Clickhouse21.3.4.25]# ll
总用量 698960
-rw-r--r-- 1 root root     46224 628 20:24 clickhouse-client-21.3.4.25-2.noarch.rpm
-rw-r--r-- 1 root root 126245942 628 20:25 clickhouse-common-static-21.3.4.25-2.x86_64.rpm
-rw-r--r-- 1 root root 589359990 628 20:27 clickhouse-common-static-dbg-21.3.4.25-2.x86_64.rpm
-rw-r--r-- 1 root root     69097 628 20:24 clickhouse-server-21.3.4.25-2.noarch.rpm
[root@ch01 Clickhouse21.3.4.25]# 

(2)、先进入我们创建的clickhouse目录下,使用shell命令sudo rpm -ivh *.rpm 安装4个rpm包,执行安装

[root@ch01 Clickhouse21.3.4.25]# sudo rpm -ivh *.rpm
警告:clickhouse-client-21.3.4.25-2.noarch.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID e0c56bd4: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:clickhouse-common-static-21.3.4.2################################# [ 25%]
   2:clickhouse-client-21.3.4.25-2    ################################# [ 50%]
   3:clickhouse-server-21.3.4.25-2    ################################# [ 75%]

节点2同样步骤

(3)、启动 clickhouse

[root@ch01 ~]# systemctl start clickhouse-server.service
查看启动状态 
[root@ch01 ~]# systemctl status clickhouse-server.service
● clickhouse-server.service - ClickHouse Server (analytic DBMS for big data)
   Loaded: loaded (/etc/systemd/system/clickhouse-server.service; enabled; vendor preset: disabled)
   Active: activating (auto-restart) (Result: exit-code) since 三 2022-06-29 17:12:19 CST; 5s ago
  Process: 28187 ExecStart=/usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickhouse-server.pid (code=exited, status=70)
 Main PID: 28187 (code=exited, status=70)

629 17:12:19 ch01 systemd[1]: Unit clickhouse-server.service entered failed state.
629 17:12:19 ch01 systemd[1]: clickhouse-server.service failed.

节点2同样步骤

(4)、进入clickhouse-client

[root@ch01 ~]# clickhouse-client -h localhost --port 9000 -u default  # 回车 初始没有密码
ClickHouse client version 21.3.4.25 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 21.3.4 revision 54447.

# 验证数据
ch01 :) show databases;

SHOW DATABASES

Query id: 994f4d84-908d-4092-bf48-227d70c3e212

┌─name────┐
│ default │
│ system  │
└─────────┘

2 rows in set. Elapsed: 0.001 sec. 

ch01 :)

节点2同样步骤

到此 证明clickhouse完全安装成功并可以正确使用

5、集群部署

两个节点全部按照上面的指导部署单节点成功后开始配置部署集群需要的配置

(1)、首先以一个节点为例配置, 进入 /etc/clickhouse-server 目录下,添加配置信息如下:

将config.xml , users.xml 备份起来 避免配置修改失误,导致clickhouse 启动失败。

[root@ch01 clickhouse-server]# cp config.xml config_bak20220630.xml 
[root@ch01 clickhouse-server]# cp users.xml users_bak20220630.xml 

编辑 config.xml 清空 内容,将以下内容粘贴进去

[root@ch01 clickhouse-server]# vim config.xml
<?xml version="1.0"?>
<!--
  NOTE: User and query level settings are set up in "users.xml" file.
  If you have accidentally specified user-level settings here, server won't start.
  You can either move the settings to the right place inside "users.xml" file
   or add <skip_check_for_incorrect_settings>1</skip_check_for_incorrect_settings> here.
-->
<yandex>
    <logger>
        <!-- Possible levels: https://github.com/pocoproject/poco/blob/poco-1.9.4-release/Foundation/include/Poco/Logger.h#L105 -->
        <level>trace</level>
        <log>/var/log/clickhouse-server/clickhouse-server.log</log>
        <errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
        <!-- Rotation policy
             See https://github.com/pocoproject/poco/blob/poco-1.9.4-release/Foundation/include/Poco/FileChannel.h#L54-L85
          -->
        <size>1000M</size>
        <count>10</count>
        <!-- <console>1</console> --> <!-- Default behavior is autodetection (log to console if not daemon mode and is tty) -->

        <!-- Per level overrides (legacy):

        For example to suppress logging of the ConfigReloader you can use:
        NOTE: levels.logger is reserved, see below.
        -->
        <!--
        <levels>
          <ConfigReloader>none</ConfigReloader>
        </levels>
        -->

        <!-- Per level overrides:

        For example to suppress logging of the RBAC for default user you can use:
        (But please note that the logger name maybe changed from version to version, even after minor upgrade)
        -->
        <!--
        <levels>
          <logger>
            <name>ContextAccess (default)</name>
            <level>none</level>
          </logger>
          <logger>
            <name>DatabaseOrdinary (test)</name>
            <level>none</level>
          </logger>
        </levels>
        -->
    </logger>
		<timezone>Asia/Shanghai</timezone>
		<database_atomic_delay_before_drop_table_sec>0</database_atomic_delay_before_drop_table_sec>
    <!-- It is the name that will be shown in the clickhouse-client.
         By default, anything with "production" will be highlighted in red in query prompt.
    -->
    <!--display_name>production</display_name-->

    <!-- Port for HTTP API. See also 'https_port' for secure connections.
         This interface is also used by ODBC and JDBC drivers (DataGrip, Dbeaver, ...)
         and by most of web interfaces (embedded UI, Grafana, Redash, ...).
      -->
    <http_port>8123</http_port>

    <!-- Port for interaction by native protocol with:
         - clickhouse-client and other native ClickHouse tools (clickhouse-benchmark, clickhouse-copier);
         - clickhouse-server with other clickhouse-servers for distributed query processing;
         - ClickHouse drivers and applications supporting native protocol
         (this protocol is also informally called as "the TCP protocol");
         See also 'tcp_port_secure' for secure connections.
    -->
    <tcp_port>9000</tcp_port>

    <!-- Compatibility with MySQL protocol.
         ClickHouse will pretend to be MySQL for applications connecting to this port.
    -->
    <mysql_port>9004</mysql_port>

    <!-- Compatibility with PostgreSQL protocol.
         ClickHouse will pretend to be PostgreSQL for applications connecting to this port.
    -->
    <!-- <postgresql_port>9005</postgresql_port> -->

    <!-- HTTP API with TLS (HTTPS).
         You have to configure certificate to enable this interface.
         See the openSSL section below.
    -->
    <!-- <https_port>8443</https_port> -->

    <!-- Native interface with TLS.
         You have to configure certificate to enable this interface.
         See the openSSL section below.
    -->
    <!-- <tcp_port_secure>9440</tcp_port_secure> -->

    <!-- Native interface wrapped with PROXYv1 protocol
         PROXYv1 header sent for every connection.
         ClickHouse will extract information about proxy-forwarded client address from the header.
    -->
    <!-- <tcp_with_proxy_port>9011</tcp_with_proxy_port> -->

    <!-- Port for communication between replicas. Used for data exchange.
         It provides low-level data access between servers.
         This port should not be accessible from untrusted networks.
         See also 'interserver_http_credentials'.
         Data transferred over connections to this port should not go through untrusted networks.
         See also 'interserver_https_port'.
      -->
    <interserver_http_port>9009</interserver_http_port>

    <!-- Port for communication between replicas with TLS.
         You have to configure certificate to enable this interface.
         See the openSSL section below.
         See also 'interserver_http_credentials'.
      -->
    <!-- <interserver_https_port>9010</interserver_https_port> -->

    <!-- Hostname that is used by other replicas to request this server.
         If not specified, than it is determined analogous to 'hostname -f' command.
         This setting could be used to switch replication to another network interface
         (the server may be connected to multiple networks via multiple addresses)
      -->
    <!--
    <interserver_http_host>example.yandex.ru</interserver_http_host>
    -->

    <!-- You can specify credentials for authenthication between replicas.
         This is required when interserver_https_port is accessible from untrusted networks,
         and also recommended to avoid SSRF attacks from possibly compromised services in your network.
      -->
    <!--<interserver_http_credentials>
        <user>interserver</user>
        <password></password>
    </interserver_http_credentials>-->

    <!-- Listen specified address.
         Use :: (wildcard IPv6 address), if you want to accept connections both with IPv4 and IPv6 from everywhere.
         Notes:
         If you open connections from wildcard address, make sure that at least one of the following measures applied:
         - server is protected by firewall and not accessible from untrusted networks;
         - all users are restricted to subset of network addresses (see users.xml);
         - all users have strong passwords, only secure (TLS) interfaces are accessible, or connections are only made via TLS interfaces.
         - users without password have readonly access.
         See also: https://www.shodan.io/search?query=clickhouse
      -->
    <!-- <listen_host>::</listen_host> -->

    <!-- Same for hosts without support for IPv6: -->
    <!-- <listen_host>0.0.0.0</listen_host> -->
    <listen_host>0.0.0.0</listen_host>

    <!-- Default values - try listen localhost on IPv4 and IPv6. -->
    <!--
    <listen_host>::1</listen_host>
    <listen_host>127.0.0.1</listen_host>
    -->

    <!-- Don't exit if IPv6 or IPv4 networks are unavailable while trying to listen. -->
    <!-- <listen_try>0</listen_try> -->

    <!-- Allow multiple servers to listen on the same address:port. This is not recommended.
      -->
    <!-- <listen_reuse_port>0</listen_reuse_port> -->

    <!-- <listen_backlog>64</listen_backlog> -->

    <max_connections>4096</max_connections
### 验证ClickHouse集群部署成功的步骤 为了确保ClickHouse集群已经成功部署并正常运行,可以采取多种方法来验证其状态和服务可用性。 #### 使用命令行检查服务状态 可以通过Linux命令`ps -ef | grep clickhouse`查看ClickHouse服务器进程是否正在运行[^3]。此命令能够显示所有与ClickHouse有关的活动进程,如果看到`clickhouse-server`的相关条目,则说明该服务已经在指定节点上启动。 #### 查询系统表获取集群信息 另外一种有效的方式是从内部查询ClickHouse数据库本身的状态。通过执行SQL语句访问系统表中的数据可以帮助了解整个集群的工作情况: ```sql SELECT * FROM system.clusters; ``` 这条指令返回的结果集应该包含所定义的所有分片及其对应的副本列表,这有助于确认各个节点之间的通信状况良好,并且都加入了预期的集群配置中[^4]。 #### 测试分布式表的功能 创建一个简单的分布式表并向其中插入一些测试记录也是一个不错的检验手段。当这些操作顺利完成而没有任何错误提示时,基本上就可以断定集群环境设置无误了。下面是一个具体的例子: ```sql CREATE TABLE test_dist AS default.test_local ENGINE = Distributed('cluster_name', 'default', 'test_local'); INSERT INTO test_dist VALUES ('example data'); SELECT * FROM test_dist; ``` 上述代码片段展示了如何基于已有的本地表结构建立一个新的分布式的表对象,接着向里面添加一条新纪录最后读取出来以证明跨节点的数据交换机制运作正常[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值