大数据-134 - ClickHouse 集群三节点 安装配置启动

点一下关注吧!!!非常感谢!!持续更新!!!

目前已经更新到了:

  • Hadoop(已更完)
  • HDFS(已更完)
  • MapReduce(已更完)
  • Hive(已更完)
  • Flume(已更完)
  • Sqoop(已更完)
  • Zookeeper(已更完)
  • HBase(已更完)
  • Redis (已更完)
  • Kafka(已更完)
  • Spark(已更完)
  • Flink(正在更新!)

章节内容

上节我们完成了如下的内容:

  • ClickHouse 简要介绍

官网网站

shell 复制代码
https://clickhouse.com/

单机安装

我是 Ubuntu 的服务器:

shell 复制代码
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates dirmngr

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv E0C56BD4
echo "deb https://repo.clickhouse.com/deb/stable/ main/" | sudo tee /etc/apt/sources.list.d/clickhouse.list

sudo apt-get update
sudo apt-get install -y clickhouse-server clickhouse-client

等待安装 ClickHouse

等待之后,可以看到已经顺利的安装完毕:

默认的密码路径是:

shell 复制代码
/etc/clickhouse-server/users.d/default-password.xml

配置权限

不配置后续可能会报错

shell 复制代码
sudo chown -R clickhouse:clickhouse /etc/clickhouse-server
sudo chmod -R 755 /etc/clickhouse-server
sudo chown -R clickhouse:clickhouse /var/lib/clickhouse
sudo chmod -R 755 /var/lib/clickhouse

单机测试

启动ClickServer

shell 复制代码
sudo -u clickhouse clickhouse-server

启动ClickClient

shell 复制代码
clickhouse-client -m

集群安装

集群安装

目前我有的节点是三台:

  • h121 2C4G
  • h122 2C4G
  • h123 2C4G
    刚才单机安装是在 h121 节点上,我们需要对三台云服务都执行相应的Shell:
shell 复制代码
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates dirmngr
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv E0C56BD4
echo "deb https://repo.clickhouse.com/deb/stable/ main/" | sudo tee /etc/apt/sources.list.d/clickhouse.list
sudo apt-get update
sudo apt-get install -y clickhouse-server clickhouse-client

停止服务

我们需要停止之前的服务,来空出一定的内存和端口给 ClickHouse 使用。

(如果你的内存比较富裕可以忽略)

只保留 ZooKeeper 即可,其他服务可以都关闭掉。比如Hadoop集群、Kafka集群、Redis集群等。

配置文件

config.xml

我们需要三台云服务器都修改config.xml

shell 复制代码
cd /etc/clickhouse-server
vim config.xml

修改如下内容:

shell 复制代码
<!-- Path to data directory, with trailing slash. -->
<path>/var/lib/clickhouse/</path>

开放远程访问,允许所有连接:

shell 复制代码
<listen_host>::</listen_host>

在根标签下加入内容(我是放入了头部):

shell 复制代码
<include_from>/etc/clickhouse-server/config.d/metrika.xml</include_from>

内容修改为如下的样子:

metrika.xml

shell 复制代码
cd /etc/clickhouse-server/config.d
# 该文件是新增的
vim metrika.xml

注意,下面的内容需要根据你的服务器IP来进行配置:

xml 复制代码
<yandex>
  <remote_servers>
    <perftest_3shards_1replicas>
      <shard>
        <internal_replication>true</internal_replication>
        <replica>
          <host>h121.wzk.icu</host>
          <port>9000</port>
          <user>default</user>
          <password>clickhouse@wzk.icu</password>
        </replica>
      </shard>
      <shard>
        <internal_replication>true</internal_replication>
        <replica>
          <host>h122.wzk.icu</host>
          <port>9000</port>
          <user>default</user>
          <password>clickhouse@wzk.icu</password>
        </replica>
      </shard>
      <shard>
        <internal_replication>true</internal_replication>
        <replica>
          <host>h123.wzk.icu</host>
          <port>9000</port>
          <user>default</user>
          <password>clickhouse@wzk.icu</password>
        </replica>
      </shard>
    </perftest_3shards_1replicas>
  </remote_servers>
  <zookeeper-servers>
    <node index="1">
      <host>h121.wzk.icu</host>
      <port>2181</port>
    </node>
    <node index="2">
      <host>h122.wzk.icu</host>
      <port>2181</port>
    </node>
    <node index="3">
      <host>h123.wzk.icu</host>
      <port>2181</port>
    </node>
  </zookeeper-servers>
  <macros>
    <shard>01</shard>
    <replica>h121.wzk.icu</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>

保存之后,修改一下权限:

shell 复制代码
sudo chown -R clickhouse:clickhouse /etc/clickhouse-server/config.d/metrika.xml

修改密码

shell 复制代码
vim /etc/clickhouse-server/users.d/default-password.xml

为了测试方便,修改为如下的内容:

xml 复制代码
<clickhouse>
    <users>
        <default>
            <password>clickhouse@wzk.icu</password>
            <networks>
                <ip>::/0</ip>
            </networks>
        </default>
    </users>
</clickhouse>
shell 复制代码
vim /etc/clickhouse-server/users.xml

为了测试方便,修改的密码如下:

xml 复制代码
省略其他内容
<password>clickhouse@wzk.icu</password>

启动测试

shell 复制代码
sudo -u clickhouse clickhouse-server --config-file=/etc/clickhouse-server/config.xml

正式启动

我们需要编辑一下 system 的文件,来实现优化的启停

shell 复制代码
vim /etc/systemd/system/clickhouse-server.service

可以看到,里边的配置已经在我们安装的时候就配置好了,你可以根据你的需要来修改:

接着我们使用系统命令启动:

shell 复制代码
systemctl start clickhouse-server
systemctl status clickhouse-server

我们可以看到程序已经顺利的运行了:

相关推荐
碎叶城李白4 分钟前
若依学习笔记1-validated
java·笔记·学习·validated
Edingbrugh.南空10 分钟前
Flink MySQL CDC 环境配置与验证
mysql·adb·flink
都叫我大帅哥31 分钟前
🌊 Redis Stream深度探险:从秒杀系统到面试通关
java·redis
都叫我大帅哥32 分钟前
Redis持久化全解析:从健忘症患者到记忆大师的逆袭
java·redis
程序猿阿越1 小时前
Kafka源码(一)Controller选举与创建Topic
java·后端·源码
程序无bug1 小时前
Spring6 当中 Bean 的生命周期的详细解析:有五步,有七步,有十步
java
二川bro1 小时前
飞算智造JavaAI:智能编程革命——AI重构Java开发新范式
java·人工智能·重构
Jiude1 小时前
MinIO 社区版被故意阉割,Web管理功能全面移除。我来试试国产RustFS
后端·docker·架构
Q_970956391 小时前
java+vue+SpringBoo校园失物招领网站(程序+数据库+报告+部署教程+答辩指导)
java·数据库·vue.js