clickhouse server安裝
1.檢查是否支持SSE 4.2:
grep -q sse4_2 /proc/cpuinfo && echo “SSE 4.2 supported” || echo “SSE 4.2 not supported”
2.安裝依賴
sudo yum install -y curl
3.下載運行腳本(centos7顯式指定os=centos dist=7兩個參數)
curl -s https://packagecloud.io/install/repositories/altinity/clickhouse/script.rpm.sh | sudo os=centos dist=7 bash
4.查看clickhouse可用安裝包,並安裝
yum list ‘clickhouse*’
yum install -y clickhouse-server clickhouse-client
yum list installed ‘clickhouse*’ #查看安裝
5.配置文件默認目錄
/etc/clickhouse-server/ #配置文件路徑在,通過查看配置文件 /etc/clickhouse-server/config.xml 可以看到其他配置
/var/lib/clickhouse #數據目錄
/var/lib/clickhouse/tmp/ #臨時目錄
/var/log/clickhouse-server #日誌目錄
/etc/rc.d/init.d/clickhouse-server #默認啓動腳本
/etc/security/limits.d/clickhouse.conf #最大打開文件數
/etc/cron.d/clickhouse-server #定時任務文件,cron進程執行時,就會自動掃描該目錄下的所有文件,按照文件中的時間設定執行後面的命令
/usr/bin/clickhouse* #二進制文件目錄
/usr/share/clickhouse/ #共享文件目錄:
6.如有需求修改端口等,需要修改/etc/clickhouse-server/config.xml文件
8123->28123
9000->29000
9004->29004
9009->29009
7.修改IP 127.0.0.1-> 本機IP
8.啓動
#服務端啓動
service clickhouse-server start
service clickhouse-server stop
/etc/init.d/clickhouse-server start
/etc/init.d/clickhouse-server stop
sudo -u clickhouse clickhouse-server --config-file=/etc/clickhouse-server/config.xml #單節點多實例多配置文件啓動方式
nohup sudo -u clickhouse clickhouse-server --config-file=/etc/clickhouse-server/config.xml >/var/log/clickhouse.log 2>&1 & #後臺開啓
#客戶端啓動
clickhouse-client #默認爲9000
clickhouse-client --port=9099
clickhouse集羣配置
#集羣配置錢每天節點上都要安裝好clickhouse server
1.修改 /etc/clickhouse-server/config.xml 配置文件
#放開遠程主機監聽
<listen_host>::1</listen_host>
<listen_host>0.0.0.0</listen_host>
2.創建 metrika.xml 集羣配置文件 參考https://www.jianshu.com/p/5f7809b1965e
#默認路徑爲/etc/metrika.xml,但是在config可以配置路徑
<include_from> /etc/clickhouse-server/metrica.xml </include_from>
全文配置
<yandex>
<clickhouse_remote_servers>
<test_cluster> #集羣名稱
<shard> #數據分片1(節點1)
<internal_replication>true</internal_replication>
<replica>
<host>10.10.10.99</host>
<port>9099</port>
</replica>
</shard>
<shard> #數據分片2(節點2)
<replica>
<internal_replication>true</internal_replication>
<host>10.10.10.100</host>
<port>9099</port>
</replica>
</shard>
</test_cluster>
</clickhouse_remote_servers>
<zookeeper-servers> #ZK配置
<node index="1">
<host>10.10.10.98</host>
<port>2181</port>
</node>
<node index="2">
<host>10.10.10.99</host>
<port>2181</port>
</node>
<node index="3">
<host>10.10.10.100</host>
<port>2181</port>
</node>
</zookeeper-servers>
<macros> #本機IP
<replica>10.10.10.99</replica>
</macros>
<networks> #監聽網絡,::/0代表監聽所有ip
<ip>::/0</ip>
</networks>
<clickhouse_compression> #數據壓縮算法
<case>
<min_part_size>10000000000</min_part_size>
<min_part_size_ratio>0.01</min_part_size_ratio>
<method>lz4</method>
</case>
</clickhouse_compression>
</yandex>
–分佈式集羣測試
drop table ontime_local;
drop table ontime_all;
#創建表
CREATE TABLE ontime_local (FlightDate Date,Year UInt16) ENGINE = MergeTree(FlightDate, (Year, FlightDate), 8192);
CREATE TABLE ontime_all AS ontime_local ENGINE = Distributed(test_cluster, default, ontime_local, rand());
#插入測試數據
insert into ontime_all (FlightDate,Year)values(‘2001-10-12’,2001);
insert into ontime_all (FlightDate,Year)values(‘2002-10-12’,2002);
insert into ontime_all (FlightDate,Year)values(‘2002-10-12’,2003);
#可以發現所有節點上的ontime_all都有數據
select * from ontime_local;
select * from ontime_all;