在Ubuntu20.04安装单节点ClickHouse22.8.4并解决DB::NetException: Connection refused NETWORK_ERROR导致无法远程访问的问题

106 篇文章 15 订阅
42 篇文章 0 订阅

在Ubuntu20.04安装单节点ClickHouse22.8.4并解决DB::NetException: Connection refused (192.168.88.22:9000). (NETWORK_ERROR)导致无法远程访问的问题

前言

参照ClickHouse官网提供的安装文档:https://clickhouse.com/docs/zh/getting-started/install

虚拟机准备

轻车熟路,参照:https://lizhiyong.blog.csdn.net/article/details/126236516

基础网络

在这里插入图片描述

静态IP:192.168.88.22

子网掩码:255.255.255.0

网关:192.168.88.2

DNS:8.8.8.8

禁用IPV6

更换源

不一定每次都指定阿里云。。。自动选个速度最快的即可。

安装必要命令

sudo apt-get install net-tools
sudo apt-get install openssh-server
sudo apt-get install openssh-client
apt install vim

之后可以使用MobaXterm连接:

zhiyong@zhiyong-ck1:~$ hostname
zhiyong-ck1
zhiyong@zhiyong-ck1:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.88.22  netmask 255.255.255.0  broadcast 192.168.88.255
        inet6 fe80::20c:29ff:fee6:a0de  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:e6:a0:de  txqueuelen 1000  (以太网)
        RX packets 41276  bytes 57382342 (57.3 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 9374  bytes 728677 (728.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (本地环回)
        RX packets 3536  bytes 320114 (320.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3536  bytes 320114 (320.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

指令集检查

根据官方文档介绍:

ClickHouse可以在任何具有x86_64,AArch64或PowerPC64LE CPU架构的Linux,FreeBSD或Mac OS X上运行。

官方预构建的二进制文件通常针对x86_64进行编译,并利用SSE 4.2指令集,因此,除非另有说明,支持它的CPU使用将成为额外的系统需求。下面是检查当前CPU是否支持SSE 4.2的命令:

$ grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"

要在不支持SSE 4.2AArch64PowerPC64LE架构的处理器上运行ClickHouse,您应该通过适当的配置调整从源代码构建ClickHouse

执行:

zhiyong@zhiyong-ck1:~$ grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
SSE 4.2 supported

笔者的Intel Xeon 2693V3双路显然支持该指令集,可以使用官方编译好的包继续安装。

安装ClickHouse

官方离线安装包下载地址:https://packages.clickhouse.com/deb/pool/stable/

在这里插入图片描述

大版本号目前最新是22.8。自己玩玩,当然是最新版。。。

安装包列表:

  • clickhouse-common-static — ClickHouse编译的二进制文件。
  • clickhouse-server — 创建clickhouse-server软连接,并安装默认配置服务
  • clickhouse-client — 创建clickhouse-client客户端工具软连接,并安装客户端配置文件。
  • clickhouse-common-static-dbg — 带有调试信息的ClickHouse二进制文件。

使用Deb安装包

由于虚拟机是Ubuntu,当然应该是用Deb的apt安装包。如果一定要使用RPM的yum源,自己想办法实现,坑不是一般的大。。。dev没什么安全策略,直接在线下载安装就行:

sudo apt-get install -y apt-transport-https ca-certificates dirmngr
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754

echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee \
    /etc/apt/sources.list.d/clickhouse.list
sudo apt-get update

sudo apt-get install -y clickhouse-server clickhouse-client

sudo service clickhouse-server start
clickhouse-client # or "clickhouse-client --password" if you've set up a password.

照着敲即可【安装包265M,慢慢下载】:

zhiyong@zhiyong-ck1:~$ grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
SSE 4.2 supported
zhiyong@zhiyong-ck1:~$ sudo apt-get install -y apt-transport-https ca-certificates dirmngr
[sudo] zhiyong 的密码:
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
将会同时安装下列软件:
  gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgconf gpgsm gpgv
建议安装:
  tor parcimonie xloadimage scdaemon
下列【新】软件包将被安装:
  apt-transport-https
下列软件包将被升级:
  ca-certificates dirmngr gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgconf gpgsm gpgv
升级了 12 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 278 个软件包未被升级。
需要下载 2,708 kB 的归档。
解压缩后会消耗 157 kB 的额外空间。
获取:1 https://mirror.nju.edu.cn/ubuntu focal-updates/main amd64 gpg-wks-client amd64 2.2.19-3ubuntu2.2 [97.4 kB]
获取:2 https://mirror.nju.edu.cn/ubuntu focal-updates/main amd64 dirmngr amd64 2.2.19-3ubuntu2.2 [330 kB]
获取:3 https://mirror.nju.edu.cn/ubuntu focal-updates/main amd64 gnupg-utils amd64 2.2.19-3ubuntu2.2 [481 kB]
获取:4 https://mirror.nju.edu.cn/ubuntu focal-updates/main amd64 gpg-wks-server amd64 2.2.19-3ubuntu2.2 [90.2 kB]
获取:5 https://mirror.nju.edu.cn/ubuntu focal-updates/main amd64 gpg-agent amd64 2.2.19-3ubuntu2.2 [232 kB]
获取:6 https://mirror.nju.edu.cn/ubuntu focal-updates/main amd64 gpg amd64 2.2.19-3ubuntu2.2 [482 kB]
获取:7 https://mirror.nju.edu.cn/ubuntu focal-updates/main amd64 gpgconf amd64 2.2.19-3ubuntu2.2 [124 kB]
获取:8 https://mirror.nju.edu.cn/ubuntu focal-updates/main amd64 gnupg-l10n all 2.2.19-3ubuntu2.2 [51.7 kB]
获取:9 https://mirror.nju.edu.cn/ubuntu focal-updates/main amd64 gnupg all 2.2.19-3ubuntu2.2 [259 kB]
获取:10 https://mirror.nju.edu.cn/ubuntu focal-updates/main amd64 gpgsm amd64 2.2.19-3ubuntu2.2 [217 kB]
获取:11 https://mirror.nju.edu.cn/ubuntu focal-updates/main amd64 gpgv amd64 2.2.19-3ubuntu2.2 [200 kB]
获取:12 https://mirror.nju.edu.cn/ubuntu focal-updates/main amd64 ca-certificates all 20211016~20.04.1 [144 kB]
获取:13 https://mirror.nju.edu.cn/ubuntu focal-updates/universe amd64 apt-transport-https all 2.0.9 [1,704 B]
已下载 2,708 kB,耗时 1(3,152 kB/s)
正在预设定软件包 ...
(正在读取数据库 ... 系统当前共安装有 149909 个文件和目录。)
准备解压 .../00-gpg-wks-client_2.2.19-3ubuntu2.2_amd64.deb  ...
正在解压 gpg-wks-client (2.2.19-3ubuntu2.2) 并覆盖 (2.2.19-3ubuntu2.1) ...
准备解压 .../01-dirmngr_2.2.19-3ubuntu2.2_amd64.deb  ...
正在解压 dirmngr (2.2.19-3ubuntu2.2) 并覆盖 (2.2.19-3ubuntu2.1) ...
准备解压 .../02-gnupg-utils_2.2.19-3ubuntu2.2_amd64.deb  ...
正在解压 gnupg-utils (2.2.19-3ubuntu2.2) 并覆盖 (2.2.19-3ubuntu2.1) ...
准备解压 .../03-gpg-wks-server_2.2.19-3ubuntu2.2_amd64.deb  ...
正在解压 gpg-wks-server (2.2.19-3ubuntu2.2) 并覆盖 (2.2.19-3ubuntu2.1) ...
准备解压 .../04-gpg-agent_2.2.19-3ubuntu2.2_amd64.deb  ...
正在解压 gpg-agent (2.2.19-3ubuntu2.2) 并覆盖 (2.2.19-3ubuntu2.1) ...
准备解压 .../05-gpg_2.2.19-3ubuntu2.2_amd64.deb  ...
正在解压 gpg (2.2.19-3ubuntu2.2) 并覆盖 (2.2.19-3ubuntu2.1) ...
准备解压 .../06-gpgconf_2.2.19-3ubuntu2.2_amd64.deb  ...
正在解压 gpgconf (2.2.19-3ubuntu2.2) 并覆盖 (2.2.19-3ubuntu2.1) ...
准备解压 .../07-gnupg-l10n_2.2.19-3ubuntu2.2_all.deb  ...
正在解压 gnupg-l10n (2.2.19-3ubuntu2.2) 并覆盖 (2.2.19-3ubuntu2.1) ...
准备解压 .../08-gnupg_2.2.19-3ubuntu2.2_all.deb  ...
正在解压 gnupg (2.2.19-3ubuntu2.2) 并覆盖 (2.2.19-3ubuntu2.1) ...
准备解压 .../09-gpgsm_2.2.19-3ubuntu2.2_amd64.deb  ...
正在解压 gpgsm (2.2.19-3ubuntu2.2) 并覆盖 (2.2.19-3ubuntu2.1) ...
准备解压 .../10-gpgv_2.2.19-3ubuntu2.2_amd64.deb  ...
正在解压 gpgv (2.2.19-3ubuntu2.2) 并覆盖 (2.2.19-3ubuntu2.1) ...
正在设置 gpgv (2.2.19-3ubuntu2.2) ...
(正在读取数据库 ... 系统当前共安装有 149909 个文件和目录。)
准备解压 .../ca-certificates_20211016~20.04.1_all.deb  ...
正在解压 ca-certificates (20211016~20.04.1) 并覆盖 (20210119~20.04.2) ...
正在选中未选择的软件包 apt-transport-https。
准备解压 .../apt-transport-https_2.0.9_all.deb  ...
正在解压 apt-transport-https (2.0.9) ...
正在设置 apt-transport-https (2.0.9) ...
正在设置 ca-certificates (20211016~20.04.1) ...
Updating certificates in /etc/ssl/certs...
rehash: warning: skipping ca-certificates.crt,it does not contain exactly one certificate or CRL
7 added, 8 removed; done.
正在设置 gnupg-l10n (2.2.19-3ubuntu2.2) ...
正在设置 gpgconf (2.2.19-3ubuntu2.2) ...
正在设置 gpg (2.2.19-3ubuntu2.2) ...
正在设置 gnupg-utils (2.2.19-3ubuntu2.2) ...
正在设置 gpg-agent (2.2.19-3ubuntu2.2) ...
正在设置 gpgsm (2.2.19-3ubuntu2.2) ...
正在设置 dirmngr (2.2.19-3ubuntu2.2) ...
正在设置 gpg-wks-server (2.2.19-3ubuntu2.2) ...
正在设置 gpg-wks-client (2.2.19-3ubuntu2.2) ...
正在设置 gnupg (2.2.19-3ubuntu2.2) ...
正在处理用于 man-db (2.9.1-1) 的触发器 ...
正在处理用于 install-info (6.7.0.dfsg.2-5) 的触发器 ...
正在处理用于 ca-certificates (20211016~20.04.1) 的触发器 ...
Updating certificates in /etc/ssl/certs...
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.
zhiyong@zhiyong-ck1:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754
Executing: /tmp/apt-key-gpghome.fL9eortNDc/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754
gpg: 密钥 8919F6BD2B48D754:公钥 “ClickHouse Inc. Repositories Key <packages@clickhouse.com>” 已导入
gpg: 处理的总数:1
gpg:               已导入:1
zhiyong@zhiyong-ck1:~$ echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee \
>     /etc/apt/sources.list.d/clickhouse.list
deb https://packages.clickhouse.com/deb stable main
zhiyong@zhiyong-ck1:~$ sudo apt-get update
命中:1 https://mirror.nju.edu.cn/ubuntu focal InRelease
命中:2 https://mirror.nju.edu.cn/ubuntu focal-updates InRelease
命中:3 https://mirror.nju.edu.cn/ubuntu focal-backports InRelease
命中:4 https://mirror.nju.edu.cn/ubuntu focal-security InRelease
获取:5 https://packages.clickhouse.com/deb stable InRelease [5,536 B]
获取:6 https://packages.clickhouse.com/deb stable/main i386 Packages [5,568 B]
获取:7 https://packages.clickhouse.com/deb stable/main amd64 Packages [18.1 kB]
已下载 29.2 kB,耗时 2(14.9 kB/s)
正在读取软件包列表... 完成
zhiyong@zhiyong-ck1:~$ sudo apt-get install -y clickhouse-server clickhouse-client
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
将会同时安装下列软件:
  clickhouse-common-static
建议安装:
  clickhouse-common-static-dbg
下列【新】软件包将被安装:
  clickhouse-client clickhouse-common-static clickhouse-server
升级了 0 个软件包,新安装了 3 个软件包,要卸载 0 个软件包,有 278 个软件包未被升级。
需要下载 265 MB 的归档。
解压缩后会消耗 773 MB 的额外空间。
获取:1 https://packages.clickhouse.com/deb stable/main amd64 clickhouse-common-static amd64 22.8.4.7 [265 MB]
获取:2 https://packages.clickhouse.com/deb stable/main amd64 clickhouse-client amd64 22.8.4.7 [75.3 kB]
获取:3 https://packages.clickhouse.com/deb stable/main amd64 clickhouse-server amd64 22.8.4.7 [99.2 kB]
已下载 265 MB,耗时 237(1,684 kB/s)
正在选中未选择的软件包 clickhouse-common-static。
(正在读取数据库 ... 系统当前共安装有 149912 个文件和目录。)
准备解压 .../clickhouse-common-static_22.8.4.7_amd64.deb  ...
正在解压 clickhouse-common-static (22.8.4.7) ...
正在选中未选择的软件包 clickhouse-client。
准备解压 .../clickhouse-client_22.8.4.7_amd64.deb  ...
正在解压 clickhouse-client (22.8.4.7) ...
正在选中未选择的软件包 clickhouse-server。
准备解压 .../clickhouse-server_22.8.4.7_amd64.deb  ...
正在解压 clickhouse-server (22.8.4.7) ...
正在设置 clickhouse-common-static (22.8.4.7) ...
正在设置 clickhouse-server (22.8.4.7) ...
ClickHouse binary is already located at /usr/bin/clickhouse
Symlink /usr/bin/clickhouse-server already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-server to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-client already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-client to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-local already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-local to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-benchmark already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-benchmark to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-copier already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-copier to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-obfuscator already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-obfuscator to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-git-import to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-compressor already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-compressor to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-format already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-format to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-extract-from-config already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-extract-from-config to /usr/bin/clickhouse.
Symlink /usr/bin/clickhouse-keeper already exists but it points to /clickhouse. Will replace the old symlink to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-keeper-converter to /usr/bin/clickhouse.
Creating symlink /usr/bin/clickhouse-disks to /usr/bin/clickhouse.
Creating clickhouse group if it does not exist.
 groupadd -r clickhouse
Creating clickhouse user if it does not exist.
 useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse clickhouse
Will set ulimits for clickhouse user in /etc/security/limits.d/clickhouse.conf.
Creating config directory /etc/clickhouse-server/config.d that is used for tweaks of main server configuration.
Creating config directory /etc/clickhouse-server/users.d that is used for tweaks of users configuration.
Config file /etc/clickhouse-server/config.xml already exists, will keep it and extract path info from it.
/etc/clickhouse-server/config.xml has /var/lib/clickhouse/ as data path.
/etc/clickhouse-server/config.xml has /var/log/clickhouse-server/ as log path.
Users config file /etc/clickhouse-server/users.xml already exists, will keep it and extract users info from it.
Creating log directory /var/log/clickhouse-server/.
Creating data directory /var/lib/clickhouse/.
Creating pid directory /var/run/clickhouse-server.
 chown -R clickhouse:clickhouse '/var/log/clickhouse-server/'
 chown -R clickhouse:clickhouse '/var/run/clickhouse-server'
 chown  clickhouse:clickhouse '/var/lib/clickhouse/'
 groupadd -r clickhouse-bridge
 useradd -r --shell /bin/false --home-dir /nonexistent -g clickhouse-bridge clickhouse-bridge
 chown -R clickhouse-bridge:clickhouse-bridge '/usr/bin/clickhouse-odbc-bridge'
 chown -R clickhouse-bridge:clickhouse-bridge '/usr/bin/clickhouse-library-bridge'
Enter password for default user:
Password for default user is saved in file /etc/clickhouse-server/users.d/default-password.xml.
Setting capabilities for clickhouse binary. This is optional.
 chown -R clickhouse:clickhouse '/etc/clickhouse-server'

ClickHouse has been successfully installed.

Start clickhouse-server with:
 sudo clickhouse start

Start clickhouse-client with:
 clickhouse-client --password

Synchronizing state of clickhouse-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable clickhouse-server
Created symlink /etc/systemd/system/multi-user.target.wants/clickhouse-server.service → /lib/systemd/system/clickhouse-server.service.
正在设置 clickhouse-client (22.8.4.7) ...
正在处理用于 systemd (245.4-4ubuntu3.15) 的触发器 ...
zhiyong@zhiyong-ck1:~$

中间会让敲密码,笔者习惯性敲:123456

启动服务

zhiyong@zhiyong-ck1:~$ sudo service clickhouse-server start

命令行连接测试

zhiyong@zhiyong-ck1:~$ clickhouse-client --password 123456
ClickHouse client version 22.8.4.7 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 22.8.4 revision 54460.

zhiyong-ck1 :) select 1;

SELECT 1

Query id: 94ceec60-3e9f-4c48-9fd1-d37f3d34568f

┌─1─┐
│ 1 │
└───┘

1 row in set. Elapsed: 0.002 sec.

zhiyong-ck1 :) show databases;

SHOW DATABASES

Query id: 1af1c8b0-cda6-4316-bb9e-ddcfd41f32cd

┌─name───────────────┐
│ INFORMATION_SCHEMA │
│ default            │
│ information_schema │
│ system             │
└────────────────────┘

4 rows in set. Elapsed: 0.002 sec.

zhiyong-ck1 :)

由于设置了密码=123456,需要敲密码才能使用客户端连接。

至此,单机版本ClickHouse安装成功。可以根据Log看到目前安装的单节点ClickHouse是22.8.4。

更多命令行使用方法可以参照官网:https://clickhouse.com/docs/zh/interfaces/cli/

贴一些命令行参数:

  • --host, -h -– 服务端的host名称, 默认是localhost。您可以选择使用host名称或者IPv4或IPv6地址。
  • --port – 连接的端口,默认值:9000。注意HTTP接口以及TCP原生接口使用的是不同端口。
  • --user, -u – 用户名。 默认值:default
  • --password – 密码。 默认值:空字符串。
  • --query, -q – 使用非交互模式查询。
  • --database, -d – 默认当前操作的数据库. 默认值:服务端默认的配置(默认是default)。
  • --multiline, -m – 如果指定,允许多行语句查询(Enter仅代表换行,不代表查询语句完结)。
  • --multiquery, -n – 如果指定, 允许处理用;号分隔的多个查询,只在非交互模式下生效。
  • --format, -f – 使用指定的默认格式输出结果。
  • --vertical, -E – 如果指定,默认情况下使用垂直格式输出结果。这与–format=Vertical相同。在这种格式中,每个值都在单独的行上打印,这种方式对显示宽表很有帮助。
  • --time, -t – 如果指定,非交互模式下会打印查询执行的时间到stderr中。
  • --stacktrace – 如果指定,如果出现异常,会打印堆栈跟踪信息。
  • --config-file – 配置文件的名称。
  • --secure – 如果指定,将通过安全连接连接到服务器。
  • --history_file — 存放命令历史的文件的路径。
  • --param_<name> — 查询参数配置查询参数.

尝试使用:

zhiyong-ck1 :) exit
Bye.
zhiyong@zhiyong-ck1:~$ clickhouse-client -h 192.168.88.22 --port 9000 --user default --password 123456
ClickHouse client version 22.8.4.7 (official build).
Connecting to 192.168.88.22:9000 as user default.
Code: 210. DB::NetException: Connection refused (192.168.88.22:9000). (NETWORK_ERROR)

zhiyong@zhiyong-ck1:~$ clickhouse-client -h localhost --port 9000 --user default --password 123456
ClickHouse client version 22.8.4.7 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 22.8.4 revision 54460.

zhiyong-ck1 :) exit
Bye.
zhiyong@zhiyong-ck1:~$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.88.22  netmask 255.255.255.0  broadcast 192.168.88.255
        inet6 fe80::20c:29ff:fee6:a0de  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:e6:a0:de  txqueuelen 1000  (以太网)
        RX packets 228418  bytes 337558377 (337.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 41775  bytes 2733956 (2.7 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (本地环回)
        RX packets 3802  bytes 563177 (563.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3802  bytes 563177 (563.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

zhiyong@zhiyong-ck1:~$ hostname
zhiyong-ck1
zhiyong@zhiyong-ck1:~$ clickhouse-client -h zhiyong-ck1 --port 9000 --user default --password 123456
ClickHouse client version 22.8.4.7 (official build).
Connecting to zhiyong-ck1:9000 as user default.
Code: 210. DB::NetException: Connection refused (zhiyong-ck1:9000). (NETWORK_ERROR)

zhiyong@zhiyong-ck1:~$ cat /etc/hosts
127.0.0.1       localhost
127.0.1.1       zhiyong-ck1

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

可以看到只能使用localhost作为-h的参数。。。使用IP及host都会失败,也是醉了。

在另一台Ubuntu的dev机器只安装ClickHouse的Client:

zhiyong@zhiyong-vm-dev:~$ sudo apt-get install -y apt-transport-https ca-certificates dirmngr
[sudo] zhiyong 的密码:
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
dirmngr 已经是最新版 (2.2.20-1ubuntu4)。
dirmngr 已设置为手动安装。
ca-certificates 已经是最新版 (20211016~21.10.1)。
ca-certificates 已设置为手动安装。
下列软件包是自动安装的并且现在不需要了:
  libfwupdplugin1
使用'sudo apt autoremove'来卸载它(它们)。
下列【新】软件包将被安装:
  apt-transport-https
升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 52 个软件包未被升级。
需要下载 1,514 B 的归档。
解压缩后会消耗 167 kB 的额外空间。
【警告】:下列软件包不能通过认证!
  apt-transport-https
E: 存在未认证的软件包同时使用了 -y 选项,然而未搭配  --allow-unauthenticated
zhiyong@zhiyong-vm-dev:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
Executing: /tmp/apt-key-gpghome.az4XPIUxQR/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv 8919F6BD2B48D754
gpg: 密钥 8919F6BD2B48D754:公钥 “ClickHouse Inc. Repositories Key <packages@clickhouse.com>” 已导入
gpg: 处理的总数:1
gpg:               已导入:1
zhiyong@zhiyong-vm-dev:~$ echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee \
    /etc/apt/sources.list.d/clickhouse.list
sudo apt-get update
deb https://packages.clickhouse.com/deb stable main
忽略:1 http://cn.archive.ubuntu.com/ubuntu impish InRelease
忽略:2 http://security.ubuntu.com/ubuntu impish-security InRelease
错误:3 http://security.ubuntu.com/ubuntu impish-security Release
  404  Not Found [IP: 185.125.190.36 80]
忽略:4 http://cn.archive.ubuntu.com/ubuntu impish-updates InRelease
获取:5 https://packages.clickhouse.com/deb stable InRelease [5,536 B]
忽略:6 http://cn.archive.ubuntu.com/ubuntu impish-backports InRelease
错误:7 http://cn.archive.ubuntu.com/ubuntu impish Release
  404  Not Found [IP: 91.189.91.38 80]
错误:8 http://cn.archive.ubuntu.com/ubuntu impish-updates Release
  404  Not Found [IP: 91.189.91.38 80]
获取:9 https://packages.clickhouse.com/deb stable/main amd64 Packages [18.1 kB]
错误:10 http://cn.archive.ubuntu.com/ubuntu impish-backports Release
  404  Not Found [IP: 91.189.91.38 80]
获取:11 https://packages.clickhouse.com/deb stable/main i386 Packages [5,568 B]
正在读取软件包列表... 完成
E: 仓库 “http://security.ubuntu.com/ubuntu impish-security Release” 不再含有 Release 文件。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
E: 仓库 “http://cn.archive.ubuntu.com/ubuntu impish Release” 没有 Release 文件。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
E: 仓库 “http://cn.archive.ubuntu.com/ubuntu impish-updates Release” 没有 Release 文件。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
E: 仓库 “http://cn.archive.ubuntu.com/ubuntu impish-backports Release” 没有 Release 文件。
N: 无法安全地用该源进行更新,所以默认禁用该源。
N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。
zhiyong@zhiyong-vm-dev:~$
zhiyong@zhiyong-vm-dev:~$
zhiyong@zhiyong-vm-dev:~$ sudo apt-get install -y clickhouse-client
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
下列软件包是自动安装的并且现在不需要了:
  libfwupdplugin1
使用'sudo apt autoremove'来卸载它(它们)。
将会同时安装下列软件:
  clickhouse-common-static
建议安装:
  clickhouse-common-static-dbg
下列【新】软件包将被安装:
  clickhouse-client clickhouse-common-static
升级了 0 个软件包,新安装了 2 个软件包,要卸载 0 个软件包,有 52 个软件包未被升级。
需要下载 265 MB 的归档。
解压缩后会消耗 772 MB 的额外空间。
获取:1 https://packages.clickhouse.com/deb stable/main amd64 clickhouse-common-static amd64 22.8.4.7 [265 MB]
获取:2 https://packages.clickhouse.com/deb stable/main amd64 clickhouse-client amd64 22.8.4.7 [75.3 kB]
已下载 265 MB,耗时 252(1,538 kB/s)
正在选中未选择的软件包 clickhouse-common-static。
(正在读取数据库 ... 系统当前共安装有 212008 个文件和目录。)
准备解压 .../clickhouse-common-static_22.8.4.7_amd64.deb  ...
正在解压 clickhouse-common-static (22.8.4.7) ...
正在选中未选择的软件包 clickhouse-client。
准备解压 .../clickhouse-client_22.8.4.7_amd64.deb  ...
正在解压 clickhouse-client (22.8.4.7) ...
正在设置 clickhouse-common-static (22.8.4.7) ...
正在设置 clickhouse-client (22.8.4.7) ...
zhiyong@zhiyong-vm-dev:~$

使用这台Ubuntu的Client连接另一台的Server:

zhiyong@zhiyong-vm-dev:~$ ping 192.168.88.22
PING 192.168.88.22 (192.168.88.22) 56(84) bytes of data.
64 bytes from 192.168.88.22: icmp_seq=1 ttl=64 time=0.948 ms
64 bytes from 192.168.88.22: icmp_seq=2 ttl=64 time=0.929 ms
64 bytes from 192.168.88.22: icmp_seq=3 ttl=64 time=0.883 ms
64 bytes from 192.168.88.22: icmp_seq=4 ttl=64 time=1.59 ms
64 bytes from 192.168.88.22: icmp_seq=5 ttl=64 time=0.889 ms
^C
--- 192.168.88.22 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4008ms
rtt min/avg/max/mdev = 0.883/1.047/1.589/0.271 ms
zhiyong@zhiyong-vm-dev:~$ clickhouse-client -h 192.168.88.22 --port 9000 --user default --password 123456
ClickHouse client version 22.8.4.7 (official build).
Connecting to 192.168.88.22:9000 as user default.
Code: 210. DB::NetException: Connection refused (192.168.88.22:9000). (NETWORK_ERROR)

zhiyong@zhiyong-vm-dev:~$

目前这状态显然是不正常的。正常情况需要能够远程连接到服务器,正常人谁会localhost访问。。。

DB::NetException: Connection refused (192.168.88.22:9000). (NETWORK_ERROR)这个问题必须解决,否则之后通过JDBC等方式远程访问大概率也不正常。

解决无法远程访问的问题

配置文件的官方文档:https://clickhouse.com/docs/zh/operations/configuration-files/

参照官方的文档可以找到配置文件:

zhiyong@zhiyong-ck1:~$ sudo su root
[sudo] zhiyong 的密码:
root@zhiyong-ck1:/home/zhiyong# cd /etc/clickhouse-server
root@zhiyong-ck1:/etc/clickhouse-server# ll
总用量 100
drwx------   4 clickhouse clickhouse  4096 97 08:19 ./
drwxr-xr-x 131 root       root       12288 97 07:27 ../
dr-x------   2 clickhouse clickhouse  4096 97 07:27 config.d/
-r--------   1 clickhouse clickhouse 67935 97 08:19 config.xml
dr-x------   2 clickhouse clickhouse  4096 97 07:27 users.d/
-r--------   1 clickhouse clickhouse  6115 831 20:52 users.xml

主要的2个配置文件就是config.xml和users.xml。

定位问题

执行:

:set nu
/<listen_host>

可以看到这个配置项有问题:

177     <!-- Listen specified address.
 178          Use :: (wildcard IPv6 address), if you want to accept connections both with IPv4 and IPv6 from everywhere.
 179          Notes:
 180          If you open connections from wildcard address, make sure that at least one of the following measures applied:
 181          - server is protected by firewall and not accessible from untrusted networks;
 182          - all users are restricted to subset of network addresses (see users.xml);
 183          - all users have strong passwords, only secure (TLS) interfaces are accessible, or connections are only made via TLS interfaces.
 184          - users without password have readonly access.
 185          See also: https://www.shodan.io/search?query=clickhouse
 186       -->
 187     <!-- <listen_host>::</listen_host> -->

尝试解决

修改为:

<listen_host>::</listen_host>

使用:

:wq!

强制保存。

重启服务:

root@zhiyong-ck1:/etc/clickhouse-server# exit
exit
zhiyong@zhiyong-ck1:~$ sudo systemctl restart clickhouse-server

重试命令行连接

zhiyong@zhiyong-ck1:~$ clickhouse-client -h 192.168.88.22 --port 9000 --user default --password 123456
ClickHouse client version 22.8.4.7 (official build).
Connecting to 192.168.88.22:9000 as user default.
Connected to ClickHouse server version 22.8.4 revision 54460.

zhiyong-ck1 :) show databases;

SHOW DATABASES

Query id: 26da3836-a2e1-42c3-82e0-37ad6f34c77b

┌─name───────────────┐
│ INFORMATION_SCHEMA │
│ default            │
│ information_schema │
│ system             │
└────────────────────┘

4 rows in set. Elapsed: 0.002 sec.

zhiyong-ck1 :) exit
Bye.

在另一台Ubuntu尝试:

zhiyong@zhiyong-vm-dev:~$ clickhouse-client -h 192.168.88.22 --port 9000 --user default --password 123456
ClickHouse client version 22.8.4.7 (official build).
Connecting to 192.168.88.22:9000 as user default.
Connected to ClickHouse server version 22.8.4 revision 54460.

zhiyong-ck1 :) show databases;

SHOW DATABASES

Query id: 1cda3ec4-b9ce-4ee7-ad3a-f627bcdd7f83

┌─name───────────────┐
│ INFORMATION_SCHEMA │
│ default            │
│ information_schema │
│ system             │
└────────────────────┘

4 rows in set. Elapsed: 0.005 sec.

zhiyong-ck1 :) exit
Bye.
zhiyong@zhiyong-vm-dev:~$

显然此时状态正常。

使用DataGrip测试访问

在这里插入图片描述

最新版本的驱动包有点问题:未找到驱动程序类 org.apache.http.conn.HttpClientConnectionManager

需要使用稍微老一点的驱动包。ClickHouse默认的JDBC端口是8123,不是9000【Client用9000端口是因为底层走TCP,不是走JDBC】。
在这里插入图片描述

这下再去写JDBC连接ClickHouse就问题少一些。。。一步一个坑。

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值