Clickhouse docker安装与用户、远程连接配置

Docker安装

首先,clickhouse的服务端与客户端是分开的,server(服务端)是用来启动数据库,提供增删改查服务的;而client(客户端)是告诉server要操作什么数据的

clickhouse docker主页地址:https://hub.docker.com/r/yandex/clickhouse-server

拉取clickhouse server的镜像:

docker pull yandex/clickhouse-server
# docker pull clickhouse/clickhouse-server # 这个也可以哈!

运行:

docker run -d --name=clickhouse-server --ulimit nofile=262144:262144 -p 8123:8123 -p 9009:9009 -p 9090:9000 yandex/clickhouse-server

然后clickhouse的服务就启动了,可以访问:http://localhost:8123/,看到一个“OK”,即代表clickhouse运行成功

默认的clickhouse启动后:

  • 用户名:default
  • 密码:<空>

修改配置

进入容器:

docker exec -it clickhouse的容器ID /bin/sh
# 如:
# docker exec -it 082242cb73de0c3fccff9758c16d7e535055063d1d576dd70a1ea73b09c20208 /bin/sh

因为我们后续对文件的修改要使用vim,因此先安装一下,便于修改配置文件

apt-get update
apt-get install vim -y

1. 修改用户名密码

cd /etc/clickhouse-server
vim users.xml

从40+行左右就可以看到如下内容:

<!-- Users and ACL. -->
    <users>
        <!-- If user name was not specified, 'default' user is used. -->
        <default>
            <!-- See also the files in users.d directory where the password can be overridden.

                 Password could be specified in plaintext or in SHA256 (in hex format).

                 If you want to specify password in plaintext (not recommended), place it in 'password' element.
..........

新增用户的配置方法如下:

<users>
	<新增的用户名>
        <password>这里是新增用户名,对应的密码</password>
        <networks incl="networks" replace="replace">
            <ip>::/0</ip>
        </networks>
        <profile>default</profile>
        <quota>default</quota>
	</新增的用户名>
</users>

比如新建一个用户:

  • 用户名:test_user
  • 密码:test_password

则可以增加配置内容:

<!-- Users and ACL. -->
<users>
	<test_user>
        <password>test_password</password>
        <networks incl="networks" replace="replace">
            <ip>::/0</ip>
        </networks>
        <profile>default</profile>
        <quota>default</quota>
	</test_user>
	
	<!-- If user name was not specified, 'default' user is used. -->
    <default> <!-- 看,这个是默认的用户名 default,它下面的password是空的,所以没有密码 -->
    	.........
    </default>
</users>

2. 配置远程访问

cd /etc/clickhouse-server
vi config.xml

查询修改:/listen_,即可定位到配置标签:

<!-- <listen_host>::</listen_host> -->

取消注释即可配置远程访问:

<listen_host>::</listen_host>
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
以下是使用Docker安装ClickHouse配置远程访问的步骤: 1. 首先,确保已经安装Docker。如果没有安装,请根据您的操作系统进行安装。 2. 打开终端或命令提示符,并运行以下命令来拉取ClickHouseDocker镜像: ```shell docker pull yandex/clickhouse-server ``` 3. 运行以下命令来创建并启动一个ClickHouse容器: ```shell docker run -d --name clickhouse-server -p 8123:8123 -p 9000:9000 yandex/clickhouse-server ``` 这将创建一个名为clickhouse-server的容器,并将ClickHouse的HTTP端口映射到主机的8123端口,将ClickHouse的TCP端口映射到主机的9000端口。 4. 确认容器已经成功启动。运行以下命令来查看容器的状态: ```shell docker ps ``` 您应该能够看到clickhouse-server容器正在运行。 5. 现在,您可以通过访问http://localhost:8123来访问ClickHouse的Web界面。在Web界面中,您可以执行SQL查询和其他操作。 6. 要配置远程访问,您需要编辑ClickHouse配置文件。运行以下命令进入ClickHouse容器的bash终端: ```shell docker exec -it clickhouse-server bash ``` 7. 在容器中,找到ClickHouse配置文件,并使用文本编辑器进行编辑。默认情况下,配置文件位于/etc/clickhouse-server/config.xml。您可以运行以下命令来编辑配置文件: ```shell vi /etc/clickhouse-server/config.xml ``` 8. 在配置文件中,找到以下行: ```xml <listen_host>::</listen_host> ``` 将其修改为: ```xml <listen_host>0.0.0.0</listen_host> ``` 这将允许ClickHouse接受来自任何IP地址的连接。 9. 保存并关闭配置文件。 10. 重新启动ClickHouse容器,以使配置更改生效: ```shell docker restart clickhouse-server ``` 现在,您应该能够通过使用ClickHouse的IP地址和端口号来远程访问ClickHouse数据库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呆萌的代Ma

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值