问题
最近需要试用clklog数据收集的社区版,clklog用数据库是Clickhouse。这就需要我先单机部署一个Clickhouse数据库,先试用试用。
步骤
这里假设我们已经拥有一台Ubuntu的服务器了,现在我们需要在这台机器上面安装Clickhouse数据库。Clickhouse官方推荐生产环境是要集群部署的,我这里只是单机试用,不能作为生产环境使用。
添加apt存储库
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg
curl -fsSL 'https://packages.clickhouse.com/rpm/lts/repodata/repomd.xml.key' | sudo gpg --dearmor -o /usr/share/keyrings/clickhouse-keyring.gpg
ARCH=$(dpkg --print-architecture)
echo "deb [signed-by=/usr/share/keyrings/clickhouse-keyring.gpg arch=${ARCH}] https://packages.clickhouse.com/deb stable main" | sudo tee /etc/apt/sources.list.d/clickhouse.list
sudo apt-get update
安装指定版本数据库
sudo apt-get install -y clickhouse-server=25.3.2.39 clickhouse-client=25.3.2.39 clickhouse-common-static=25.3.2.39
安装数据库的过程中,会提示你需要设置数据库密码。下面设置数据库随机启动,具体如下:
# 启用随机启动
sudo systemctl enable clickhouse-server
# 启动数据库
sudo systemctl start clickhouse-server
# 查看数据库状态
sudo systemctl status clickhouse-server
登录数据库
clickhouse-client -u default
然后输入数据库密码即可。具体效果如下:
ClickHouse client version 25.3.2.39 (official build).
Connecting to localhost:9000 as user default.
Password for user (default):
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 25.3.2.
Warnings:
* Available memory at server startup is too low (2GiB).
* Maximum number of threads is lower than 30000. There could be problems with handling a lot of simultaneous queries.
* Delay accounting is not enabled, OSIOWaitMicroseconds will not be gathered. You can enable it using `echo 1 > /proc/sys/kernel/task_delayacct` or by using sysctl.
* Linux threads max count is too low. Check /proc/sys/kernel/threads-max
ip-10-0-2-43.cn-north-1.compute.internal :)
看到笑脸就说明数据库登录成功了。但是这里有4个告警,需要我们尽可能处理一下。
- 第1个告警:说我们内存只有2G太小了,这里我资源有限,就这样了。文档上面说,你的数据量不大的话,内存最少8G起步。
- 第2个和第4个告警:最大线程数低于3w。据说可以修改/proc/sys/kernel/threads-max文件,我就没有尝试了。
- 第3个告警:按照Clickhouse方法修改就好
echo 1 > /proc/sys/kernel/task_delayacct
。
总结
我这免费的EC2实例类型,安装完Clickhouse数据库后,就快卡死了。算了到此为止。后面,我有时间再试一试本地mac m1上面能不能安装吧!