clickhouse 入門之環(huán)境搭建(1)

安裝方式

詳細見官網:https://clickhouse.com/docs/zh/getting-started/install

這里使用 install.sh 腳本安裝
修改 LATEST_VERSION 為所需版本,從 https://packages.clickhouse.com/tgz/stable/ 中找到

LATEST_VERSION=21.1.9.41
ARCH=amd64

for PKG in clickhouse-common-static clickhouse-common-static-dbg clickhouse-server clickhouse-client
do
curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION-${ARCH}.tgz" \
|| curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION.tgz"
done

tar -xzvf "clickhouse-common-static-$LATEST_VERSION-${ARCH}.tgz" \
|| tar -xzvf "clickhouse-common-static-$LATEST_VERSION.tgz"
sudo "clickhouse-common-static-$LATEST_VERSION/install/doinst.sh"

tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION-${ARCH}.tgz" \
|| tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION.tgz"
sudo "clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh"

tar -xzvf "clickhouse-server-$LATEST_VERSION-${ARCH}.tgz" \
|| tar -xzvf "clickhouse-server-$LATEST_VERSION.tgz"
sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh" configure
sudo /etc/init.d/clickhouse-server start

tar -xzvf "clickhouse-client-$LATEST_VERSION-${ARCH}.tgz" \
|| tar -xzvf "clickhouse-client-$LATEST_VERSION.tgz"
sudo "clickhouse-client-$LATEST_VERSION/install/doinst.sh"

啟動方式

  1. 后臺啟動
    sudo /etc/init.d/clickhouse-server start

  2. 手動啟動
    sudo -u clickhouse clickhouse-server --config-file=/etc/clickhouse-server/config.xml

  3. 使用 systemctl 控制器啟動

systemctl start clickhouse-server.service
systemctl restart clickhouse-server.service
systemctl stop clickhouse-server.service
systemctl status clickhouse-server.service

踩坑記錄

1. Init script is already running

錯誤原因:
使用 sudo /etc/init.d/clickhouse-server start 命令啟動導致,大概意思就是使用了 systemd 軟件的 linux 系統(tǒng)需要使用 systemctl xxx 方式啟動 (見啟動方式-2)
詳見:https://github.com/ClickHouse/ClickHouse/issues/14861

2. 2022.11.18 12:01:44.446923 [ 13459 ] {} <Warning> Application: Listen [::1]:8123 failed: Poco::Exception. Code: 1000, e.code() = 99, e.displayText() = Net Exception: Cannot assign requested address: [::1]:8123 (version 21.1.9.41 (official build)). If it is an IPv6 or IPv4 address and your host has disabled IPv6 or IPv4, then consider to specify not disabled IPv4 or IPv6 address to listen in <listen_host> element of configuration file. Example for disabled IPv6: <listen_host>0.0.0.0</listen_host> . Example for disabled IPv4: <listen_host>::</listen_host>

錯誤原因:
當前系統(tǒng)未開放 ipv6,只支持 ipv4,所以需要修改 <listen_host></listen_host> 鍵值對,根據提示可選兩種,一種禁用 ipv6、一種禁用 ipv4
Example for disabled IPv6: <listen_host>0.0.0.0</listen_host>
Example for disabled IPv4: <listen_host>::</listen_host>

按照網上說法,如:https://blog.csdn.net/qq_35423190/article/details/109629855,需要修改 /etc/clickhouse-server/config.xml 中 listen_host 為: <listen_host>0.0.0.0</listen_host>

image.png

這里按照步驟修改了,但是仍然無法啟動,報錯原因仍然是同一個,這里懷疑是否引入其他配置導致 config.xml 中的 listen_host 修改未生效,于是去看了下 clickhouse 的配置文件相關文檔

ClickHouse supports multi-file configuration management. The main server configuration file is /etc/clickhouse-server/config.xml or /etc/clickhouse-server/config.yaml. Other files must be in the /etc/clickhouse-server/config.d directory. Note, that any configuration file can be written either in XML or YAML, but mixing formats in one file is not supported. For example, you can have main configs as config.xml and users.xml and write additional files in config.d and users.d directories in .yaml.

發(fā)現(xiàn)在 /etc/clickhouse-server/config.xml 只是主配置,還可以設置其他配置,在當前目錄的 config.d 文件夾下,過不其然,還真有一個 listen.xml 的文件,里面真的配置的是 [::] ,修改為 127.0.0.1 之后重新啟動即可生效


image.png

3.2022.11.18 11:59:47.322965 [ 13072 ] {} <Error> Application: DB::Exception: Listen [127.0.0.1]:8123 failed: Poco::Exception. Code: 1000, e.code() = 98, e.displayText() = Net Exception: Address already in use: 127.0.0.1:8123 (version 21.1.9.41 (official build))

image.png

當(listen_host 配置如下)同時出現(xiàn)時,將導致該錯誤,看報錯是端口被占用,實際則是綁定了多次,

<listen_host>0.0.0.0</listen_host>
<listen_host>127.0.0.1</listen_host>

解決辦法:只保留其中一個

配置文件說明

主配置 /etc/clickhouse-server/config.xml
其他配置 /etc/clickhouse-server/config.d/
服務日志 /var/log/clickhouse-server/clickhouse-server.log
錯誤日志 /var/log/clickhouse-server/clickhouse-server.err.log

https://clickhouse.com/docs/zh/operations/configuration-files

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容