clickhouse单机安装及配置--Centos7
一、操作系统要求:
只要是Linux,64位都可以
rpm包下载地址:
https://repo.yandex.ru/clickhouse/rpm/stable/x86_64/
具体安装详情看官网:
https://clickhouse.tech/docs/zh/getting-started/install/#from-sources
CPU要求:
机器的CPU必须支持SSE 4.2指令集
检测机器的cpu是否支持:
检测命令:
grep -q sse4_2 /proc/cpuinfo && echo “SSE 4.2 supported” || echo “SSE 4.2 not supported”
二、离线安装部署单机版
1. 下载对应操作系统版本的ClickHouse对应版本的rpm包
clickhouse-client-21.4.5.46-2.noarch.rpm
clickhouse-common-static-21.4.5.46-2.x86_64.rpm
clickhouse-common-static-dbg-21.4.5.46-2.x86_64.rpm
clickhouse-server-21.4.5.46-2.noarch.rpm
ps:我用上述的rpm包在centos也可安装成功,所以具体怎么选自个选-->
Clickhouse官方并没有提供centos的rpm包,我们可以使Altinity公司所提供的rpm包
下载地址:https://packagecloud.io/Altinity/clickhouse
2. 配置Linux相关环境设置系统参数
2.1 CentOS取消打开文件数限制
#修改
vi /etc/security/limits.conf
在最后增加:
#增加:
* soft nofile 65536
* hard nofile 65536
* soft nproc 131072
* hard nproc 131072
注意:
对于RedHat6.x/CENTOS 6.X系统,还需要将vi /etc/security/limits.d/90-nproc.conf文件中的1024修改为131072。
对于RedHat7.x/CENTOS 7.X系统,还需要将vi 录vi /etc/security/limits.d/20-nproc.conf文件中的4096修改为131072。
或者直接类似修改 /etc/security/limits.conf一样
2.2 CentOS取消SELINUX
vi /etc/sysconfig/selinux
#找到SELINUX修改:
SELINUX=disabled
2.3 关闭防火墙
#contos7:
systemctl stop firewalld
systemctl disable firewalld
firewall-cmd --state
#contos7以下:
service iptables stop
service iptables status
chkconfig iptables off(永久性生效,重启后不会复原)
#service iptables stop(即时生效,重启后复原)
2.4 安装ClickHouse相关依赖包
yum -y install expect
yum install -y perl perl-devel autoconf libaio libtool libicu
yum install -y *unixODBC*
3. sftp到安装部署的服务器安装部署
安装命令:
rpm -ivh clickhouse-\*
4. ClickHouse安装后的重要的目录解析
- /etc/clickhouse-server 服务配置文件目录,主要有config.xml,users.xml服务配置文件
- /etc/clickclient 客户端配置文件目录
- /var/lib/clickhouse 默认数据目录
- /var/log/clickhouse-server 日志目录
- /etc/init.d/clickhouse-server ClickHouse服务shell脚本文件
- /etc/security/limits.d/clickhouse.conf 最大文件打开数
- /etc/cron.d/clickhouse-server 定时服务配置
- /usr/bin 主程序可执行文件目录
5. 修改ClickHouse服务相关参数配置
vi /etc/clickhouse-server/config.xml
5.1 开放远程访问
#放开下面这项注释
<!-- Listen specified host. use :: (wildcard IPv6 address), if you want to accept connections both with IPv4 and IPv6 from everywhere. -->
<listen_host>::</listen_host>
5.2 设置日志生成目录
<logger>
<level>trace</level>
<log>/data1/clickhouse/logs/clickhouse-server.log</log>
<errorlog>/data1/clickhouse/logsr/clickhouse-server.err.log</errorlog>
<size>1000M</size>
<count>10</count>
</logger>
5.3 设置数据的目录
<!-- Path to data directory, with trailing slash. -->
<path>/data1/clickhouse/</path>
<!-- Path to temporary data for processing hard queries. -->
<tmp_path>/data1/clickhouse/tmp/</tmp_path>
<!-- Policy from the <storage_configuration> for the temporary files.
If not set <tmp_path> is used, otherwise <tmp_path> is ignored.
Notes:
- move_factor is ignored
- keep_free_space_bytes is ignored
- max_data_part_size_bytes is ignored
- you must have exactly one volume in that policy
-->
<!-- <tmp_policy>tmp</tmp_policy> -->
<!-- Directory with user provided files that are accessible by 'file' table function. -->
<user_files_path>/data1/clickhouse/user_files/</user_files_path>
5.4 配置时间:
<timezone>Asia/Shanghai</timezone>
6. 启动:
指定配置文件:
nohup /usr/bin/clickhouse-server -C=/etc/clickhouse-server/config.xml --pid-file=/etc/clickhouse-server/clickhouse-server.pid &
或者默认/etc/clickhouse-server/
systemctl start clickhouse-server.service
检查线程
ps -ef|grep click
7.验证客户端
配置完之后,便可使用如下命令访问该数据库。
clickhouse-client --host 127.0.0.1 --port 9000
clickhouse-client
clickhouse-client --host hostname --port 9000
注意:以上命令中的某个可能会出现如下错误。
ClickHouse client version 20.4.1.1.
Connecting to localhost:9000 as user default.
Code: 210. DB::NetException: Connection refused (localhost:9000)
- 如果检查节点端口未开放,则可能是clickhouse-server启动的错误。
- 如果检查节点端口已经开放,则可能是–host后边加的参数的问题,试一下localhose、127.0.0.1等。
下面是成功访问:
[zhicheng@wydsj-gpapp04 ~]$ clickhouse-client --host 127.0.0.1 --port 9000
ClickHouse client version 21.4.5.46 (official build).
Connecting to 127.0.0.1:9000 as user default.
Connected to ClickHouse server version 21.4.5 revision 54447.
wydsj-gpapp04.novalocal :) select now();
SELECT now()
Query id: 937aaacc-fc74-42b8-8dce-b9577bce34b3
┌───────────────now()─┐
│ 2021-05-18 18:51:13 │
└─────────────────────┘
1 rows in set. Elapsed: 0.010 sec.
wydsj-gpapp04.novalocal :)
8.设置默认账户密码
#用户相关配置在/etc/clickhouse-server/users.xml文件中设置
vi /etc/clickhouse-server/users.xml
#找到users >>default标签下面的password项,配置密码为123456
<password>123456</password>
# 重启服务
# 验证 ,替换具体IP
clickhouse-client -h 127.0.0.1 --port 9000 -u default --password "123456"
#出现一下说明配置成功
ClickHouse client version 21.4.5.46 (official build).
Connecting to 127.0.0.1:9000 as user default.
Connected to ClickHouse server version 21.4.5 revision 54447.
新增账户密码
vi /etc/clickhouse-server/users.xml
#找到users标签,在下面增加一下内容,用户名为test,配置密码为123456
<test>
<password>123456</password>
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</test>
三、常见问题
ClickHouse 启动报错Init script is already running,clickhouse-client报错Code: 210. DB::NetException: Connection refused (localhost:9000)
新安装的ClickHouse, 在启动时报错Init script is already running,执行clickhouse-client时报Code: 210. DB::NetException: Connection refused (localhost:9000)。在REdhat 7和之后的操作系统,需要用systemctl启动才可以。
[root@wydsj-gpapp04 ~]# /etc/init.d/clickhouse-server start
Init script is already running
[root@wydsj-gpapp04 ~]# clickhouse-client
ClickHouse client version 21.4.5.46 (official build).
Connecting to localhost:9000 as user default.
Code: 210. DB::NetException: Connection refused (localhost:9000)
解决:
如下用systemctl start clickhouse-server.service
后,查看status确认服务正常。用clickhouse-client可以正常登录执行SQL了。