ClickHouse 3s1r 集群安装

  |   0 评论   |   0 浏览

ClickHouse 3s1r 集群安装

前提安装 ZooKeeper集群

参考:ClickHouse 3s1r 集群安装 | Zookeeper集群

单机安装(IP18,IP19,IP20)

官方单机/集群安装部署文档
https://clickhouse.tech/docs/zh/getting-started/install/#from-rpm-packages
https://clickhouse.tech/docs/zh/getting-started/tutorial/#cluster-deployment

下载 https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG

stable rpm 下载地址
浏览器打开 https://repo.yandex.ru/clickhouse/rpm/stable/x86_64/

下载版本号为 20.12.3.3-2 的 rpm

ctrl + f 搜索 20.12.3.3-2 找到5个 rpm,含test的不下载

Xshell Xftp 上传到服务器(GPG、rpm) ck-rpm 目录

ck-rpm

[root@node18 ck-rpm]# pwd
/app/software/ck-rpm
[root@node18 ck-rpm]# ls -alh
total 624M
drwxr-xr-x. 2 root root  242 Dec 21 07:02 .
drwxr-xr-x. 7 root root 4.0K Dec 27 13:39 ..
-rw-r--r--. 1 root root 154K Dec 21 06:56 clickhouse-client-20.12.3.3-2.noarch.rpm
-rw-r--r--. 1 root root 113M Dec 21 06:57 clickhouse-common-static-20.12.3.3-2.x86_64.rpm
-rw-r--r--. 1 root root 511M Dec 21 06:57 clickhouse-common-static-dbg-20.12.3.3-2.x86_64.rpm
-rw-r--r--. 1 root root 3.1K Dec 21 06:58 CLICKHOUSE-KEY.GPG
-rw-r--r--. 1 root root 174K Dec 21 06:57 clickhouse-server-20.12.3.3-2.noarch.rpm

安装

rpm --import ./CLICKHOUSE-KEY.GPG
rpm -ivh ./*.rpm

ClickHouse 数据,日志等 存数据盘

在数据盘创建目录

mkdir -p /data/ck/{log,lib/{temp,access,format_schemas},task_queue/ddl} && chmod -R 777 /data/ck

修改配置文件

  • config.xml
替换路径 命令模式 
vim /etc/clickhouse-server/config.xml

%s#/var/log/clickhouse-server#/data/ck/log#g
%s#/var/lib/clickhouse#/data/ck/lib#g
%s#/clickhouse/task_queue/ddl#/data/ck/task_queue/ddl#g

远程访问,时区设置 去掉注释 编辑模式
<listen_host>::</listen_host>
<timezone>Asia/Shanghai</timezone>

删除节点remote_servers内所有内容

文件末尾节点前加入
<include_from>/etc/clickhouse-server/metrika.xml</include_from>

上传 metrika.xml 到 /etc/clickhouse-server/ 目录
  • users.xml
生成密码:
PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'

设置密码:
vim /etc/clickhouse-server/users.xml

<!--c3oGDK75-->
<password_sha256_hex>93df3e007a15f42f6d137c76f6856ce602d625c20f35861b97d3666181205042</password_sha256_hex>

加root用户:
<root>
	 <!--092j3AnV-->
	<password_sha256_hex>35542ded44184b1b4b6cd621e052662578025b58b4187176a3ad2b9548c8356e</password_sha256_hex>
	 <networks incl="networks" replace="replace">
		<ip>::/0</ip>
	</networks>
	<profile>default</profile>
	<quota>default</quota>
</root>

其他节点步骤基本一样

修改 metrika.xml macros 节点内ip为当前主机ip

metrika.xml 文件内容

<yandex>
    <clickhouse_remote_servers>
        <ck_cluster><!--集群名称自定义-->
            <shard>
                <internal_replication>true</internal_replication>
                <replica>
                    <host>192.168.1.18</host>
                    <port>9000</port>
					<user>default</user>
                    <password>c3oGDK75</password>
                </replica>
            </shard>
            <shard>
                <replica>
                    <internal_replication>true</internal_replication>
                    <host>192.168.1.19</host>
                    <port>9000</port>
					<user>default</user>
                    <password>c3oGDK75</password>
                </replica>
            </shard>
            <shard>
                <internal_replication>true</internal_replication>
                <replica>
                    <host>192.168.1.20</host>
                    <port>9000</port>
					<user>default</user>
                    <password>c3oGDK75</password>
                </replica>
            </shard>
        </ck_cluster>
    </clickhouse_remote_servers>

    <zookeeper-servers>
        <node index="1">
            <host>192.168.1.18</host>
            <port>2182</port>
        </node>
        <node index="2">
            <host>192.168.1.19</host>
            <port>2182</port>
        </node>
        <node index="3">
            <host>192.168.1.20</host>
            <port>2182</port>
        </node>
    </zookeeper-servers>

    <macros>
        <replica>192.168.1.18</replica>
    </macros>

    <networks>
        <ip>::/0</ip>
    </networks>

    <clickhouse_compression>
        <case>
            <min_part_size>10000000000</min_part_size>
            <min_part_size_ratio>0.01</min_part_size_ratio>
            <method>lz4</method>
        </case>
    </clickhouse_compression>
</yandex>

启动集群 所有节点执行

clickhouse start

DataGrip 链接

  • 下载驱动 用 Maven 指定版本号下载
  • https://github.com/housepower/ClickHouse-Native-JDBC
    

测试

ddl,dml 集群上 创建本地表 和 分布式表

SELECT * FROM system.clusters;

CREATE TABLE default.`test_local` on cluster ck_cluster
(
    a Int32,
    b String,
    c Date
) ENGINE = MergeTree(c, (a), 8192);

#drop table default.test_local on cluster ck_cluster;

CREATE TABLE default.test_all AS default.test_local
    ENGINE = Distributed(ck_cluster, default, test_local, intHash64(a));

select * from test_all order by a;
select count(*) as num from test_all;

select * from default.test_local;

insert into test_all values (rand(10), replaceAll(toString(generateUUIDv4()), '-', ''), now());

卸载

yum remove -y clickhouse*
rm -rf /etc/clickhouse* /var/lib/clickhouse* /var/log/clickhouse* /var/run/clickhouse* \
/usr/bin/clickhouse* /etc/rc.d/init.d/clickhouse* /etc/cron.d/clickhouse* /etc/systemd/system/clickhouse*

userdel clickhouse && groupdel clickhouse

标题:ClickHouse 3s1r 集群安装
作者:uid1024
地址:http://javadaily.cn/articles/2021/01/05/1609833873559.html