环境
192.168.1.240 apm01
192.168.1.241 apm02
192.168.1.243 clickhouse02
安装JDK
在三台服务器上分别安装JDK1.8(此步骤略)
安装zookeeper
- 下载 zookeeper-3.4.12.tar.gz 安装包,放置到上面三台服务器的/opt目录下
- 进入到/opt目录下,解压tar包,tar -zxvf zookeeper-3.4.12.tar.gz
- 修改目录名,mv zookeeper-3.4.12 zookeeper
- 进入zookeeper的conf目录,拷贝zoo_sample.cfg为zoo.cfg,cp zoo_sample.cfg zoo.cfg
- 修改zoo.cfg文件
tickTime=2000 initLimit=10 syncLimit=5 dataDir=/data/zookeeper dataLogDir=/data/zookeeper clientPort=2181 autopurge.purgeInterval=0 globalOutstandingLimit=200 server.1=apm01:2888:3888 server.2=apm02:2888:3888 server.3=clickhouse02:2888:3888
- 设置环境变量
export ZOOKEEPER_HOME=/opt/zookeeper
export PATH=$PATH:$ZOOKEEPER_HOME/bin
- 创建目录
mkdir -p /data/zookeeper
- 设置myid
vim /data/zookeeper/myid #240为1,241为2,243为3 - 启动zookeeper
进入zookeeper的bin目录下,执行./zkServer.sh start - 测试zookeeper
./zkCli.sh -server 192.168.1.241:2181
如果出现拒绝连接,查看防火墙是否关闭,关闭防火墙 systemctl stop firewalld 重启zookeeper
部署clickhouse
单节点安装(rpm包安装)
- 添加clickhouse用户
useradd clickhouse - 把下载好的rpm包上传到各个节点的/home/clickhouse目录下
- 安装rpm包
rpm -ivh clickhouse-server-common-19.1.8-1.el7.x86_64.rpm
rpm -ivh clickhouse-common-static-19.1.8-1.el7.x86_64.rpm
rpm -ivh clickhouse-server-19.1.8-1.el7.x86_64.rpm
rpm -ivh clickhouse-client-19.1.8-1.el7.x86_64.rpm
rpm -ivh unixODBC-2.3.1-11.el7.x86_64.rpm
- 配置/etc/clickhouse-server/config.xml
<log>/var/log/clickhouse-server/clickhouse-server.log</log>
<path>/data/clickhouse/</path>
<tmp_path>/data/clickhouse/tmp/</tmp_path>
<user_files_path>/data/clickhouse/user_files/</user_files_path>
<errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
- 把上述目录的用户都赋权给clickhouse
chown -R clickhouse:clickhouse 目录 - 启动clickhouse
/etc/init.d/clickhouse-server start
- 验证单节点的clickhouse
输入clickhouse-client进入clickhouse客户端,查询system数据库中的表名
配置集群
- 修改配置文件 vim /etc/clickhouse-server/config.xml
打开 <listen_host>::</listen_host> 的注释 - 创建配置文件 vim /etc/metrika.xml
<yandex>
<clickhouse_remote_servers>
<perftest_3shards_1replicas>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>192.168.1.240</host>
<port>9000</port>
</replica>
</shard>
<shard>
<replica>
<internal_replication>true</internal_replication>
<host>192.168.1.241</host>
<port>9000</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>192.168.1.243</host>
<port>9000</port>
</replica>
</shard>
</perftest_3shards_1replicas>
</clickhouse_remote_servers>
<!--zookeeper相关配置-->
<zookeeper-servers>
<node index="1">
<host>192.168.1.240</host>
<port>2181</port>
</node>
<node index="2">
<host>192.168.1.241</host>
<port>2181</port>
</node>
<node index="3">
<host>192.168.1.243</host>
<port>2181</port>
</node>
</zookeeper-servers>
<macros>
<replica>192.168.1.240</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>
上述配置中三个节点中不同的地方在于
<macros>
<replica>192.168.1.240</replica>
</macros>
改为当前节点的IP即可
- 重启clickhouse服务
/etc/init.d/clickhouse-server restart