前言

最近在梳理公司的架构,想用 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. SmartSql = Dapper + MyBatis + Cache(Memory | Redis) + ZooKeeper + R/W Splitting + ......

    SmartSql Why 拥抱 跨平台 DotNet Core,是时候了. 高性能.高生产力,超轻量级的ORM.156kb (Dapper:168kb) So SmartSql TargetFrame ...

  2. JDK源码分析(4)之 LinkedList 相关

    LinkedList的源码大致分三个部分,双向循环链表的实现.List的API和Deque的API. 一.定义 public class LinkedList<E> extends Abs ...

  3. Java线程Thread的状态解析以及状态转换分析 多线程中篇(七)

    线程与操作系统中线程(进程)的概念同根同源,尽管千差万别. 操作系统中有状态以及状态的切换,Java线程中照样也有. State 在Thread类中有内部类 枚举State,用于抽象描述Java线程的 ...

  4. msf中exploit的web_delivery模块

    背景:目标设备存在远程文件包含漏洞或者命令注入漏洞,想在目标设备上加载webshell,但不想在目标设备硬盘上留下任何webshell文件信息 解决思路:让目标设备从远端服务器加载webshell代码 ...

  5. .Net基础——程序集与CIL

    1. 程序集和CIL: 程序集是由.NET语言的编译器接受源代码文件产生的输出文件,通常分为 exe和dll两类,其中exe包含Main入口方法可以双击执行,dll则需要被其他程序集调用执行. CIL ...

  6. nginx系列3:搭建一个静态资源web服务器

    搭建静态资源web服务器 1,创建静态页面 在nginx的安装目录(/usr/local/nginx)下创建文件夹webapplications/helloworld,然后创建一个名为index.ht ...

  7. 搞懂 JavaScript 继承原理

    在理解继承之前,需要知道 js 的三个东西: 什么是 JS 原型链 this 的值到底是什么 JS 的 new 到底是干什么的 1. 什么是 JS 原型链? 我们知道 JS 有对象,比如 var ob ...

  8. springboot之配置文件

    springboot在加载配置文件的时候是有先后顺序的,了解加载配置文件的先后顺序,可以减少编写程序出现错误 1 springboot加载配置文件的先后顺序如下: SpringApplication将 ...

  9. 配置ADB到Windows环境变量

    adb 命令可以帮我们快速的管理连接的手机设备,例如执行一些安装apk,卸载apk命令,对于熟悉linux系统的人,可以方便的管理手机目录操作手机文件,还可以通过adb命令查看手机的系统日志等操作. ...

  10. JMeter中文返回乱码

    JMeter中文返回乱码 结果树响应数据中文返回乱码 其实有几个方法: 在线程组->http请求的字符集里设置 ​ 在http 消息管理头中设置 ​ 3.如果以上方法还没有解决,请打开安装目录 ...