暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Clickhouse使用远程表引擎建表失败原因探讨

运维笔谈 2025-01-21
880
升级到较新版本Clickhouse,在进行备份恢复操作的时候,出现了某些表建表报错,具体报错如下:
can't create table 'db_ops.white_lists_delete': code: 491, message: URL "r-xx-xxxx.service.consul:3306" is not allowed in configuration file, see <remote_url_allow_hosts>, will try again.
一、报错解析
从报错信息来看,这是由于创建表时使用了远程表引擎(如 MySQL、URL 或 Remote),但 ClickHouse 配置中未允许访问指定的 URL 或主机。我们需要在配置中添加<remote_url_allow_hosts>配置项。此配置是ClickHouse在20.5版本中引入的安全特性,从该版本开始,ClickHouse默认禁止访问未明确允许的外部URL或主机,以增强安全性。
二、解决方法
1. 修改 ClickHouse 配置文件
打开 ClickHouse 的配置文件,通常位于 /etc/clickhouse-server/config.xml 或 /etc/clickhouse-server/config.d/ 目录下。找到 <remote_url_allow_hosts> 配置项,将目标主机添加进去。
    <yandex>
        <remote_url_allow_hosts>
            <host>r-xx-xxxx.service.consul</host>
            <!-- 如果需要允许所有主机,可以使用通配符,生产环境不建议 -->
            <host>*</host>
        </remote_url_allow_hosts>
    </yandex>
    这里端口号需要注意,若只允许3306端口,其他不允许,我们需要配置里显式添加上3306端口,只填写域名或者IP则允许所有端口。
    2. 重启ClickHouse服务
    配置修改之后,我们需要重启服务生效
      sudo systemctl restart clickhouse-server
      3. 若我们不想修改配置文件并重启 ClickHouse,可以通过 SQL 动态设置 remote_url_allow_hosts,然后再尝试建表,不过动态配置只是当前的会话临时有效,永久还是建议走配置文件方式。
        SET remote_url_allow_hosts = 'r-xx-xxxx.service.consul';
        阅读累了,舒缓下眼睛,大佬们

        文章转载自运维笔谈,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

        评论