美文网首页
clickhouse 入门之环境搭建(1)

clickhouse 入门之环境搭建(1)

作者: coding400 | 来源:发表于2022-11-17 14:57 被阅读0次

    安装方式

    详细见官网:https://clickhouse.com/docs/zh/getting-started/install

    这里使用 install.sh 脚本安装
    修改 LATEST_VERSION 为所需版本,从 https://packages.clickhouse.com/tgz/stable/ 中找到

    LATEST_VERSION=21.1.9.41
    ARCH=amd64
    
    for PKG in clickhouse-common-static clickhouse-common-static-dbg clickhouse-server clickhouse-client
    do
    curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION-${ARCH}.tgz" \
    || curl -fO "https://packages.clickhouse.com/tgz/stable/$PKG-$LATEST_VERSION.tgz"
    done
    
    tar -xzvf "clickhouse-common-static-$LATEST_VERSION-${ARCH}.tgz" \
    || tar -xzvf "clickhouse-common-static-$LATEST_VERSION.tgz"
    sudo "clickhouse-common-static-$LATEST_VERSION/install/doinst.sh"
    
    tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION-${ARCH}.tgz" \
    || tar -xzvf "clickhouse-common-static-dbg-$LATEST_VERSION.tgz"
    sudo "clickhouse-common-static-dbg-$LATEST_VERSION/install/doinst.sh"
    
    tar -xzvf "clickhouse-server-$LATEST_VERSION-${ARCH}.tgz" \
    || tar -xzvf "clickhouse-server-$LATEST_VERSION.tgz"
    sudo "clickhouse-server-$LATEST_VERSION/install/doinst.sh" configure
    sudo /etc/init.d/clickhouse-server start
    
    tar -xzvf "clickhouse-client-$LATEST_VERSION-${ARCH}.tgz" \
    || tar -xzvf "clickhouse-client-$LATEST_VERSION.tgz"
    sudo "clickhouse-client-$LATEST_VERSION/install/doinst.sh"
    

    启动方式

    1. 后台启动
      sudo /etc/init.d/clickhouse-server start

    2. 手动启动
      sudo -u clickhouse clickhouse-server --config-file=/etc/clickhouse-server/config.xml

    3. 使用 systemctl 控制器启动

    systemctl start clickhouse-server.service
    systemctl restart clickhouse-server.service
    systemctl stop clickhouse-server.service
    systemctl status clickhouse-server.service

    踩坑记录

    1. Init script is already running

    错误原因:
    使用 sudo /etc/init.d/clickhouse-server start 命令启动导致,大概意思就是使用了 systemd 软件的 linux 系统需要使用 systemctl xxx 方式启动 (见启动方式-2)
    详见:https://github.com/ClickHouse/ClickHouse/issues/14861

    2. 2022.11.18 12:01:44.446923 [ 13459 ] {} <Warning> Application: Listen [::1]:8123 failed: Poco::Exception. Code: 1000, e.code() = 99, e.displayText() = Net Exception: Cannot assign requested address: [::1]:8123 (version 21.1.9.41 (official build)). If it is an IPv6 or IPv4 address and your host has disabled IPv6 or IPv4, then consider to specify not disabled IPv4 or IPv6 address to listen in <listen_host> element of configuration file. Example for disabled IPv6: <listen_host>0.0.0.0</listen_host> . Example for disabled IPv4: <listen_host>::</listen_host>

    错误原因:
    当前系统未开放 ipv6,只支持 ipv4,所以需要修改 <listen_host></listen_host> 键值对,根据提示可选两种,一种禁用 ipv6、一种禁用 ipv4
    Example for disabled IPv6: <listen_host>0.0.0.0</listen_host>
    Example for disabled IPv4: <listen_host>::</listen_host>

    按照网上说法,如:https://blog.csdn.net/qq_35423190/article/details/109629855,需要修改 /etc/clickhouse-server/config.xml 中 listen_host 为: <listen_host>0.0.0.0</listen_host>

    image.png

    这里按照步骤修改了,但是仍然无法启动,报错原因仍然是同一个,这里怀疑是否引入其他配置导致 config.xml 中的 listen_host 修改未生效,于是去看了下 clickhouse 的配置文件相关文档

    ClickHouse supports multi-file configuration management. The main server configuration file is /etc/clickhouse-server/config.xml or /etc/clickhouse-server/config.yaml. Other files must be in the /etc/clickhouse-server/config.d directory. Note, that any configuration file can be written either in XML or YAML, but mixing formats in one file is not supported. For example, you can have main configs as config.xml and users.xml and write additional files in config.d and users.d directories in .yaml.

    发现在 /etc/clickhouse-server/config.xml 只是主配置,还可以设置其他配置,在当前目录的 config.d 文件夹下,过不其然,还真有一个 listen.xml 的文件,里面真的配置的是 [::] ,修改为 127.0.0.1 之后重新启动即可生效


    image.png

    3.2022.11.18 11:59:47.322965 [ 13072 ] {} <Error> Application: DB::Exception: Listen [127.0.0.1]:8123 failed: Poco::Exception. Code: 1000, e.code() = 98, e.displayText() = Net Exception: Address already in use: 127.0.0.1:8123 (version 21.1.9.41 (official build))

    image.png

    当(listen_host 配置如下)同时出现时,将导致该错误,看报错是端口被占用,实际则是绑定了多次,

    <listen_host>0.0.0.0</listen_host>
    <listen_host>127.0.0.1</listen_host>
    

    解决办法:只保留其中一个

    配置文件说明

    主配置 /etc/clickhouse-server/config.xml
    其他配置 /etc/clickhouse-server/config.d/
    服务日志 /var/log/clickhouse-server/clickhouse-server.log
    错误日志 /var/log/clickhouse-server/clickhouse-server.err.log

    https://clickhouse.com/docs/zh/operations/configuration-files

    相关文章

      网友评论

          本文标题:clickhouse 入门之环境搭建(1)

          本文链接:https://www.haomeiwen.com/subject/xzjpxdtx.html