Linux Tutorials

Install ClickHouse on Ubuntu 24.04 / Rocky Linux 10

ClickHouse is an open-source columnar database management system built for online analytical processing (OLAP). It handles billions of rows and terabytes of data with sub-second query performance, making it a top choice for log analytics, time-series data, real-time dashboards, and business intelligence workloads. Companies like Cloudflare, Uber, and eBay run ClickHouse in production for high-volume analytics.

Original content from computingforgeeks.com - post 11850

This guide walks through installing ClickHouse on Ubuntu 24.04 and Rocky Linux 10 (also applies to RHEL 10 and AlmaLinux 10). We cover server and client installation from the official repository, remote access configuration, firewall rules, user authentication, and basic SQL operations to get you running queries fast.

Prerequisites

Before starting, make sure you have:

  • A server running Ubuntu 24.04 LTS or Rocky Linux 10 (RHEL 10 / AlmaLinux 10)
  • Root or sudo access
  • At least 2 GB RAM (4 GB+ recommended for production workloads)
  • Internet access to reach the ClickHouse package repository
  • Ports 8123 (HTTP interface) and 9000 (native TCP) available

Step 1: Install ClickHouse on Ubuntu 24.04

ClickHouse maintains its own APT repository with packages for Debian and Ubuntu. Start by installing the prerequisites and importing the GPG signing key.

sudo apt-get install -y apt-transport-https ca-certificates curl gnupg

Import the ClickHouse repository signing key:

curl -fsSL 'https://packages.clickhouse.com/rpm/lts/repodata/repomd.xml.key' | sudo gpg --dearmor -o /usr/share/keyrings/clickhouse-keyring.gpg

Add the stable ClickHouse repository to your APT sources:

ARCH=$(dpkg --print-architecture)
echo "deb [signed-by=/usr/share/keyrings/clickhouse-keyring.gpg arch=${ARCH}] https://packages.clickhouse.com/deb stable main" | sudo tee /etc/apt/sources.list.d/clickhouse.list

Update the package index and install the ClickHouse server and client packages:

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

During installation, you will be prompted to set a password for the default user. Set a strong password or press Enter to leave it empty (not recommended for production). Verify the installed version:

clickhouse-server --version

The output confirms the installed ClickHouse release:

ClickHouse server version 26.1.6.6 (official build).

Step 2: Install ClickHouse on RHEL 10 / Rocky Linux 10

On RHEL-based systems, ClickHouse provides an RPM repository. Install the yum-utils package first, then add the ClickHouse repository.

sudo dnf install -y yum-utils
sudo yum-config-manager --add-repo https://packages.clickhouse.com/rpm/clickhouse.repo

Install the ClickHouse server and client:

sudo dnf install -y clickhouse-server clickhouse-client

Verify the installation completed successfully:

clickhouse-server --version

You should see the same version output as on Ubuntu:

ClickHouse server version 26.1.6.6 (official build).

Step 3: Start and Enable ClickHouse Server

Enable the ClickHouse server to start on boot and start the service. These commands work on both Ubuntu 24.04 and Rocky Linux 10.

sudo systemctl enable --now clickhouse-server

Check that the server is running:

sudo systemctl status clickhouse-server

The service should show active (running):

● clickhouse-server.service - ClickHouse Server (analytic DBMS for big data)
     Loaded: loaded (/etc/systemd/system/clickhouse-server.service; enabled; preset: disabled)
     Active: active (running)
   Main PID: 2847 (clickhouse-serv)
     Memory: 218.4M
        CPU: 1.245s
     CGroup: /system.slice/clickhouse-server.service
             └─2847 /usr/bin/clickhouse-server --config=/etc/clickhouse-server/config.xml --pid-file=/run/clickhouse-server/clickhouse-server.pid

Confirm that ClickHouse is listening on its default ports:

sudo ss -tlnp | grep clickhouse

You should see port 8123 (HTTP) and 9000 (native TCP) bound to localhost:

LISTEN  0  4096  127.0.0.1:9000   0.0.0.0:*  users:(("clickhouse-serv",pid=2847,fd=214))
LISTEN  0  4096  127.0.0.1:8123   0.0.0.0:*  users:(("clickhouse-serv",pid=2847,fd=212))

Step 4: Configure ClickHouse for Remote Access

By default, ClickHouse only listens on 127.0.0.1. To allow connections from remote clients, Grafana dashboards, or application servers, you need to update the listen address. The recommended approach is to create a custom config override file instead of editing the main config.xml.

Create a new override file:

sudo vi /etc/clickhouse-server/config.d/listen.xml

Add the following configuration to bind ClickHouse to all interfaces:

<clickhouse>
    <listen_host>0.0.0.0</listen_host>
</clickhouse>

If you want to restrict access to a specific network interface, replace 0.0.0.0 with the server’s private IP address. Restart ClickHouse to apply the change:

sudo systemctl restart clickhouse-server

Verify that ClickHouse is now listening on all interfaces:

sudo ss -tlnp | grep clickhouse

The output should show 0.0.0.0 instead of 127.0.0.1:

LISTEN  0  4096  0.0.0.0:9000   0.0.0.0:*  users:(("clickhouse-serv",pid=3012,fd=214))
LISTEN  0  4096  0.0.0.0:8123   0.0.0.0:*  users:(("clickhouse-serv",pid=3012,fd=212))

ClickHouse uses override files in /etc/clickhouse-server/config.d/ that merge with the main config. This keeps your customizations separate and safe during package upgrades. See the ClickHouse configuration files documentation for the full merge behavior.

Step 5: Configure Firewall

ClickHouse uses two main ports: 8123 for the HTTP interface (used by Grafana, REST clients, and the web UI) and 9000 for the native TCP protocol (used by clickhouse-client and drivers). Open these ports in your firewall.

Ubuntu 24.04 (UFW)

Allow ClickHouse ports through the UFW firewall:

sudo ufw allow 8123/tcp comment "ClickHouse HTTP"
sudo ufw allow 9000/tcp comment "ClickHouse Native"
sudo ufw reload

Rocky Linux 10 / RHEL 10 (firewalld)

Add permanent firewall rules using firewalld:

sudo firewall-cmd --permanent --add-port=8123/tcp
sudo firewall-cmd --permanent --add-port=9000/tcp
sudo firewall-cmd --reload

Verify the rules are active:

sudo firewall-cmd --list-ports

The output should include both ClickHouse ports:

8123/tcp 9000/tcp

Step 6: Connect with clickhouse-client

The clickhouse-client tool provides an interactive SQL shell for running queries. Connect to the local server:

clickhouse-client --password

Enter the password you set during installation when prompted. You will see the ClickHouse interactive prompt:

ClickHouse client version 26.1.6.6 (official build).
Connecting to localhost:9000 as user default.
Password for user (default):
Connected to ClickHouse server version 26.1.6.

computingforgeeks :)

If you did not set a password during installation, connect without the --password flag:

clickhouse-client

To connect from a remote machine, specify the host:

clickhouse-client --host 192.168.1.50 --password

You can also query ClickHouse over HTTP using curl. This is useful for health checks and quick queries:

curl http://localhost:8123/?query=SELECT%20version()

The server responds with the version string:

26.1.6.6

Step 7: Create Database and Tables

ClickHouse uses a SQL dialect that will feel familiar if you have worked with PostgreSQL or MariaDB. The main difference is that ClickHouse requires you to specify a table engine. For analytics workloads, the MergeTree engine family is the standard choice.

Connect to the client and create a new database:

CREATE DATABASE analytics;

Switch to the new database and create a table for storing web access logs:

USE analytics;

CREATE TABLE access_logs (
    timestamp DateTime,
    ip_address String,
    method String,
    url String,
    status_code UInt16,
    response_time_ms UInt32,
    user_agent String
) ENGINE = MergeTree()
ORDER BY (timestamp, ip_address);

The ORDER BY clause defines how data is sorted on disk – this directly impacts query performance. Choose columns you frequently filter or group by. Verify the table was created:

SHOW TABLES;

The output lists the table in the analytics database:

┌─name────────┐
│ access_logs  │
└─────────────┘

Step 8: Insert and Query Data

Insert sample records to test queries. ClickHouse handles bulk inserts extremely well, but for demonstration we will insert a few rows:

INSERT INTO access_logs VALUES
    ('2026-03-22 10:00:00', '192.168.1.10', 'GET', '/api/users', 200, 45, 'Mozilla/5.0'),
    ('2026-03-22 10:00:01', '192.168.1.11', 'POST', '/api/orders', 201, 120, 'curl/8.5'),
    ('2026-03-22 10:00:02', '192.168.1.10', 'GET', '/api/products', 200, 33, 'Mozilla/5.0'),
    ('2026-03-22 10:00:03', '10.0.0.5', 'GET', '/api/users', 500, 5012, 'Python/3.12'),
    ('2026-03-22 10:00:04', '192.168.1.12', 'DELETE', '/api/orders/42', 204, 89, 'curl/8.5');

Run a simple SELECT to verify the data:

SELECT * FROM access_logs ORDER BY timestamp;

ClickHouse displays the results in a formatted table:

┌───────────timestamp─┬─ip_address────┬─method─┬─url──────────────┬─status_code─┬─response_time_ms─┬─user_agent──┐
│ 2026-03-22 10:00:00 │ 192.168.1.10  │ GET    │ /api/users       │         200 │               45 │ Mozilla/5.0 │
│ 2026-03-22 10:00:01 │ 192.168.1.11  │ POST   │ /api/orders      │         201 │              120 │ curl/8.5    │
│ 2026-03-22 10:00:02 │ 192.168.1.10  │ GET    │ /api/products    │         200 │               33 │ Mozilla/5.0 │
│ 2026-03-22 10:00:03 │ 10.0.0.5      │ GET    │ /api/users       │         500 │             5012 │ Python/3.12 │
│ 2026-03-22 10:00:04 │ 192.168.1.12  │ DELETE │ /api/orders/42   │         204 │               89 │ curl/8.5    │
└─────────────────────┴───────────────┴────────┴──────────────────┴─────────────┴──────────────────┴─────────────┘

5 rows in set. Elapsed: 0.003 sec.

Now run an aggregation query to see average response times by HTTP method:

SELECT
    method,
    count() AS requests,
    avg(response_time_ms) AS avg_ms,
    max(response_time_ms) AS max_ms
FROM access_logs
GROUP BY method
ORDER BY requests DESC;

The query returns aggregated results instantly:

┌─method─┬─requests─┬─avg_ms─┬─max_ms─┐
│ GET    │        3 │   1697 │   5012 │
│ POST   │        1 │    120 │    120 │
│ DELETE │        1 │     89 │     89 │
└────────┴──────────┴────────┴────────┘

3 rows in set. Elapsed: 0.004 sec.

This is where ClickHouse shines. On production datasets with millions of rows, these aggregation queries still complete in milliseconds thanks to the columnar storage format – ClickHouse only reads the columns referenced in the query, not entire rows.

Step 9: Configure Users and Authentication

The default ClickHouse installation has a single default user. For production use, create dedicated users with specific permissions. User management is handled through SQL commands or XML config files.

Create a new user with a password and grant access to the analytics database:

CREATE USER analyst IDENTIFIED WITH sha256_password BY 'StrongP@ssw0rd';
GRANT SELECT ON analytics.* TO analyst;

Create an admin user with full privileges:

CREATE USER ch_admin IDENTIFIED WITH sha256_password BY 'Adm1nP@ssw0rd';
GRANT ALL ON *.* TO ch_admin WITH GRANT OPTION;

Verify the user list:

SHOW USERS;

The output lists all configured users:

┌─name─────┐
│ analyst  │
│ ch_admin │
│ default  │
└──────────┘

Test the new user connection by exiting the current session and reconnecting:

clickhouse-client --user analyst --password

The analyst user can query the analytics database but cannot create or modify databases, which follows the principle of least privilege. For detailed access control options, see the ClickHouse access rights documentation.

ClickHouse Ports and Configuration Files

This reference table lists the key ports and file paths you will work with when managing a ClickHouse installation.

ResourcePath / PortDescription
Main config/etc/clickhouse-server/config.xmlPrimary server configuration
Config overrides/etc/clickhouse-server/config.d/Custom config files (merged with main config)
User config/etc/clickhouse-server/users.xmlDefault user profiles and quotas
User overrides/etc/clickhouse-server/users.d/Custom user configuration files
Data directory/var/lib/clickhouse/Database files and table data
Log files/var/log/clickhouse-server/Server and error logs
HTTP interface8123/TCPREST API, Grafana connections, web UI
Native TCP9000/TCPclickhouse-client and native drivers
Inter-server9009/TCPReplication and distributed queries between nodes

Conclusion

You now have ClickHouse installed and running on Ubuntu 24.04 or Rocky Linux 10 with remote access, firewall rules, user authentication, and a working analytics database. ClickHouse is ready to ingest and query large datasets at speed.

For production deployments, consider enabling TLS encryption on ports 8123 and 9000, setting up Grafana for monitoring ClickHouse metrics, configuring automated backups with clickhouse-backup, and deploying ClickHouse Keeper for high availability clusters.

Related Articles

Desktop Install Chromium Browser on Ubuntu 24.04 / Linux Mint / Debian 13 Databases Monitor PostgreSQL with Prometheus and Grafana Databases Install SQL Server Management Studio on Windows Arch Linux How To Connect To Bluetooth Device from Linux Terminal

Leave a Comment

Press ESC to close