# wget -P
# 下载到指定目录
$ wget https://repo.yandex.ru/clickhouse/rpm/stable/x86_64/clickhouse-client-21.8.4.51-2.noarch.rpm
$ wget https://repo.yandex.ru/clickhouse/rpm/stable/x86_64/clickhouse-common-static-21.8.4.51-2.x86_64.rpm
$ wget https://repo.yandex.ru/clickhouse/rpm/stable/x86_64/clickhouse-common-static-dbg-21.8.4.51-2.x86_64.rpm
$ wget https://repo.yandex.ru/clickhouse/rpm/stable/x86_64/clickhouse-server-21.8.4.51-2.noarch.rpm
$ sudo rpm -ivh {CLICKHOUSE-HOME}/*.rpm
$ sudo rpm -qa|grep clickhouse
$ sudo vim /etc/clickhouse-server/config.xml
# 1.打开listen_host,二选一
# 如果支持IPV6
::
# 如果支持IPV4
0.0.0.0
# 2.修改端口号,9000被python占用
9099
# 默认数据文件路径:/var/lib/clickhouse/
# 默认日志文件路径:/var/log/clickhouse-server/clickhouse-server.log
$ sudo systemctl start clickhouse-server
$ sudo systemctl status clickhouse-server
$ sudo systemctl stop clickhouse-server
$ sudo clickhouse restart
$ clickhouse-client -m --password {PASSWORD} --port 9099 --user default --host {HOST}
show databases;
use default;
show tables;
# 1. 在/etc/clickhouse-server/config.d 目录下创建一个名为 metrika.xml的配置文件
$ sudo vim /etc/clickhouse-server/config.d/metrika.xml
true
{host_01}
9099
{host_02}
9099
{host_01}
2181
{host_02}
2181
{host_03}
2181
01
rep_1_1
$ sudo vim /etc/clickhouse-server/config.xml
/etc/clickhouse-server/config.d/metrika.xml
参考步骤2单机安装
$ sudo scp /etc/clickhouse-server/config.d/metrika.xml remote_user@remote_host:/etc/clickhouse-server/config.d/metrika.xml
$ sudo scp /etc/clickhouse-server/config.xml remote_user@remote_host:/etc/clickhouse-server/config.xml
$ sudo vim /etc/clickhouse-server/config.d/metrika.xml
01
rep_1_2
$ sudo clickhouse restart
create table test_local on cluster test_cluster (
id UInt32,
sku_id String,
total_amount Decimal(16,2),
create_time Datetime
) engine=ReplicatedMergeTree('/clickhouse/tables/{shard}/test_local','{replica}')
partition by toYYYYMMDD(create_time)
primary key (id)
order by (id,sku_id);
create table test_local_all on cluster test_cluster (
id UInt32,
sku_id String,
total_amount Decimal(16,2),
create_time Datetime
) engine = Distributed(test_cluster,default,test_local,hiveHash(sku_id));
show tables;
# 主机1和主机2上都有test_local表和test_local_all表,则证明建表成功
insert into test_local_all values (207,'sku_006',700.00,'2020-06-02 12:00:00');
select * from test_local;
select * from test_local_all;
# 如果主机1和主机2上的test_local和test_local_all共4个表查询结果相同,则证明数据写入成功
# 可以直接向本地表test_local写入数据,来验证4个表数据是否一致。
解决方案:在/etc/clickhouse-server/config.xml中,注释
解决方案:在/etc/clickhouse-server/config.xml中,修改
$ tail -n 100 /var/log/clickhouse-server/clickhouse-server.err.log
问题1:在使用副本时,日志报错replicateMergetree异常,提示hostnamenotfound
解决方案:将提示找不到的hostname配置到/etc/hosts文件中,并source /etc/hosts使其生效
问题2:在启动clickhouse-server时,日志报错,提示已有进程在运行中
解决方案:查看 /var/lib/clickhouse/status文件,找到pid后,使用kill -9 pid,然后再启动clickhouse-server
原文链接:Clickhouse安装及使用 - maybe兔 - 博客园