前言

最近在梳理公司的架构,想用 VPS 先做一些测试,然后就开始踩坑了!我用 Vultr 新买了个 VPS。

安装的 CentOS 版本:

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

安装

先安装 Nginx,图方便,用了个自动脚本:

wget http://mirrors.linuxeye.com/oneinstack-full.tar.gz && tar xzf oneinstack-full.tar.gz && ./oneinstack/install.sh --nginx_option 1

安装 Nginx 成功,重启服务器,连接 SSH。

再安装 Docker:

# 移除旧版本的 Docker
yum remove docker \
  docker-client \
  docker-client-latest \
  docker-common \
  docker-latest \
  docker-latest-logrotate \
  docker-logrotate \
  docker-selinux \
  docker-engine-selinux \
  docker-engine
# 安装 Docker 依赖
yum install -y yum-utils device-mapper-persistent-data lvm2
# 添加源
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 更新 yum 缓存
yum makecache fast
# 安装 Docker-CE
yum install -y docker-ce
# 开启 Docker
systemctl start docker
# 安装 Docker Compose
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
# Docker 和 Swarm 相关防火墙配置
systemctl status firewalld
systemctl start firewalld
firewall-cmd --add-port=9010/tcp --permanent
firewall-cmd --add-port=9020/tcp --permanentfirewall-cmd --add-port=443/tcp --permanent
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=80/udp --permanentfirewall-cmd --add-port=22/tcp --permanent
firewall-cmd --add-port=22/udp --permanent
firewall-cmd --reload
systemctl restart docker
# 开机自启动
systemctl enable firewalld
systemctl enable docker

一顿操作下来,执行顺利,无任何差错 Perfect!!

# 这里说明一下如果开始 firewalld 服务被锁定:Unit is masked
# 需要先解除锁定,然后才能开放端口
systemctl unmask firewalld

重启的悲剧

Docker 安装成功后,只要重启了 VPS(不重启什么问题都没有),就会出现问题: SSH 连接不上了。

我重新安装了四遍才定位到是由于安装 Docker 重启导致 SSH 连接不上。前两次操作较多,没有定位到问题,期间我还升级了一下配置!!

尝试过的解决方案:

  • 万能重启大法:无效,依然连接不上 SSH。
  • IP 被河蟹了?TCP 阻断了?
    • 国内工具扫描 22 端口:关闭。国外工具扫描 22 端口:关闭。
    • 国内 Ping :不通。国外 Ping :不通。
    • 由此断定是服务器出现问题了。
  • 尝试在安装完毕后关闭防火墙:无效,依然连接不上 SSH。
  • 厂商有问题?我尝试切换机房,然而问题再次出现了。

至此我就有点凌乱了,我反复确认了下自己操作的步骤,没有问题啊!得了,去网上找答案,爬着梯子就开始逛各个论坛,最后我在 segmentfault 发现了一个问答:参考资料①,然后我看的了这个博文:参考资料②,最后找到了 Vultr 的官方文档:参考资料③。

解决问题

对于 CentOS 7 实例,Docker 团队和 RHEL 团队提供 Selinux 支持。它已在 Vultr 一键式应用程序上禁用,但可以通过编辑 /etc/selinux/config 文件再次启用。

Fully securing a system that runs containers is an involved task. This task includes minimizing the attack surface on the Docker daemon. For a system that intends to run containers comparable to how a normal system would run binary apps, it is not as much of a concern. But for multi-tenant container configurations, or container configurations that need isolation (such as for credit card processing), securing the Docker daemon is more important.

至此我重置了 VPS ,运行命令:

[root@dbn-seattle ~]# getenforce
Disabled

看到了 Selinux 的初始状态是禁止的状态。然后我安装 Docker ,安装完成后我再次运行命令:

[root@dbn-seattle ~]# getenforce
Permissive

这里发现 Selinux 打开了,我们需要手动关闭下:

[root@dbn-seattle ~]# vim /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

SELINUX 修改成 disabled ,然后重启 VPS ,一切正常!!!

参考资料

① https://segmentfault.com/q/1010000015306843/a-1020000016431863

② https://hunterx.xyz/install-docker-on-vultr-centos-vps.html

③ https://www.vultr.com/docs/one-click-docker

Vultr CentOS 7 安装 Docker的更多相关文章

  1. CentOS 7 安装 Docker

    CentOS 7 安装 Docker 这里介绍 ContOS 7 的安装 docker V1.2+,包括阿里云加速 docker 镜像下载的设置,这对提升使用 docker 体验至关重要.其他系统安装 ...

  2. 在RedHat/CentOS下安装Docker(不升级内核)

    由于内核版本问题,最初仅Ubuntu可以较好的支持Docker.不过,由于RedHat系列OS(REHL.CentOS)是目前主流的Linux服务器操作系统,所以令RedHat系列OS支持Docker ...

  3. 简单介绍一下在CentOS上安装Docker。

    简单介绍一下在CentOS上安装Docker. 前置条件: 64-bit 系统 kernel 3.10+ 1.检查内核版本,返回的值大于3.10即可. $ uname -r 2.使用 sudo 或 r ...

  4. Centos 下面安装 docker

    试过了虚拟机VM ,今天尝试在虚拟机centos 中安装 docker ,入门是看的阮一峰的http://www.ruanyifeng.com/blog/2018/02/docker-tutorial ...

  5. docker学习之路-centos下安装docker

    前言 我要在云服务器上做一个asp.net core的webapi应用,使用docker来部署应用,中间用到的任何组件包括nginx和sqlserver 2017都是用docker来装载运行,所以,这 ...

  6. Centos下安装Docker,并配置国内docker源

    Centos下安装Docker 替换为国内的yum源(可选): mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.re ...

  7. Docker学习笔记之-在CentOS中安装Docker

    上一节演示了如何 通过Xshell连接CentOS服务,链接:Docker学习笔记之-通过Xshell连接 CentOS服务 本节将演示 如何在CentOS中安装 Docker 第一步:更新系统包到最 ...

  8. CentOS 7 安装Docker

    1.安装前检查: a.内核版本 uname -a b.检查Device Mapper ls -l /sys/class/misc/device-mapper 2.安装Docker: a.更新系统包到最 ...

  9. CentOS 7安装Docker

    在虚拟机CentOS 7上安装Docker   ## 零:检查前提条件:   在Red Hat 和Red Hat系列的Linux发行版中,安装Docker所需的前提提交并不多.     ### 1.内 ...

随机推荐

  1. 【Java基础】【26网络编程】

    26.01_网络编程(网络编程概述)(了解) A:计算机网络 是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来,在网络操作系统,网络管理软件及网络通信协议的管理和协调下, ...

  2. SmartSql For Asp.Net Core 最佳实践

    常规操作 安装 SmartSql Install-Package SmartSql 安装 SmartSql.DIExtension Install-Package SmartSql.DIExtensi ...

  3. [八]基础数据类型之Double详解

    Double 基本数据类型double  的包装类 Double 类型的对象包含一个 double 类型的字段   属性简介 用来以二进制补码形式表示 double 值的比特位数 public sta ...

  4. ubuntu 修改网卡名称 更改设备网卡名称 修改eno16777736为eth0 ubuntu 15.10网卡名称为eno16777736

    ubuntu linux 进入root用户,管理员模式 编辑这个文件需要管理员模式 在GRUB_CMD_LINUX后面增加图中所示 看到这个地方了没,有提示信息的,想要改变这个文件,记得运行 upda ...

  5. 大前端的自动化工厂(2)—— SB Family

    原文链接:https://bbs.huaweicloud.com/blogs/53c0c3509b7a11e89fc57ca23e93a89f 我坦白我是标题党,SB只是SCSS-Bourbon的简写 ...

  6. 第35章 秘密(secrets) - Identity Server 4 中文文档(v1.0.0)

    在某些情况下,客户端需要使用身份服务器进行身份验证,例如 在令牌端点请求令牌的机密应用程序(也称为客户端) API在内省端点验证引用令牌 为此,您可以将秘密列表分配给客户端或API资源. 秘密解析和验 ...

  7. [转]gitlab配置通过smtp发送邮件(QQ exmail腾讯企业为例)

    本文转自:http://www.fayfox.com/post/39.html 首先祭出官网文档链接:https://docs.gitlab.com/omnibus/settings/smtp.htm ...

  8. .NET Core[MVC] 利用特性捕捉异常

    声明:本方式适用于MVC.本代码只适用于.NET Core MVC. 先创建一个类继承ExceptionFilterAttribute这个抽象类,并override它的方法OnException. 代 ...

  9. sql 参数化查询问题

    一.正确案例 string name=“梅”; string sql="select * from test where  Name  like @Name"; //包含 梅Sql ...

  10. C# 设置Excel条件格式(二)

    上一篇文章中介绍了关于设置Excel条件格式,包括基于单元格值.自定义公式等应用条件格式.应用数据条条件类型格式.删除条件格式等内容.在本篇文章中将继续介绍C# 设置条件格式的方法. 要点概述: 1. ...