Skip to content
🧮 Is Lifetime with ZapX Pass worth it? Work it out for your own servers in 30 seconds. Open the Lifetime calculator →

Set Up ClickHouse on a Linux Server – Analytics Database for Logs and Statistics

Set up ClickHouse as a One-Click App or with Docker, secure its ports, and analyze large volumes of data with SQL in seconds.

2 December 202613 min read2 Views0 helpful

Introduction

ClickHouse is a column-oriented, open-source database for analytics. It is designed to count, group, and analyze millions or billions of rows in fractions of a second. Typical data includes logs, metrics, website clicks, or events from a game, such as logins, kills, or purchases. You write queries in SQL.

In this guide, we’ll show you two ways to get started: the easy way, as a One-Click App, which gets ClickHouse running in a few minutes with an automatically generated username and password, and a manual installation with Docker Compose via the console. Then you’ll learn how to secure the ports, create tables, set up dedicated users for applications, connect tools such as Grafana, and back up your data.

When ClickHouse makes sense on a VPS

Running your own ClickHouse server is worthwhile if:

  • you want to store and analyze many events, such as game server player statistics, bot commands, or orders, and keep queries like “kills per player per day” fast even with millions of rows.
  • you want to collect logs or metrics centrally and search through them later with SQL.
  • you’re building dashboards, for example with Grafana, and need a fast data source.
  • a piece of software requires ClickHouse, such as an analytics or observability tool that you run yourself.
  • you want to learn or test ClickHouse without paying a cloud service for each query or for storage.

ClickHouse is less suitable as a database for a regular application that often changes or deletes individual rows, such as user accounts, shopping carts, or bot settings. A traditional database such as PostgreSQL or MariaDB is a better choice for that.

ClickHouse or PostgreSQL?

ClickHousePostgreSQL
StrengthAnalyzing very large numbers of rows (counting, summing, grouping)Many small read and write operations on individual records
Changing dataPossible, but slow and intended for occasional correctionsRoutine, with transactions
Typical dataLogs, metrics, events, statisticsUsers, orders, settings
Storage requirementsHighly compressed, often a fraction of the raw dataNormal
RAMFrom 2 GB; significantly more for larger volumes of dataFrom 256 MB

You can also use both: your application stores its data in PostgreSQL and writes events to ClickHouse as well. See Set Up PostgreSQL on a Linux Server to learn how to set up PostgreSQL.

The easy way: ClickHouse as a One-Click App

With your VPS One-Click Apps, you can start a standalone ClickHouse server running LTS version 26.8. During installation, the app creates a database, a user with a randomly generated name, and a long, random password. The default user default, which has no password, is disabled. Data and logs are stored in persistent volumes on your VPS.

Requirements

  • A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. See VPS: One-Click Apps for instructions.
  • At least 2 vCPU cores, 2 GB RAM, and 5 GB of storage. We recommend 4 vCPU cores, 8 GB RAM, and 50 GB of storage. Your actual requirements depend on the amount of data and your queries.
  • Ports 8123 and 9000 must be available on your VPS. Otherwise, choose different ports during installation.

Install

  1. Open your VPS in the ZapX dashboard and go to the One-Click Apps tab.
  2. Search for “ClickHouse” in the App catalog and click Install app next to ClickHouse.
  3. Under App name, you can enter a custom name, such as “ClickHouse Statistics.”
  4. You can adjust three values under App configuration, but you don’t need to:
FieldDefaultDescription
CLICKHOUSE_DBappName of the database created during installation
CLICKHOUSE_HTTP_PORT8123HTTP interface port, used by most tools and programming languages
CLICKHOUSE_NATIVE_PORT9000Port for ClickHouse’s own protocol, for example, for clickhouse-client
  1. Click Queue installation. The app will show as Online after one to two minutes.

You don’t need a custom domain. ClickHouse is accessible through your VPS IP address. The app card shows both addresses under Connection, for example, 123.123.123.123:8123 and 123.123.123.123:9000.

Find your login credentials

The app generates a username and password during installation. You can find them in the app settings (gear icon) under App environment > Automatically generated values. Click the eye icon to display a value or the copy icon to copy it.

ValueDescription
SERVICE_USER_CLICKHOUSEUsername, a short random string
SERVICE_PASSWORD_CLICKHOUSEThis user’s password, consisting of 32 random characters

This user has full permissions. It can create and delete databases and tables, and manage other users. So don’t share these credentials with applications or dashboards. Instead, create a separate user for each application, as described in “Create users for applications.”

Info: Set the database name and ports at the start

CLICKHOUSE_DB only takes effect on the first start. Changing it later won’t create a new database. You can create additional databases with CREATE DATABASE.

Test your first connection

The quickest way to test ClickHouse is directly on the server. Connect to your VPS via SSH and open the app container’s command-line client:

Code
docker ps --filter name=clickhouse-
docker exec -it CONTAINER_NAME sh -c 'clickhouse-client --user "$CLICKHOUSE_USER" --password "$CLICKHOUSE_PASSWORD"'

The first command shows you the container name, which starts with clickhouse-. The second command gets the username and password from the app, so you don’t have to type them in. Run SELECT version(); to see the version currently running, and exit to close the client.

From outside the server, connect to ClickHouse through the HTTP interface. Send a query as text to port 8123:

Code
curl -u DB_USER:DB_PASSWORD 'http://SERVER_IP:8123/' --data-binary 'SELECT version()'

Secure access

Warning: Ports 8123 and 9000 are accessible from the internet

The app publishes both ports on all of your VPS’s addresses. Anyone on the internet can reach them and try passwords, and the connection is not encrypted because the app doesn’t configure TLS. No one can access your data without a valid password, but you should still restrict the ports immediately after installation to the IP addresses that actually need to connect.

The firewall on the VPS itself (ufw) won’t help here: ports published by Docker are accessible even if ufw blocks them. Instead, use the Network firewall in the ZapX dashboard. It filters traffic before it reaches your VPS:

  1. Open your VPS in the ZapX dashboard and go to the Network firewall tab. Make sure Firewall active is turned on.
  2. Click Add rule. Set Direction to IN, Action to ACCEPT, and Service template to Custom. Set Protocol to tcp and Destination port to 8123.
  3. Under Source, enter the IP address that’s allowed to connect, such as your web server’s or game server’s IP address, and click Create. If that address also needs port 9000, create a second rule for it.
  4. Then create a rule for each port with Direction set to IN, Action set to DROP, Protocol set to tcp, and the port set as the Destination port. Leave Source empty.
  5. Check the order under Custom rules: the first matching rule takes precedence, so the ACCEPT rules must be above the DROP rules. New rules are added to the end of the list; use the arrows to move them.

Connections from apps on the same VPS don’t pass through the Network Firewall and will continue to work. For more on ports and firewalls, see VPS: Open Ports and Manage the Firewall on Linux.

Tip: Connect from your PC using an SSH tunnel

You don’t need to open a port to connect from your own PC. Open an SSH tunnel with ssh -L 8123:127.0.0.1:8123 root@SERVER_IP and connect your program to localhost:8123. This encrypts the connection.

Run queries in your browser

ClickHouse includes a simple query interface. With the SSH tunnel running, open http://localhost:8123/play in your browser, click the key icon in the top-right corner, and enter your username and password. Then write SQL in the input field and run the query by clicking Run or pressing Ctrl + Enter.

The page is also accessible directly at http://SERVER_IP:8123/play. However, your password and data will then be sent over the internet unencrypted, so it’s better to use the tunnel.

Updates and backups

  • Updates: Open the app settings (gear icon) > App update and click Check for updates. If a new app version is available, install it by clicking Apply update. Your data will be retained.
  • Back up: A VPS backup in the Backups tab also backs up the volumes. You can also back up individual databases with the SQL command BACKUP, as described under “Back up your data.”
  • Uninstall: Under App actions > Uninstall app, you can also delete the data volumes. This permanently deletes all databases. Back them up first.

Manual installation

The rest of this guide describes a manual installation of ClickHouse with Docker Compose via the console, for example, on a server without One-Click Apps. The commands are written for Debian and Ubuntu. Unlike the One-Click App, ClickHouse initially listens only on the server itself.

Requirements

MinimumRecommended
CPU2 vCPU cores4 vCPU cores
RAM2 GB8 GB
Storage5 GB free (image is just over 1 GB)50 GB, depending on the amount of data

These values apply to small to medium data volumes. By default, ClickHouse uses up to 90 percent of the available RAM. The manufacturer recommends significantly more RAM for large data volumes. You’ll also need Docker with the Compose plugin, as described in Set Up Docker on a Linux Server, and SSH access; see VPS: First Connection via SSH.

Prepare the firewall

ClickHouse doesn’t need an open port for this setup because it’s bound only to 127.0.0.1. Open only SSH in ufw:

Code
sudo apt install -y ufw
sudo ufw allow OpenSSH
sudo ufw enable
Warning: Docker bypasses ufw

Ports that Docker publishes on all addresses with ports: are accessible from outside even if ufw blocks them. So leave the 127.0.0.1: prefix on the ports in the Compose file unless you need external access.

Install with Docker Compose

Create a folder and create a .env file in it with a random password:

Code
sudo mkdir -p /opt/clickhouse
cd /opt/clickhouse
echo "CLICKHOUSE_PASSWORD=$(openssl rand -hex 24)" | sudo tee .env > /dev/null
sudo chmod 600 .env
sudo nano compose.yaml

Add the following content to compose.yaml:

yaml
services:
  clickhouse:
    image: clickhouse/clickhouse-server:26.8.37.168-alpine
    container_name: clickhouse
    restart: unless-stopped
    environment:
      CLICKHOUSE_USER: admin
      CLICKHOUSE_PASSWORD: ${CLICKHOUSE_PASSWORD}
      CLICKHOUSE_DB: app
      CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
    ports:
      - "127.0.0.1:8123:8123"
      - "127.0.0.1:9000:9000"
    ulimits:
      nofile:
        soft: 262144
        hard: 262144
    volumes:
      - clickhouse-data:/var/lib/clickhouse
      - clickhouse-logs:/var/log/clickhouse-server
    healthcheck:
      test: ["CMD-SHELL", "wget -q -O /dev/null http://127.0.0.1:8123/ping || exit 1"]
      interval: 10s
      timeout: 5s
      retries: 10
      start_period: 20s

volumes:
  clickhouse-data:
  clickhouse-logs:

The important lines:

  • image: clickhouse/clickhouse-server:26.8.37.168-alpine is the same version as the One-Click App. The fixed version number prevents a restart from unexpectedly downloading a new version.
  • CLICKHOUSE_USER and CLICKHOUSE_PASSWORD create the admin user and disable the default user, which would otherwise be able to log in without a password. The password comes from .env.
  • CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1 allows admin to create additional users and grant permissions using SQL.
  • 127.0.0.1:8123 and 127.0.0.1:9000 make ClickHouse accessible only from the server itself.
  • ulimits increases the number of open files. ClickHouse recommends this value because it opens many files at the same time.
  • The clickhouse-data volume contains all databases and users created with SQL; clickhouse-logs contains the server’s log files.

Start ClickHouse and check its status:

Code
sudo docker compose up -d
sudo docker compose ps

After about 20 seconds, the STATUS column should show healthy.

First connection

Open the command-line client in the container:

Code
sudo docker exec -it clickhouse sh -c 'clickhouse-client --user admin --password "$CLICKHOUSE_PASSWORD"'

Run SHOW DATABASES; to see the app database, and exit to close the client. You can access the Play interface from your PC through the SSH tunnel described in the “Secure access” tip; the password is in .env.

Access via HTTPS through a reverse proxy

If applications on other servers need to connect, a reverse proxy with TLS is better than opening port 8123. To do this, create a subdomain such as clickhouse.example.com that points to your server, and configure nginx to forward it to the HTTP interface:

Code
server {
    listen 80;
    server_name clickhouse.example.com;

    location / {
        proxy_pass http://127.0.0.1:8123;
        proxy_set_header Host $host;
        proxy_read_timeout 300s;
        client_max_body_size 100m;
    }
}

proxy_read_timeout allows longer queries, and client_max_body_size allows larger data imports. See VPS: Set Up a Reverse Proxy with nginx on Linux and VPS: Create an SSL Certificate (Let's Encrypt) for Linux Servers to learn how to set up nginx and issue the certificate. Applications can then connect to https://clickhouse.example.com on port 443. ClickHouse’s own protocol on port 9000 doesn’t go through nginx. If you need external access to it, open the port and restrict it to fixed IP addresses.

Back up your data

ClickHouse backs up databases with the SQL command BACKUP. The File destination writes the backup to the /var/lib/clickhouse/backups/ folder in the volume:

sql
BACKUP DATABASE app TO File('app-2026-01-31');

Each backup needs a new name. To download it from the server, copy it out of the container:

Code
sudo mkdir -p /root/backups
sudo docker cp clickhouse:/var/lib/clickhouse/backups/app-2026-01-31 /root/backups/

For the One-Click App, replace clickhouse with the app’s container name. Restore a backup under a new name and check it before replacing the old database:

sql
RESTORE DATABASE app AS app_restore FROM File('app-2026-01-31');

Download backups from the server regularly, for example, via SFTP. A backup stored only on the same server won’t help if the disk fails.

Update ClickHouse

Enter the new version number for image in compose.yaml and restart:

Code
cd /opt/clickhouse
sudo nano compose.yaml
sudo docker compose pull
sudo docker compose up -d

Updates within an LTS version such as 26.8 are low-risk. Before upgrading to a new version, read the changelog and create a backup first. LTS versions receive bug fixes for one year.

Working with ClickHouse

These steps are the same for the One-Click App and the manual installation.

Create and query your first table

In ClickHouse, you usually create tables with the MergeTree engine. The ORDER BY clause is important: ClickHouse stores data in this order and reads only the necessary parts for matching queries. Choose the columns that you filter by most often:

sql
CREATE TABLE app.events
(
    ts DateTime,
    player String,
    action LowCardinality(String),
    value UInt32
)
ENGINE = MergeTree
ORDER BY (action, ts);

LowCardinality(String) saves space in columns with few distinct values, such as join or kill. Add data with INSERT, ideally in batches of many rows rather than one row at a time. A typical analysis query looks like this:

sql
SELECT action, count() AS events, round(avg(value), 1) AS avg_value
FROM app.events
GROUP BY action
ORDER BY events DESC;

Create users for applications

Create a separate user for each application and give it only the permissions it needs. A dashboard, for example, only needs read access:

sql
CREATE USER grafana_ro IDENTIFIED BY 'CHANGE_ME' HOST ANY;
GRANT SELECT ON app.* TO grafana_ro;

Replace CHANGE_ME with a long, random password. If the application also needs to write, grant it INSERT as well. To restrict a user to a fixed IP address, use HOST IP '203.0.113.10' instead of HOST ANY. Users created with SQL are stored in the data volume and persist through restarts and app updates. Set a new password with ALTER USER grafana_ro IDENTIFIED BY 'NEW_PASSWORD';.

Connect applications and tools

  • Grafana: Install the ClickHouse data source plugin in Grafana and enter the server, port 8123 (HTTP protocol) or 9000 (Native), and a read-only user. See Set Up Grafana on a Linux Server to learn how to run Grafana on your VPS.
  • Programming languages: Official clients are available for Python, Node.js, Go, Java, and others. Many use the HTTP interface on port 8123; some, such as the Go client, also use port 9000.
  • Database tools: Tools such as DBeaver connect through the JDBC driver on port 8123. Use the SSH tunnel to connect from your PC.

If your application is running on the same VPS, it connects using the VPS IP address. For information about other database systems such as MariaDB, Redis, or MongoDB, see the overview Set Up Databases on a Linux Server.

Limitations

  • No encryption by default: The One-Click App doesn’t configure TLS. For internet access, use an SSH tunnel or restrict the ports to fixed IP addresses.
  • No management interface: The Play interface only runs SQL. You manage users, tables, and permissions with SQL.
  • A single server: The app runs ClickHouse without replication or a cluster. If the VPS goes down, the database won’t be accessible.
  • High memory usage for large queries: Queries across very large numbers of rows or with large GROUP BY results need a lot of RAM. If there isn’t enough, ClickHouse stops the query and returns an error.

Conclusion

With ClickHouse, you analyze logs and statistics in a fast analytics database on your own server and back up your data with BACKUP. Next, the guide Set Up Grafana on a Linux Server shows you how to visualize your ClickHouse data in dashboards in your browser.

If you have any other questions or need help, our support team is available every day! 🙂

Free tools

Related tools for servers and developers

View all

FAQ

Frequently asked questions

The One-Click App is the faster option: ClickHouse 26.8 is running in one to two minutes, a username and password are generated automatically, and you can install updates with a click under App Update. Manual installation with Docker Compose is a good choice if your server doesn’t use One-Click Apps or if ClickHouse should only be accessible from the server itself, since you bind the ports to 127.0.0.1.
In the app settings (gear icon), go to App Environment > Automatically Generated Values. SERVICE_USER_CLICKHOUSE is the username, and SERVICE_PASSWORD_CLICKHOUSE is the password. Click the eye icon to display a value. The passwordless default user is disabled in the app.
Yes. The One-Click App publishes ports 8123 (HTTP) and 9000 (Native) on all of your VPS’s addresses, and the connection isn’t encrypted. No one can access the data without a valid password. Still, restrict the ports in the Network Firewall tab to the IP addresses that need access, and connect from your PC via an SSH tunnel. The ufw firewall on the VPS won’t help because Docker bypasses it.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.