環(huán)境
- 已安裝單機(jī)版的ClickHouse识藤,官方推薦使用 rpm 安裝,也可以安裝好一臺(tái)后復(fù)制文件過去
- CentOS Linux release 7.8.2003 (Core)
- ClickHouse 20.11.6.6
多實(shí)例配置
創(chuàng)建目錄
cd /clickhouse
mkdir data9200 log9200
chown -R clickhouse.clickhouse /clickhouse/data9200 /clickhouse/log9200
復(fù)制一份已有的配置文件
復(fù)制一份已有配置修改下血筑,配置第二個(gè)實(shí)例
cp /etc/clickhouse-server/config.xml /etc/clickhouse-server/config9200.xml
授權(quán)
chown clickhouse.clickhouse /etc/clickhouse-server/config9200.xml
修改默認(rèn)存放路徑
由于之前安裝時(shí)已經(jīng)將默認(rèn)路徑從 /var/log/clickhouse-server 修改為了 /clickhouse/log闰围,這次需要修改為如下:
# 更改日志路徑
sed -i "s:/clickhouse/log:/clickhouse/log9200:g" /etc/clickhouse-server/config9200.xml
# 更改數(shù)據(jù)路徑
sed -i "s:/clickhouse/data:/clickhouse/data9200:g" /etc/clickhouse-server/config9200.xml
/** 實(shí)際修改的地方
<log>//clickhouse/log9200/clickhouse-server.log</log>
<errorlog>//clickhouse/log9200/clickhouse-server.err.log</errorlog>
<path>/clickhouse/data9200/</path>
<tmp_path>/clickhouse/data9200/tmp/</tmp_path>
<user_files_path>/clickhouse/data9200/user_files/</user_files_path>
<path>/clickhouse/data9200/access/</path>
<format_schema_path>/clickhouse/data9200/format_schemas/</format_schema_path>
*/
更改端口
修改第二個(gè)實(shí)例的配置
vi /etc/clickhouse-server/config9200.xml
/**
<http_port>8123</http_port>
<tcp_port>9000</tcp_port>
<mysql_port>9004</mysql_port>
<interserver_http_port>9009</interserver_http_port> # 復(fù)制副本之間通信的端口。用于數(shù)據(jù)交換榴徐。
*/
改成
<http_port>8223</http_port>
<tcp_port>9200</tcp_port>
<mysql_port>9204</mysql_port>
<interserver_http_port>9209</interserver_http_port>
啟動(dòng)或停止
方式1 systemctl
- 復(fù)制啟動(dòng)腳本
cp /etc/systemd/system/clickhouse-server.service /etc/systemd/system/clickhouse-server9200.service
- 修改啟動(dòng)腳本
只需要修改一行
/**
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/config9200.xml --pid-file=/run/clickhouse-server/clickhouse-server9200.pid
- 啟動(dòng)/關(guān)閉
# 啟動(dòng)
systemctl start clickhouse-server
systemctl start clickhouse-server9200
# 關(guān)閉
systemctl stop clickhouse-server
systemctl stop clickhouse-server9200
方式2 編寫腳本啟動(dòng)/關(guān)閉
- 啟動(dòng)
vi start_clickhouse.sh
#!/bin/bash
nohup sudo -u clickhouse /usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml &
sleep 3
nohup sudo -u clickhouse /usr/bin/clickhouse-server --config=/etc/clickhouse-server/config9200.xml &
- 關(guān)閉
vi stop_clickhouse.sh
#!/bin/bash
ps -ef|grep clickhouse|grep config.xml|grep -v grep|awk '{print "kill -9 "$2}'|sh
ps -ef|grep clickhouse|grep config9200.xml|grep -v grep|awk '{print "kill -9 "$2}'|sh
- 授權(quán)
chmod +x start_clickhouse.sh
chmod +x stop_clickhouse.sh
驗(yàn)證是否正常啟動(dòng)
# 端口
ss -ntpl|grep 9000
ss -ntpl|grep 9200
# 登陸查看
clickhouse-client --port 9000
clickhouse-client --port 9200
# 數(shù)據(jù)
ll /clickhouse/data9200/