Euler21.10部署ClickHouse集群

环境信息

主机名 IP地址 角色 软件版本
ch01 192.168.1.17 zookeeper、clickhouse zookeeper 3.9.2 clickhouse 21.7.3.14
ch02 192.168.1.18 zookeeper、clickhouse zookeeper 3.9.2 clickhouse 21.7.3.14
ch03 192.168.1.19 zookeeper、clickhouse zookeeper 3.9.2 clickhouse 21.7.3.14

基础环境配置

修改主机名添加hosts

hostnamectl set-hostname ch01
bash

cat /etc/hosts
192.168.1.17 ch01
192.168.1.18 ch02
192.168.1.19 ch03

安装jdk

tar xf jdk-8u212-linux-x64.tar.gz -C /usr/local/

cat >/etc/profile.d/java.sh << 'EOF'
export JAVA_HOME=/usr/local/jdk1.8.0_212
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
EOF
source /etc/profile
java -version

修改最大文件数限制

cat >> /etc/security/limits.conf <<EOF
soft nofile 65536
hard nofile 65536
soft nproc 131072
hard nproc 131072
EOF

cat >> /etc/security/limits.d/20-nproc.conf <<EOF
soft nofile 65536
hard nofile 65536
soft nproc 131072
hard nproc 131072
EOF

ZooKeeper

下载软件包

wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.9.2/apache-zookeeper-3.9.2-bin.tar.gz

解压压缩包

tar xf apache-zookeeper-3.9.2-bin.tar.gz -C /opt/
mv /opt/apache-zookeeper-3.9.2-bin/ /opt/apache-zookeeper-3.9.2

配置环境变量

cat >/etc/profile.d/zookeeper.sh << 'EOF'
export ZOOKEEPER_HOME=/opt/apache-zookeeper-3.9.2
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$ZOOKEEPER_HOME/bin:$PATH
EOF

source /etc/profile

创建配置文件

cp /opt/apache-zookeeper-3.9.2/conf/zoo_sample.cfg /opt/apache-zookeeper-3.9.2/conf/zoo.cfg

创建目录

mkdir -p /opt/apache-zookeeper-3.9.2/{data,log}

编辑配置文件

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/tmp/zookeeper
clientPort=2181
dataDir=/opt/apache-zookeeper-3.9.2/data
dataLogDir=/opt/apache-zookeeper-3.9.2/logs
server.0=192.168.1.17:2888:3888
server.1=192.168.1.18:2888:3888
server.2=192.168.1.19:2888:3888

创建节点id,ch01:0,ch02:1,ch03:2

echo $id >/opt/apache-zookeeper-3.9.2/data/myid

创建systemd配置文件

cat > /etc/systemd/system/zookeeper.service << EOF
[Unit]
Description=Apache ZooKeeper Server
After=network.target

[Service]
User=root
Group=root
Type=forking
Environment=JAVA_HOME=/usr/local/jdk1.8.0_212
ExecStart=/opt/apache-zookeeper-3.9.2/bin/zkServer.sh start
ExecStop=/opt/apache-zookeeper-3.9.2/bin/zkServer.sh stop
ExecReload=/opt/apache-zookeeper-3.9.2/bin/zkServer.sh restart
RestartSec=10
Restart=on-failure
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target
EOF

启动zk服务

systemctl enable zookeeper
systemctl start zookeeper

ClickHouse

部署架构图

+---------+ +---------+ +---------+
| CH01 | | CH02 | | CH03 |
|---------| |---------| |---------|
| Shard 1 | | Shard 1 | | Shard 1 |
| +-----+ | | +-----+ | | +-----+ |
| | R1 | | | | R1 | | | | R1 | |
| +-----+ | | +-----+ | | +-----+ |
| Shard 2 | | Shard 2 | | Shard 2 |
| +-----+ | | +-----+ | | +-----+ |
| | R1 | | | | R1 | | | | R1 | |
| +-----+ | | +-----+ | | +-----+ |
| Shard 3 | | Shard 3 | | Shard 3 |
| +-----+ | | +-----+ | | +-----+ |
| | R1 | | | | R1 | | | | R1 | |
| +-----+ | | +-----+ | | +-----+ |
+---------+ +---------+ +---------+

部署

安装包下载地址:https://github.com/ClickHouse/ClickHouse/releases/tag/v21.7.3.14-stable

安装软件

rpm -ivh clickhouse-client-21.7.3.14-2.noarch.rpm clickhouse-common-static-21.7.3.14-2.x86_64.rpm clickhouse-server-21.7.3.14-2.noarch.rpm

编辑配置文件/etc/clickhouse-server/config.xml

<yandex>
<listen_host>::</listen_host>
<zookeeper>
<node>
<host>192.168.1.17</host>
<port>2181</port>
</node>
<node>
<host>192.168.1.18</host>
<port>2181</port>
</node>
<node>
<host>192.168.1.19</host>
<port>2181</port>
</node>
</zookeeper>
<remote_servers>
<default>
<shard>
<replica>
<host>192.168.1.17</host>
<port>9000</port>
</replica>
</shard>
<shard>
<replica>
<host>192.168.1.18</host>
<port>9000</port>
</replica>
</shard>
<shard>
<replica>
<host>192.168.1.19</host>
<port>9000</port>
</replica>
</shard>
</default>
</remote_servers>
</yandex>

编辑配置文件/etc/clickhouse-server/users.xml

<yandex>
<user>
<default>
<password>123456</password>
</default>
</user>
</yandex>

启动服务

systemctl enable clickhouse-server
systemctl start clickhouse-server

验证

登录CH

clickhouse-client --password
ClickHouse client version 21.7.3.14 (official build).
Password for user (default):
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 21.7.3 revision 54449.
ch01 :)

查看集群状态

ch01 :) select cluster,shard_num,shard_weight,replica_num,host_address,port from system.clusters;

SELECT
cluster,
shard_num,
shard_weight,
replica_num,
host_address,
port
FROM system.clusters

Query id: 7119c4c2-ac7d-4b78-b4ea-128f8b94c7ff

┌─cluster─┬─shard_num─┬─shard_weight─┬─replica_num─┬─host_address─┬─port─┐
│ default │ 1 │ 1 │ 1 │ 192.168.1.17 │ 9000 │
│ default │ 2 │ 1 │ 1 │ 192.168.1.18 │ 9000 │
│ default │ 3 │ 1 │ 1 │ 192.168.1.19 │ 9000 │
└─────────┴───────────┴──────────────┴─────────────┴──────────────┴──────┘

3 rows in set. Elapsed: 0.005 sec.

参考链接:https://blog.csdn.net/qq_44700578/article/details/134859622

文章作者: 慕容峻才
文章链接: https://www.acaiblog.top/Euler21-10部署ClickHouse集群/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 阿才的博客
微信打赏
支付宝打赏