ClickHouse安装(集群版)

一、准备工作

1、设置hostname

# 三台机器分别执行
hostnamectl set-hostname node1
hostnamectl set-hostname node2
hostnamectl set-hostname node3

2、hosts映射

# 三台机器均执行(根据自己ip进行修改)
vim /etc/hosts
192.168.117.30 node1
192.168.117.31 node2
192.168.117.32 node3

3、关闭防火墙

# 三台机器均执行
systemctl stop firewalld.service
systemctl disable firewalld.service

4、同步时间

# 三台机器均执行
yum install ntpdate
ntpdate ntp5.aliyun.com

5、关闭selinux

# 三台机器均执行
vim /etc/selinux/config
修改为 SELINUX=disabled

6、安装好zookeeper

这里我简单的用docker安装了一个单机版的zookeeper作为测试使用

docker pull zookeeper
docker run -d --name zookeeper --privileged=true -p 2181:2181 zookeeper

7、重启

二、搭建ClickHouse集群

本次集群规划:三台机器组成集群中的三个节点,每个节点设置一个副本

1、下载安装包

可以使用如下地址下载(阿里镜像比较快一些)

https://repo.yandex.ru/clickhouse/rpm/stable/x86_64/

https://mirrors.aliyun.com/clickhouse/rpm/lts/

在这里插入图片描述

2、安装

rpm -ivh clickhouse*

安装过程中需要输入密码,不设置密码直接回车即可
在这里插入图片描述

3、修改配置文件

注:配置文件需要同步到集群中的所有机器
配置文件位置:/etc/clickhouse-server
(1)放开listen_host配置,使clickhouse可以外部访问
在这里插入图片描述
(2)修改**/etc/clickhouse-server/config.xml**

# remote_servers 标签下默认的配置不需要可以删掉
# 添加“incl”,并且名称要和metrika.xml中标签定义名称相同,如下图1对应关系
# 添加“include_from”标签,配置“metrika.xml”路径
# 新建“metrika.xml”文件并编辑内容,内容说明如下图2
<remote_servers incl="clickhouse_button">
<include_from>/etc/clickhouse-server/metrika.xml</include_from>

“incl”值与metrika.xml的对应关系(图1)
在这里插入图片描述
metrika.xml文件配置(图2)
注:metrika.xml文件配置根据自己的集群规划来进行配置即可

<yandex>
    <!-- incl="clickhouse_button"  --> 
    <clickhouse_button>
        <!--  自定义集群名称(自己定义即可)  -->
        <button_cluster>
            <!--  定义集群的分片数量,几个shard标签则说明几个节点  -->
            <shard>
                <!--  定义分片的副本数量,这里只配置了一个,如果需要配置多个,追加replica即可  -->
                <replica>
                    <host>node1</host>
                    <port>9000</port>
                </replica>
            </shard>
            <shard>
                <replica>
                    <host>node2</host>
                    <port>9000</port>
                </replica>
            </shard>
			<shard>
                <replica>
                    <host>node3</host>
                    <port>9000</port>
                </replica>
            </shard>
        </button_cluster>
    </clickhouse_button>
 
    <zookeeper-servers>
	    <!-- zookeeper多个节点追加node配置即可 -->
        <node index="1">
            <host>node1</host>
            <port>2181</port>
        </node>
    </zookeeper-servers>
</yandex>

4、启动

# 启动 ClickHouse
systemctl start clickhouse-server
# 查看 ClickHouse 运行状态,运行状态如下图所示
systemctl status clickhouse-server

在这里插入图片描述

三、验证集群

# 使用clickhouse-client
clickhouse-client --password *****
select cluster,shard_num,replica_num,host_name,port,user from system.clusters;

在这里插入图片描述

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用 Ansible 安装部署 ClickHouse 集群,需要完成以下步骤: 1. 确保已经在每个目标主机上安装ClickHouse,并确保 ClickHouse 已经可以正常运行。 2. 创建一个 Ansible 的 inventory 文件,该文件列出了所有 ClickHouse 集群中的主机及其 IP 地址。一个简单的 inventory 文件可能如下所示: ``` [clickhouse] ch1.example.com ch2.example.com ch3.example.com ``` 3. 创建一个 Ansible playbook 文件,该文件包含用于安装和配置 ClickHouse 的任务。以下是一个示例 playbook: ``` - name: Install and configure ClickHouse hosts: clickhouse become: true tasks: - name: Install ClickHouse apt: name: clickhouse-server state: present become: true become_user: root - name: Configure ClickHouse template: src: clickhouse-server.xml.j2 dest: /etc/clickhouse-server/config.xml become: true become_user: clickhouse ``` 在这个 playbook 中,我们首先使用 Ansible 的 apt 模块安装 ClickHouse,然后使用 Ansible 的 template 模块将 ClickHouse 配置文件复制到目标主机的 `/etc/clickhouse-server/config.xml` 文件中。 4. 创建一个 ClickHouse 配置模板文件。这个模板文件应该包含用于配置 ClickHouse 的所有参数。以下是一个示例配置文件: ``` <yandex> <clickhouse_server> <interserver_http_host>0.0.0.0</interserver_http_host> <listen_host>0.0.0.0</listen_host> <listen_port>9000</listen_port> <max_connections>1000</max_connections> <max_concurrent_queries>1000</max_concurrent_queries> <distributed_ddl> <num_tries>3</num_tries> <try_delay_sec>3</try_delay_sec> </distributed_ddl> <users> <default> <password></password> <networks> <ip>::/0</ip> </networks> </default> </users> </clickhouse_server> </yandex> ``` 请注意,这个配置文件只包含了一些基本的 ClickHouse 配置选项。您应该根据自己的需求进行修改。 5. 运行 playbook,部署 ClickHouse 集群。要运行 playbook,请使用以下命令: ``` ansible-playbook -i inventory_file playbook_file.yml ``` 这将在 ClickHouse 集群中的所有主机上运行 playbook。 以上就是使用 Ansible 安装部署 ClickHouse 集群的一般步骤。请注意,这只是一个基本的例子。要根据自己的需求对 playbook 进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值