docker-composs运行常用服务应用
song
1
2
3
4
5
[root@ct01 ~]# uname -a
Linux ct01 3.10.0-1160.71.1.el7.x86_64 #1 SMP Tue Jun 28 15:37:28 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

[root@ct01 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

安装docker前的准备

  1. 备份已有yum源
    1
    2
    3
    4
    # 创建备份目录
    mkdir -p /etc/yum.repos.d/backup/
    # 备份本地yum包
    mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup/
  2. 配置阿里云yum源、epel库
    1
    2
    3
    4
    # 下载对应系统版本的阿里云yum源
    wget -O /etc/yum.repos.d/CentOs-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    # 下载epel开源发行软件包版本库,可以提供额外的软件包
    wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  3. 重新生成yum缓存,更新软件包
    1
    2
    3
    4
    # 删除缓存数据
    yum clean all
    # 创建元数据缓存
    yum makecache
  4. 其他命令
    1
    2
    3
    4
    5
    6
    7
    8
    # 下载软件包,-y表示安装过程中回答全部问题为'是'
    yum -y install [软件包名]
    # 删除软件包
    yum -y remove [软件包名]
    # 显示已配置的源
    yum repolist
    # 更新软件包
    yum update

安装docker

  1. 卸载旧版本(如果有)
    1
    yum remove docker  docker-common docker-selinux docker-engine
  2. 安装需要的软件包, yum-util 提供yum-config-manager功能,另两个是devicemapper驱动依赖
    1
    2
    ## yum install -y yum-utils device-mapper-persistent-data lvm2
    yum install -y yum-utils
  3. 设置 yum 源(任意一个都可)
    1
    2
    3
    4
    5
    6
    7
    ### 中央仓库
    yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo
    ### 阿里仓库
    yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

    ### 更新yum软件包索引
    yum makecache fast
  4. 选择docker版本并安装

查看可用的版本

1
2
3
4
5
6
7
8
9
10
11
12
yum list docker-ce --showduplicates | sort -r
docker-ce.x86_64 3:18.09.2-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.1-3.el7 docker-ce-stable
docker-ce.x86_64 3:18.09.0-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.3.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.2.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.1.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.06.0.ce-3.el7 docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos docker-ce-stable
docker-ce.x86_64 18.03.1.ce-1.el7.centos @docker-ce-stable
docker-ce.x86_64 18.03.0.ce-1.el7.centos docker-
...

选择一个版本安装 yum install docker-ce-版本号

1
2
yum -y install docker-ce-18.03.1.ce
yum -y install docker-ce //安装最新版

启动 Docker 并设置开机自启

1
2
systemctl start docker
systemctl enable docker
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
docker version

Client: Docker Engine - Community
Version: 26.1.4
API version: 1.45
Go version: go1.21.11
Git commit: 5650f9b
Built: Wed Jun 5 11:32:04 2024
OS/Arch: linux/amd64
Context: default

Server: Docker Engine - Community
Engine:
Version: 26.1.4
API version: 1.45 (minimum version 1.24)
Go version: go1.21.11
Git commit: de5c9cf
Built: Wed Jun 5 11:31:02 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.33
GitCommit: d2d58213f83a351ca8f528a95fbd145f5654e957
runc:
Version: 1.1.12
GitCommit: v1.1.12-0-g51d5e94
docker-init:
Version: 0.19.0
GitCommit: de40ad0

安装docker-compose

  1. 安装旧版本 https://github.com/docker/compose/releases?page=14
    1
    2
    curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
  2. 安装v2.29.6当前日志最新版 https://docs.docker.com/compose/install/standalone/
    1
    2
    curl -SL https://github.com/docker/compose/releases/download/v2.29.6/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
    chmod +x /usr/local/bin/docker-compose
  3. 查看安装版本
    1
    2
    docker-compose version
    Docker Compose version v2.29.6

elasticsearch、kibana、redis、rabbitmq安装运行

编写docker-compose.yml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
version: '3'
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.2.0
    container_name: es8
    volumes:
      - "/software/elastic:/usr/share/elasticsearch/data:rw"
      - "/etc/localtime:/etc/localtime"
      - "/etc/timezone:/etc/timezone"      
    environment:
      - node.name=es8
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - xpack.security.enabled=false
      - xpack.security.http.ssl.enabled=false
      - xpack.security.transport.ssl.enabled=false
      - TAKE_FILE_OWNERSHIP=111
    ports:
      - 9200:9200
    privileged: true
    mem_limit: 2g
    restart: no
  kibana:
    image: docker.elastic.co/kibana/kibana:8.2.0
    depends_on:
      - elasticsearch
    environment:
      TZ: "Asia/Shanghai"
      ELASTICSEARCH_HOSTS: '["http://es8:9200"]'
    volumes:
      - "/etc/localtime:/etc/localtime"
      - "/etc/timezone:/etc/timezone"      
    ports:
      - 5601:5601
    restart: no
    container_name: kibana8
  redis:
    image: redis:5.0.6
    environment:
      - TZ=Asia/Shanghai
    container_name: redis_sigle
    restart: no
    command: redis-server /usr/local/etc/redis/redis.conf
    ports:
      - 6379:6379
    volumes:
      - /software/redis/data:/data:rw
      - /software/redis/redis.conf:/usr/local/etc/redis/redis.conf
  rabbitmq:
    image: rabbitmq:3.12-management
    container_name: rabbitmq
    ports:
        - 5672:5672
        - 15672:15672
    environment:
      - TZ=Asia/Shanghai
      - RABBITMQ_DEFAULT_USER=admin
      - RABBITMQ_DEFAULT_PASS=P@ssw0rd
    restart: no

composs文件对应外挂文件

redis 外挂配置 创建data目录挂载redis数据、创建redis.conf挂载配置文件

1
2
3
4
5
6
7
bind 0.0.0.0
port 6379
daemonize no
loglevel notice
logfile redis.log
dbfilename dump6379.rdb
dir /data

启动运行

1
docker-compose up -d

其他问题

  1. es报错
    1
    es8          | java.lang.IllegalStateException: failed to obtain node locks, tried [/usr/share/elasticsearch/data]; maybe these locations are not writable or multiple nodes were started on the same data path?
  • 是es启动了,占用了node,需要杀死es进程再启动
  • 是权限的问题 解决思路是修改elk目录下的data目录权限
    1
    2
    chown -R 1000:1000 data
    chmod -R 777 data
由 Hexo 驱动 & 主题 Keep