下载安装文件
这里直接去GitHub下载最新版本,我下载的是最新的ClickHouse stable release v21.12.2.17-stable,用rpm方式安装,主要下载一下几个文件:
clickhouse-server-21.12.2.17-2.noarch.rpm
clickhouse-common-static-21.12.2.17-2.x86_64.rpm
clickhouse-client-21.12.2.17-2.noarch.rpm
clickhouse-common-static-dbg-21.12.2.17-2.x86_64.rpm
下载之后上传到服务器的文件夹下:
/home/software/clickhouse
安装
sudo rpm -ivh *.rpm
升级
yum upgrade *.rpm -y
出现下面提示代表升级完成
Installed:
clickhouse-server.noarch 0:21.12.2.17-2
Updated:
clickhouse-client.noarch 0:21.12.2.17-2 clickhouse-common-static.x86_64 0:21.12.2.17-2
Replaced:
clickhouse-server-common.x86_64 0:1.1.54390-1.el7
Complete!
安装或升级完验证
rpm -qa|grep clickhouse
启动
sudo systemctl start clickhouse-server
查看是否启动成功
systemctl status clickhouse-server
或者
ps -ef | grep clickhouse-server
启动失败
查看clickhouse的启动日志,发现有Application: filesystem error: in remove_all: Permission denied [xxx],这个是改文件没有权限,如果是通过systemctl启动的,需要看下启动脚步里面配置的用户,比如:
[Unit]
Description=ClickHouse Server (analytic DBMS for big data)
Requires=network-online.target
# NOTE: that After/Wants=time-sync.target is not enough, you need to ensure
# that the time was adjusted already, if you use systemd-timesyncd you are
# safe, but if you use ntp or some other daemon, you should configure it
# additionaly.
After=time-sync.target network-online.target
Wants=time-sync.target
[Service]
Type=simple
User=clickhouse
Group=clickhouse
Restart=always
RestartSec=30
RuntimeDirectory=clickhouse-server
ExecStart=/usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickhouse-server.pid
LimitCORE=infinity
LimitNOFILE=500000
CapabilityBoundingSet=CAP_NET_ADMIN CAP_IPC_LOCK CAP_SYS_NICE
[Install]
# ClickHouse should not start from the rescue shell (rescue.target).
WantedBy=multi-user.target
这里的用户是clickhouse,那么刚刚报错的文件是没有clickhose用户的权限的,查看权限:
ll xxxx
添加权限:
chown clickhouse:clickhouse xxxx
同时给多个目录授权:
chown -R clickhouse:clickhouse /var/lib/clickhouse /var/log/clickhouse-server /etc/clickhouse-server /etc/clickhouse-client /usr/bin/clickhouse /opt/topology/db_data/clickhouse
查看systemctl start xxx的日志
journalctl -u xxx
进入命令行
clickhouse-client
查看数据库
show databases;
导出csv文件
clickhouse-client -h 127.0.0.1 --database="db" --query="select * from db.test_table FORMAT CSV" > test.csv
导入csv文件
clickhouse-client -h 127.0.0.1 --database="db" --query="insert into db.test_table FORMAT CSV" < ./test.csv