Rancher 快速上手指南操作(1)
该指南知道用户如何快速的部署Rancher Server 管理容器。
前提是假设你的机器已经安装好docker了。
1 确认 docker 的版本,下面是 ubuntu 的输出

[#63#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker version


[sudo] password for cloudsoar:


Client:


 Version:      1.9.1


 API version:  1.21


 Go version:   go1.4.3


 Git commit:   a34a1d5


 Built:        Fri Nov 20 17:56:04 UTC 2015


 OS/Arch:      linux/amd64


 


Server:


 Version:      1.9.1


 API version:  1.21


 Go version:   go1.4.3


 Git commit:   a34a1d5


 Built:        Fri Nov 20 17:56:04 UTC 2015


 OS/Arch:      linux/amd64


2 确认 docker 服务已经启动


[#64#cloudsoar@cloudsoar-virtual-machine ~]$sudo service docker status


● docker.service - Docker Application Container Engine


   Loaded: loaded (/lib/systemd/system/docker.service; disabled; vendor preset: enabled)


   Active: inactive (dead)


     Docs: https://docs.docker.com


 


[#9#cloudsoar@cloudsoar-virtual-machine ~]$service  docker start


==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===


Authentication is required to manage system services or units.


Authenticating as: cloudsoar,,, (cloudsoar)


Password:


 


[#10#cloudsoar@cloudsoar-virtual-machine ~]$service  docker status


● docker.service - Docker Application Container Engine


   Loaded: loaded (/lib/systemd/system/docker.service; disabled; vendor preset: enabled)


   Active: active (running) since 三 2016-03-16 13:48:08 CST; 3s ago


     Docs: https://docs.docker.com


 Main PID: 10526 (docker)


   CGroup: /system.slice/docker.service


           └─10526 /usr/bin/docker daemon -H fd://


我使用 sudo docker status 观察的时候,发现 docker 服务并没有启动,手动调用 service do

cker start 启动。然后再次查看,看到状态是 running 了。

3 启动 Rancher 服务器

Rancher 服务器是一个 Docker image,所以其软件本身不需要安装,只需要执行 Docker 命

令下载并且成功运行 Docker 服务器镜像即可。


[#13#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker run -d --restart=always -p 8080:8080 rancher/server


Unable to find image 'rancher/server:latest' locally


latest: Pulling from rancher/server


d46dba346816: Pulling fs layer


a2851d201e25: Pulling fs layer


b262e58356c2: Pulling fs layer


ceffdc5777c7: Pulling fs layer


a28d44434980: Pulling fs layer


f800a1597427: Pulling fs layer


60af5060daf4: Pull complete


b1dd93d5a711: Pull complete


0d7dfe35cf6a: Pull complete


58e93f0715e7: Pull complete


a9dbd765bf44: Pull complete


4bfcf74f9624: Pull complete


d330fcc1e464: Pull complete


3da33c2536ae: Pull complete


95241837a38f: Pull complete


ec54f4e41d98: Pull complete


cdc934c804b3: Pull complete


ab8a261178e3: Pull complete


89833fcf633e: Pull complete


7df15d047ef2: Pull complete


2c5bb9b85b2e: Pull complete


2517d3de4cde: Pull complete


dca61fda9ea4: Pull complete


8566ccc2c63c: Pull complete


720ffa009a71: Pull complete


3c65bd6b0c6d: Pull complete


f8b5f2d5eebe: Pull complete


9c495859a0e4: Pull complete


20bee38968e6: Pull complete


f80a8ea9cd3e: Pull complete


c9c864eb9bef: Pull complete


Digest: sha256:989c47a7eb94352826f420c48ec4d0343ef43aee83d619bfa064f1642f1811fb


Status: Downloaded newer image for rancher/server:latest


1613c4b9d70d6f39a82e6148a0ce08422cef3541de19de5d68dfed22196c4076



命令行参数解释:

docker run 的 -d 参数标示在后台运行, --restart=always 容器如果异常停止自动重启。-p 

8080:8080 把 Rancher 服务器的UI 对外服务(容器内)的端口 8080 ,绑定到到宿主机的

。 后面跟的镜像名 rancher/server ,Docker 会首先检查本地有没有这个镜像,

如果没有,Docker 会去 Docker Hub 将这个镜像下载下来,并且启动。

我这里下载了将近一个小时。

4 检查是否成功正确下载了 rancher/server 镜像


[#15#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker images


REPOSITORY                  TAG                 IMAGE ID            CREATED             VIRTUAL SIZE


ubuntu                      latest              001d664e2dd4        7 hours ago         188 MB


zhiyewang/apache2           latest              e9c0ce8fc3ae        23 hours ago        244.6 MB


rancher/server              latest              c9c864eb9bef        28 hours ago        768.2 MB


paulcos11/docker-tutorial   latest              e37931352714        9 days ago          587.8 MB


fedora                      latest              9bdb5101e5fc        11 days ago         204.7 MB


ubuntu                      14.04               8ed581e3fa7a        12 days ago         188 MB


hello-world                 latest              0a6ba66e537a        5 months ago        960 B


可以看到我这里成功下载了。

5 检查 Rancher 服务器容器是否已经正常运行


[#17#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker ps -a


CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS         PORTS                              NAMES


1613c4b9d70d        rancher/server      "/usr/bin/s6-svscan /"   5 minutes ago       Up 5 minutes   3306/tcp, 0.0.0.0:8080->8080/tcp   modest_bell


042ff0ac2af7        zhiyewang/apache2   "/bin/bash"              20 minutes ago      Up 20 minutes  elated_hoover


6 用浏览器打开 Rancher 服务器容器 UI 界面



[#20#cloudsoar@cloudsoar-virtual-machine ~]$ifconfig


eth0      Link encap:以太网  硬件地址 00:0c:29:72:dc:f7 


          inet 地址:192.168.2.28  广播:192.168.2.255  掩码:255.255.255.0


          inet6 地址: fe80::20c:29ff:fe72:dcf7/64 Scope:Link


          UP BROADCAST RUNNING MULTICAST  MTU:1500  跃点数:1


          接收数据包:571758 错误:0 丢弃:0 过载:0 帧数:0


          发送数据包:335098 错误:0 丢弃:0 过载:0 载波:0


          碰撞:0 发送队列长度:1000


          接收字节:620330947 (620.3 MB)  发送字节:125962556 (125.9 MB)



可以看到我的宿主机的 IP 是 192.168.2.28,之前我们通过 docker run 命令将 Rancher Serv

er 容器的 8080 端口绑定到了宿主机的 8080 端口。现在要想访问容器内部的网页,可以输入宿

主机器的 IP 和端口即可。


Rancher 快速上手指南操作(1)_docker


7  Rancher 服务器配置

7.1 添加账号

首次登录,还没有配置访问权限,为了安全期间,首先点击上面的 ACCESS CONTROL 来新建

一个本地账号和密码。

Rancher 快速上手指南操作(1)_服务器_02


输入自己要设置的账号和密码


Rancher 快速上手指南操作(1)_服务器_03


点击 Enable Local Authentication,打开本地验证,下次就需要输入用户名和密码才能登录了。

7.2 日志观测

单独开一个终端,打开 Rancher Server 容器的日志输出,观测:

命令是: sudo docker logs -f 容器ID 

7.3 添加主机

主机是 Rancher 工作的节点,类似服务器虚拟化的 Hypervisor,我们现在做 All-in-one 测试

,将宿主机添加到 Rancher 节点主机。


Rancher 快速上手指南操作(1)_服务器_04


选择 APPLICATIONS 下面的 Add Host,弹出的界面选择 Custom,将页面第 4 步出现的内

容复制粘贴下来。拿到宿主机的命令行执行。


Rancher 快速上手指南操作(1)_docker_05


7.4 安装 Rancher Agent

将上述的命令拷贝到宿主机粘贴执行


[#26#cloudsoar@cloudsoar-virtual-machine ~]$sudo docker run -d --privileged -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/rancher:/var/lib/rancher rancher/agent:v0.10.0 http://192.168.2.28:8080/v1/scripts/D7A384BCBAC6FF19B5FC:1458111600000:JFTgk9cNkZFY5iZVQM9kInyRmuw


[sudo] password for cloudsoar:


Unable to find image 'rancher/agent:v0.10.0' locally


v0.10.0: Pulling from rancher/agent


b3efe11ed0e2: Downloading 526.1 kB/65.69 MB


会自动下载 rancher/agent 镜像并运行。等待下载完毕。

查看一下进程,多出一个 rancher/agent 的进程,并且已经运行。

此时再回网页查看 Web 控制台界面,查看 Host 添加之后的结果。


Rancher 快速上手指南操作(1)_docker_06


可以看到已经多了一台活动主机(宿主机),上面运行一个 Rancher Server 容器,就是 Ranc

如果你有其他主机,也可以添加其他主机进来。

8 通过 Web UI 运行容器

现在通过图形界面来运行容器,而不是通过命令行。


Rancher 快速上手指南操作(1)_服务器_07


8.1 添加容器

 在 INFRASTRUCTURE 标签选择 CONTAINERS,选择 Add Container

1 输入 first_container 作为容器名称

 2 使用默认的 Ubuntu 14.04.3 镜像

 3 点击Create 按钮


Rancher 快速上手指南操作(1)_docker_08


点击创建即可。


Rancher 快速上手指南操作(1)_服务器_09


经过几秒钟可以看到多出一个 first_container 容器和一个 Network Agent。first_container

作为本测试创建的容器。

下面哪个 Network Agent 作用是用户主机之间的网络通信。


Rancher 快速上手指南操作(1)_docker_10


1 在新建的 Ubuntu 容器的菜单上点击向下按钮

 2 在Web 页面中选择运行 Shell 选项


Rancher 快速上手指南操作(1)_ubuntu_11


以后就可以在此操作容器了。如果您偏爱 CLI 命令行,可以直接到宿主机的命令行操作。