Docker 部署单机 ES + exporter

资源清单

主机 IP
es 10.0.0.1
软件 版本
docker 20.10.12
docker-compose 1.23.1
es 5.4.0

一、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: '2'
services:
  elasticsearch:
    image: elasticsearch:5.4.0
    container_name: elasticsearch
    hostname: elasticsearch
    privileged: true
    user: elasticsearch
    restart: always
    environment:
      - cluster.name=elasticsearch-cluster
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - http.cors.enabled=true
      - TAKE_FILE_OWNERSHIP=true
      - http.cors.allow-origin=*
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m -Duser.timezone=Asia/Shanghai"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    mem_limit: 1g
    volumes:
      - /etc/localtime:/etc/localtime
      - /data/elasticsearch/data:/usr/share/elasticsearch/data
      - /data/elasticsearch/logs:/usr/share/elasticsearch/logs
      - /data/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
    ports:
      - 9300:9300
      - 9200:9200
      
  elasticsearch_exporter:
    container_name: elasticsearch_exporter
    privileged: true
    user: root
    depends_on:
      - elasticsearch
    restart: always 
    image: quay.io/prometheuscommunity/elasticsearch-exporter:v1.5.0
    command:
     - '--es.uri=http://elasticsearch:9200'
    ports:
    - 9114:9114
    volumes:
      - /etc/localtime:/etc/localtime

2. elasticsearch.yml 外挂配置文件信息

暴露 9300 端口给 业务主机访问,默认是监听在 127.0.0.1

# cat /data/elasticsearch/config/elasticsearch.yml

http.host: 0.0.0.0
transport.host: 0.0.0.0

3. 部署服务

# docker-compose up -d

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