一.安裝前准備
1.文件打開數調整
在 /etc/security/limits.conf和/etc/security/limits.d/20-nproc.conf 這兩個文件的末尾加入以下內容:
sudo vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072
重啟服務器之后生效,用 ulimit -n 或者 ulimit -a 查看設置結果
2.取消selinux
修改 /etc/selinux/config 中的 SELINUX=disabled 后重啟
vim /etc/selinux/config
SELINUX=disabled
3.關閉防火牆
systemctl status firewalld.service
systemctl stop firewalld.service
4.安裝依賴
root用戶執行:
yum install -y libtool
yum install -y *unixODBC*
5.驗證是否支持sse 4.2指令集
需要驗證當前服務器的CPU是否支持SSE 4.2指令集,因為向量化執行需要用到這項特性
grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not
supported"
二.安裝clickhouse
1.單機安裝
參照官網安裝步驟:
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/clickhouse.repo
sudo yum install clickhouse-server clickhouse-client
如果沒法鏈接互聯網,則也可以使用 rpm 的方式來進行離線安裝,需要下載的安裝包有:
clickhouse-server-20.5.4.40-2.noarch.rpm
clickhouse-common-static-20.5.4.40-2.x86_64.rpm
clickhouse-client-20.5.4.40-2.noarch.rpm
下載地址在:
https://repo.yandex.ru/clickhouse/rpm/stable/x86_64/
https://packagecloud.io/Altinity/clickhouse
啟動ck服務:
前台啟動:
clickhouse-server --config-file=/etc/clickhouse-server/config.xml
后台啟動:
nohup clickhouse-server --config-file=/etc/clickhouse-server/config.xml
1>~/logs/clickhouse_std.log 2>~/logs/clickhouse_err.log &
啟動ck客戶端:
clickhouse-client --port=xxx --host=xxx --user=xxx --password=xxx -m
常用參數:端口,主機,用戶,密碼
-m:多行模式
基本使用:
創建庫,表:
create database test;
create table test01(id Int8,name String) engine = TinyLog;
插入數據:
insert into table test01 values (1, 'naixue'), (2, 'clickhouse'), (3,'spark');
查詢數據:
select id ,name from test01;
select count(*) from test01;
這里補充一下創建用戶,默認只有default用戶,一般不用.
vim /etc/clickhouse-server/users.xml
在users標簽中添加以下內容:
<lemo>
<password>lemo</password>
<networks>
<ip>::/0</ip>
</networks>
<!-- Settings profile for user. -->
<profile>default</profile>
<!-- Quota for user. -->
<quota>default</quota>
</lemo>
2.搭建集群模式
三台服務器分別安裝上clickhouse
2.1 修改配置文件:
修改端口:(默認9000端口跟hdfs沖突)
vim /etc/clickhouse-server/config.xml
<tcp_port>9001</tcp_port>
listen_host 表示能監聽的主機,:: 表示任意主機都可以訪問
<listen_host>::</listen_host>
添加集群相關配置
<remote_servers>
<clickhouse_3shards_1replicas>
<shard>
<!-- 數據自動同步 -->
<internal_replication>true</internal_replication>
<replica>
<host>hadoop101</host>
<port>9001</port>
</replica>
</shard>
<shard>
<replica>
<internal_replication>true</internal_replication>
<host>hadoop102</host>
<port>9001</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>hadoop103</host>
<port>9001</port>
</replica>
</shard>
</clickhouse_3shards_1replicas>
</remote_servers>
<zookeeper>
<node>
<host>hadoop101</host>
<port>2181</port>
</node>
<node>
<host>hadoop102</host>
<port>2181</port>
</node>
<node>
<host>hadoop103</host>
<port>2181</port>
</node>
</zookeeper>
<macros>
<shard>01</shard>
<replica>hadoop101</replica>
</macros>
網上資料大都是說要新建/etc/metrika.xml文件並添加集群配置,我試了一下好像不行,可能是跟版本有關系,后面發現/etc/clickhouse-server/config.xml配置文件里有集群相關配置就進行了如上配置.
可參考下面這位大佬的博客,可能也不是版本問題,以后再研究一下這個配置問題,直接在config.xml文件配置是沒有問題的.
https://www.cnblogs.com/jiashengmei/p/11991243.html
分發配置文件到所有服務器.修改以下內容(以hadoop103為例):
<macros>
<shard>03</shard>
<replica>hadoop103</replica>#修改成對應的hostname
</macros>
2.2 啟動服務
先啟動zookeeper,再啟動clickhouse
nohup clickhouse-server --config-file=/etc/clickhouse-server/config.xml > /dev/null &
2.3 查看集群信息
客戶端連接任意節點:
clickhouse-client --host=hadoop102 --port=9001 --user=lemo --password=lemo -m
select * from system.clusters;
2.4 建庫測試
create database test01 on cluster clickhouse_3shards_1replicas;
客戶端連接其他節點查看數據庫也有test01這個庫.
ck集群搭建完成...