服务器信息 主机名IPmy-db01192.168.1.214my-db02192.168.1.215my-db03192.168.1.216 hosts设置 # 切换成rootsudo -i# my
主机名 | IP |
---|---|
my-db01 | 192.168.1.214 |
my-db02 | 192.168.1.215 |
my-db03 | 192.168.1.216 |
# 切换成rootsudo -i# my-db01 执行echo '192.168.1.215 my-db02' >> /etc/hostsecho '192.168.1.216 my-db03' >> /etc/hosts# my-db02 执行echo '192.168.1.214 my-db01' >> /etc/hostsecho '192.168.1.216 my-db03' >> /etc/hosts# my-db03 执行echo '192.168.1.214 my-db01' >> /etc/hostsecho '192.168.1.215 my-db02' >> /etc/hosts
使用admin
用户安装:
sudo yum install -y yum-utilssudo yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo
clickhouse-server和clickhouse-client
sudo yum install -y clickhouse-server clickhouse-client
版本信息:
操作系统:Centos linux release 7.9.2009 (Core)
systemd:219
clickhouse-client:23.2.4.12-1.x86_64
clickhouse-server:23.2.4.12-1.x86_64
clickhouse-common-static:23.2.4.12-1.x86_64
yum install -y nc
# 创建数据目录sudo mkdir -p /data/clickhouse/lib# 创建日志目录sudo mkdir -p /data/clickhouse/log# 授权sudo chown -R clickhouse:clickhouse /data/clickhousesudo chmod 777 /data# 备份原始配置文件sudo cp /etc/clickhouse-server/users.xml ~sudo cp /etc/clickhouse-server/config.xml ~# 更改目录配置## 权限更改sudo chmod 666 /etc/clickhouse-server/config.xmlsudo chmod 666 /etc/clickhouse-server/users.xml## 日志目录替换sudo sed -i 's?/var/log/clickhouse-server?/data/clickhouse/log?g' /etc/clickhouse-server/config.xml## 数据目录替换sudo sed -i 's?/var/lib/clickhouse?/data/clickhouse/lib?g' /etc/clickhouse-server/config.xml
sudo vi /usr/lib/systemd/system/clickhouse-server.service
参考:《问题记录->启动超时》sudo systemctl enable clickhouse-server
sudo systemctl start clickhouse-server
sudo systemctl stop clickhouse-server
sudo systemctl status clickhouse-server
sudo vi /etc/clickhouse-server/config.xml
中的配置:
background_pool_size
:默认16,可以调整到CPU个数的两倍。本次调整到32
max_concurrent_queries
:默认100,可以调整到200或者300。本次调整到200
设置外网(ipv4)可访问:<listen_host>0.0.0.0listen_host>设置interserver_listen_host,因为服务器不支持ipv6(如果不设置,配置了clickhouse-keeper后,会无法启动,报错:RaftInstance: Got exception: open: Address family not supported by protocol)<interserver_listen_host>0.0.0.0interserver_listen_host>
users.xml
中的配置:
# 使用下述命令生成随机密码PASSWord=$(base64 < /dev/urandom | head -c12); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'# 明文密码:z+yJwbcWv6MA# 密文密码:b53ad819c11d5790655464f2d6ec0e78916551b62141fec0d1342a25138082d2
b53ad819c11d5790655464f2d6ec0e78916551b62141fec0d1342a25138082d2
上述配置在每个节点都需要设置
echo 0 | sudo tee /proc/sys/vm/overcommit_memory
# 使用rootecho never > /sys/kernel/mm/transparent_hugepage/enabledecho never > /sys/kernel/mm/transparent_hugepage/defragecho 'echo never > /sys/kernel/mm/transparent_hugepage/defrag' >> /etc/rc.d/rc.localecho 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.d/rc.localsudo chmod +x /etc/rc.d/rc.local
1. sudo swapoff -a2. echo "vm.swappiness = 0">> /etc/sysctl.conf3. sudo sysctl -p4. sudo vi /etc/fstab # 注释swap那一行
在每台clickhouse服务器中的/etc/clickhouse-server/config.d/
目录下新建clickhouse-keeper.xml
,内容如下:
<clickhouse><keeper_server> <tcp_port>9181tcp_port> <server_id>1server_id> <log_storage_path>/data/clickhouse/lib/coordination/loglog_storage_path> <snapshot_storage_path>/data/clickhouse/lib/coordination/snapshotssnapshot_storage_path> <coordination_settings> <operation_timeout_ms>10000operation_timeout_ms> <session_timeout_ms>30000session_timeout_ms> <raft_logs_level>warningraft_logs_level> coordination_settings> <raft_configuration> <server> <id>1id> <hostname>my-db01hostname> <port>9444port> server> <server> <id>2id> <hostname>my-db02hostname> <port>9444port> server> <server> <id>3id> <hostname>my-db03hostname> <port>9444port> server> raft_configuration>keeper_server> <ZooKeeper> <node> <host>my-db01host> <port>9181port> node> <node> <host>my-db02host> <port>9181port> node> <node> <host>my-db03host> <port>9181port> node> zookeeper>clickhouse>
注意事项:
- 每个节点server_id配置正确
- log_storage_path和snapshot_storage_path目录正确
- 端口能访问
- 文件授权:
chown clickhouse:clickhouse /etc/clickhouse-server/config.d/clickhouse-keeper.xml
本次搭建情况如下:
- my-db01的server_id为1、my-db02的server_id为2、my-db03的server_id为3
- 开放端口9181、9444
imok
表示正常echo ruok | nc localhost 9181; echo# imok
集群设置为:0分片3副本的结构
配置如下(将该配置追加到clickhouse-keeper.xml
文件中):
cluster_1S_3R_01 my-db01 my-db01 9000 default my-db02 9000 default my-db03 9000 default
安装完之后,通过命令sudo systemctl start clickhouse-server
无法正常启动,日志如下:
● clickhouse-server.service - ClickHouse Server (analytic DBMS for big data) Loaded: loaded (/usr/lib/systemd/system/clickhouse-server.service; enabled; vendor preset: disabled) Active: activating (auto-restart) (Result: timeout) since Tue 2023-03-21 16:59:02 CST; 6s ago Process: 12585 ExecStart=/usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=%t/%p/%p.pid (code=killed, signal=TERM) Main PID: 12585 (code=killed, signal=TERM)Mar 21 16:59:02 my-db02 systemd[1]: Failed to start ClickHouse Server (analytic DBMS for big data).Mar 21 16:59:02 my-db02 systemd[1]: Unit clickhouse-server.service entered failed state.Mar 21 16:59:02 my-db02 systemd[1]: clickhouse-server.service failed.
看出是timeout导致的,翻阅资料后发现问题:
/usr/lib/systemd/system/clickhouse-server.service
文件中超时设置,使用的是:TimeoutStartSec=infinity
通过systemctl --version
查看systemd
的版本为219
TimeoutStartSec
的infinity
设置是229版本之后才有的,229之前设置为0,来禁用超时
这里提供一份修改过的clickhouse-server.service
文件,可供参考
[Unit]Description=ClickHouse Server (analytic DBMS for big data)Requires=network-online.target# NOTE: that After/Wants=time-sync.target is not enough, you need to ensure# that the time was adjusted already, if you use systemd-timesyncd you are# safe, but if you use ntp or some other daemon, you should configure it# additionaly.After=time-sync.target network-online.targetWants=time-sync.target[Service]Type=notify# NOTE: we leave clickhouse watchdog process enabled to be able to see OOM/SIGKILL traces in clickhouse-server.log files.# If you wish to disable the watchdog and rely on systemd logs just add "Environment=CLICKHOUSE_WATCHDOG_ENABLE=0" line.User=clickhouseGroup=clickhouseRestart=alwaysRestartSec=30# Since ClickHouse is systemd aware default 1m30sec may not be enough# TimeoutStartSec=infinityTimeoutStartSec=0# %p is resolved to the systemd unit nameRuntimeDirectory=%p ExecStart=/usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=%t/%p/%p.pid# Minus means that this file is optional.EnvironmentFile=-/etc/default/%p# Bring back /etc/default/clickhouse for backward compatibilityEnvironmentFile=-/etc/default/clickhouseLimitCORE=infinityLimitNOFILE=500000CapabilityBoundingSet=CAP_NET_ADMIN CAP_IPC_LOCK CAP_SYS_NICE CAP_NET_BIND_SERVICE[Install]# ClickHouse should not start from the rescue shell (rescue.target).WantedBy=multi-user.target
注意事项:
如果已经启动失败,修改后systemd相关文件后,需要执行
systemctl daemon-reload
安装:Https://clickhouse.com/docs/en/install#from-rpm-packages
使用建议:https://clickhouse.com/docs/en/operations/tips
关闭swap:https://blog.csdn.net/weixin_43224440/article/details/111556962
参数调优:https://blog.csdn.net/qq_35128600/article/details/125897196
集群搭建参考:https://clickhouse.com/docs/en/guides/sre/keeper/clickhouse-keeper#clickhouse-keeper-user-guide
不支持ipv6参考:https://GitHub.com/ClickHouse/ClickHouse/issues/33381
来源地址:https://blog.csdn.net/wlj15059332248/article/details/129931603
--结束END--
本文标题: 基于clickhouse keeper搭建clickhouse集群
本文链接: https://lsjlt.com/news/388590.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0