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@gbase_rh7_001 ~]# /etc/init.d/clickhouse-server start
Init script is already running
[root@gbase_rh7_001 ~]# clickhouse-client
ClickHouse client version 21.3.4.25 (official build).
Connecting to localhost:9000 as user default.
Code: 210. DB::NetException: Connection refused (localhost:9000)

原因

在redhat 7操作系统,要使用systemctl启动服务

解决方法

如下用systemctl start clickhouse-server.service 后,查看status确认服务正常。用clickhouse-client可以正常登录执行SQL了。

[root@gbase_rh7_001 log]# systemctl start clickhouse-server.service
[root@gbase_rh7_001 log]# systemctl status clickhouse-server.service
● clickhouse-server.service - ClickHouse Server (analytic DBMS for big data)
   Loaded: loaded (/etc/systemd/system/clickhouse-server.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-03-30 14:02:27 CST; 7s ago
 Main PID: 29877 (clckhouse-watch)
   CGroup: /system.slice/clickhouse-server.service
           ├─29877 clickhouse-watchdog --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickhouse-server.pid
           └─29881 /usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickhouse-server.pid

Mar 30 14:02:27 gbase_rh7_001 systemd[1]: Started ClickHouse Server (analytic DBMS for big data).
Mar 30 14:02:27 gbase_rh7_001 systemd[1]: Starting ClickHouse Server (analytic DBMS for big data)...
Mar 30 14:02:27 gbase_rh7_001 clickhouse-server[29877]: Processing configuration file '/etc/clickhouse-server/config.xml'.
Mar 30 14:02:27 gbase_rh7_001 clickhouse-server[29877]: Logging trace to /var/log/clickhouse-server/clickhouse-server.log
Mar 30 14:02:27 gbase_rh7_001 clickhouse-server[29877]: Logging errors to /var/log/clickhouse-server/clickhouse-server.err.log
Mar 30 14:02:27 gbase_rh7_001 clickhouse-server[29877]: Processing configuration file '/etc/clickhouse-server/config.xml'.
Mar 30 14:02:27 gbase_rh7_001 clickhouse-server[29877]: Saved preprocessed configuration to '/var/lib/clickhouse/preprocessed_configs/config.xml'.
Mar 30 14:02:27 gbase_rh7_001 clickhouse-server[29877]: Processing configuration file '/etc/clickhouse-server/users.xml'.
Mar 30 14:02:27 gbase_rh7_001 clickhouse-server[29877]: Saved preprocessed configuration to '/var/lib/clickhouse/preprocessed_configs/users.xml'.
[root@gbase_rh7_001 log]#
[root@gbase_rh7_001 log]#
[root@gbase_rh7_001 log]#
[root@gbase_rh7_001 log]# clickhouse-client
ClickHouse client version 21.3.4.25 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 21.3.4 revision 54447.

gbase_rh7_001 :) show databases;

SHOW DATABASES

Query id: 0c324cd8-6ba1-496e-85a7-57288fd6a74c

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

2 rows in set. Elapsed: 0.003 sec.

gbase_rh7_001 :)