clickhouse-(01)-安装
下载
下载地址: https://repo.clickhouse.tech/tgz/stable/
下载的包:
clickhouse-common-static
clickhouse-server
clickhouse-client
单机安装
tar -zxvf clickhouse-common-static-20.5.4.40.tgz
cd clickhouse-common-static-20.5.4.40/install
sudo doinst.sh
tar -zxvf clickhouse-common-static-dbg-20.5.4.40.tgz
cd clickhouse-common-static-dbg-20.5.4.40/install
sudo doinst.sh
tar -zxvf clickhouse-server-20.5.4.40.tgz
cd clickhouse-server-20.5.4.40/install
sudo doinst.sh
tar -zxvf clickhouse-client-20.5.4.40.tgz
cd clickhouse-client-20.5.4.40/install
sudo doinst.sh
设置
内存限制设置
vi /etc/clickhouse-server/users.xml
<max_memory_usage></max_memory_usage> 单位:bytes
设置数据目录
vi /etc/clickhouse-server/config.xml
<path></data> 数据存储目录
<tmp_path><tmp_path> 临时缓存目录
启动服务
手动启动
clickhouse-server --config-file=/etc/clickhouse-server/config.xml
server启动
sudo service clickhouse-server start
sudo service clickhouse-server status
sudo service clickhouse-server stop
sudo service clickhouse-server restart
systemctl启动
sudo systemctl start clickhouse-server
sudo systemctl status clickhouse-server
sudo systemctl stop clickhouse-server
sudo systemctl restart clickhouse-server
sudo systemctl enable clickhouse-server
查看服务是否启动
ps -aux | grep clickhouse
连接
用clickhouse-client连接本机clickhouse-server服务器:
clickhouse-client
用本机clickhouse-client连接远程clickhouse-server服务器:
clickhouse-client –host 192.168.3.54 –port 9000 –database default–user default –password “”
目录
- /etc/clickhouse-server:服务端的配置文件目录,包括全局配置config.xml和用户配置users.xml等
- /var/lib/clickhouse:默认的数据存储目录(通常会修改默认路径配置,将数据保存到大容量磁盘挂载的路径)
- /var/log/clickhouse:默认保存日志的目录(最好也修改路径配置,将日志保存到大容量磁盘挂载的路径
集群安装
配置
3zk-2shards-2replicas)
<?xml version="1.0" encoding="utf-8"?>
<yandex>
<clickhouse_remote_servers>
<default>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>172.17.0.8</host>
<port>9000</port>
</replica>
<replica>
<host>172.17.0.7</host>
<port>9000</port>
</replica>
</shard>
<shard>
<internal_replication>true</internal_replication>
<replica>
<host>172.17.0.6</host>
<port>9000</port>
</replica>
<replica>
<host>172.17.0.5</host>
<port>9000</port>
</replica>
</shard>
</default>
</clickhouse_remote_servers>
<zookeeper-servers>
<node index="1">
<host>172.17.0.4</host>
<port>2181</port>
</node>
<node index="2">
<host>172.17.0.3</host>
<port>2181</port>
</node>
<node index="3">
<host>172.17.0.2</host>
<port>2181</port>
</node>
</zookeeper-servers>
<listen_host>::</listen_host>
<listen_host>0.0.0.0</listen_host>
<listen_try>1</listen_try>
<macros>
<shard>1</shard>
<replica>172.17.0.8</replica>
</macros>
</yandex>
zk目录说明
clickhouse
└── tables
├── 1
│ ├── log_test
│ │ ├── metadata #log_test表的元数据信息
│ │ ├── temp #临时节点,存储过程中的临时数据
│ │ └── mutations #表的变更信息,ClickHouse为区别标准SQL特定的一个名词
│ ├── log #写block时记录的log
│ │ ├── log-0000000003
│ │ ├── log-0000000001
│ │ └── log-0000000002
│ ├── leader_election #副本选举leader时使用
│ │ ├── leader_election-0000000001
│ │ └── leader_election-0000000003
│ ├── colums #列信息
│ ├── blocks #和log是对应的,用于block去重
│ │ ├── 201908_12150410223201606212_2366670524718677664
│ │ ├── 201908_15367370223201604745_5325320524718463637
│ │ └── 201907_34543779872932958925_1436457470273464774
│ ├── nonincrement_block_numbers
│ ├── replicas #存储各个副本的相关信息
│ │ └── 10.0.0.71
│ │ ├── is_lost #标记副本是否过时
│ │ ├── metadata #log_test表的元数据信息
│ │ ├── is_active #标记副本是否存活
│ │ ├── mutation_pointer
│ │ ├── colums #列信息
│ │ ├── max_processed_insert_time
│ │ ├── host #主机名或域名
│ │ ├── parts #存储数据所有的parts
│ │ │ └── 201908_0_0_0
│ │ │ ├── checksums
│ │ │ └── colums
│ │ ├── flags #用于数据恢复
│ │ ├── log_pointer #log指针
│ │ ├── min_unprocessed_insert_time
│ │ └── queue #临时处理队列
│ ├── quorum #与是否配置insert_quorum有关
│ │ ├── last_part
│ │ └── failed_parts
│ └── block_number #存储所有的分区值,会根据merge实时更新
│ └── 201908
└─ 2