前言

最近在梳理公司的架构,想用 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. RabbitMQ消息队列(五)-安装amqp扩展并订阅/发布Demo(.Net Core版)

    publish发布消息 新建一个Asp.Net Core控制台项目:PublishDemo 安装Nuget包 Install-Package RabbitMQ.Client 添加命名空间引用 usin ...

  2. 补习系列(10)-springboot 之配置读取

    目录 简介 一.配置样例 二.如何注入配置 1. 缺省配置文件 2. 使用注解 3. 启动参数 还有.. 三.如何读取配置 @Value 注解 Environment 接口 @Configuratio ...

  3. ES6躬行记(18)——迭代器

    ES6将迭代器和生成器内置到语言中,不仅简化了数据处理和集合操作,还弥补了for.while等普通循环的不足,例如难以遍历无穷集合或自定义的树结构等. 迭代器(Iterator)是一种用于迭代的对象, ...

  4. Java多线程父子线程关系 多线程中篇(六)

    有的时候对于Java多线程,我们会听到“父线程.子线程”的概念. 严格的说,Java中不存在实质上的父子关系 没有方法可以获取一个线程的父线程,也没有方法可以获取一个线程所有的子线程 子线程的消亡与父 ...

  5. -1-0 Java 简介 java是什么 java简单介绍

    Java是一门纯粹的面向对象的高级的平台无关的编程语言 官网介绍: 了解 Java 技术  https://www.java.com/zh_CN/about/ 推荐词条: https://zh.wik ...

  6. Perl线程池

    Thread::Pool模块提供了Perl解释器线程的线程池,手册:https://metacpan.org/pod/Thread::Pool.

  7. webpack4.0各个击破(3)—— Assets篇

    目录 一. Assets资源的基本处理需求 二. webpack处理引用资源 2.1 资源打标 2.2 引用优化 2.3 sprites雪碧图合成 2.4 图片压缩及其他 webpack作为前端最火的 ...

  8. 第12章 添加对外部认证的支持 - Identity Server 4 中文文档(v1.0.0)

    注意 对于任何先决条件(例如模板),首先要查看概述. 接下来,我们将添加对外部认证的支持.这非常简单,因为您真正需要的是ASP.NET Core兼容的身份验证处理程序. ASP.NET Core本身支 ...

  9. 【Linux】Linux上安装Nginx

    本文介绍Linux环境安装Nginx,这里用的Linux系统是CentOS 7.2. 1. 从Nginx官网下载Nginx.这里用的版本为:1.13.6. 2. 将下载下来的Nginx上传到Linux ...

  10. python爬虫项目-爬取雪球网金融数据(关注、持续更新)

    (一)python金融数据爬虫项目 爬取目标:雪球网(起始url:https://xueqiu.com/hq#exchange=CN&firstName=1&secondName=1_ ...