服务器及ip资源:

centos版本:

CentOS Linux release 7.9.2009 (Core)

内核版本:

Linux 3.10.0-1160.el7.x86_64

IP及主机名:

192.168.199.170 ck1
192.168.199.171 ck2
192.168.199.172 ck3
192.168.199.173 ck4
192.168.199.174 ck5
192.168.199.175 ck6

说明:在三台机上部署zookeeper集群,及clickhouse集群

CentOS 取消打开文件数限制 (所有机器)

vim /etc/security/limits.conf
在文件末尾添加(clickhouse安装时也会单独生成etc/security/limits.d/clickhouse.conf 的句柄数配置文件,这里还是要加上给zk使用):

* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072

CentOS 取消 SELINUX (所有机器)

修改 /etc/selinux/config 中的 SELINUX=disabled 后重启

vim /etc/selinux/config
SELINUX=disabled

关闭防火墙 (所有机器)

systemctl stop firewalld.service
systemctl disable firewalld.service

安装依赖 (所有机器)

yum install yum-utils
rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG
yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/clickhouse.repo

Zookeeper 集群安装 (所有机器)

mkdir -p /data
cd /data
wget https://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
tar -xzvf zookeeper-3.4.14.tar.gz
mv zookeeper-3.4.14 zookeeper

编辑配置文件 (所有机器)

cp /data/zookeeper/conf/zoo_sample.cfg /data/zookeeper/conf/zoo.cfg
vim /data/zookeeper/conf/zoo.cfg
dataDir=/data/zookeeper/data
dataLogDir=/data/zookeeper/logs
server.1=ck1:2888:3888
server.2=ck2:2888:3888
server.3=ck3:2888:3888
#建立zk目录
mkdir -p /data/zookeeper/data
mkdir -p /data/zookeeper/logs
#建立myid
vim /data/zookeeper/data/myid
# ck1输入1, ck2输入2, ck3输入3

启动zk及查看状态 (所有机器)

/data/zookeeper/bin/zkServer.sh start
# 查看状态
/data/zookeeper/bin/zkServer.sh status

安装clickhouse(yum安装 所有机器)

yum install clickhouse-server clickhouse-client

安装clickhouse(rpm包安装 所有机器)

yum install -y unixODBC libicudata
yum install -y libxml2-devel expat-devel libicu-devel
#按如下顺序进行先static、common、server、client
rpm -ivh clickhouse-common-static-20.8.3.18-1.el7.x86_64.rpm 
rpm -ivh clickhouse-server-common-20.8.3.18-1.el7.x86_64.rpm
rpm -ivh clickhouse-server-20.8.3.18-1.el7.x86_64.rpm 
rpm -ivh clickhouse-client-20.8.3.18-1.el7.x86_64.rpm

编辑配置文件(所有机器)

#编辑config.xml配置文件
#日志存放位置 根据个人所需修改
<log>/var/log/clickhouse-server/clickhouse-server.log</log>
<errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>

#数据目录 个人所需修改
<path>/var/lib/clickhouse/</path>
<tmp_path>/var/lib/clickhouse/tmp/</tmp_path>

#允许被访问 放开注释
<listen_host>::</listen_host>

#映射(可选)
<remote_servers incl="clickhouse_remote_servers">
<zookeeper incl="zookeeper-servers" optional="true" />
<macros incl="macros" optional="true" />
<include_from>/etc/clickhouse-server/metrika.xml</include_from>

#最大连接数
<max_connections>4096</max_connections>

#编辑用户配置文件user.xml
#内存限制
<max_memory_usage>30000000000</max_memory_usage>

#增加默认用户的密码,否则clickhouse不需要密码都可登录
<users>
    <default>
        <password>密码自定义</password>
    </default>
</users>

#编辑分片副本规则文件metrika.xml
<yandex>
<clickhouse_remote_servers>
<!-- 数据3分片 2 副本 cdh1 cdh2 cdh3 为主机名,建议主机名有规划取名,internal_replication 自动同步 -->
<cluster_3shards_2replicas>
        <!-- 数据分片1  -->
    <shard>
            <internal_replication>true</internal_replication>
            <replica>
                <host>192.168.199.170</host>
                <port>9999</port>
        <user>default</user>
                <password>123456</password> 
            </replica>
                   <replica>
                <host>192.168.199.171</host>
                <port>9999</port>
        <user>default</user>
                <password>123456</password> 
            </replica>
        </shard>

        <!-- 数据分片2  -->
        <shard>
            <internal_replication>true</internal_replication>
            <replica>
                <host>192.168.199.172</host>
                <port>9999</port>
        <user>default</user>
                <password>123456</password>
            </replica>
                   <replica>
                <host>192.168.199.173</host>
                <port>9999</port>
        <user>default</user>
                <password>123456</password> 
            </replica>
        </shard>

        <!-- 数据分片3  -->
        <shard>
            <internal_replication>true</internal_replication>
            <replica>
                <host>192.168.199.174</host>
                <port>9999</port>
        <user>default</user>
                <password>123456</password>
            </replica>
                   <replica>
                <host>192.168.199.175</host>
                <port>9999</port>
        <user>default</user>
                <password>123456</password> 
            </replica>
        </shard>
    </cluster_3shards_2replicas>
</clickhouse_remote_servers>

<!-- 本节点副本名称 配置副本 分片 层 信息 -->

<macros>
    <replica>02</replica>
    <shard>02</shard>
    <layer>01</layer>
</macros>

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

<!-- 配置 ZK 信息   -->
<zookeeper-servers>
  <node index="1">
    <host>192.168.199.170</host>
    <port>2181</port>
  </node>
  <node index="2">
    <host>192.168.199.171</host>
    <port>2181</port>
  </node>
  <node index="3">
    <host>192.168.199.172</host>
    <port>2181</port>
  </node>
</zookeeper-servers>

<!-- 数据压缩算法  -->
<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实例存放什么 -->
    <macros>
              <!-- 几号分片 -->
        <shard>01</shard>
              <!-- 1分片的2副本 -->
        <replica>集群名-01-2</replica>
    </macros>

建立ck所需目录 (所有机器)

mkdir -p /data/clickhouse
#注意:有时需要单独建立子目录
mkdir -p /data/clickhouse/access
mkdir -p /data/clickhouse/user_files
mkdir -p /data/clickhouse/data
mkdir -p /data/clickhouse/tmp
chown -R clickhouse:clickhouse /data/clickhouse

启动ck服务并验证 (所有机器)

systemctl start clickhouse-server
systemctl status clickhouse-server

通过命令行模式或Dbeaver客户端访问

最后修改日期: 2022年2月14日

作者

留言

撰写回覆或留言

发布留言必须填写的电子邮件地址不会公开。