# Docker 安装 ClickHouse

https://developer.aliyun.com/article/859792#slide-1 (opens new window)

  1. 创建挂载路径

    mkdir -p ~/clickhouse/data ~/clickhouse/conf ~/clickhouse/log
    
    1
  2. 启动容器(临时)

    docker run -d --name clickhouse-server \
    --ulimit nofile=262144:262144 \
    -p 8123:8123 -p 9000:9000 -p 9009:9009 \
    yandex/clickhouse-server
    
    1
    2
    3
    4
  3. 配置文件复制到挂载目录下

    docker cp clickhouse-server:/etc/clickhouse-server/config.xml ~/clickhouse/conf/config.xml
    docker cp clickhouse-server:/etc/clickhouse-server/users.xml ~/clickhouse/conf/users.xml
    
    1
    2
  4. 关闭删除临时容器

    docker stop clickhouse-server && docker rm clickhouse-server
    
    1
  5. 启动容器

    docker run -d --name=clickhouse-server \
    -p 8123:8123 -p 9009:9009 -p 9004:9004 -p 9090:9000 \
    --ulimit nofile=262144:262144 \
    -v ~/clickhouse/data:/var/lib/clickhouse:rw \
    -v ~/clickhouse/conf/config.xml:/etc/clickhouse-server/config.xml \
    -v ~/clickhouse/conf/users.xml:/etc/clickhouse-server/users.xml \
    -v ~/clickhouse/log:/var/log/clickhouse-server:rw \
    yandex/clickhouse-server
    
    1
    2
    3
    4
    5
    6
    7
    8
  6. 连接,可以使用mysql客户端,或者DBeaver

    1.在config.xml中添加mysql端口,重启clickhouse后,就可以登录了
    <mysql_port>9004</mysql_port>

    2.MySQL客户端登录

    mysql -h192.168.198.129 -udefault -P9004 -p
    SELECT * FROM system.build_options WHERE upper(name) LIKE '%VERSION%';
    show databases;
    use netjoytest1; 
    show tables;
    select * from tank1_all limit 2; 
    
    1
    2
    3
    4
    5
    6

    zQMpfH.md.png