关于版本和系统的选择
操作系统:Centos-7
ClickHouse: rpm 在安装,20.x
安装前的准备
CentOS7 打开文件数限
在 /etc/security/limits.conf 这个文件的末尾加入一下内容:
[hadoop@hadoop001 ~]$ sudo vim /etc/security/limits.conf
- * soft nofile 65536
- * hard nofile 65536
- * soft nproc 131072
- * hard nproc 131072
/etc/security/limits.d/20-nproc.conf (centos6 是90-nproc.conf) 这个文件的末尾加入一下内容:
[hadoop@hadoop001 ~]$ sudo vim /etc/security/limits.d/20-nproc.conf
- * soft nofile 65536
- * hard nofile 65536
- * soft nproc 131072
- * hard nproc 131072
重启服务器之后生效,用 ulimit -n 或者 ulimit -a 查看设置结果
- ulimit -n
- ulimit -a
- [hadoop@hadoop001 ~]$ ulimit -n
- 65536
- [hadoop@hadoop001 ~]$ ulimit -a
- core file size (blocks, -c) 0
- data seg size (kbytes, -d) unlimited
- scheduling priority (-e) 0
- file size (blocks, -f) unlimited
- pending signals (-i) 14994
- max locked memory (kbytes, -l) 64
- max memory size (kbytes, -m) unlimited
- open files (-n) 65536
- pipe size (512 bytes, -p) 8
- POSIX message queues (bytes, -q) 819200
- real-time priority (-r) 0
- stack size (kbytes, -s) 8192
- cpu time (seconds, -t) unlimited
- max user processes (-u) 131072
- virtual memory (kbytes, -v) unlimited
- file locks (-x) unlimited
CentOS7 取消 SELINUX
修改 /etc/selinux/config 中的 SELINUX=disabled 后重启
[hadoop@hadoop001 ~]$ sudo vim /etc/selinux/config
SELINUX=disabled
关闭防火墙
- [hadoop@hadoop001 ~]$ sudo systemctl stop firewalld.service
- [hadoop@hadoop001 ~]$ sudo systemctl disable firewalld.servie
- [hadoop@hadoop001 ~]$ sudo systemctl status firewalld.service
- ● firewalld.service - firewalld - dynamic firewall daemon
- Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
- Active: inactive (dead)
- Docs: man:firewalld(1)
- [hadoop@hadoop001 ~]$
-
安装依赖
- [hadoop@hadoop001 ~]$ sudo yum install -y libtool
- [hadoop@hadoop001 ~]$ sudo yum install -y *unixODBC*
安装
官网:https://clickhouse.yandex/
具体安装细节看:https://clickhouse.tech/#quick-start
先检查是否已经安装clickhouse,如果已经安装,先卸载 clickhouse
查询是否安装 clickhouse:
[hadoop@hadoop001 software]rpm -qa | grep clickhouse
卸载 clickhouse:
- [hadoop@hadoop001 software]rpm -e --nodeps clickhouse-client-20.1.4.14-2.noarch
- [hadoop@hadoop001 software]rpm -e --nodeps clickhouse-server-20.1.4.14-2.noarch
- [hadoop@hadoop001 software]rpm -e --nodeps clickhouse-common-static-20.1.4.14-2-2.x86_64
删除数据目录:
[hadoop@hadoop001 software]rm -rf /var/lib/clickhouse
删除集群配置文件:
[hadoop@hadoop001 software]rm -rf /etc/metrika.xml
删除集群配置文件:
[hadoop@hadoop001 software]rm -rf /etc/metrika.xml
删除配置文件:
[hadoop@hadoop001 software]rm -rf /etc/clickhouse-*
删除日志文件:
[hadoop@hadoop001 software]rm -rf /var/log/clickhouse-server
删除 zookeeper 上 clickhouse 的数据:
rmr /clickhouse
也可以进行全局寻找,然后执行删除操作
[hadoop@hadoop001 software]find / -name 'clickhouse'
单机模式
ClickHouse的安装可以使用 yum在线安装,也可以使用 rpm 离线安装的方式!
具体信息见官网文档:https://clickhouse.tech/#quick-start
准备操作
需要验证当前服务器的 CPU 是否支持 SSE 4.2 指令集,因为向量化执行需要用到这项特性:
- [hadoop@hadoop001 clickhouse]$ grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
- SSE 4.2 supported
安装
依次执行如下命令:
- [hadoop@hadoop001 clickhouse]$ sudo yum install yum-utils -y
- [hadoop@hadoop001 clickhouse]$ sudo rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG
- [hadoop@hadoop001 clickhouse]$ yum-config-manager --add-repo ttps://repo.clickhouse.tech/rpm/clickhouse.repo
- [hadoop@hadoop001 clickhouse]$ yum install clickhouse-server clickhouse-client -y
如果您没法链接互联网,则也可以使用 rpm 的方式来进行离线安装(下载地址在:https://repo.yandex.ru/clickhouse/rpm/stable/x86_64/https://packagecloud.io/Altinity/clickhouse)需要下载的安装包有:
- [hadoop@hadoop001 clickhouse]$ ll
- total 1212764
- -rw-r--r-- 1 hadoop hadoop 120430 Nov 5 18:20 clickhouse-client-20.1.4.14-2.noarch.rpm
- -rw-r--r-- 1 hadoop hadoop 113426346 Nov 5 18:23 clickhouse-common-static-20.1.4.14-2.x86_64.rpm
- -rw-r--r-- 1 hadoop hadoop 1128177078 Nov 6 09:18 clickhouse-common-static-dbg-20.1.4.14-2.x86_64.rpm
- -rw-r--r-- 1 hadoop hadoop 141391 Nov 5 18:20 clickhouse-server-20.1.4.14-2.noarch.rpm
rpm安装
- [hadoop@hadoop001 clickhouse]$ sudo rpm -ivh *.rpm
- warning: clickhouse-client-20.1.4.14-2.noarch.rpm: Header V4 RSA/SHA1 Signature, key ID e0c56bd4: NOKEY
- Preparing... ################################# [100%]
- Updating / installing...
- 1:clickhouse-common-static-20.1.4.1################################# [ 25%]
- 2:clickhouse-client-20.1.4.14-2 ################################# [ 50%]
- 3:clickhouse-server-20.1.4.14-2 ################################# [ 75%]
- Created symlink from /etc/systemd/system/multi-user.target.wants/clickhouse-server.service to /etc/systemd/system/clickhouse-server.service.
- Path to data directory in /etc/clickhouse-server/config.xml: /var/lib/clickhouse/
- 4:clickhouse-common-static-dbg-20.1################################# [100%]
启动服务端
前段启动:
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 1>/tmp/clickhouse/clickhouse_std.log 2>/tmp/clickhouse/clickhouse_err.log &
验证测试
- [root@hadoop001 ~]# ps aux | grep clickhouse
- clickho+ 2955 0.1 3.1 2425796 122628 ? Ssl 00:55 0:01 /usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickhouse-server.pid
- root 3347 0.0 0.0 112704 980 pts/1 S+ 01:08 0:00 grep --color=auto clickhouse
- [root@hadoop001 ~]# netstat -ntlp | grep clickhouse
- tcp6 0 0 :::8123 :::* LISTEN 3966/clickhouse-ser
- tcp6 0 0 :::9000 :::* LISTEN 3966/clickhouse-ser
- tcp6 0 0 :::9009 :::* LISTEN 3966/clickhouse-ser
- [root@hadoop001 ~]# clickhouse-client
- ClickHouse client version 20.1.4.14 (official build).
- Connecting to localhost:9000 as user default.
- Connected to ClickHouse server version 20.1.4 revision 54431.
-
- hadoop001 :) show databases;
-
- SHOW DATABASES
-
- ┌─name────┐
- │ default │
- │ system │
- └─────────┘
-
- 2 rows in set. Elapsed: 0.012 sec.
-
- hadoop001 :) create database test;
-
- CREATE DATABASE test
-
- Ok.
-
- hadoop001 :) insert into test01 values (1, 'Russia'), (2, 'clickhouse'), (3, 'spark');
-
- INSERT INTO test01 VALUES
-
- Ok.
-
- 3 rows in set. Elapsed: 0.003 sec.
-
- hadoop001 :) select id, name from test01;
-
- SELECT
- id,
- name
- FROM test01
-
- ┌─id─┬─name───────┐
- │ 1 │ Russia │
- │ 2 │ clickhouse │
- │ 3 │ spark │
- └────┴────────────┘
-
- 3 rows in set. Elapsed: 0.012 sec.
-
- hadoop001 :)
-
-
- 0 rows in set. Elapsed: 0.002 sec.
问题汇总
问题一:启动报错
启动参数:sudo clickhouse-server --config-file=/etc/clickhouse-server/config.xml
2020.08.20 18:49:28.189321 [ 29338 ] {} <Error> Application: DB::Exception: Effective user of the process (root) does not match the owner of the data (clickhouse). Run under 'sudo -u clickhouse'
解决办法,已经有了提示,Run under ‘sudo -u clickhouse’.
修改后启动参数: sudo -u clickhouse clickhouse-server --config-file=/etc/clickhouse-server/config.xml
问题二:clickhouse-clict 连接失败
- [root@hadoop001 ~]# clickhouse-client
- ClickHouse client version 20.1.4.14 (official build).
- Connecting to localhost:9000 as user default.
- Code: 210. DB::NetException: Connection refused (localhost:9000)
[root@hadoop001 clickhouse]# vim /etc/clickhouse-server/config.xml
打开此处注释
</article>