在Ubuntu 16.04上安装Rancher

介绍

Rancher是运行容器和构建私有容器服务的开源平台。 Rancher基于Docker,因此您可以在专用的box,KVM机器上甚至LXC容器上运行它。 Rancher提供了一个庞大的应用程序库,只需点击几下即可安装,并且还支持来自Dockerhub的Docker镜像。

要求

  • 一个Vultr实例Ubuntu 16.04 x64。
  • 至少1GB内存。
  • 支持的Docker版本。

安装Docker

如上所述,Docker需要运行Rancher,所以我们会先安装它。

首先,如有必要,删除所有旧的Docker文件。

sudo apt-get remove docker docker-engine docker.io

注意:您可能会收到没有安装Docker文件的报告。 这是可以忽略的。

更新软件包列表。

sudo apt-get update

允许apt通过HTTPS使用存储库。

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

添加官方的GPG密钥。

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

通过搜索密钥指纹的最后8位数字来验证您是否拥有密钥。

sudo apt-key fingerprint 0EBFCD88

输出将类似于以下文本。

pub  4096R/0EBFCD88 2017-02-22
      Key fingerprint = 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid                  Docker Release (CE deb) <docker@docker.com>
sub  4096R/F273FCD8 2017-02-22

添加一个稳定的repo。

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

再次更新软件包列表。

sudo apt-get update

检查Docker CE的可用版本。

apt-cache madison docker-ce

您将看到类似于以下块的输出。

docker-ce | 17.09.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.09.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.06.2~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.06.1~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.06.0~ce-0~ubuntu | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.03.2~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.03.1~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages
docker-ce | 17.03.0~ce-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu xenial/stable amd64 Packages

在以下命令中追加=后的最新稳定版本的版本字符串(第二列)以安装最新版本的Docker CE。

sudo apt-get install docker-ce=17.09.1~ce-0~ubuntu 

注意:您可以安装最新版本的Docker CE,而无需将版本附加到sudo apt-get install docker-ce命令的末尾,但在生产环境中,我建议您安装特定版本而不是最新版本。

确认Docker安装正确。

sudo docker run hello-world

该命令在测试容器中运行测试图像以打印消息,然后退出。 该消息将与以下输出类似。

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

安装Rancher

现在我们准备安装Rancher。

sudo docker run -d --restart=unless-stopped -p 8080:8080 rancher/server:stable

等待几分钟让Rancher UI启动。 然后,打开您最喜欢的浏览器并转到服务器上的端口8080。

http://192.0.2.0:8080

请务必将192.0.2.0替换为您的实际服务器的IP地址。

Rancher默认情况下不配置访问控制,因此立即设置它非常重要,否则拥有您的IP的任何人都可以访问UI和API。

将鼠标悬停在管理员标签上,然后点击访问控制。

按照Rancher UI中的说明设置您喜欢的任何形式的访问控制。

结论

现在已经安装了所有东西,您可以开始配置Rancher。 有关配置和使用Rancher的更多深入信息,请访问其官方文档

相关推荐