> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-detect-table-modification.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Руководство по настройке защищённого соединения по SSL/TLS между ClickHouse и ZooKeeper

# Необязательная настройка защищённого соединения между ClickHouse и ZooKeeper

<CloudNotSupportedBadge />

<Note>
  Эта страница не применима к [ClickHouse Cloud](https://clickhouse.com/cloud). Описанная здесь процедура в сервисах ClickHouse Cloud выполняется автоматически.
</Note>

Для связи с клиентом ClickHouse по SSL необходимо указать `ssl.keyStore.location`, `ssl.keyStore.password`, `ssl.trustStore.location` и `ssl.trustStore.password`. Эти параметры доступны начиная с версии Zookeeper 3.5.2.

Вы можете добавить `zookeeper.crt` в список доверенных сертификатов.

```bash theme={null}
sudo cp zookeeper.crt /usr/local/share/ca-certificates/zookeeper.crt
sudo update-ca-certificates
```

Раздел клиента в файле `config.xml` будет выглядеть так:

```xml theme={null}
<client>
    <certificateFile>/etc/clickhouse-server/client.crt</certificateFile>
    <privateKeyFile>/etc/clickhouse-server/client.key</privateKeyFile>
    <loadDefaultCAFile>true</loadDefaultCAFile>
    <cacheSessions>true</cacheSessions>
    <disableProtocols>sslv2,sslv3</disableProtocols>
    <preferServerCiphers>true</preferServerCiphers>
    <invalidCertificateHandler>
        <name>RejectCertificateHandler</name>
    </invalidCertificateHandler>
</client>
```

Добавьте Zookeeper в конфигурацию ClickHouse вместе с параметрами кластера и макросами:

```xml theme={null}
<clickhouse>
    <zookeeper>
        <node>
            <host>localhost</host>
            <port>2281</port>
            <secure>1</secure>
        </node>
    </zookeeper>
</clickhouse>
```

Запустите `clickhouse-server`. В журнале должны появиться:

```text theme={null}
<Trace> ZooKeeper: initialized, hosts: secure://localhost:2281
```

Префикс `secure://` указывает на то, что соединение защищено с помощью SSL.

Чтобы убедиться, что трафик зашифрован, запустите `tcpdump` на защищённом порту:

```bash theme={null}
tcpdump -i any dst port 2281 -nnXS
```

И выполните запрос в `clickhouse-client`:

```sql theme={null}
SELECT * FROM system.zookeeper WHERE path = '/';
```

При незашифрованном соединении в выводе `tcpdump` вы увидите примерно следующее:

```text theme={null}
..../zookeeper/quota.
```

При зашифрованном соединении этого быть не должно.
