# 拉取最新的ClickHouse镜像(推荐)
docker pull clickhouse/clickhouse-server
# 拉取指定版本的MySQL镜像
docker pull clickhouse/clickhouse-server:22.12
# 1.拉取镜像
docker pull clickhouse/clickhouse-server:22.12
# 2.启动镜像
docker run \
-p 8123:8123 \
--name clickhouse-server \
--ulimit nofile=262144:262144 \
-e CLICKHOUSE_DB=test \
-e CLICKHOUSE_USER=root \
-e CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1 \
-e TZ=Asia/Shanghai \
-e CLICKHOUSE_PASSWORD=123456 \
-d clickhouse/clickhouse-server:22.12
# 3.使用工具连接使用即可
# 1.启动一个临时容器,为了拿配置文件
docker run --rm -d --name=temp-clickhouse-server clickhouse/clickhouse-server:22.12
# 2.复制配置文件到宿主机
mkdir -p /data/clickhouse/conf
docker cp temp-clickhouse-server:/etc/clickhouse-server/users.xml /data/clickhouse/conf/users.xml
docker cp temp-clickhouse-server:/etc/clickhouse-server/config.xml /data/clickhouse/conf/config.xml
# 3.删除临时容器
docker rm -f temp-clickhouse-server
18138372fad4b94533cd4881f03dc6c69296dd897234e0cee83f727e2e6b1f63
::/0
default
default
其中18138372fad4b94533cd4881f03dc6c69296dd897234e0cee83f727e2e6b1f63生成方式
echo -n "qwe123" | sha256sum | tr -d '-'
18138372fad4b94533cd4881f03dc6c69296dd897234e0cee83f727e2e6b1f63
sudo docker run -d --name=clickhouse-server \
-p 8123:8123 \
-e TZ=Asia/Shanghai \
--volume=/data/clickhouse/conf/config.xml:/etc/clickhouse-server/config.xml \
--volume=/data/clickhouse/conf/users.xml:/etc/clickhouse-server/users.xml \
--volume=/data/clickhouse/log:/var/log/clickhouse-server \
--volume=/data/clickhouse/data:/var/lib/clickhouse/ \
clickhouse/clickhouse-server:22.12
# 这个重启后就会打开
systemctl status firewalld.service
systemctl stop firewalld.service
# 打开端口(建议)
# 查看当前文件打开最大数量
ulimit -n
在 /etc/security/limits.conf和/etc/security/limits.d/20-nproc.conf 这两个文件的末尾加入以下内容:
注意:没有20-nproc.conf 该文件就创建一个
[root@localhost ~]# vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
* soft nproc 131072
* hard nproc 131072
[root@localhost ~]# vi /etc/security/limits.d/20-nproc.conf
* soft nofile 65535
* hard nofile 65535
* soft nproc 131072
* hard nproc 131072
# 修改 /etc/selinux/config 中的 SELINUX=disabled 后重启
vi /etc/selinux/config
SELINUX=disabled
# root用户执行:
yum install -y libtool
yum install -y *unixODBC*
# 需要验证当前服务器的CPU是否支持SSE 4.2指令集,因为向量化执行需要用到这项特性
[root@localhost ~]# grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"
SSE 4.2 supported
reboot
# 创建一个临时文件夹
mkdir temp && cd temp
# 选择21.10.6.2版本下载,共有四个安装包
wget https://packages.clickhouse.com/rpm/stable/clickhouse-client-21.10.6.2-2.noarch.rpm
wget https://packages.clickhouse.com/rpm/stable/clickhouse-server-21.10.6.2-2.noarch.rpm
wget https://packages.clickhouse.com/rpm/stable/clickhouse-common-static-21.10.6.2-2.x86_64.rpm
wget https://packages.clickhouse.com/rpm/stable/clickhouse-common-static-dbg-21.10.6.2-2.x86_64.rpm
rpm -ivh clickhouse-*
# 在 /etc/clickhouse-server 路径下的config.xml中查找listen_host 并将如下注释打开,使其可以被除本机以外的其他IP所访问
vi /etc/clickhouse-server/config.xml
# 配置完重新加载配置:
clickhouse restart
启停命令
1. 启动
clickhouse-server start
systemctl start clickhouse-server.service
2. 查看状态
clickhouse-server status
systemctl status clickhouse-server.service
3. 重启
clickhouse-server restart
systemctl restart clickhouse-server.service
4.开机自启
systemctl enable clickhouse-server.service
systemctl disable clickhouse-server.service