1.下载安装包
下面通过阿里镜像(https://mirrors.aliyun.com/clickhouse/rpm/lts/)进行下载,下载哪里,自行指定。
# rpm包下载使用如下4行
wget https://mirrors.aliyun.com/clickhouse/rpm/lts/clickhouse-server-22.8.5.29.x86_64.rpm \
wget https://mirrors.aliyun.com/clickhouse/rpm/lts/clickhouse-client-22.8.5.29.x86_64.rpm \
wget https://mirrors.aliyun.com/clickhouse/rpm/lts/clickhouse-common-static-dbg-22.8.5.29.x86_64.rpm \
wget https://mirrors.aliyun.com/clickhouse/rpm/lts/clickhouse-common-static-22.8.5.29.x86_64.rpm
# deb包下载使用如下4行
wget https://mirrors.aliyun.com/clickhouse/deb/pool/stable/clickhouse-client_22.8.5.29_amd64.deb \
wget https://mirrors.aliyun.com/clickhouse/deb/pool/stable/clickhouse-common-static-dbg_22.8.5.29_amd64.deb \
wget https://mirrors.aliyun.com/clickhouse/deb/pool/stable/clickhouse-common-static_22.8.5.29_amd64.deb \
wget https://mirrors.aliyun.com/clickhouse/deb/pool/stable/clickhouse-server_22.8.5.29_amd64.deb
2.安装包说明
- clickhouse-common-static — ClickHouse编译的二进制文件。
- clickhouse-server — 创建clickhouse-server软连接,并安装默认配置服务
- clickhouse-client — 创建clickhouse-client客户端工具软连接,并安装客户端配置文件。
- clickhouse-common-static-dbg — 带有调试信息的ClickHouse二进制文件。
下面我已经把安装包下载打包整理好,下载解压即可安装:
rpm:
2.安装
以下安装均使用rpm包进行。
切换到安装包所在目录,执行如下命令。
# rpm包
sudo rpm -ivh clickhouse*
# deb包
sudo dpkg -i clickhouse*
安装过程中需要设置密码,可以自行根据提示输入即可(这里默认安装用户chdba
密码chdba123456
),如果不设置密码可以直接回车
跳过。下面是安装输入日志。
Verifying... ################################# [100%]
准备中... ################################# [100%]
正在升级/安装...
1:clickhouse-common-static-dbg-0:22################################# [ 25%]
2:clickhouse-common-static-0:22.8.5################################# [ 50%]
3:clickhouse-client-0:22.8.5.29-1 ################################# [ 75%]
4:clickhouse-server-0:22.8.5.29-1 ################################# [100%]
ClickHouse binary is already located at /usr/bin/clickhouse
Symlink /usr/bin/clickhouse-server already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-server to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-client already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-client to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-local already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-local to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-benchmark already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-benchmark to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-copier already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-copier to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-obfuscator already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-obfuscator to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-git-import to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-compressor already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-compressor to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-format already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-format to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-extract-from-config already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-extract-from-config to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-keeper already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper-converter to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-disks to /usr/bin/clickhouse.
Creating clickhouse group if it does not exist.
groupadd -r clickhouse
Creating clickhouse user if it does not exist.
useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse clickhouse
Will set ulimits for clickhouse user in /etc/security/limits.d/clickhouse.conf.
Creating config directory /etc/clickhouse-server/config.d that is used for tweaks of main server configuration.
Creating config directory /etc/clickhouse-server/users.d that is used for tweaks of users configuration.
Config file /etc/clickhouse-server/config.xml already exists, will keep it and extract path info from it.
/etc/clickhouse-server/config.xml has /var/lib/clickhouse/ as data path.
/etc/clickhouse-server/config.xml has /var/log/clickhouse-server/ as log path.
Users config file /etc/clickhouse-server/users.xml already exists, will keep it and extract users info from it.
Creating log directory /var/log/clickhouse-server/.
Creating data directory /var/lib/clickhouse/.
Creating pid directory /var/run/clickhouse-server.
chown -R clickhouse:clickhouse '/var/log/clickhouse-server/'
chown -R clickhouse:clickhouse '/var/run/clickhouse-server'
chown clickhouse:clickhouse '/var/lib/clickhouse/'
groupadd -r clickhouse-bridge
useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse-bridge clickhouse-bridge
chown -R clickhouse-bridge:clickhouse-bridge '/usr/bin/clickhouse-odbc-bridge'
chown -R clickhouse-bridge:clickhouse-bridge '/usr/bin/clickhouse-library-bridge'
Enter password for default user:
Password for default user is saved in file /etc/clickhouse-server/users.d/default-password.xml.
Setting capabilities for clickhouse binary. This is optional.
chown -R clickhouse:clickhouse '/etc/clickhouse-server'
ClickHouse has been successfully installed.
Start clickhouse-server with:
sudo clickhouse start
Start clickhouse-client with:
clickhouse-client --password
Synchronizing state of clickhouse-server.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable clickhouse-server
Created symlink /etc/systemd/system/multi-user.target.wants/clickhouse-server.service → /usr/lib/systemd/system/clickhouse-server.service.
到此,安装成功!常用命令如下:
# 启动|停止|重启|查看状态
systemctl start|stop|restart|status clickhouse-server.service
3.配置
3.1 设置clickhouse支持外网访问
sudo vim /etc/clickhouse-server/config.xml
# 找到<listen_host>::</listen_host>配置,将注释打开即可!
<!-- Listen specified address.
Use :: (wildcard IPv6 address), if you want to accept connections both with IPv4 and IPv6 from everywhere.
Notes:
If you open connections from wildcard address, make sure that at least one of the following measures applied:
- server is protected by firewall and not accessible from untrusted networks;
- all users are restricted to subset of network addresses (see users.xml);
- all users have strong passwords, only secure (TLS) interfaces are accessible, or connections are only made via TLS interfaces.
- users without password have readonly access.