如何用docker 安装clickhouse server
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io
systemctl start docker
docker pull yandex/clickhouse-server
docker pull yandex/clickhouse-clinet
mkdir /work/clickhouse/clickhouse-test-db
mkdir /etc/clickhouse-server
docker cp clickhouse-server:/etc/clickhouse-server/ /etc/
修改主机 /etc/clickhouse-server/config.xml 中 65行 注释去掉<listen_host>::</listen_host>
运行命令
PASSWORD=$(base64 < /dev/urandom | head -c8); echo "$PASSWORD"; echo -n "$PASSWORD" | sha256sum | tr -d '-'
会输出明文和密文
dLZWIZxt
24b81ed09bbf8378a6829769804cf765a221275237f274d232e051fac2d6fedf
修改 /app/cloud/clickhouse/conf/users.xml
把default账号设为只读权限,并设置密码 yandex-->users-->default-->profile 节点设为 readonly
注释掉 yandex-->users-->default-->password 节点
新增
yandex-->users-->default-->password_sha256_hex 节点,填入生成的密码
新增root账号
<root>
<password_sha256_hex>24b81ed09bbf8378a6829769804cf765a221275237f274d232e051fac2d6fedf</password_sha256_hex>
<networks incl="networks" replace="replace">
<ip>::/0</ip>
</networks>
<profile>default</profile>
<quota>default</quota>
</root>
启动clickhouse-test-server
docker run -d --name clickhouse-test-server --ulimit nofile=262144:262144 --volume=/work/clickhouse/clickhouse_test_db:/var/lib/clickhouse -p 8123:8123 -p 9000:9000 -p 9009:9009 -v /etc/clickhouse-server/config.xml:/etc/clickhouse-server/config.xml -v /etc/clickhouse-server/users.xml:/etc/clickhouse-server/users.xml yandex/clickhouse-server
停止、启动、删除 clickhouse-test-server
docker stop clickhouse-test-server
docker start clickhouse-test-server
docker rm clickhouse-test-server
附一个python3查询click-house的代码的例子
# pip3 install clickhouse-driver from clickhouse_driver import Client client = Client(host='127.0.0.1',port='9000',user='default' ,password='') sql = 'SHOW DATABASES' ans = client.execute(sql) print(ans)