clickhouse集群部署(三台机器)
1、安装前的准备工作
首先安装clickhouse
(1)yum安装:
Centos、RedHat
sudo yum install yum-utils -y
sudo rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG
sudo yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/stable/x86_64
sudo yum install clickhouse-server clickhouse-client -y
sudo /etc/init.d/clickhouse-server start
(2)启动后验证clickhouse-server是否启动
#ps -ef | grep clickhouse
(3)关闭防火墙
#systemctl stop firewalld.service
#systemctl disable firewalld.service
(4)修改 /etc/selinux/config 中的 SELINUX=disabled
注意:所有的配置文件修改时都在clickhouse-server关闭状态,这样在重新启动后会生效
2、部署zookeeper集群
众所周知,clickhouse是一款单机性能强悍的数据库,但正所谓“双拳难敌四手,好汉架不住人多”,如果不支持横向扩展的话,那么clichouse相比其他分布式的MPP数据库就没有什么优势了,所以理所当然的,clickhouse引入了分布式集群的工作模式;那么既然是分布式软件,就需要考虑数据的一致性问题,在这种情况下,考虑使用zookeeper。
zookeeper在clickhouse中主要用在副本表数据的同步(ReplicatedMergeTree引擎)以及分布式(Distributed)的操作上。
在安装zookeeper之前要先安装jdk,因为zookeeper是需要JDK来编译的。
(1)下载jdk(官网上下载)
(2)上传至虚拟机
(3)解压安装jdk
mkdir /usr/local/java(用于存放jdk)
tar -zxvf jdk-8u11-linux-x64.tar.gz -C /usr/local/java/(本人使用得使1.8.0_11版本的jdk)
(4)修改配置文件,添加以下内容(jdk的路径)
#vi /etc/profile
#java
JAVA_HOME=/usr/local/java/jdk1.8.0_11
export PATH=$PATH:$JAVA_HOME/bin
(5)是环境变量生效
#source /etc/profile
接下来配置zookeeper集群
(1)下载zookeeper
#mkdir /usr/local/zookeeper(创建zookeeper安装目录)
#cd /usr/local/zookeeper(切换到该目录地下)
#wget https://archive.apache.org/dist/zookeeper/zookeeper-3.7.0/apache-zookeeper-3.7.0-bin.tar.gz
(这里我下载的是3.7.0版本的zookeeper)
#tar -xvf apache-zookeeper-3.7.0-bin.tar.gz(解压)
(2)创建配置
#cp /usr/local/zookeeper/zookeeper-3.7.0/pache-zookeeper-3.7.0-bin/conf/zoo_sample.cfg /usr/local/zookeeper/zookeeper-3.7.0/pache-zookeeper-3.7.0-bin/conf/zoo.cfg
(3)修改配置参数(config.xml)
#vim /usr/local/zookeeper/zookeeper-3.7.0/conf/zoo.cfg
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs
server.1=ip1:2888:3888
server.2=ip2:2888:3888 (ip1,ip2,ip3为三台机器的ip地址,为主机之间建立互信做准备)
server.3=ip3:2888:3888
(4)每台创建不一样的server id标识
#mkdir -p /usr/local/zookeeper/data
#mkdir -p /usr/local/zookeeper/logs
#touch /usr/local/zookeeper/data/myid
#vim /usr/local/zookeeper/data/myid(ip1输入1, ip2输入2, ip3输入3)
(5)启动zk
#/usr/local/zookeeper/zookeeper-3.7.0/bin/zkServer.sh start
#/usr/local/zookeeper/zookeeper-3.7.0/bin/zkServer.sh status(必须每台机器都启动,状态才会显示安装成功)
出现这种问题的时候, 1、多检查三台虚拟机zoo.cfg配置文件是否有问题 2、检查自己myid是否写对 3、防火墙是否已关闭 4、确定是否都三台虚拟机都启动了集群
3、接下来进行clickhouse分布式集群安装
(1)修改配置文件 /etc/clickhouse-server/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>
#最大连接数 <max_connections>4096</max_connections>
#配置3分片2副本集群
<remote_servers> <ck_cluster> <shard> <weight>1</weight> <internal_replication>true</internal_replication> <replica> <host>ip1</host> <port>9000</port> </replica> <replica> <host>ip2</host> <port>9000</port> </replica> </shard> <shard> <weight>1</weight> <internal_replication>true</internal_replication> <replica> <host>ip1</host> <port>9100</port> </replica> <replica> <host>ip3</host> <port>9000</port> </replica> </shard> <shard> <weight>1</weight> <internal_replication>true</internal_replication> <replica> <host>ip2</host> <port>9100</port> </replica> <replica> <host>ip3</host> <port>9100</port> </replica> </shard> </ck_cluster> </remote_servers> <zookeeper> <node> <host>ip1</host> <port>2181</port> </node> <node> <host>ip2</host> <port>2181</port> </node> <node> <host>ip3</host> <port>2181</port> </node> </zookeeper> <macros>
<!-- 几号分片 -->
<shard>01</shard>
<!-- 1分片的2副本 -->
<replica>集群名-01-2</replica>
</macros>
(2)修改配置文件 users.xml
vi /etc/clickhouse-server/users.xml
#内存限制 <max_memory_usage>30000000000</max_memory_usage>
#增加默认用户的密码,否则clickhouse不需要密码都可登录
<users> <default> <password>密码自定义</password> <access_management>1</access_management> </default> </users>修改完成后,重新启动zk
#cd /usr/local/zookeeper/zookeeper-3.7.0/pache-zookeeper-3.7.0-bin/bin
#./zkServer.sh start
#ps -ef | grep zookeeper(查看zookeeper进程状态)
重新启动ck
#systemctl start clickhouse-server
#systemctl status clickhouse-server(查看clickhouse进程状态)
查看集群
#select * from system.clusters
版权归原作者 you are my soul mate 所有, 如有侵权,请联系我们删除。