安装前的准备

  1. 取消服务打开的文件数限制
    centos默认打开文件数为1024,但是OLAP引擎都是海量文件读取,所以需要修改访问文件数限制。
首先看一下文件数限制
ulimit -n
1024
centos默认是1024个文件数

vi /etc/security/limits.conf
在最后追加:
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072

vi /etc/security/limits.d/**--nproc.conf  
也同样追加这四条配置,**表示两位数字,有随机性。

这四条配置的意思是一个服务最多可以同时读取65536个文件,可以同时开启131072个进程。
*表示所有用户的所有服务。
soft是软设定,超过这个标准就会报警,hard是硬设定,最多不能超过这个数值。
nofile是同时操作的文件数,nproc是同时操作的进程数。

注:配置完成后要重启服务器,等所有配置都完成后再重启。
  1. 取消SELINUX
vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled   这里是disabled就行
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
  1. 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
  1. 安装依赖
yum install -y libtool
yum install -y *unixODBC*

安装

官网:https://clickhouse.tech/

下载镜像:http://repo.yandex.ru/clickhouse/tgz/

单机安装

下载四个rpm包,上传。

检查 clickhouse服务正常 java clickhouse readonly_zookeeper

安装

rpm包的安装是有固定顺序的,怕弄错就让系统自己安装

rpm -ivh *.rpm

检查 clickhouse服务正常 java clickhouse readonly_配置文件_02

启动

service clickhouse-server start

检查 clickhouse服务正常 java clickhouse readonly_配置文件_03

出现DONE表示启动成功

命令行

检查 clickhouse服务正常 java clickhouse readonly_clickhouse_04

常用参数

参数

详解

–host,-h

服务端的host名称,默认是“localhost”

–port

连接的端口,默认值是9000(和HDFS冲突)

–user,-u

用户名,默认default

–password

密码,默认空字符串

–query,-q

非交互模式下运行SQL语句

–database,-d

当前操作的数据库,默认default

–multiline,-m

运行多行语句查询

–format,-f

使用指定的格式打印输出结果

–time,-t

非交互模式下会打印查询执行的时间到窗口

–stacktrace

如果出现异常,会打印堆栈跟踪信息

–config-file

配置文件的名称

这里有个需要注意的地方:ClickHouse的SQL语句执行的时候,自带分号。

关闭

service clickhouse-server stop

集群安装

clickhouse集群推荐搭建在zookeeper集群上。

首先在所有规划的节点上按照单机模式按照。

然后修改配置文件:

vi /etc/clickhouse-server/config.xml

这里是打开远程访问,修改配置文件第65行。

检查 clickhouse服务正常 java clickhouse readonly_重启_05

这里是ClickHouse默认的存储路径,可以修改,也可以不修改。

检查 clickhouse服务正常 java clickhouse readonly_重启_06

新建一个配置文件

vi /etc/metrika.xml

<yandex>
<!-- 备份节点信息 -->
<clickhouse_remote_servers>
    <perftest_3shards_1replicas>
        <shard>
            <internal_replication>true</internal_replication>
            <replica>
                <host>ch1</host>
                <port>9000</port>
            </replica>
        </shard>
        <shard>
            <replica>
                <internal_replication>true</internal_replication>
                <host>ch2</host>
                <port>9000</port>
            </replica>
        </shard>
        <shard>
            <internal_replication>true</internal_replication>
            <replica>
                <host>ch3</host>
                <port>9000</port>
            </replica>
        </shard>
    </perftest_3shards_1replicas>
</clickhouse_remote_servers>

<!-- zookeeper配置信息 -->
<zookeeper-servers>
  <node index="1">
    <host>ch1</host>
    <port>2181</port>
  </node>

  <node index="2">
    <host>ch2</host>
    <port>2181</port>
  </node>
  <node index="3">
    <host>ch3</host>
    <port>2181</port>
  </node>
</zookeeper-servers>

<!-- 备份主机名,根据实际情况修改 -->
<macros>
    <replica>ch1</replica>
</macros>


<networks>
   <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>

然后启动zookeeper

zkServer.sh start

然后在三台节点上启动服务。

service clickhouse-server start

然后在任意一台节点上启动click,输入一条语句:

select * from system.clusters;

检查 clickhouse服务正常 java clickhouse readonly_重启_07


可以看到集群所有的节点ip表示成功了。