一、拉取ClickHouse镜像文件
[root@prd-clickhouse001 ~]$ docker pull yandex/clickhouse-server:21.3.20.1
二、创建挂载目录并授权
[root@prd-clickhouse001 ~]$ mkdir -p /data/clickhouse/conf
[root@prd-clickhouse001 ~]$ mkdir -p /data/clickhouse/conf
[root@prd-clickhouse001 ~]$ mkdir -p /data/clickhouse/logs
三、拷贝ClickHouse文件
[root@prd-clickhouse001 ~]$ docker run -d --rm --name=clickhouse yandex/clickhouse-server:21.3.20.1
[root@prd-clickhouse001 ~]$ docker cp clickhouse:/etc/clickhouse-server/users.xml /data/clickhouse/conf/users.xml
[root@prd-clickhouse001 ~]$ docker cp clickhouse:/etc/clickhouse-server/config.xml /data/clickhouse/conf/config.xml
[root@prd-clickhouse001 ~]$ docker stop clickhouse
[root@prd-clickhouse001 ~]$ docker rm -f clickhouse
四、修改密码
#1.生成密码
[root@prd-clickhouse001 ~]$ PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
#2.自定义密码
FJ/LMeo5 明文
2fd00187e0d3eab261af4769686405538c3a24e09601b26a78efb5694d2b8bb1 密文
#3.编辑 /data/clickhouse/conf/users.xml, 替换密文
[root@prd-clickhouse001 ~]$ vim /data/clickhouse/conf/users.xml
... ...
<users>
<default>
<password_sha256_hex>2fd00187e0d3eab261af4769686405538c3a24e09601b26a78efb5694d2b8bb1</password_sha256_hex>
五、启动 ClickHouse
#1.启动容器
[root@prd-clickhouse001 ~]$ docker run -d --name clickhouse-server -p 8123:8123 -p 9009:9009 -p 9000:9000 --ulimit nofile=262144:262144 \
--volume=/data/clickhouse/data:/var/lib/clickhouse \
--volume=/data/clickhouse/log:/var/log/clickhouse-server \
--volume=/data/clickhouse/conf/config.xml:/etc/clickhouse-server/config.xml \
--volume=/data/clickhouse/conf/users.xml:/etc/clickhouse-server/users.xml \
yandex/clickhouse-server:21.3.20.1
#2.验证容器
[root@prd-clickhouse001 ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
21173e54d9dd yandex/clickhouse-server:21.3.20.1 "/entrypoint.sh" 7 days ago Up 7 days 0.0.0.0:8123->8123/tcp, :::8123->8123/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp, 0.0.0.0:9009->9009/tcp, :::9009->9009/tcp clickhouse-server
六、安装 clickhouse-client
[root@prd-clickhouse001 ~]$ yum install yum-utils
[root@prd-clickhouse001 ~]$ rpm --import https://repo.clickhouse.com/CLICKHOUSE-KEY.GPG
[root@prd-clickhouse001 ~]$ yum-config-manager --add-repo https://repo.clickhouse.com/rpm/stable/x86_64
[root@prd-clickhouse001 ~]$ yum install clickhouse-client
七、连接 clickhouse
[root@ip-10-0-12-212 ~]# clickhouse-client -h localhost --port 9000 -u default --password FJ/LMeo5
ClickHouse client version 19.15.2.2.
Connecting to localhost:9000 as user default.
Connected to ClickHouse server version 21.3.20 revision 54447.
ClickHouse client version is older than ClickHouse server. It may lack support for new features.
21173e54d9dd :)