Merge pull request #3075 from GOLinux/master

[Translated]20150612 How to Configure Swarm Native Clustering for Docker.md
This commit is contained in:
joeren 2015-07-27 09:32:09 +08:00
commit bc359a7605
2 changed files with 95 additions and 96 deletions

View File

@ -1,96 +0,0 @@
Translating by GOLinux!
How to Configure Swarm Native Clustering for Docker
================================================================================
Hi everyone, today we'll learn about Swarm and how we can create native clusters using Docker with Swarm. [Docker Swarm][1] is a native clustering program for Docker which turns a pool of Docker hosts into a single virtual host. Swarm serves the standard Docker API, so any tool which can communicate with a Docker daemon can use Swarm to transparently scale to multiple hosts. Swarm follows the "batteries included but removable" principle as other Docker Projects. It ships with a simple scheduling backend out of the box, and as initial development settles, an API will develop to enable pluggable backends. The goal is to provide a smooth out-of-box experience for simple use cases, and allow swapping in more powerful backends, like Mesos, for large scale production deployments. Swarm is extremely easy to setup and get started.
So, here are some features of Swarm 0.2 out of the box.
1. Swarm 0.2.0 is about 85% compatible with the Docker Engine.
2. It supports Resource Management.
3. It has Advanced Scheduling feature with constraints and affinities.
4. It supports multiple Discovery Backends (hubs, consul, etcd, zookeeper)
5. It uses TLS encryption method for security and authentication.
So, here are some very simple and easy steps on how we can use Swarm.
### 1. Pre-requisites to run Swarm ###
We must install Docker 1.4.0 or later on all nodes. While each node's IP need not be public, the Swarm manager must be able to access each node across the network.
Note: Swarm is currently in beta, so things are likely to change. We don't recommend you use it in production yet.
### 2. Creating Swarm Cluster ###
Now, we'll create swarm cluster by running the below command. Each node will run a swarm node agent. The agent registers the referenced Docker daemon, monitors it, and updates the discovery backend with the node's status. The below command returns a token which is a unique cluster id, it will be used when starting the Swarm Agent on nodes.
# docker run swarm create
![Creating Swarm Cluster](http://blog.linoxide.com/wp-content/uploads/2015/05/creating-swarm-cluster.png)
### 3. Starting the Docker Daemon in each nodes ###
We'll need to login into each node that we'll use to create clusters and start the Docker Daemon into it using flag -H . It ensures that the docker remote API on the node is available over TCP for the Swarm Manager. To do start the docker daemon, we'll need to run the following command inside the nodes.
# docker -H tcp://0.0.0.0:2375 -d
![Starting Docker Daemon](http://blog.linoxide.com/wp-content/uploads/2015/05/starting-docker-daemon.png)
### 4. Adding the Nodes ###
After enabling Docker Daemon, we'll need to add the Swarm Nodes to the discovery service. We must ensure that node's IP must be accessible from the Swarm Manager. To do so, we'll need to run the following command.
# docker run -d swarm join --addr=<node_ip>:2375 token://<cluster_id>
![Adding Nodes to Cluster](http://blog.linoxide.com/wp-content/uploads/2015/05/adding-nodes-to-cluster.png)
**Note**: Here, we'll need to replace <node_ip> and <cluster_id> with the IP address of the Node and the cluster ID we got from step 2.
### 5. Starting the Swarm Manager ###
Now, as we have got the nodes connected to the cluster. Now, we'll start the swarm manager, we'll need to run the following command in the node.
# docker run -d -p <swarm_port>:2375 swarm manage token://<cluster_id>
![Starting Swarm Manager](http://blog.linoxide.com/wp-content/uploads/2015/05/starting-swarm-manager.png)
### 6. Checking the Configuration ###
Once the manager is running, we can check the configuration by running the following command.
# docker -H tcp://<manager_ip:manager_port> info
![Accessing Swarm Clusters](http://blog.linoxide.com/wp-content/uploads/2015/05/accessing-swarm-cluster.png)
**Note**: We'll need to replace <manager_ip:manager_port> with the ip address and port of the host running the swarm manager.
### 7. Using the docker CLI to access nodes ###
After everything is done perfectly as explained above, this part is the most important part of the Docker Swarm. We can use Docker CLI to access the nodes and run containers on them.
# docker -H tcp://<manager_ip:manager_port> info
# docker -H tcp://<manager_ip:manager_port> run ...
### 8. Listing nodes in the cluster ###
We can get a list of all of the running nodes using the swarm list command.
# docker run --rm swarm list token://<cluster_id>
![Listing Swarm Nodes](http://blog.linoxide.com/wp-content/uploads/2015/05/listing-swarm-nodes.png)
### Conclusion ###
Swarm is really an awesome feature of docker that can be used for creating and managing clusters. It is pretty easy to setup and use. It is more beautiful when we use constraints and affinities on top of it. Advanced Scheduling is an awesome feature of it which applies filters to exclude nodes with ports, labels, health and it uses strategies to pick the best node. So, if you have any questions, comments, feedback please do write on the comment box below and let us know what stuffs needs to be added or improved. Thank You! Enjoy :-)
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-how-to/configure-swarm-clustering-docker/
作者:[Arun Pyasi][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://linoxide.com/author/arunp/
[1]:https://docs.docker.com/swarm/

View File

@ -0,0 +1,95 @@
为Docker配置Swarm本地集群
================================================================================
大家好。今天我们来学一学Swarm相关的内容吧我们将学习通过Swarm来创建Docker本地集群。[Docker Swarm][1]是用于Docker的本地集群项目它可以将Docker主机池转换成单个的虚拟主机。Swarm提供了标准的Docker API,所以任何可以和Docker守护进程通信的工具都可以使用Swarm来透明地规模化多个主机。Swarm遵循“包含电池并可拆卸”的原则就像其它Docker项目一样。它附带有一个开箱即用的简单的后端调度程序而且作为初始开发套件也为其开发了一个可启用即插即用后端的API。其目标在于为一些简单的使用情况提供一个平滑的、开箱即用的体验并且它允许在更强大的后端如Mesos中开启交换以达到大量生产部署的目的。Swarm配置和使用极其简单。
这里给大家提供Swarm 0.2开箱的即用一些特性。
1. Swarm 0.2.0大约85%与Docker引擎兼容。
2. 它支持资源管理。
3. 它具有一些带有限制器和类同器高级调度特性。
4. 它支持多个发现后端hubsconsuletcdzookeeper
5. 它使用TLS加密方法进行安全通信和验证。
那么我们来看一看Swarm的一些相当简单而简易的使用步骤吧。
### 1. 运行Swarm的先决条件 ###
我们必须在所有节点安装Docker 1.4.0或更高版本。虽然哥哥节点的IP地址不需要要公共地址但是Swarm管理器必须可以通过网络访问各个节点。
注意Swarm当前还处于beta版本因此功能特性等还有可能发生改变我们不推荐你在生产环境中使用。
### 2. 创建Swarm集群 ###
现在我们将通过运行下面的命令来创建Swarm集群。各个节点都将运行一个swarm节点代理该代理会注册、监控相关的Docker守护进程并更新发现后端获取的节点状态。下面的命令会返回一个唯一的集群ID标记在启动节点上的Swarm代理时会用到它。
# docker run swarm create
![Creating Swarm Cluster](http://blog.linoxide.com/wp-content/uploads/2015/05/creating-swarm-cluster.png)
### 3. 启动各个节点上的Docker守护进程 ###
我们需要使用-H标记登陆进我们将用来创建几圈和启动Docker守护进程的各个节点它会保证Swarm管理器能够通过TCP访问到各个节点上的Docker远程API。要启动Docker守护进程我们需要在各个节点内部运行以下命令。
# docker -H tcp://0.0.0.0:2375 -d
![Starting Docker Daemon](http://blog.linoxide.com/wp-content/uploads/2015/05/starting-docker-daemon.png)
### 4. 添加节点 ###
在启用Docker守护进程后我们需要添加Swarm节点到发现服务我们必须确保节点IP可从Swarm管理器访问到。要完成该操作我们需要运行以下命令。
# docker run -d swarm join --addr=<node_ip>:2375 token://<cluster_id>
![Adding Nodes to Cluster](http://blog.linoxide.com/wp-content/uploads/2015/05/adding-nodes-to-cluster.png)
** 注意**我们需要用步骤2中获取到的节点IP地址和集群ID替换这里的<node_ip><cluster_id>
### 5. 开启Swarm管理器 ###
现在由于我们已经获得了连接到集群的节点我们将启动swarm管理器。我们需要在节点中运行以下命令。
# docker run -d -p <swarm_port>:2375 swarm manage token://<cluster_id>
![Starting Swarm Manager](http://blog.linoxide.com/wp-content/uploads/2015/05/starting-swarm-manager.png)
### 6. 检查配置 ###
一旦管理运行起来后,我们可以通过运行以下命令来检查配置。
# docker -H tcp://<manager_ip:manager_port> info
![Accessing Swarm Clusters](http://blog.linoxide.com/wp-content/uploads/2015/05/accessing-swarm-cluster.png)
** 注意**:我们需要替换<manager_ip:manager_port>为运行swarm管理器的主机的IP地址和端口。
### 7. 使用docker CLI来访问节点 ###
在一切都像上面说得那样完美地完成后这一部分是Docker Swarm最为重要的部分。我们可以使用Docker CLI来访问节点并在节点上运行容器。
# docker -H tcp://<manager_ip:manager_port> info
# docker -H tcp://<manager_ip:manager_port> run ...
### 8. 监听集群中的节点 ###
我们可以使用swarm list命令来获取所有运行中节点的列表。
# docker run --rm swarm list token://<cluster_id>
![Listing Swarm Nodes](http://blog.linoxide.com/wp-content/uploads/2015/05/listing-swarm-nodes.png)
### 尾声 ###
Swarm真的是一个有着相当不错的功能的docker它可以用于创建和管理集群。它相当易于配置和使用当我们在它上面使用限制器和类同器师它更为出色。高级调度程序是一个相当不错的特性它可以应用过滤器来通过端口、标签、健康状况来排除节点并且它使用策略来挑选最佳节点。那么如果你有任何问题、评论、反馈请在下面的评论框中写出来吧好让我们知道哪些材料需要补充或改进。谢谢大家了尽情享受吧 :-)
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-how-to/configure-swarm-clustering-docker/
作者:[Arun Pyasi][a]
译者:[GOLinux](https://github.com/GOLinux)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://linoxide.com/author/arunp/
[1]:https://docs.docker.com/swarm/