可能出现的问题
如果无法启动,大概率为权限问题,如果测试环境,将使用到的目录改为777,如果正式环境,改为拥有者为clickhouse再次尝试
IP |
---|
192.168.0.81 | 192.168.0.102 | 192.168.0.103 |
1 准备工作
1.1 CentOS 取消打开文件数限制 (所有机器)
在 /etc/security/limits.conf 的末尾分别加入以下内容:
[root@ch1 ~]# vim /etc/security/limits.conf
在文件末尾添加:
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072
1.2 CentOS 取消 SELINUX (所有机器)
修改 /etc/selinux/config 中的 SELINUX=disabled 后重启
[root@ch1 ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
1.3 关闭防火墙 (所有机器)
[root@ch1 ~]# systemctl stop firewalld.service
[root@ch1 ~]# systemctl disable firewalld.service
1.4 安装依赖 (所有机器)
sudo yum install yum-utils
sudo rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG
sudo yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/clickhouse.repo
2 Zookeeper 安装
Zookeeper 需要安装奇数台来安装
2.1 下载zookeeper (所有机器)
mkdir /usr/local/zookeeper
cd /usr/local/zookeeper
wget https://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
tar -xvf zookeeper-3.4.14.tar.gz
2.2 创建配置 (所有机器)
cp /usr/local/zookeeper/zookeeper-3.4.14/conf/zoo_sample.cfg /usr/local/zookeeper/zookeeper-3.4.14/conf/zoo.cfg
2.3 修改配置参数 (所有机器)
vim /usr/local/zookeeper/zookeeper-3.4.14/conf/zoo.cfg
dataDir=/home/apps/zookeeper/data
dataLogDir=/home/apps/zookeeper/logs
server.1=ip1:2888:3888
server.2=ip2:2888:3888
server.3=ip3:2888:3888
2.4 每台创建不一样的server id标识 (所有机器)
# /tmp在linux中是临时目录,linux会对此目录定期清理,所以需要修改此目录
[root@ch1 ~]# mkdir -p /home/apps/zookeeper/data
[root@ch1 ~]# mkdir -p /home/apps/zookeeper/logs
[root@ch1 ~]# touch /home/apps/zookeeper/data/myid
[root@ch1 ~]# vim /home/apps/zookeeper/data/myid
# ip1输入1, ip2输入2, ip3输入3
2.5 启动zk (所有机器)
/usr/local/zookeeper/zookeeper-3.4.14/bin/zkServer.sh start
# 查看状态
/usr/local/zookeeper/zookeeper-3.4.14/bin/zkServer.sh status
3 分布式安装
官网步骤
3.1 安装 (所有机器)
[root@ch1 ~]# sudo yum install clickhouse-server clickhouse-client
3.2 修改配置文件 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>
#新增 控制分片与副本参数目录
<include_from>/etc/clickhouse-server/metrika.xml</include_from>
3.2 创建刚才修改的目录,并授权 (所有机器)
3.2 修改配置文件 user.xml (所有机器)
#内存限制
<max_memory_usage>30000000000</max_memory_usage>
#增加默认用户的密码,否则clickhouse不需要密码都可登录
<users>
<default>
<password>密码自定义</password>
</default>
</users>
3.2 创建配置文件 metrika.xml (所有机器)
3.2.1相同之处
<yandex>
<clickhouse_remote_servers>
<!-- 集群名称 -->
<report_shards_replicas>
<!-- 集群第一个分片 -->
<shard>
<!-- 分片权重 -->
<weight>1</weight>
<!-- 是否写入多副本 -->
<internal_replication>true</internal_replication>
<replica>
<!-- 1分片的副本1 ip与port -->
<host>192.168.0.81</host>
<port>9000</port>
</replica>
<replica>
<!-- 1分片的副本2 ip与port -->
<host>192.168.0.102</host>
<port>9000</port>
</replica>
</shard>
<!-- 集群第二个分片 -->
<shard>
<weight>1</weight>
<internal_replication>true</internal_replication>
<!-- 2分片的副本1 ip与port -->
<replica>
<host>192.168.0.102</host>
<port>9100</port>
</replica>
<!-- 2分片的副本2 ip与port -->
<replica>
<host>192.168.0.103</host>
<port>9000</port>
</replica>
</shard>
<!-- 第三个分片 -->
<shard>
<weight>1</weight>
<internal_replication>true</internal_replication>
<!-- 3分片的副本1 ip与port -->
<replica>
<host>192.168.0.81</host>
<port>9100</port>
</replica>
<!-- 3分片的副本2 ip与port -->
<replica>
<host>192.168.0.103</host>
<port>9100</port>
</replica>
</shard>
</report_shards_replicas>
</clickhouse_remote_servers>
<networks>
<ip>::/0</ip>
</networks>
<!-- zookeeper集群节点 -->
<zookeeper-servers>
<node index="1">
<host>192.168.0.81</host>
<port>2181</port>
</node>
<node index="2">
<host>192.168.0.102</host>
<port>2181</port>
</node>
<node index="3">
<host>192.168.0.103</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>
3.2.2 不同之处
<!-- 定义该clickhouse实例存放什么 -->
<macros>
<!-- 几号分片 -->
<shard>01</shard>
<!-- 1分片的2副本 -->
<replica>集群名-01-2</replica>
</macros>
3.3拷贝配置文件做第二个实例 (所有机器)
3.3.1config.xml拷贝一份config1.xml
#修改为第二个实例所需
<log>/var/log/clickhouse-server/clickhouse-server*.log</log>
<errorlog>/var/log/clickhouse-server/clickhouse-server0*.err.log</errorlog>
<http_port>8*23</http_port>
<tcp_port>9*00</tcp_port>
<mysql_port>9*04</mysql_port>
<interserver_http_port>9*09</interserver_http_port>
<path>/data/database/clickhouse*/</path>
<tmp_path>/data/database/clickhouse*/tmp/</tmp_path>
<include_from>/etc/clickhouse-server/metrika*.xml</include_from>
3.3.2metrika拷贝一份metrika1.xml
修改的部分应该与上方配置相同,该实例对应的是哪个分片哪个副本
#81的应为 1分片1副本 3分片1副本 其中选一
<macros>
<shard>01</shard>
<replica>cluster01-01-1</replica>
</macros>
<macros>
<shard>03</shard>
<replica>cluster01-03-1</replica>
</macros>
#102的应为 1分片2副本 2分片1副本 其中选一
<macros>
<shard>01</shard>
<replica>cluster01-01-2</replica>
</macros>
<macros>
<shard>03</shard>
<replica>cluster01-02-1</replica>
</macros>
#103的应为 2分片2副本 3分片2副本 其中选一
<macros>
<shard>01</shard>
<replica>cluster01-02-2</replica>
</macros>
<macros>
<shard>03</shard>
<replica>cluster01-03-2</replica>
</macros>
3.4修改启动配置信息 (所有机器)
添加第二个实例的启动配置信息
cp /etc/systemd/system/clickhouse-server.service /etc/systemd/system/clickhouse-server1.service
sudo vim /etc/systemd/system/clickhouse-server1.service
修改一行即可
/**
ExecStart=/usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickhouse-server.pid
*/
改为
ExecStart=/usr/bin/clickhouse-server --config=/etc/clickhouse-server/config1.xml --pid-file=/run/clickhouse-server/clickhouse-server1.pid
4.启动并查看 (所有机器)
#第一种方式启动
sudo -u clickhouse clickhouse-server --config-file=/etc/clickhouse-server/config.xml
clickhouse-server --config-file=/etc/clickhouse-server/config1.xml
#第二种方式启动
systemctl status clickhouse-server
#把2号文件权限更改为clickhouse
systemctl status clickhouse-server1
#查看
systemctl status clickhouse-server
systemctl status clickhouse-server1
#查看端口
netstat -nlutp
|