Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Connecting to clickhouse db using @clickhouse/client npm package #4396

Closed
Flowko opened this issue Nov 25, 2024 · 6 comments
Closed

Comments

@Flowko
Copy link

Flowko commented Nov 25, 2024

Error Message and Logs

Error: Port 9000 is for clickhouse-client program You must use port 8123 for HTTP.

Steps to Reproduce

  1. Add resourcee
  2. Pick Clickhouse
  3. start the service
  4. set a public port
  5. make it public
  6. connect to it through @clickhouse/client in node
import { createClient } from "@clickhouse/client";

export const clickhouseClient = createClient({
  url: "http://default:{password}@{ip}:{public port}",
});

Coolify Version

v4.0.0-beta.370

Are you using Coolify Cloud?

No (self-hosted)

Operating System and Version (self-hosted)

Ubuntu 24.04.1 LTS

Additional Information

i would like to know if this is by design, or im using the wrong port, tried to look up some fixes but cant find anything related to this issue

@Flowko Flowko added 🐛 Bug Reported issues that need to be reproduced by the team. 🔍 Triage Issues that need assessment and prioritization. labels Nov 25, 2024
@Flowko Flowko changed the title [Bug]: Connecting to clickhousee db using @clickhouse/client npm package [Bug]: Connecting to clickhouse db using @clickhouse/client npm package Dec 27, 2024
@rndD
Copy link

rndD commented Feb 13, 2025

HTTP should be exposed instead of tcp

@rndD
Copy link

rndD commented Feb 13, 2025

you can make it work if you swap parts in env vars:

Image

@Flowko
Copy link
Author

Flowko commented Feb 13, 2025

thanks, will test it out, forgot i had opened an issue about this, i had to write a docker compose file that used original clickhouse image instead of the one provided in coolify, it seems to work as expected.

@Flowko Flowko closed this as completed Feb 13, 2025
@github-actions github-actions bot removed 🐛 Bug Reported issues that need to be reproduced by the team. 🔍 Triage Issues that need assessment and prioritization. labels Feb 13, 2025
@rndD
Copy link

rndD commented Feb 13, 2025

@Flowko can you share? Or it's just generic docker compose with no tricks?

@Flowko
Copy link
Author

Flowko commented Feb 14, 2025

@rndD yeah sure thing:

this uses clickhouse-server from clickhouse, coolify uses some other companies image, it might need some tweaks ofc, but yeah this works as expected for me

services:
  clickhouse:
    image: 'clickhouse/clickhouse-server:latest'
    environment:
      - 'CLICKHOUSE_DB=${CLICKHOUSE_DB:-default}'
      - 'CLICKHOUSE_USER=${CLICKHOUSE_USER:-default}'
      - 'CLICKHOUSE_PASSWORD=${CLICKHOUSE_PASSWORD:-clickhouse}'
      - CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1
    volumes:
      - type: bind
        source: ./clickhouse-data
        target: /var/lib/clickhouse
        is_directory: true
      - type: bind
        source: ./clickhouse-logs
        target: /var/log/clickhouse-server
        is_directory: true
      - type: bind
        source: ./config/config.xml
        target: /etc/clickhouse-server/config.xml
        is_directory: false
    user: "101:101"
    ports:
      - '${CLICKHOUSE_HTTP_PORT:-18123}:8123'
      - '${CLICKHOUSE_TCP_PORT:-19000}:9000'
    healthcheck:
      test:
        - CMD
        - wget
        - '--no-verbose'
        - '--tries=1'
        - '--spider'
        - 'http://localhost:8123/ping'
      interval: 30s
      timeout: 5s
      retries: 3
    labels:
      - traefik.enable=true
      - 'traefik.http.routers.clickhouse.rule=Host(`${SERVICE_FQDN_CLICKHOUSE}`)'
      - traefik.http.routers.clickhouse.entrypoints=http

the config.xml file has:

<?xml version="1.0"?>
<clickhouse>
    <logger>
        <level>trace</level>
        <log>/var/log/clickhouse-server/clickhouse-server.log</log>
        <errorlog>/var/log/clickhouse-server/clickhouse-server.err.log</errorlog>
        <size>1000M</size>
        <count>10</count>
    </logger>

    <http_port>8123</http_port>
    <tcp_port>9000</tcp_port>
    <interserver_http_port>9009</interserver_http_port>
    <listen_host>0.0.0.0</listen_host>

    <max_connections>4096</max_connections>
    <keep_alive_timeout>3</keep_alive_timeout>
    <max_concurrent_queries>100</max_concurrent_queries>
    <uncompressed_cache_size>8589934592</uncompressed_cache_size>
    <mark_cache_size>5368709120</mark_cache_size>

    <path>/var/lib/clickhouse/</path>
    <tmp_path>/var/lib/clickhouse/tmp/</tmp_path>
    <user_files_path>/var/lib/clickhouse/user_files/</user_files_path>

    <users_config>users.xml</users_config>
    <default_profile>default</default_profile>
    <default_database>default</default_database>

    <http_server_default_response>
       <add_http_cors_header>1</add_http_cors_header>
    </http_server_default_response>

    <http_options_response>
        <header>
            <name>Access-Control-Allow-Origin</name>
            <value>*</value>
        </header>
        <header>
            <name>Access-Control-Allow-Headers</name>
            <value>origin, x-requested-with, x-clickhouse-format, x-clickhouse-user, x-clickhouse-key, Authorization</value>
        </header>
        <header>
            <name>Access-Control-Allow-Methods</name>
            <value>POST, GET, OPTIONS</value>
        </header>
        <header>
            <name>Access-Control-Max-Age</name>
            <value>86400</value>
        </header>
    </http_options_response>
</clickhouse>

@rndD
Copy link

rndD commented Feb 14, 2025

@Flowko thanks mate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants