首页 > 其他分享 >docker-compose部署单机clickhouse

docker-compose部署单机clickhouse

时间:2024-03-07 14:56:46浏览次数:29  
标签:compose tcp server clickhouse docker root localhost

【转载:https://www.cnblogs.com/crow1840/p/17506884.html】

1、创建clickhouse目录

[root@localhost docker]# ls
gitlab_docker  jenkins_docker  mysql_docker
[root@localhost docker]# mkdir clickhouse/conf -p

2.创建docker-compose.yml

[root@localhost clickhouse]# cat docker-compose.yml 
version: '3'
services:
  ch_server:
    image: yandex/clickhouse-server
    ports:
      - "8123:8123"
      - "9100:9100"
    volumes:
      - ./conf/docker_related_config.xml:/etc/clickhouse-server/config.d/docker_related_config.xml:rw
      - ./conf/config.xml:/etc/clickhouse-server/config.xml:rw
      - ./conf/users.xml:/etc/clickhouse-server/users.xml:rw
      - /etc/localtime:/etc/localtime:ro
      - ./log:/var/log/clickhouse-server
      - ./db:/var/lib/clickhouse:rw
  ch_client:
    image: yandex/clickhouse-client
    entrypoint:
      - /bin/sleep
    command:
      - infinity

3、配置文件

1)临时启动一个clickhouse容器
[root@localhost clickhouse]# docker run -d --name chtmp yandex/clickhouse-server
Unable to find image 'yandex/clickhouse-server:latest' locally
latest: Pulling from yandex/clickhouse-server
ea362f368469: Pull complete 
38ba82a23e2b: Pull complete 
9b17d04b6c62: Pull complete 
5658714e4e8b: Pull complete 
6bde977a0bf8: Pull complete 
39053b27290b: Pull complete 
762d3d237065: Pull complete 
Digest: sha256:1cbf75aabe1e2cc9f62d1d9929c318a59ae552e2700e201db985b92a9bcabc6e
Status: Downloaded newer image for yandex/clickhouse-server:latest
8d0d3076bef1ba56cb4adf45cf1584e6874e8c4753dc2ea0657e7a5efcbde9a0
[root@localhost clickhouse]# docker ps
CONTAINER ID   IMAGE                                                          COMMAND                   CREATED          STATUS                 PORTS                                                                                      NAMES
8d0d3076bef1   yandex/clickhouse-server                                       "/entrypoint.sh"          28 seconds ago   Up 26 seconds          8123/tcp, 9000/tcp, 9009/tcp                                                               chtmp

2) 从容器中拷贝出配置文件
[root@localhost conf]# docker cp chtmp:/etc/clickhouse-server/config.d/docker_related_config.xml ./
Successfully copied 2.05kB to /usr/local/docker/clickhouse/conf/./
[root@localhost conf]# docker cp chtmp:/etc/clickhouse-server/config.xml ./
Successfully copied 63.5kB to /usr/local/docker/clickhouse/conf/./
[root@localhost conf]# docker cp chtmp:/etc/clickhouse-server/users.xml ./
Successfully copied 8.19kB to /usr/local/docker/clickhouse/conf/./
[root@localhost conf]# ll
总用量 76
-rw-rw-rw- 1 root root 61476 1月  23 2022 config.xml
-rw-rw-r-- 1 root root   314 1月  23 2022 docker_related_config.xml
-rw-rw-rw- 1 root root  6248 1月  23 2022 users.xml

3) 关闭临时容器
[root@localhost conf]# docker stop chtmp
chtmp
[root@localhost conf]# docker rm chtmp
chtmp

4、启动

[root@localhost clickhouse]# docker-compose up -d
[+] Running 5/5
 ✔ ch_client 4 layers [⣿⣿⣿⣿]      0B/0B      Pulled                                                                                                                  719.5s 
   ✔ 2f94e549220a Pull complete                                                                                                                                       24.6s 
   ✔ a72d8599d7c2 Pull complete                                                                                                                                        1.7s 
   ✔ e9232762ed9d Pull complete                                                                                                                                      702.2s 
   ✔ 29c8f4b1e77e Pull complete                                                                                                                                        6.0s 
[+] Running 2/3
 ⠧ Network clickhouse_default        Created                                                                                                                           1.7s 
 ✔ Container clickhouse-ch_server-1  Started                                                                                                                           1.5s 
 ✔ Container clickhouse-ch_client-1  Started                                                                                                                           1.5s 
[root@localhost clickhouse]# docker-compose ps
NAME                     IMAGE                      COMMAND                 SERVICE     CREATED          STATUS          PORTS
clickhouse-ch_client-1   yandex/clickhouse-client   "/bin/sleep infinity"   ch_client   14 seconds ago   Up 12 seconds   
clickhouse-ch_server-1   yandex/clickhouse-server   "/entrypoint.sh"        ch_server   14 seconds ago   Up 12 seconds   9000/tcp, 0.0.0.0:8123->8123/tcp, :::8123->8123/tcp, 0.0.0.0:9100->9100/tcp, :::9100->9100/tcp, 9009/tcp
[root@localhost clickhouse]# docker-compose ps
NAME                     IMAGE                      COMMAND                 SERVICE     CREATED          STATUS          PORTS
clickhouse-ch_client-1   yandex/clickhouse-client   "/bin/sleep infinity"   ch_client   17 seconds ago   Up 15 seconds   
clickhouse-ch_server-1   yandex/clickhouse-server   "/entrypoint.sh"        ch_server   17 seconds ago   Up 15 seconds   9000/tcp, 0.0.0.0:8123->8123/tcp, :::8123->8123/tcp, 0.0.0.0:9100->9100/tcp, :::9100->9100/tcp, 9009/tcp

5、测试

[root@localhost conf]# docker exec -it -u root 73b2e11644b3 bash
root@73b2e11644b3:/# clickhouse-client 
ClickHouse client version 22.1.3.7 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 22.1.3 revision 54455.

73b2e11644b3 :) show databases

SHOW DATABASES

Query id: bd604a15-5f23-4b21-86cb-7560e62744e1

┌─name───────────────┐
│ INFORMATION_SCHEMA │
│ default            │
│ information_schema │
│ system             │
└────────────────────┘

4 rows in set. Elapsed: 0.003 sec. 

73b2e11644b3 :) exit
Bye.
root@73b2e11644b3:/# exit
exit

6、用户名密码

1) 默认用户
修改刚才拷贝的配置文件中的users.xml文件
修改<users>中<default>部分,<password></password>一行如下
    <users>
        <!-- If user name was not specified, 'default' user is used. -->
        <default>
            ......
            <password>wjht#%$347</password>
            <networks>
                <ip>::/0</ip>
            </networks>
            <profile>default</profile>
            <quota>default</quota>
        </default>
    </users>

2) 测试登录
root@73b2e11644b3:/# clickhouse-client --password 'wjht#%$347'
ClickHouse client version 22.1.3.7 (official build).
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 22.1.3 revision 54455.

73b2e11644b3 :) show databases

SHOW DATABASES

Query id: 959365a2-db8b-44e9-ad5e-5a22c711fb63

┌─name───────────────┐
│ INFORMATION_SCHEMA │
│ default            │
│ information_schema │
│ system             │
└────────────────────┘

5 rows in set. Elapsed: 0.004 sec. 


7、创建其他用户

    <users>
        <!-- If user name was not specified, 'default' user is used. -->
        <default>
            ......
        </default>
        <wjhtwxx>
            <password>root123</password>
            <networks incl="networks" replace="replace">
                <ip>::/0</ip>
            </networks>
            <profile>default</profile>
            <quota>default</quota>
            <allow_databases>
                <database>aaa</database>
            </allow_databases>
        </wjhtwxx>
    </users>

标签:compose,tcp,server,clickhouse,docker,root,localhost
From: https://www.cnblogs.com/sddll/p/18058882

相关文章

  • 在Docker中,如何清理后台停止的容器?
    在Docker中,清理后台停止的容器可以通过多种方式完成。以下是一些常用的方法:1.手动删除你可以使用dockerps-a命令查看所有的容器,包括已停止的容器。找到你想要删除的容器的ID或名称。然后,使用dockerrm<container_id_or_name>命令来删除它。例如:dockerps-a#列出所有容......
  • 在Docker中,如何退出一个镜像的bash,而不终止它?
    在Docker中,当你使用dockerexec-it<container_id_or_name>bash命令进入一个正在运行的容器的bashshell时,你实际上是启动了一个新的进程。要退出这个bashshell而不终止容器,你可以使用几种不同的方法。1.使用exit命令在bashshell中,你可以简单地输入exit命令来退出。这将终......
  • 在Docker中,如何查看镜像支持的环境变量?
    在Docker中,要查看镜像支持的环境变量,有几种方法可以采用:使用Dockerfile:查看Docker镜像的环境变量最直接的方式是查看构建该镜像的Dockerfile。Dockerfile中的ENV指令用于设置环境变量,这些变量在构建镜像时会被创建并保存在镜像中。因此,通过检查Dockerfile,你可以找到所有通过E......
  • Nextcloud 基于 Docker 部署
    1、Docker、Docker-Compose安装https://www.cnblogs.com/a120608yby/p/9883175.htmlhttps://www.cnblogs.com/a120608yby/p/14582853.html2、基于Docker-Compose部署nextcloud#vimdocker-compose.ymlversion:'3'services:db:image:mariadb:10.6......
  • CentOS7 解决宝塔面板安装 Docker 和 Docker-compose 的问题
    在宝塔面板的软件商店安装Docker管理器时提示需手动安装Docker,再在面板中开启Docker插件进行可视化管理但是我手动安装Docker后依旧提示当前未安装Docker或Docker-compose,即宝塔面板的Docker管理插件仍无法识别到这些安装,在此记录下我的解决过程,如有错误,欢迎指正!1......
  • docker镜像
    1.base镜像base镜像有两层含义:(1)不依赖其他镜像,从scratch构建(2)其他镜像可以以之为基础进行扩展。所以,能称作base镜像的通常都是各种Linux发行版的Docker镜像,比如Ubuntu、Debian、CentOS等。dockerpullubuntuUbuntu镜像只有78M左右,下边解释为什么会这么......
  • Docker使用Dockerfile文件(五)
    前言Dockerfile是一个文本文件,其中包含了创建Docker镜像所需的所有指令。这意味着任何人都可以通过运行dockerbuild命令并使用相同的Dockerfile来创建完全相同的镜像。这确保了镜像创建的可重复性,使得在不同的环境中部署应用程序变得更加容易。Dockerfile提供了丰......
  • 【Docker】Docker安装MongoDB最新版并连接使用附加docker常用命令
    【Docker】Docker安装MongoDB最新版并连接使用附加docker常用命令前言确保centos7已经安装docker,没安装docker的可以百度自行安装一、docker安装mongodb步骤1、docker拉取mongo镜像dockerpullmongo:latest2、查看本地镜像命令#查看镜像命令dockerimages#查看正在运......
  • 本地快速搭建airflow docker镜像,映射本地路径
    airflow官方文档拉取镜像dockerpullapache/airflow:2.8.2拉取配置文件curl-LfO'https://airflow.apache.org/docs/apache-airflow/2.8.2/docker-compose.yaml'修改刚刚拉取的yaml文件关闭示例dagAIRFLOW__CORE__LOAD_EXAMPLES:'false'映射本地路径volumes:......
  • 在Docker中,stage和step有什么区别?
    在Docker的上下文中,特别是在Dockerfile构建和CI/CD流程中,“stage”和“step”这两个术语具有不同的含义:Stage(阶段):在Dockerfile中,stage(也称为构建阶段或构建阶段目标)是一种构建策略,允许开发者将Docker镜像构建过程分割成多个逻辑部分或阶段。每个阶段定义了一个新的构建环境,可......