CentOS7.3安装Docker及rabbitmq

前言

不建议centos6.5上安装docker,太麻烦,要升级内核,而且会缺失一大堆依赖,结果就是浪费一下午,还没安装成功,气人!

Docker极简安装步骤:

CentOS7.3安装Docker及rabbitmq_第1张图片

1.查看linux版本

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

2.更新yum

文件比较大,1G左右,下载安装需要十分钟左右吧

yum update

如果有下面提示,rm -f /var/run/yum.pid 删除进程id文件重试,如果删不掉,kill -9 pid的值,将yum进程杀掉,然后再yum update
CentOS7.3安装Docker及rabbitmq_第2张图片

3. 安装所需软件包

yum-util提供yum-config-manager功能,另外两个是devicemapper驱动依赖

[root@promote ~]# yum install  -y yum-utils device-mapper-persistent-data lvm2
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.ustc.edu.cn
 * updates: ap.stykers.moe
Package yum-utils-1.1.31-52.el7.noarch already installed and latest version
Package device-mapper-persistent-data-0.8.5-1.el7.x86_64 already installed and latest version
Package 7:lvm2-2.02.185-2.el7_7.2.x86_64 already installed and latest version
Nothing to do

提示已经是最新版本了

4.设置yum源为阿里云

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

5.查看docker版本

[root@promote ~]# yum list docker-ce --showduplicates | sort -r
 * updates: mirrors.cn99.com
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror, langpacks
 * extras: ap.stykers.moe
docker-ce.x86_64            3:19.03.6-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.0-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.9-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.8-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.7-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.6-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.3-3.el7                     docker-ce-stable
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.0.ce-1.el7.centos             docker-ce-stable

6. 安装docker

直接安装最新版本:sudo yum install docker-ce -y
安装其他版本,如18.03.1.ce版本:sudo yum install docker-ce-18.03.1.ce

[root@promote ~]# sudo yum install docker-ce -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.ustc.edu.cn
 * updates: ap.stykers.moe
Resolving Dependencies
--> Running transaction check
---> Package docker-ce.x86_64 3:19.03.6-3.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: 3:docker-ce-19.03.6-3.el7.x86_64
--> Processing Dependency: containerd.io >= 1.2.2-3 for package: 3:docker-ce-19.03.6-3.el7.x86_64
--> Processing Dependency: docker-ce-cli for package: 3:docker-ce-19.03.6-3.el7.x86_64
--> Running transaction check
---> Package container-selinux.noarch 2:2.107-3.el7 will be installed
---> Package containerd.io.x86_64 0:1.2.10-3.2.el7 will be installed
---> Package docker-ce-cli.x86_64 1:19.03.6-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================
 Package                             Arch                     Version                           Repository                          Size
=========================================================================================================================================
Installing:
 docker-ce                           x86_64                   3:19.03.6-3.el7                   docker-ce-stable                    24 M
Installing for dependencies:
 container-selinux                   noarch                   2:2.107-3.el7                     extras                              39 k
 containerd.io                       x86_64                   1.2.10-3.2.el7                    docker-ce-stable                    23 M
 docker-ce-cli                       x86_64                   1:19.03.6-3.el7                   docker-ce-stable                    40 M

Transaction Summary
=========================================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 87 M
Installed size: 363 M
Downloading packages:
(1/4): container-selinux-2.107-3.el7.noarch.rpm                                                                   |  39 kB  00:00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-19.03.6-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for docker-ce-19.03.6-3.el7.x86_64.rpm is not installed
(2/4): docker-ce-19.03.6-3.el7.x86_64.rpm                                                                         |  24 MB  00:00:04
(3/4): containerd.io-1.2.10-3.2.el7.x86_64.rpm                                                                    |  23 MB  00:00:11
(4/4): docker-ce-cli-19.03.6-3.el7.x86_64.rpm                                                                     |  40 MB  00:00:10
-----------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                    5.9 MB/s |  87 MB  00:00:14
Retrieving key from https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) "
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2:container-selinux-2.107-3.el7.noarch                                                                                1/4
  Installing : containerd.io-1.2.10-3.2.el7.x86_64                                                                                   2/4
  Installing : 1:docker-ce-cli-19.03.6-3.el7.x86_64                                                                                  3/4
  Installing : 3:docker-ce-19.03.6-3.el7.x86_64                                                                                      4/4
  Verifying  : 3:docker-ce-19.03.6-3.el7.x86_64                                                                                      1/4
  Verifying  : 1:docker-ce-cli-19.03.6-3.el7.x86_64                                                                                  2/4
  Verifying  : containerd.io-1.2.10-3.2.el7.x86_64                                                                                   3/4
  Verifying  : 2:container-selinux-2.107-3.el7.noarch                                                                                4/4

Installed:
  docker-ce.x86_64 3:19.03.6-3.el7

Dependency Installed:
  container-selinux.noarch 2:2.107-3.el7        containerd.io.x86_64 0:1.2.10-3.2.el7        docker-ce-cli.x86_64 1:19.03.6-3.el7

Complete!
[root@promote ~]#

7.验证docker是否安装成功

[root@promote ~]# docker -v
Docker version 19.03.6, build 369ce74a3c

验证docker是否安装成功: docker version ,此时服务没有开启
CentOS7.3安装Docker及rabbitmq_第3张图片

8. 配置镜像加速

将下面的脚本语句复制进去执行:

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://0wrdwn6.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

查看是否配置成功:

cat /etc/docker/daemon.json

CentOS7.3安装Docker及rabbitmq_第4张图片

9.启动docker,查看镜像

$ sudo systemctl start docker
dock# 开机自启可以不加
$ sudo systemctl enable docker

启动并查看docker版本:

[root@promote ~]# systemctl start docker
[root@promote ~]# docker version
Client: Docker Engine - Community
 Version:           19.03.6
 API version:       1.40
 Go version:        go1.12.16
 Git commit:        369ce74a3c
 Built:             Thu Feb 13 01:29:29 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          19.03.6
  API version:      1.40 (minimum version 1.12)
  Go version:       go1.12.16
  Git commit:       369ce74a3c
  Built:            Thu Feb 13 01:28:07 2020
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.2.10
  GitCommit:        b34a5c8af56e510852c35414db4c1f4fa6172339
 runc:
  Version:          1.0.0-rc8+dev
  GitCommit:        3e425f80a8c931f88e6d94a8c831b9d5aa481657
 docker-init:
  Version:          0.18.0
  GitCommit:        fec3683

查看docker镜像:

[root@promote ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE

如果看到上面的信息,说明安装成功

10.安装rabbitmq

  • 拉取rabbitmq镜像

[root@promote ~]# docker pull rabbitmq:management
management: Pulling from library/rabbitmq
5c939e3a4d10: Pull complete
c63719cdbe7a: Pull complete
19a861ea6baf: Pull complete
651c9d2d6c4f: Pull complete
da31881b2e3b: Pull complete
df67acc10503: Pull complete
31f8b0bc70f4: Pull complete
a1cd9cbfba9d: Pull complete
9bae18855d32: Pull complete
e094f487f477: Pull complete
ac805691c3d6: Pull complete
948b009690a3: Pull complete
Digest: sha256:024de6f485a96c2a2e80507c96c94a5fc18709725c90714d9918328cd3020c1c
Status: Downloaded newer image for rabbitmq:management
docker.io/library/rabbitmq:management

下载成功,可以看到rabbitmq的镜像(类似压缩包):

[root@promote ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
rabbitmq            management          a64a4ae7bc1f        13 days ago         181MB
  • 创建并启动容器
    命令比较长,要保证是一行,不能有回车
    docker run -di --name myrabbit -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -p 15672:15672 -p 5672:5672 -p 25672:25672 -p 61613:61613 -p 1883:1883 rabbitmq:management
[root@promote ~]# docker run -di --name myrabbit -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -p 15672:15672 -p 5672:5672 -p 25672:25672 -p 61613:61613 -p 1883:1883 rabbitmq:management
9bd6ffaa494a75349a12d6f7df9a63a4d21808db95352baba44256a5a23f8ec6
[root@promote ~]#

浏览器访问http://192.168.61.130:15672/ (ip是虚拟机的ip)
CentOS7.3安装Docker及rabbitmq_第5张图片
输入账号密码: admin admin 登录:
CentOS7.3安装Docker及rabbitmq_第6张图片

  • 查看rabbitmq启动日志

[root@promote ~]# docker ps
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS                                                                                                                                                         NAMES
9bd6ffaa494a        rabbitmq:management   "docker-entrypoint.s…"   3 minutes ago       Up 3 minutes        4369/tcp, 0.0.0.0:1883->1883/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 0.0.0.0:15672->15672/tcp, 0.0.0.0:25672->25672/tcp, 0.0.0.0:61613->61613/tcp, 15671/tcp   myrabbit
[root@promote ~]# docker logs -f myrabbit
2020-02-20 00:41:25.644 [info] <0.8.0> Feature flags: list of feature flags found:
2020-02-20 00:41:25.644 [info] <0.8.0> Feature flags:   [ ] drop_unroutable_metric
2020-02-20 00:41:25.645 [info] <0.8.0> Feature flags:   [ ] empty_basic_get_metric
2020-02-20 00:41:25.645 [info] <0.8.0> Feature flags:   [ ] implicit_default_bindings
2020-02-20 00:41:25.645 [info] <0.8.0> Feature flags:   [ ] quorum_queue
2020-02-20 00:41:25.645 [info] <0.8.0> Feature flags:   [ ] virtual_host_metadata
2020-02-20 00:41:25.645 [info] <0.8.0> Feature flags: feature flag states written to disk: yes
2020-02-20 00:41:25.722 [info] <0.268.0> ra: meta data store initialised. 0 record(s) recovered
2020-02-20 00:41:25.722 [info] <0.273.0> WAL: recovering []
2020-02-20 00:41:25.724 [info] <0.277.0>
 Starting RabbitMQ 3.8.2 on Erlang 22.2.6
 Copyright (c) 2007-2019 Pivotal Software, Inc.
 Licensed under the MPL 1.1. Website: https://rabbitmq.com

  ##  ##      RabbitMQ 3.8.2
  ##  ##
  ##########  Copyright (c) 2007-2019 Pivotal Software, Inc.
  ######  ##
  ##########  Licensed under the MPL 1.1. Website: https://rabbitmq.com

  Doc guides: https://rabbitmq.com/documentation.html
  Support:    https://rabbitmq.com/contact.html
  Tutorials:  https://rabbitmq.com/getstarted.html
  Monitoring: https://rabbitmq.com/monitoring.html

  Logs: 

  Config file(s): /etc/rabbitmq/rabbitmq.conf

  Starting broker...2020-02-20 00:41:25.725 [info] <0.277.0>
 node           : rabbit@9bd6ffaa494a
 home dir       : /var/lib/rabbitmq
 config file(s) : /etc/rabbitmq/rabbitmq.conf
 cookie hash    : Z/H5mhsbaIGkU8XzO/7rPg==
 log(s)         : 
 database dir   : /var/lib/rabbitmq/mnesia/rabbit@9bd6ffaa494a
2020-02-20 00:41:25.739 [info] <0.277.0> Running boot step pre_boot defined by app rabbit
2020-02-20 00:41:25.739 [info] <0.277.0> Running boot step rabbit_core_metrics defined by app rabbit
2020-02-20 00:41:25.739 [info] <0.277.0> Running boot step rabbit_alarm defined by app rabbit
2020-02-20 00:41:25.747 [info] <0.283.0> Memory high watermark set to 207 MiB (217581158 bytes) of 518 MiB (543952896 bytes) total
2020-02-20 00:41:25.766 [info] <0.285.0> Enabling free disk space monitoring
2020-02-20 00:41:25.766 [info] <0.285.0> Disk free limit set to 50MB
……………………………………

11. 停止docker上的rabbitmq

docker ps -n 5 查看容器的id
docker stop 容器id

[root@promote ~]# docker ps -n 5
CONTAINER ID        IMAGE                 COMMAND                  CREATED             ST                                                ATUS              PORTS                                                                                                                                                                                                         NA                                                MES
9bd6ffaa494a        rabbitmq:management   "docker-entrypoint.s…"   3 hours ago         Up                                                 3 hours          4369/tcp, 0.0.0.0:1883->1883/tcp, 5671/tcp, 0.0.0.0:5672->5672/tcp, 0.0                                                .0.0:15672->15672/tcp, 0.0.0.0:25672->25672/tcp, 0.0.0.0:61613->61613/tcp, 15671/tcp   my                                                rabbit
[root@promote ~]# docker stop 9bd6ffaa494a
9bd6ffaa494a
[root@promote ~]# docker ps -n 5
CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS                       PORTS               NAMES
9bd6ffaa494a        rabbitmq:management   "docker-entrypoint.s…"   3 hours ago         Exited (137) 8 seconds ago                       myrabbit
[root@promote ~]#

12.Docker重启容器

docker restart 容器ID或容器名 :不管容器是否启动,直接重启容器

13.停止docker服务

[root@promote ~]# service  docker status
Redirecting to /bin/systemctl status docker.service
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: active (running) since 四 2020-02-20 08:28:57 CST; 14h ago
     Docs: https://docs.docker.com
 Main PID: 50122 (dockerd)
    Tasks: 11
   Memory: 28.3M
   CGroup: /system.slice/docker.service
           └─50122 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.s...

2月 20 08:28:56 promote.cache-dns.local dockerd[50122]: time="2020-02-20T08:28:56.73..."
2月 20 08:28:57 promote.cache-dns.local dockerd[50122]: time="2020-02-20T08:28:57.16..."
2月 20 08:28:57 promote.cache-dns.local dockerd[50122]: time="2020-02-20T08:28:57.26...2
2月 20 08:28:57 promote.cache-dns.local dockerd[50122]: time="2020-02-20T08:28:57.26...6
2月 20 08:28:57 promote.cache-dns.local dockerd[50122]: time="2020-02-20T08:28:57.28..."
2月 20 08:28:57 promote.cache-dns.local dockerd[50122]: time="2020-02-20T08:28:57.51..."
2月 20 08:28:57 promote.cache-dns.local systemd[1]: Started Docker Application Conta....
2月 20 12:06:05 promote.cache-dns.local dockerd[50122]: time="2020-02-20T12:06:05.14..."
2月 20 12:06:06 promote.cache-dns.local dockerd[50122]: time="2020-02-20T12:06:06.46..."
2月 20 23:08:02 promote.cache-dns.local dockerd[50122]: time="2020-02-20T23:08:02.51..."
Hint: Some lines were ellipsized, use -l to show in full.
[root@promote ~]#

上面状态中有这么一行:Active: active (running) since 四 2020-02-20 08:28:57 CST; 14h ago 显示docker正在运行, 执行下面的service docker stop命令后, Active: inactive (dead) ,Active的状态变成了inactive ,也就是docker服务已经停了

[root@promote ~]# service docker stop
Redirecting to /bin/systemctl stop docker.service
[root@promote ~]# service  docker status
Redirecting to /bin/systemctl status docker.service
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: https://docs.docker.com

2月 20 08:28:57 promote.cache-dns.local dockerd[50122]: time="2020-02-20T08:28:57.28..."
2月 20 08:28:57 promote.cache-dns.local dockerd[50122]: time="2020-02-20T08:28:57.51..."
2月 20 08:28:57 promote.cache-dns.local systemd[1]: Started Docker Application Conta....
2月 20 12:06:05 promote.cache-dns.local dockerd[50122]: time="2020-02-20T12:06:05.14..."
2月 20 12:06:06 promote.cache-dns.local dockerd[50122]: time="2020-02-20T12:06:06.46..."
2月 20 23:08:02 promote.cache-dns.local dockerd[50122]: time="2020-02-20T23:08:02.51..."
2月 20 23:12:07 promote.cache-dns.local systemd[1]: Stopping Docker Application Cont....
2月 20 23:12:07 promote.cache-dns.local dockerd[50122]: time="2020-02-20T23:12:07.48..."
2月 20 23:12:07 promote.cache-dns.local dockerd[50122]: time="2020-02-20T23:12:07.54..."
2月 20 23:12:07 promote.cache-dns.local systemd[1]: Stopped Docker Application Conta....
Hint: Some lines were ellipsized, use -l to show in full.
[root@promote ~]#

参考:
docker官网指导: https://docs.docker.com/install/linux/docker-ce/centos/
https://www.cnblogs.com/zhangjianbin/p/10014535.html
https://www.cnblogs.com/yufeng218/p/8370670.html
https://www.cnblogs.com/black-fact/p/10915435.html
安装docker,并配置使用阿里镜像

你可能感兴趣的:(Docker)