How to deploy ClickHouse Server with Docker Compose

Containers / SQL 14-05-2023, 22:16 sobir 4 250 0


ClickHouse is an open-source column-oriented database management system that allows generating analytical data reports in real-time. (developed by Yandex)

In this tutorial, I will show you how to install a ClickHouse database server on your machine with Docker Compose. Assuming you have already installed the Docker containerization engine with Compose.

1. Create a directory for our project:
mkdir /opt/clickhouse

2. Change directory and create a docker-compose.yml file:
cd /opt/clickhouse

vi docker-compose.yml
version: '3.7'

networks:
  default:
    name: ch-net
    external: true

services:
  
  clickhouse-server:
    image: yandex/clickhouse-server
    container_name: clickhouse-server
    ports:
      - '8123:8123'
      - '9000:9000'
    volumes:
      - ./db:/var/lib/clickhouse
    ulimits:
      nofile: 262144 

3. Create a persistent network for the ClickHouse server container:
docker create network ch-net

4. Pull the image and run it:
docker compose up -d

5. Check the status:
docker ps

6. Connect to the ClickHouse server via the native client:
docker compose exec clickhouse-server clickhouse-client

Next, we need to:

1) Turn on SQL based access control;
2) Create a superuser account;
3) Restrict the default user.

For this, first, we need to get the configuration file users.xml from the running container and save it on the host permanently.

7. Get the configuration file users.xml from the running container:
docker inspect clickhouse-server | grep -i merged
cp /var/lib/docker/overlay2/put_your_path/merged/etc/clickhouse-server/users.xml /opt/clickhouse/

replace put_your_path with your correctly path

8. Edit users.xml by uncommenting the option access_management:
vi /opt/clickhouse/users.xml
<clickhouse>
    ...
    <users>
        ...
        <default>
            ...
            <access_management>1</access_management>
        </default>
    </users>
    ...
</clickhouse>

9. Include the config in docker-compose.yml:
vi docker-compose.yml
version: '3.7'

networks:
  default:
    name: ch-net
    external: true

services:

  clickhouse-server:
    image: yandex/clickhouse-server
    container_name: clickhouse-server
    ports:
      - '8123:8123'
      - '9000:9000'
    volumes:
      - ./users.xml:/etc/clickhouse-server/users.xml
      - ./db:/var/lib/clickhouse
    ulimits:
      nofile: 262144

9. Restart the container:
docker compose down
docker compose up -d

10. Connect to the ClickHouse server via the native client:
docker compose exec clickhouse-server clickhouse-client

11. Create a local account for the superuser:
:) CREATE USER root HOST LOCAL IDENTIFIED WITH sha256_password BY 'password';

12. Grant all privileges to the superuser:
:) GRANT ALL ON *.* TO root WITH GRANT OPTION;

13. Quit the cli:
:) quit

10. Restrict read-only access for the default user:
vi /opt/clickhouse/users.xml
<clickhouse>
    ...
    <users>
        ...
        <default>
            ...
            <profile>readonly</profile>
            ...
            <access_management>0</access_management>
        </default>
    </users>
    ...
</clickhouse>

11. Restart the container:
docker compose down
docker compose up -d
Похожие новости
How to deploy Zimbra Mail server with Docker and Compose

Quick setup Zimbra Mail server with Docker and Compose....

Подробнее
Разворачиваем LEMP-стэк на контейнерах Docker

Контейнеризируем сервисы LEMP с помощью docker-compose....

Подробнее
How to install Docker and Compose on AlmaLinux

Quick setup docker and docker-compose with a simple bash script....

Подробнее
Как назначить конкретную подсеть контейнерам Docker

Создание выделенной сети контейнерам Docker....

Подробнее
Поднимаем ocserv с аутентификацией LDAP

Поднимаем VPN сервер OpenConnect (ocserv) в контейнере Docker с аутентификацией пользователей из Microsoft...

Подробнее
How to install Docker and Compose on Ubuntu

Quick setup docker and docker compose with a simple bash script....

Подробнее
Комментарии (0)
Новые комментарии
komronu8 сентября 2022 18:23

Салом, можно ещё создать файл в /etc/nginx/proxy_params, a потом добавить туда

img
К комментарию
sobir26 августа 2022 10:43

Можно ещё так: 1. Создаем отдельную сеть для наших контейнеров docker network

img
К комментарию
komronu22 августа 2022 15:12

Спасибо за отзыв, написал отдельную статью по установке и настройке Ansible

img
К комментарию
sobir19 августа 2022 18:00

Думаю в статье необходимо также описать процесс установки Ansible.

img
К комментарию
sobir17 октября 2021 11:40

Принудительное обновление сертификата: certbot certonly --force-renew -d

img
К комментарию
sobir3 июля 2021 14:19

Можно, но я решил описать процесс копирования ключей более подробно.

img
К комментарию
Все комментарии
Какой дистрибутив Linux вы часто используете?
Календарь
«    Март 2024    »
ПнВтСрЧтПтСбВс
 123
45678910
11121314151617
18192021222324
25262728293031
Подпишись на канал