其他分享
首页 > 其他分享> > 安装单节点clickhouse

安装单节点clickhouse

作者:互联网

目录

https://clickhouse.com/docs/zh/

单节点安装跟集群安装都需要提前把clickhouse-server软件装好。
单节点与集群的区别就是一个连接了zookeeper,另外一个只读本地文件。

单节点

前置检查

CPU是否支持sse4_2

centos系统查看方法:

[root@clickhouse01 ~]# grep  -c sse4_2 /proc/cpuinfo
1

运行前置脚本

前置脚本目的是拉去yum源, 如果是离线安装,也可以自己取yum源指向的节点下载好安装包。

  1. 先挂载ISO 我的系统版本是

[root@192 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)


  1. 运行脚本

[root@192 ~]# curl -s https://packagecloud.io/install/repositories/altinity/clickhouse/script.rpm.sh | sudo bash

...
Complete!
Generating yum cache for Altinity_clickhouse...
Generating yum cache for Altinity_clickhouse-source...

The repository is setup! You can now install packages.

格式化新的分区

格式化分区的目的是为了存放clickhouse的数据

pvcreate /dev/sdb 
vgcreate vgdata /dev/sdb
lvcreate -l 5119 vgdata

[root@localhost ~]# mkfs.xfs /dev/vgdata/lvol0
meta-data=/dev/vgdata/lvol0      isize=512    agcount=4, agsize=1310464 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=5241856, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0


## 使用yum安装之后,如果希望重新挂载这个目录,则需要授权给clickhouse用户
[root@localhost lib]# pwd
/var/lib
[root@localhost lib]# ls -ld clickhouse/
drwx------ 2 clickhouse clickhouse 4096 Nov 28 10:31 clickhouse/
[root@localhost lib]# mount /dev/mapper/vgdata-lvol0 /var/lib/clickhouse/
[root@localhost lib]# chown -R clickhouse:clickhouse /var/lib/clickhouse/
[root@localhost lib]# chmod 700 clickhouse/


[root@localhost lib]#  echo "/dev/mapper/vgdata-lvol0 /var/lib/clickhouse/ xfs defaults 0 0" >> /etc/fstab


使用yum安装

使用yum安装


yum install -y clickhouse-server clickhouse-client
[root@192 ~]# yum install -y clickhouse-server clickhouse-client
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package clickhouse-client.x86_64 0:20.8.3.18-1.el7 will be installed
---> Package clickhouse-server.x86_64 0:20.8.3.18-1.el7 will be installed
--> Processing Dependency: clickhouse-server-common = 20.8.3.18-1.el7 for package: clickhouse-server-20.8.3.18-1.el7.x86_64
--> Processing Dependency: clickhouse-common-static = 20.8.3.18-1.el7 for package: clickhouse-server-20.8.3.18-1.el7.x86_64
--> Running transaction check
---> Package clickhouse-common-static.x86_64 0:20.8.3.18-1.el7 will be installed
---> Package clickhouse-server-common.x86_64 0:20.8.3.18-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================
 Package                           Arch            Version                    Repository                    Size
=================================================================================================================
Installing:
 clickhouse-client                 x86_64          20.8.3.18-1.el7            Altinity_clickhouse          6.2 k
 clickhouse-server                 x86_64          20.8.3.18-1.el7            Altinity_clickhouse           35 M
Installing for dependencies:
 clickhouse-common-static          x86_64          20.8.3.18-1.el7            Altinity_clickhouse           66 M
 clickhouse-server-common          x86_64          20.8.3.18-1.el7            Altinity_clickhouse           14 k

Transaction Summary
=================================================================================================================
Install  2 Packages (+2 Dependent packages)

Total download size: 101 M
Installed size: 547 M
Downloading packages:
(1/4): clickhouse-client-20.8.3.18-1.el7.x86_64.rpm                                       | 6.2 kB  00:00:01
(2/4): clickhouse-server-20.8.3.18-1.el7.x86_64.rpm                                       |  35 MB  00:00:03
(3/4): clickhouse-server-common-20.8.3.18-1.el7.x86_64.rpm                                |  14 kB  00:00:00
(4/4): clickhouse-common-static-20.8.3.18-1.el7.x86_64.rpm                                |  66 MB  00:00:06
-----------------------------------------------------------------------------------------------------------------
Total                                                                             15 MB/s | 101 MB  00:00:06
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : clickhouse-common-static-20.8.3.18-1.el7.x86_64                                               1/4
  Installing : clickhouse-server-common-20.8.3.18-1.el7.x86_64                                               2/4
  Installing : clickhouse-server-20.8.3.18-1.el7.x86_64                                                      3/4
Create user clickhouse.clickhouse with datadir /var/lib/clickhouse
  Installing : clickhouse-client-20.8.3.18-1.el7.x86_64                                                      4/4
Create user clickhouse.clickhouse with datadir /var/lib/clickhouse
  Verifying  : clickhouse-server-common-20.8.3.18-1.el7.x86_64                                               1/4
  Verifying  : clickhouse-common-static-20.8.3.18-1.el7.x86_64                                               2/4
  Verifying  : clickhouse-client-20.8.3.18-1.el7.x86_64                                                      3/4
  Verifying  : clickhouse-server-20.8.3.18-1.el7.x86_64                                                      4/4

Installed:
  clickhouse-client.x86_64 0:20.8.3.18-1.el7              clickhouse-server.x86_64 0:20.8.3.18-1.el7

Dependency Installed:
  clickhouse-common-static.x86_64 0:20.8.3.18-1.el7       clickhouse-server-common.x86_64 0:20.8.3.18-1.el7

Complete!



查看启动状态

安装好默认就启动了。 一般生产环境都不是自动启动的。 不然体现不出运维的价值了。
测试环境无所谓,我这里改成随着系统启动而启动。

[root@192 ~]# systemctl enable clickhouse-server
clickhouse-server.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig clickhouse-server on
[root@192 ~]# systemctl status clickhouse-server
● clickhouse-server.service - LSB: Yandex clickhouse-server daemon
   Loaded: loaded (/etc/rc.d/init.d/clickhouse-server; bad; vendor preset: disabled)
   Active: active (exited) since Mon 2021-10-18 00:26:20 CST; 6s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 7405 ExecStart=/etc/rc.d/init.d/clickhouse-server start (code=exited, status=0/SUCCESS)

Oct 18 00:26:18 192.168.150.132 systemd[1]: Starting LSB: Yandex clickhouse-server daemon...
Oct 18 00:26:19 192.168.150.132 su[7417]: (to clickhouse) root on none
Oct 18 00:26:19 192.168.150.132 clickhouse-server[7405]: Start clickhouse-server service: Path to data dire...se/
Oct 18 00:26:19 192.168.150.132 su[7422]: (to clickhouse) root on none
Oct 18 00:26:19 192.168.150.132 su[7424]: (to clickhouse) root on none
Oct 18 00:26:19 192.168.150.132 su[7427]: (to clickhouse) root on none
Oct 18 00:26:19 192.168.150.132 su[7435]: (to clickhouse) root on none
Oct 18 00:26:20 192.168.150.132 clickhouse-server[7405]: DONE
Oct 18 00:26:20 192.168.150.132 systemd[1]: Started LSB: Yandex clickhouse-server daemon.
Hint: Some lines were ellipsized, use -l to show in full.


配置clickhouse用户

如果希望使用clickhouse用户管理数据库,可以重新配置用户基本信息。

  1. 家目录
[root@localhost ~]# grep clickhouse /etc/passwd
clickhouse:x:998:996:Clickhouse server:/var/lib/clickhouse:/sbin/nologin
[root@localhost ~]# mkdir /home/clickhouse
[root@localhost ~]# usermod -d /home/clickhouse clickhouse
[root@localhost ~]# grep clickhouse /etc/passwd
clickhouse:x:998:996:Clickhouse server:/home/clickhouse:/sbin/nologin
[root@localhost ~]# usermod -s /bin/bash clickhouse
[root@localhost ~]# grep clickhouse /etc/passwd
clickhouse:x:998:996:Clickhouse server:/home/clickhouse:/bin/bash

[root@localhost ~]# cp -a /etc/skel/. /home/clickhouse


[root@localhost ~]# ls -la /home/clickhouse
total 12
drwxr-xr-x. 2 root root  62 Jul 13 08:10 .
drwxr-xr-x. 3 root root  24 Jul 13 08:05 ..
-rw-r--r--. 1 root root  18 Apr 11  2018 .bash_logout
-rw-r--r--. 1 root root 193 Apr 11  2018 .bash_profile
-rw-r--r--. 1 root root 231 Apr 11  2018 .bashrc
[root@localhost ~]# 
[root@localhost ~]# chown -R clickhouse:clickhouse /home/clickhouse
[root@localhost ~]# chmod 700 /home/clickhouse

配置clickhouse

打开远程监听

从下面lsof结果看 cslistener就是9000端口,这个名称引用了 /etc/services ,可以尝试查看这个文件的9000端口,名称就是cslistener。
如果手欠调整了这个名称,假如改成ckport, 则lsof返回的就是自定义名称。

[root@192 ~]# vi /etc/clickhouse-server/config.xml

添加配置,默认是注释的,可以打开注释。 
    <listen_host>::1</listen_host>
    <listen_host>0.0.0.0</listen_host>

这俩选项都得打开,否则登录的时候会报错
报错内容:Code: 210. DB::NetException: Connection refused (localhost:9000)

[root@192 ~]# lsof -ni
COMMAND    PID       USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
dhclient  6504       root    6u  IPv4  35859      0t0  UDP *:bootpc
sshd      6683       root    3u  IPv4  36779      0t0  TCP *:ssh (LISTEN)
sshd      6683       root    4u  IPv6  36781      0t0  TCP *:ssh (LISTEN)
sshd      7121       root    3u  IPv4  37591      0t0  TCP 192.168.150.132:ssh->192.168.150.1:58072 (ESTABLISHED)
sshd      7123       root    3u  IPv4  37674      0t0  TCP 192.168.150.132:ssh->192.168.150.1:61970 (ESTABLISHED)
clickhous 8114 clickhouse   21u  IPv4  51128      0t0  TCP *:8123 (LISTEN)
clickhous 8114 clickhouse   22u  IPv4  51129      0t0  TCP *:cslistener (LISTEN)
clickhous 8114 clickhouse   23u  IPv4  51130      0t0  TCP *:pichat (LISTEN)
clickhous 8114 clickhouse   24u  IPv4  51131      0t0  TCP *:9004 (LISTEN)


查看目前进程使用的配置文件

ps -ef | grep clickhouse-server
clickho+   7847      1  0 00:53 ?        00:00:14 clickhouse-server --daemon --pid-file=/var/run/clickhouse-server/clickhouse-server.pid --config-file=/etc/clickhouse-server/config.xml

标签:3.18,20.8,安装,server,root,节点,clickhouse,el7
来源: https://www.cnblogs.com/fooobabar/p/16490017.html