3

I'm newbie to clickhouse, I'm trying to create a clickhouse database on my unbuntu 18.04 remote server, I follow instruction to install click house from DEB package in this link: https://clickhouse.tech/docs/en/getting_started/install/#from-sources

after that when I run command clickhouse-client it shows something like this :

root@busmap-api-test:~# clickhouse-client
ClickHouse client version 20.3.5.21 (official build)
Connecting to localhost:9000 as user default.
Code: 209. DB::NetException: Timeout exceeded while reading from socket (127.0.0.1:9000)

Can someone help me to figure out what is the problem and how I can solve it? Thanks,

vladimir
  • 13,428
  • 2
  • 44
  • 70
Tấn Phát
  • 33
  • 1
  • 3
  • let's check that CH-service is run: *service clickhouse-server status* – vladimir Mar 28 '20 at 10:25
  • @vladimir yeah i got this : ``` clickhouse-server.service - ClickHouse Server (analytic DBMS for big data) Loaded: loaded (/etc/systemd/system/clickhouse-server.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2020-03-25 10:23:21 UTC; 3 days ago Main PID: 11193 (clickhouse-serv) Tasks: 59 (limit: 1152) CGroup: /system.slice/clickhouse-server.service └─11193 /usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickhouse-server.pid ``` – – Tấn Phát Mar 28 '20 at 10:33
  • if you use a remote server, need to define the *--host* option (see for details https://clickhouse.tech/docs/en/interfaces/cli/#command-line-options) – vladimir Mar 28 '20 at 10:37
  • no , i mean that i'm create clickhouse database on my remote server through terminal on remote server , not create from my local machine – Tấn Phát Mar 28 '20 at 12:36
  • look at log-file: *cat /var/log/clickhouse-server/clickhouse-server.err.log*. Check the config-file */etc/clickhouse-server/config.xml* and make sure that *127.0.0.1* uncommented (restart service after change config). – vladimir Mar 28 '20 at 13:02
  • i'm getting this after sudo nano cat /var/log/clickhouse-server/clickhouse-server.err.log. https://gyazo.com/ed61bd341f469239bfb4e98bd2ac7c79 – Tấn Phát Mar 28 '20 at 17:22
  • seem likes i already using port 9000 so that i can not connect to localhost:9000 on clickhouse , how can i change the default port 9000 in config.xml of clickhouse to new one such as 9002 ? – Tấn Phát Mar 29 '20 at 04:24
  • see param [tcp_port](https://clickhouse.tech/docs/en/operations/server_settings/settings/#server_settings-tcp_port) – vladimir Mar 29 '20 at 04:38
  • i have changed the tcp_port from 9000 to 9069 and restart clickhouse but when i run clickhouse-client it still connect to localhost:9000 and return with Code: 209. DB::NetException: Timeout exceeded while reading from socket (127.0.0.1:9000) – Tấn Phát Mar 29 '20 at 05:30
  • need to explicitly define this port - *clickhouse-client --port 9069* (see https://clickhouse.tech/docs/en/interfaces/cli/#command-line-options) – vladimir Mar 29 '20 at 05:49
  • yeah , i have tried but this time it return connection refused root@busmap-api-test:~# clickhouse-client --port=9096 ClickHouse client version 20.3.5.21 (official build). Connecting to localhost:9096 as user default. Code: 210. DB::NetException: Connection refused (localhost:9096) – Tấn Phát Mar 29 '20 at 06:07
  • i check which port are using on clickhouse and it present with port 9096 but still not why i got connection refuse when connect to it https://gyazo.com/96402cfcfd1f84fb9c621f4b24a5f6ef – Tấn Phát Mar 29 '20 at 06:19
  • maybe you misspelled: listened port 9069, but refused 9096 ? – vladimir Mar 29 '20 at 06:26
  • omg you wasr right , i misspelled 9069 by 9096 , after change it i got new return ClickHouse client version 20.3.5.21 (official build). Connecting to localhost:9069 as user default. Code: 516. DB::Exception: Received from localhost:9069. DB::Exception: default: Authentication failed: password is incorrect or there is no user with such name – Tấn Phát Mar 29 '20 at 06:37
  • haha finally it's work when i add --password , thank you a lot buddy – Tấn Phát Mar 29 '20 at 06:38
  • great, congratulations ;) – vladimir Mar 29 '20 at 06:38

2 Answers2

2

Follow these steps to resolve the issue:

  • check that clickhouse-server-service started
service clickhouse-server status
  • check the server logs to find the possible reason
cat /var/log/clickhouse-server/clickhouse-server.err.log
  • if occured the error 'Address already in use':
{} <Error> Application: Net Exception: Address already in use: [::1]:9000
{} <Error> Application: Net Exception: Address already in use: 127.0.0.1:9000
  1. need to switch CH-server to any other port by editing tcp_port-param in /etc/clickhouse-server/config.xml-file:
..
<tcp_port>9032</tcp_port>
..
  1. restart CH-server service:
service clickhouse-server restart
  1. and connect this way
clickhouse-client --port 9032
vladimir
  • 13,428
  • 2
  • 44
  • 70
1

I actually had this problem too but I got it working with the default port.

The setting should be this way if you want to connect remotely and be able to use the loopback from localhost.

<listen_host>::1</listen_host>
<listen_host>0.0.0.0</listen_host>

This allows the loopback method to work (i.e clickhouse-client no args) on localhost to connect through the IPV6 route, and the remote connection (i.e clickhouse-client -h <hostname>) through the IPV4 connection.

My original problem was that i only used <listen_host>0.0.0.0</listen_host> in my config which meant theclickhouse-client no args would not work on localhost. And I could not get both to work by adding <listen_host>127.0.0.1</listen_host>

Peter Moore
  • 1,632
  • 1
  • 17
  • 31