Docker 部署单机 Zookeeper + exporter

资源清单

主机 IP
redis 10.0.0.1
软件 版本
docker 20.10.12
docker-compose 1.23.1
zookeeper 3.4.14

一、Docker 安装

1. 使用国内 yum

# yum install -y yum-utils device-mapper-persistent-data lvm2
# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

2. 卸载旧版本的 docker

## 如果主机上已经有docker存在且不是想要安装的版本,需要先进行卸载。
# yum remove -y docker \
              docker-client \
              docker-client-latest \
              docker-common \
              docker-latest \
              docker-latest-logrotate \
              docker-logrotate \
              docker-selinux \
              docker-engine-selinux \
              docker-engine \
              container*

3. 安装 Docker20.10 版本

# yum -y install docker-ce-20.10.12-3.el7 docker-ce-cli-20.10.12-3.el7

4. 设置镜像加速

# mkdir /etc/docker
# vi /etc/docker/daemon.json

{
  "registry-mirrors": ["https://xxxxxxxxx.mirror.aliyuncs.com"]
}

5. 启动 docker

# systemctl start docker
# systemctl enable docker
# systemctl status docker

二、Docker-compose 安装

1. Docker-compose 安装

## github.com 可能访问超时,可以使用下面的获取下载下来后上传服务器即可
# curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

# curl -k "https://dl.cactifans.com/zabbix_docker/docker-compose" -o /usr/bin/docker-compose

# chmod a+x /usr/bin/docker-compose

2. 查看 docker-compose 版本

# docker-compose version

三、部署服务

1. docker-compose.yaml 资源清单

version: '3'

services:
  zookeeper:
    image: zookeeper:3.4.14
    container_name: zookeeper
    hostname: zookeeper
    privileged: true
    user: root
    restart: always
    ports:
      - 2181:2181
    environment:
      - ZOO_TICK_TIME=2000
      - ZOO_INIT_LIMIT=5
      - ZOO_SYNC_LIMIT=2
      - ZOO_MAX_CLIENT_CNXNS=1200
    volumes:
      - /etc/localtime:/etc/localtime
      - /data/zookeeper/data:/data
      - /data/zookeeper/config:/conf
      - /data/zookeeper/logs:/datalog

  zookeeper_exporter:
    restart: always
    container_name: zookeeper_exporter
    image: dabealu/zookeeper-exporter:v0.1.13
    depends_on:
      - zookeeper0
    ports:
      - 9141:9141
    command: --zk-hosts="zookeeper0:2181"
    volumes:
      - /etc/localtime:/etc/localtime

2. 创建目录结构

先启动服务后,自动生成目录结构,在上传配置文件

# mkdir /data/zookeeper/{data,config,log} -pv

3. /conf/zoo.cfg 配置文件信息

# cat /data/zookeeper/config/zoo.cfg

clientPort=2181
dataDir=/data
dataLogDir=/datalog
tickTime=2000
initLimit=5
syncLimit=2
autopurge.snapRetainCount=3
autopurge.purgeInterval=0
maxClientCnxns=1200
maxSessionTimeout=30000

4. 部署服务

# docker-compose up -d

# docker-compose ps -a
posted @ 2023-04-04 17:14  evescn  阅读(377)  评论(0编辑  收藏  举报