Overview

IPv6 is Internet Protocol Version 6 , which is a next-generation protocol IPv4 Due IPv4 , with the worldwide spread of the network, it has become less and less useful. Therefore, the promotion of IPv6

In particular, government banking institutions IPv6 the support of 0616a4e548c4ba as a promotion highlight and appeared on the homepage of the App
image.png

ClickHouse as the mainstream OLAP columnar storage database, is more and more favored and recognized by users in the application of big data, so IPv6 is also a matter of course.

This article mainly explains how to connect ClickHouse IPv6

Pre-work

How to check whether the server supports ipv6

With IPv6 popularity and the government IPv6 increase support, and now most of the equipment we have been supported IPv6 . You can use the ifconfig command to view:
image.png
As shown in the figure above, if there is inet6 , it means that the current machine supports ipv6 .

If it is a Linux server, you can also check whether there is a /proc/net/if_inet6 file in the directory to determine whether it supports IPv6 .

How to configure ClickHouse to support ipv6 connection

In use IPv6 address to connect ClickHouse before, we need to ClickHouse to do some configuration of servers, mostly configuration listen_host option. The official description is as follows:

    <!-- Listen specified address.
         Use :: (wildcard IPv6 address), if you want to accept connections both with IPv4 and IPv6 from everywhere.
         Notes:
         If you open connections from wildcard address, make sure that at least one of the following measures applied:
         - server is protected by firewall and not accessible from untrusted networks;
         - all users are restricted to subset of network addresses (see users.xml);
         - all users have strong passwords, only secure (TLS) interfaces are accessible, or connections are only made via TLS interfaces.
         - users without password have readonly access.
         See also: https://www.shodan.io/search?query=clickhouse
      -->
    <!-- <listen_host>::</listen_host> -->

    <!-- Same for hosts without support for IPv6: -->
    <!-- <listen_host>0.0.0.0</listen_host> -->

    <!-- Default values - try listen localhost on IPv4 and IPv6. -->
    <!--
    <listen_host>::1</listen_host>
    <listen_host>127.0.0.1</listen_host>

To sum up, the default configuration of ::1 only supports local connection. If you want to release remote connection, you must use :: or 0.0.0.0 . Among them, :: supports both IPv6 and IPv4 connections, while 0.0.0.0 only supports IPv4 connections. Thus, there needs to be listen_host arranged :: .
Some people say that since it supports both IPv6 and IPv4 connections, it is :: . Why is there a way to configure it to 0.0.0.0 ?

The reason is that when ClickHouse server is located does not support IPv6 an error will be reported when starting clickhouse-server

Command line tool connection

It is very simple to use the command line tool to connect, just follow the -h ipv6 address directly. If it is fe80 , you need to bring the name of the network card, as shown below:

image.png

Use code to connect

Here, by go implemented using language ipv6 connected clickhouse , other programming languages can extrapolate, probably similar.

package main

import (
    "database/sql"
    "fmt"

    _ "github.com/ClickHouse/clickhouse-go"
)

func main() {
    /*
    由于要区分ip和端口,所以一般默认的规则都是将ipv6的地址使用中括号[]包含起来。
    虽然实际上的ipv6地址是fe80::427c:e13c:50b6:d747%p5p2, 但在此处,ipv6地址是作为url的一部分出现的,因此,对于百分号%的解析会出现问题,需要用特殊符号%25代替,所以最终的地址应该是[fe80::427c:e13c:50b6:d747%25p5p2]
    当然,如果ipv6地址是一个正常的外网地址,而非局域网地址,则无需重新解析百分号。
    */
    connect, err := sql.Open("clickhouse", "tcp://[fe80::427c:e13c:50b6:d747%25p5p2]:9000?database=default&username=default&password=")
    if err != nil {
           fmt.Println("connect error ", err)
    } else {
           fmt.Println("connected")
    }

    if err = connect.Ping(); err != nil {
           fmt.Println("error:", err)
    } else {
           fmt.Println("connect success!!")
    }
}

The result of running the above code:
image.png


禹鼎侯
176 声望466 粉丝

OLAP数据库开发。跨平台数据采集。