clickhouse 21.x 集群部署

标签(空测试用例格分隔):clickhouse 系列


一:系统环境部署介绍

1.1:系统初始化

系统:
   centos7.9x64
 
 主机名字:
   cat /etc/hosts 
   
   -----
   
172.16.10.11    flyfishsrvs01
172.16.10.12    flyfishsrvs02
172.16.10.13    flyfishsrvs03
172.16.10.14    flyfishsrvs04
172.16.10.15    flyfishsrvs05
172.16.10.16    flyfishsrvs06
172.16.10.17    flyfishsrvs07 

   ------
  本次部署前四台服务器 

1.2 系统部署jdk

在flyfishsrvs02,flyfishsrvs03,flyfishsrvs04 上面部署

tar -zxvf jdk-8u301-linux-x64.tar.gz
mv jdk1.8.0_301/ /usr/local/jdk
vim /etc/profile 
----

### jdk
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
----

source /etc/profile

java -version 

![image.png](https://img-blog.csdnimg.cn/img_convert/b3c25dedfc083a0e0d2d69fb3fc9560d.png#clientId=u407d2d80-4ebc-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=120&id=u39db86a1&margin=[object Object]&name=image.png&originHeight=301&originWidth=1928&originalType=binary&ratio=1&rotation=0&showTitle=false&size=40948&status=done&style=none&taskId=u1d2ea487-6f43-49ed-ab6a-a72ce9d99d3&title=&width=771.2)

![image.png](https://img-blog.csdnimg.cn/img_convert/e288b1ad21d9c288419113d5255bd88d.png#clientId=u407d2d80-4ebc-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=149&id=u76689512&margin=[object Object]&name=image.png&originHeight=373&originWidth=1754&originalType=binary&ratio=1&rotation=0&showTitle=false&size=48598&status=done&style=none&taskId=ub45eff41-9696-4b6c-8de3-40a50ce1e8f&title=&width=701.6)

![image.png](https://img-blog.csdnimg.cn/img_convert/3bff41419eca8f5714daf61cefeae4b4.png#clientId=u407d2d80-4ebc-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=171&id=ude39715a&margin=[object Object]&name=image.png&originHeight=427&originWidth=1734&originalType=binary&ratio=1&rotation=0&showTitle=false&size=54490&status=done&style=none&taskId=ua62fe877-23bb-4cb7-99e9-bba061e25a3&title=&width=693.6)

1.3 配置zookeeper 集群

在flyfishsrvs02,flyfishsrvs03,flyfishsrvs04 上面部署
tar -zxvf apache-zookeeper-3.7.0-bin.tar.gz
mv apache-zookeeper-3.7.0-bin /usr/local/zookeeper

mkdir -p /usr/local/zookeeper/data
mkdir -p /usr/local/zookeeper/log

cd /usr/local/zookeeper/data/

echo 1 > myid
----
cd /usr/local/zookeeper/conf 

cp zoo_sample.cfg zoo.cfg 

vim zoo.cfg 

----
# 心跳时间
tickTime=2000
# follow连接leader的初始化连接时间,表示tickTime的倍数
initLimit=10
# syncLimit配置表示leader与follower之间发送消息,请求和应答时间长度。如果followe在设置的时间内不能与leader进行通信,那么此follower将被丢弃,tickTime的倍数
syncLimit=5
# 客户端连接端口
clientPort=2181
# 节点数据存储目录,需要提前创建,注意myid添加,用于标识服务器节点
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/log
server.1=172.16.10.12:2888:3888
server.2=172.16.10.13:2888:3888
server.3=172.16.10.14:2888:3888
---
-----

scp -r zookeeper root@172.16.10.13:/usr/local/
scp -r zookeeper root@172.16.10.14:/usr/local/
修改172.16.10.13 节点 myid 
cd /usr/local/zookeeper/data/
echo 2 > myid 
修改172.16.10.14 节点 myid
cd /usr/local/zookeeper/data/
echo 3 > myid


![image.png](https://img-blog.csdnimg.cn/img_convert/a5e6b31b47527c6edbab352a2205bb4c.png#clientId=uf7f9630a-a885-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=443&id=u43e3aee0&margin=[object Object]&name=image.png&originHeight=1107&originWidth=2316&originalType=binary&ratio=1&rotation=0&showTitle=false&size=151793&status=done&style=none&taskId=u36e67825-ec74-4794-af1a-22fb06dfd92&title=&width=926.4)
![image.png](https://img-blog.csdnimg.cn/img_convert/94a73d85a82633225a39fc8e57ddb3b2.png#clientId=uf7f9630a-a885-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=307&id=ued3324ec&margin=[object Object]&name=image.png&originHeight=768&originWidth=1897&originalType=binary&ratio=1&rotation=0&showTitle=false&size=67903&status=done&style=none&taskId=u684619cf-efbe-45cc-84ae-2c2c6737d07&title=&width=758.8)

启动zookeeper 

cd /usr/local/zookeeper/bin/

./zkServer.sh start

![image.png](https://img-blog.csdnimg.cn/img_convert/ba760ee4bfc22fedb08e57266e9bcda9.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=370&id=u36fb76b2&margin=[object Object]&name=image.png&originHeight=925&originWidth=2556&originalType=binary&ratio=1&rotation=0&showTitle=false&size=127457&status=done&style=none&taskId=ud3702024-cf59-4437-bbb7-f68094ac7c6&title=&width=1022.4)
![image.png](https://img-blog.csdnimg.cn/img_convert/c4d23f9ee3d6800effc29b6505b90773.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=181&id=uf521845b&margin=[object Object]&name=image.png&originHeight=453&originWidth=2155&originalType=binary&ratio=1&rotation=0&showTitle=false&size=63367&status=done&style=none&taskId=uae6a46de-cba4-4f37-b347-f3958928936&title=&width=862)
![image.png](https://img-blog.csdnimg.cn/img_convert/e4483be6cdf380d7c5f5af384a9df1c9.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=260&id=u484b2fa6&margin=[object Object]&name=image.png&originHeight=650&originWidth=2303&originalType=binary&ratio=1&rotation=0&showTitle=false&size=87768&status=done&style=none&taskId=u75ece2d3-3b62-4e56-9785-6bc81e80147&title=&width=921.2)

二: 部署clickhouse 21.x

2.1 安装clickhouse 21.x

rpm -ivh clickhouse-* [所有节点都安装处理]

![image.png](https://img-blog.csdnimg.cn/img_convert/82c3e1c15b407bf1f7b983a2c217c6ec.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=420&id=u851f81d5&margin=[object Object]&name=image.png&originHeight=1050&originWidth=2570&originalType=binary&ratio=1&rotation=0&showTitle=false&size=190999&status=done&style=none&taskId=u6a23b8e6-053b-41d1-8eb5-da073446791&title=&width=1028)

修改listen_host

vim +164 /etc/clickhouse-server/config.xml

----
<listen_host>::1</listen_host>
<listen_host>flyfishsrvs01</listen_host>  ### 其它节点修改对于主机名
-----

![image.png](https://img-blog.csdnimg.cn/img_convert/7763f2d6f6be9e2ed3b768413a335ec4.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=213&id=ub4eb2479&margin=[object Object]&name=image.png&originHeight=533&originWidth=2075&originalType=binary&ratio=1&rotation=0&showTitle=false&size=46274&status=done&style=none&taskId=u8ab42cbe-edcd-4d75-9bf4-1141644699b&title=&width=830)
![image.png](https://img-blog.csdnimg.cn/img_convert/b34890590613453994114a54b9ebdcc1.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=179&id=uf59cbdc2&margin=[object Object]&name=image.png&originHeight=448&originWidth=1546&originalType=binary&ratio=1&rotation=0&showTitle=false&size=37206&status=done&style=none&taskId=u08bca693-be57-4234-84f4-9cb1fcbac95&title=&width=618.4)
![image.png](https://img-blog.csdnimg.cn/img_convert/b76d2d79918ccfea320d0a9b9ceb6fec.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=240&id=ue955f5b6&margin=[object Object]&name=image.png&originHeight=601&originWidth=1729&originalType=binary&ratio=1&rotation=0&showTitle=false&size=46948&status=done&style=none&taskId=ude77ca56-5a9e-4b27-bba3-f4adada88fd&title=&width=691.6)
![image.png](https://img-blog.csdnimg.cn/img_convert/5eec65fd708060fa6b18ab45ea9404b2.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=212&id=u58c7c568&margin=[object Object]&name=image.png&originHeight=531&originWidth=1779&originalType=binary&ratio=1&rotation=0&showTitle=false&size=46373&status=done&style=none&taskId=ub44e9145-6a6a-4ac6-91c4-bc90d87d5ae&title=&width=711.6)

2.2 配置集群文件

配置集群连接文件
cd /etc/clickhouse-server/config.d
vim metrika.xml 
-----
<yandex> 
    <remote_servers> 
        <clickhouse_cluster_4shards_1replicas> 
           <shard> 
               <internal_replication>true</internal_replication>
                  <replica> 
                     <host>flyfishsrvs01</host> 
                     <port>9000</port> 
                  </replica> 
           </shard> 
           <shard> 
               <internal_replication>true</internal_replication> 
                  <replica> 
                     <host>flyfishsrvs02</host> 
                     <port>9000</port> 
                  </replica> 
           </shard> 
           <shard> 
               <internal_replication>true</internal_replication> 
                  <replica> 
                     <host>flyfishsrvs03</host> 
                     <port>9000</port> 
                  </replica> 
           </shard>
           <shard> 
               <internal_replication>true</internal_replication> 
                  <replica> 
                     <host>flyfishsrvs04</host> 
                     <port>9000</port> 
                  </replica> 
           </shard>
           </clickhouse_cluster_4shards_1replicas>
    </remote_servers> 
    <zookeeper>
       <node index="1"> 
           <host>flyfishsrvs02</host> 
           <port>2181</port> 
        </node> 
       <node index="2"> 
          <host>flyfishsrvs03</host> 
          <port>2181</port> 
       </node> 
       <node index="3"> 
          <host>flyfishsrvs04</host> 
          <port>2181</port> 
       </node> 
     </zookeeper>

     <macros> 
        <shard>01</shard> 
        <replica>flyfishsrvs01</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>

---------------
scp metrika.xml root@flyfishsrvs02:/etc/clickhouse-server/config.d/
scp metrika.xml root@flyfishsrvs03:/etc/clickhouse-server/config.d/
scp metrika.xml root@flyfishsrvs04:/etc/clickhouse-server/config.d/

![image.png](https://img-blog.csdnimg.cn/img_convert/3d21be90be2da5403ea7f14ec44f3a07.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=696&id=u4111374d&margin=[object Object]&name=image.png&originHeight=1739&originWidth=2447&originalType=binary&ratio=1&rotation=0&showTitle=false&size=162845&status=done&style=none&taskId=uba376bca-63cf-46aa-84ee-34c29f3168f&title=&width=978.8)

![image.png](https://img-blog.csdnimg.cn/img_convert/b522dc1e973a5d8ebc89f5d223aa57ca.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=549&id=ua82ef78d&margin=[object Object]&name=image.png&originHeight=1373&originWidth=2205&originalType=binary&ratio=1&rotation=0&showTitle=false&size=122063&status=done&style=none&taskId=u9ae8a994-59b1-4b09-aae2-de7212ae2cc&title=&width=882)
![image.png](https://img-blog.csdnimg.cn/img_convert/5be0c961a93f35634c99c0abb0b02ac8.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=152&id=u57e6cb1b&margin=[object Object]&name=image.png&originHeight=381&originWidth=3264&originalType=binary&ratio=1&rotation=0&showTitle=false&size=63417&status=done&style=none&taskId=uf9a6a768-afa4-46c7-9687-f768507960d&title=&width=1305.6)

2.3 集群启动与验证

修改对应节点的副本主机名
vim 
#flyfishsrvs02节点修改metrika.xml中的宏变量如下: 
<macros> 
<shard>02</replica>
<replica>flyfishsrvs02</replica> 
</macros> 
#flyfishsrvs03节点修改metrika.xml中的宏变量如下: 
<macros> 
<shard>03</replica>
<replica>flyfishsrvs03</replica> 
</macros>

#flyfishsrvs04节点修改metrika.xml中的宏变量如下: 
<macros> 
<shard>04</replica>
<replica>flyfishsrvs04</replica> 
</macros>
 

![image.png](https://img-blog.csdnimg.cn/img_convert/71eae686fd90a4f8f4ea5733ad833a0d.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=356&id=u514bfe4d&margin=[object Object]&name=image.png&originHeight=889&originWidth=1799&originalType=binary&ratio=1&rotation=0&showTitle=false&size=74577&status=done&style=none&taskId=ud98743e4-0e4f-4448-90fe-cab5a23b7b0&title=&width=719.6)
![image.png](https://img-blog.csdnimg.cn/img_convert/638bbf92b3d2e888ac34012cc0d50693.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=420&id=u649fe120&margin=[object Object]&name=image.png&originHeight=1050&originWidth=1988&originalType=binary&ratio=1&rotation=0&showTitle=false&size=94163&status=done&style=none&taskId=uf22ad51e-1266-4a94-91d5-0ecafa6173f&title=&width=795.2)
![image.png](https://img-blog.csdnimg.cn/img_convert/f0d9403c0e18dd7b11e3822c623fecd9.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=444&id=u0ab00365&margin=[object Object]&name=image.png&originHeight=1111&originWidth=2660&originalType=binary&ratio=1&rotation=0&showTitle=false&size=103929&status=done&style=none&taskId=uc95428d0-cc09-478d-a2ae-f4d5348e77a&title=&width=1064)

#每台节点启动Clickchouse服务 
service clickhouse-server start
#每台节点查看clickhouse服务状态 
service clickhouse-server status 
#每台节点重启clickhouse服务 
service clickhouse-server restart 
#每台节点关闭Clikchouse服务 
service clickhouse-server stop

![image.png](https://img-blog.csdnimg.cn/img_convert/23126e381b2f7a8090412a3afcae5b8e.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=158&id=u5147662a&margin=[object Object]&name=image.png&originHeight=396&originWidth=2067&originalType=binary&ratio=1&rotation=0&showTitle=false&size=54987&status=done&style=none&taskId=u3bcb695d-2523-406d-ba0a-8a4642f6cb1&title=&width=826.8)
![image.png](https://img-blog.csdnimg.cn/img_convert/5e3e75efed6ae1e5e5a324f2c7cc12b1.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=122&id=u0d02b592&margin=[object Object]&name=image.png&originHeight=306&originWidth=2104&originalType=binary&ratio=1&rotation=0&showTitle=false&size=43780&status=done&style=none&taskId=ufd0a869e-9350-4ed3-baa1-b6eddf1a33d&title=&width=841.6)
![image.png](https://img-blog.csdnimg.cn/img_convert/f91e6b3c8dd9677c0adf2b7a614908f0.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=195&id=ub025a306&margin=[object Object]&name=image.png&originHeight=487&originWidth=2078&originalType=binary&ratio=1&rotation=0&showTitle=false&size=66737&status=done&style=none&taskId=uc6f20838-6d21-410b-bcd4-46672a09540&title=&width=831.2)
![image.png](https://img-blog.csdnimg.cn/img_convert/d63864aaab536073538c3d04cc54d87f.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=160&id=u93399440&margin=[object Object]&name=image.png&originHeight=401&originWidth=2223&originalType=binary&ratio=1&rotation=0&showTitle=false&size=52188&status=done&style=none&taskId=ub479bfcc-7d03-4584-9df4-ac280ceac91&title=&width=889.2)

验证:
clickhouse-client -h flyfishsrvs01
查看集群:
select * from system.clusters;
select cluster,host_name from system.clusters;

![image.png](https://img-blog.csdnimg.cn/img_convert/b2a26fb5179d9692fd34ec6c6b99b01b.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=176&id=u551bd183&margin=[object Object]&name=image.png&originHeight=439&originWidth=2236&originalType=binary&ratio=1&rotation=0&showTitle=false&size=48930&status=done&style=none&taskId=u322ec42b-6a1d-45ae-8dce-94603bc892c&title=&width=894.4)
![image.png](https://img-blog.csdnimg.cn/img_convert/696097b2122b821bfa01e41244fa4467.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=614&id=udbbcd138&margin=[object Object]&name=image.png&originHeight=1534&originWidth=3255&originalType=binary&ratio=1&rotation=0&showTitle=false&size=173139&status=done&style=none&taskId=uc143d03a-4334-44a1-9698-04aa302abc8&title=&width=1302)
![image.png](https://img-blog.csdnimg.cn/img_convert/11acd53bc6a4bcda452fa7faefdd436f.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=486&id=uf168db02&margin=[object Object]&name=image.png&originHeight=1215&originWidth=2176&originalType=binary&ratio=1&rotation=0&showTitle=false&size=116190&status=done&style=none&taskId=ud3f83e29-563d-46fb-9aa0-4abfeb01762&title=&width=870.4)

其它节点验证:
select * from system.clusters;
select cluster,host_name from system.clusters;

![image.png](https://img-blog.csdnimg.cn/img_convert/0dcddd3b7381cee8a32ef102a18a353c.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=442&id=u089583c6&margin=[object Object]&name=image.png&originHeight=1106&originWidth=3271&originalType=binary&ratio=1&rotation=0&showTitle=false&size=128172&status=done&style=none&taskId=u456199ce-36df-4977-bd29-9fcfd19dd2f&title=&width=1308.4)
![image.png](https://img-blog.csdnimg.cn/img_convert/43014efafb9d8cc961978087f3e5a185.png#clientId=u6dd9a1e0-c897-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=418&id=u1ef658bc&margin=[object Object]&name=image.png&originHeight=1046&originWidth=2304&originalType=binary&ratio=1&rotation=0&showTitle=false&size=102528&status=done&style=none&taskId=u8eb309bf-986f-442d-a935-51813058557&title=&width=921.6)

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值