一、安装clickhouse
本示例安装在:centos7
按照官网RPM安装包安装步骤:
sudo yum install yum-utils
sudo rpm --import https://repo.clickhouse.com/CLICKHOUSE-KEY.GPG
sudo yum-config-manager --add-repo https://repo.clickhouse.com/rpm/stable/x86_64
然后运行命令安装:
sudo yum install clickhouse-server clickhouse-client
启动:
$ sudo /etc/init.d/clickhouse-server start
启动服务后,您可以使用命令行客户端连接到它:
#默认没有密码:
$ clickhouse-client
#有密码:
$ clickhouse-client -u default --password
示例:
$ ./clickhouse-client
ClickHouse client version 0.0.18749.
Connecting to localhost:9000.
Connected to ClickHouse server version 0.0.18749.
:) SELECT 1
SELECT 1
┌─1─┐
│ 1 │
└───┘
1 rows in set. Elapsed: 0.003 sec.
:)
恭喜正常工作了
也可以按指定版本安装,例如:
curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-common-static-22.2.2.1.tgz"
curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-common-static-dbg-22.2.2.1.tgz"
curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-server-22.2.2.1.tgz"
curl -O "https://packages.clickhouse.com/tgz/stable/clickhouse-client-22.2.2.1.tgz"
tar -xzvf "clickhouse-common-static-22.2.2.1.tgz"
sudo "clickhouse-common-static-22.2.2.1/install/doinst.sh"
tar -xzvf "clickhouse-common-static-dbg-22.2.2.1.tgz"
sudo "clickhouse-common-static-dbg-22.2.2.1/install/doinst.sh"
tar -xzvf "clickhouse-server-22.2.2.1.tgz"
sudo "clickhouse-server-22.2.2.1/install/doinst.sh"
sudo /etc/init.d/clickhouse-server start
tar -xzvf "clickhouse-client-22.2.2.1.tgz"
sudo "clickhouse-client-22.2.2.1/install/doinst.sh"
集群配置:
zookeeper的配置参考我另外的文章。
默认密码的修改:
vi /etc/clickhouse-server/users.xml
clickhouse配置文件:
vi /etc/clickhouse-server/config.xml
配置 listen_host字段:
配置zookeeper字段:
配置 remote_server字段:
配置macros字段:
此处根据每个节点的信息进行配置,示例为第五个分片的第一个副本,第四个的将5改为4即可,也可以自己命名。
此时配置基本完成。
尝试使用命令查询节点信息:
select * from system.clusters;
正确显示各个节点表示集群配置完成。
其他知识点:
clickhouse 数据存放在 /var/lib/clickhouse/data/
clickhouse 表存放在 /var/lib/clickhouse/store/cef/cef43d0f-85a0-422f-82d0-ebd98a26cef2/ 表文件一般为 datas.sql datas_all.sql
clickhouse 日志存放在 /var/log/clickhouse-server/
问题集锦:
Received exception from server (version 21.12.3):
Code: 279. DB::Exception: Received from localhost:9000. DB::Exception: All connection tries failed. Log:
Code: 210. DB::NetException: Net Exception: No route to host (192.168.2.20:9000). (NETWORK_ERROR) (version 21.12.3.32 (official build))
Code: 210. DB::NetException: Net Exception: No route to host (192.168.2.20:9000). (NETWORK_ERROR) (version 21.12.3.32 (official build))
Code: 210. DB::NetException: Net Exception: No route to host (192.168.2.20:9000). (NETWORK_ERROR) (version 21.12.3.32 (official build))
: While executing Remote. (ALL_CONNECTION_TRIES_FAILED)
其他资料:
出现这个错误有两个位置可能造成:
1、listen_host字段没有取消注释或者取消注释的位置不对。
2、防火墙没有关闭
防火墙的开启、关闭、禁用命令:
设置开机启用防火墙:systemctl enable firewalld.service
设置开机禁用防火墙:systemctl disable firewalld.service
启动防火墙:systemctl start firewalld
关闭防火墙:systemctl stop firewalld
检查防火墙状态:systemctl status firewalld
clickhouse 重启、启动、停止命令
启动:service clickhouse-server start
重启:service clickhouse-server restart
启动:systemctl start clickhouse-server
状态: systemctl status clickhouse-server
停止:systemctl stop clickhouse-server
使用http链接数据库:
http://default:123456@192.168.31.179:8123/?default_format=JSONCompact"
#http://用户名:密码@地址:端口
#JSONCompact 结果以json形式输出