This commit is contained in:
ZTinoZ 2015-07-30 15:29:52 +08:00
commit 7f9004cb01
7 changed files with 342 additions and 260 deletions

View File

@ -1,34 +1,37 @@
为Docker配置Swarm本地集群
如何配置一个 Docker Swarm 原生集群
================================================================================
大家好。今天我们来学一学Swarm相关的内容吧我们将学习通过Swarm来创建Docker本地集群。[Docker Swarm][1]是用于Docker的本地集群项目它可以将Docker主机池转换成单个的虚拟主机。Swarm提供了标准的Docker API,所以任何可以和Docker守护进程通信的工具都可以使用Swarm来透明地规模化多个主机。Swarm遵循“包含电池并可拆卸”的原则就像其它Docker项目一样。它附带有一个开箱即用的简单的后端调度程序而且作为初始开发套件也为其开发了一个可启用即插即用后端的API。其目标在于为一些简单的使用情况提供一个平滑的、开箱即用的体验并且它允许在更强大的后端如Mesos中开启交换以达到大量生产部署的目的。Swarm配置和使用极其简单。
大家好。今天我们来学一学Swarm相关的内容吧我们将学习通过Swarm来创建Docker原生集群。[Docker Swarm][1]是用于Docker的原生集群项目它可以将一个Docker主机池转换成单个的虚拟主机。Swarm工作于标准的Docker API所以任何可以和Docker守护进程通信的工具都可以使用Swarm来透明地伸缩到多个主机上。就像其它Docker项目一样Swarm遵循“内置电池并可拆卸”的原则LCTT 译注batteries included内置电池原来是 Python 圈里面对 Python 的一种赞誉指自给自足无需外求的丰富环境but removable并可拆卸应该指的是非强制耦合。它附带有一个开箱即用的简单的后端调度程序而且作为初始开发套件也为其开发了一个可插拔不同后端的API。其目标在于为一些简单的使用情况提供一个平滑的、开箱即用的体验并且它允许切换为更强大的后端如Mesos以用于大规模生产环境部署。Swarm配置和使用极其简单。
这里给大家提供Swarm 0.2开箱的即用一些特性。
1. Swarm 0.2.0大约85%与Docker引擎兼容。
2. 它支持资源管理。
3. 它具有一些带有限制器和类同器高级调度特性。
3. 它具有一些带有限制和类同功能的高级调度特性。
4. 它支持多个发现后端hubsconsuletcdzookeeper
5. 它使用TLS加密方法进行安全通信和验证。
那么我们来看一看Swarm的一些相当简单而简的使用步骤吧。
那么我们来看一看Swarm的一些相当简单而简的使用步骤吧。
### 1. 运行Swarm的先决条件 ###
我们必须在所有节点安装Docker 1.4.0或更高版本。虽然哥哥节点的IP地址不需要要公共地址但是Swarm管理器必须可以通过网络访问各个节点。
我们必须在所有节点安装Docker 1.4.0或更高版本。虽然各个节点的IP地址不需要要公共地址但是Swarm管理器必须可以通过网络访问各个节点。
注意Swarm当前还处于beta版本因此功能特性等还有可能发生改变我们不推荐你在生产环境中使用。
**注意**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守护进程我们需要在各个节点内部运行以下命令。
我们需要登录进我们将用来创建集群的每个节点,并在其上使用-H标记启动Docker守护进程。它会保证Swarm管理器能够通过TCP访问到各个节点上的Docker远程API。要启动Docker守护进程我们需要在各个节点内部运行以下命令。
# docker -H tcp://0.0.0.0:2375 -d
@ -42,7 +45,7 @@
![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>
**注意**我们需要用步骤2中获取到的节点IP地址和集群ID替换这里的<node_ip><cluster_id>
### 5. 开启Swarm管理器 ###
@ -60,7 +63,7 @@
![Accessing Swarm Clusters](http://blog.linoxide.com/wp-content/uploads/2015/05/accessing-swarm-cluster.png)
** 注意**:我们需要替换<manager_ip:manager_port>为运行swarm管理器的主机的IP地址和端口。
**注意**:我们需要替换<manager_ip:manager_port>为运行swarm管理器的主机的IP地址和端口。
### 7. 使用docker CLI来访问节点 ###
@ -79,7 +82,7 @@
### 尾声 ###
Swarm真的是一个有着相当不错的功能的docker它可以用于创建和管理集群。它相当易于配置和使用当我们在它上面使用限制器和类同器它更为出色。高级调度程序是一个相当不错的特性,它可以应用过滤器来通过端口、标签、健康状况来排除节点,并且它使用策略来挑选最佳节点。那么,如果你有任何问题、评论、反馈,请在下面的评论框中写出来吧,好让我们知道哪些材料需要补充或改进。谢谢大家了!尽情享受吧 :-)
Swarm真的是一个有着相当不错的功能的docker它可以用于创建和管理集群。它相当易于配置和使用当我们在它上面使用限制器和类同器它更为出色。高级调度程序是一个相当不错的特性,它可以应用过滤器来通过端口、标签、健康状况来排除节点,并且它使用策略来挑选最佳节点。那么,如果你有任何问题、评论、反馈,请在下面的评论框中写出来吧,好让我们知道哪些材料需要补充或改进。谢谢大家了!尽情享受吧 :-)
--------------------------------------------------------------------------------
@ -87,7 +90,7 @@ via: http://linoxide.com/linux-how-to/configure-swarm-clustering-docker/
作者:[Arun Pyasi][a]
译者:[GOLinux](https://github.com/GOLinux)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,14 +1,12 @@
每个Linux人应知应会的12个有用的PHP命令行用法
在 Linux 命令行中使用和执行 PHP 代码12 个 PHP 交互性 shell 的用法
================================================================================
我上一篇文章“[在Linux命令行中使用并执行PHP代码][1]”中我同时着重讨论了直接在Linux命令行中运行PHP代码以及在Linux终端中执行PHP脚本文件。
上一篇文章“[在 Linux 命令行中使用和执行 PHP 代码(一)][1]”中我同时着重讨论了直接在Linux命令行中运行PHP代码以及在Linux终端中执行PHP脚本文件。
![Run PHP Codes in Linux Commandline](http://www.tecmint.com/wp-content/uploads/2015/07/Run-PHP-Codes-in-Linux-Commandline.jpeg)
在Linux命令行运行PHP代码——第二部分
本文旨在让你了解一些相当不错的Linux终端中的PHP交互性 shell 的用法特性。
本文旨在让你了解一些相当不错的Linux终端中的PHP用法特性。
让我们先在PHP交互shell中来对`php.ini`设置进行一些配置吧。
让我们先在PHP 的交互shell中来对`php.ini`设置进行一些配置吧。
**6. 设置PHP命令行提示符**
@ -21,7 +19,8 @@
php > #cli.prompt=Hi Tecmint ::
![Enable PHP Interactive Shell](http://www.tecmint.com/wp-content/uploads/2015/07/Enable-PHP-Interactive-Shell.png)
启用PHP交互Shell
*启用PHP交互Shell*
同时,你也可以设置当前时间作为你的命令行提示符,操作如下:
@ -31,20 +30,22 @@
**7. 每次输出一屏**
在我们上一篇文章中,我们已经在原始命令中通过管道在很多地方使用了less命令。通过该操作我们可以在那些不能一次满屏输出的地方获得每次一屏的输出。但是我们可以通过配置php.ini文件设置pager的值为less以每次输出一屏操作如下
在我们上一篇文章中,我们已经在原始命令中通过管道在很多地方使用了`less`命令。通过该操作,我们可以在那些不能一屏全部输出的地方获得分屏显示。但是我们可以通过配置php.ini文件设置pager的值为less以每次输出一屏操作如下
$ php -a
php > #cli.pager=less
![Fix PHP Screen Output](http://www.tecmint.com/wp-content/uploads/2015/07/Fix-PHP-Screen-Output.png)
固定PHP屏幕输出
*限制PHP屏幕输出*
这样,下次当你运行一个命令(比如说条调试器`phpinfo();`)的时候,而该命令的输出内容又太过庞大而不能固定在一屏,它就会自动产生适合你当前屏幕的输出结果。
php > phpinfo();
![PHP Info Output](http://www.tecmint.com/wp-content/uploads/2015/07/PHP-Info-Output.png)
PHP信息输出
*PHP信息输出*
**8. 建议和TAB补全**
@ -58,50 +59,53 @@ PHP shell足够智能它可以显示给你建议和进行TAB补全你可
php > #cli.pager [TAB]
你可以一直按TAB键来获得选项,直到选项值满足要求。所有的行为都将记录到`~/.php-history`文件。
你可以一直按TAB键来获得建议的补全,直到该值满足要求。所有的行为都将记录到`~/.php-history`文件。
要检查你的PHP交互shell活动日志你可以执行
$ nano ~/.php_history | less
![Check PHP Interactive Shell Logs](http://www.tecmint.com/wp-content/uploads/2015/07/Check-PHP-Interactive-Shell-Logs.png)
检查PHP交互Shell日志
*检查PHP交互Shell日志*
**9. 你可以在PHP交互shell中使用颜色你所需要知道的仅仅是颜色代码。**
使用echo来打印各种颜色的输出结果看我信手拈来
使用echo来打印各种颜色的输出结果类似这样
php > echo “color_code1 TEXT second_color_code”;
php > echo "color_code1 TEXT second_color_code";
一个更能说明问题的例子是:
具体来说是:
php > echo "\033[0;31m Hi Tecmint \x1B[0m";
![Enable Colors in PHP Shell](http://www.tecmint.com/wp-content/uploads/2015/07/Enable-Colors-in-PHP-Shell.png)
在PHP Shell中启用彩色
*在PHP Shell中启用彩色*
到目前为止我们已经看到按回车键意味着执行命令然而PHP Shell中各个命令结尾的分号是必须的。
**10. PHP shell中的用以打印后续组件的路径名称**
**10. 在PHP shell中用basename()输出路径中最后一部分**
PHP shell中的basename函数从给出的包含有到文件或目录路径的后续组件的路径名称
PHP shell中的basename函数可以从给出的包含有到文件或目录路径的最后部分
basename()样例#1和#2。
php > echo basename("/var/www/html/wp/wp-content/plugins");
php > echo basename("www.tecmint.com/contact-us.html");
上述两个样例将输出:
上述两个样例将输出:
plugins
contact-us.html
![Print Base Name in PHP](http://www.tecmint.com/wp-content/uploads/2015/07/Print-Base-Name-in-PHP.png)
在PHP中打印基本名称
*在PHP中打印基本名称*
**11. 你可以使用PHP交互shell在你的桌面创建文件比如说test1.txt就像下面这么简单**
$ touch("/home/avi/Desktop/test1.txt");
php> touch("/home/avi/Desktop/test1.txt");
我们已经见识了PHP交互shell在数学运算中有多优秀这里还有更多一些例子会令你吃惊。
@ -112,7 +116,8 @@ strlen函数用于获取指定字符串的长度。
php > echo strlen("tecmint.com");
![Print Length String in PHP](http://www.tecmint.com/wp-content/uploads/2015/07/Print-Length-String-in-PHP.png)
在PHP中打印字符串长度
*在PHP中打印字符串长度*
**13. PHP交互shell可以对数组排序是的你没听错**
@ -137,9 +142,10 @@ strlen函数用于获取指定字符串的长度。
)
![Sort Arrays in PHP](http://www.tecmint.com/wp-content/uploads/2015/07/Sort-Arrays-in-PHP.png)
在PHP中对数组排序
**14. 在PHP交互Shell中获取Pi的值**
*在PHP中对数组排序*
**14. 在PHP交互Shell中获取π的值**
php > echo pi();
@ -151,14 +157,15 @@ strlen函数用于获取指定字符串的长度。
12.247448713916
**16. 从0-10的范围内回显一个随机数**
**16. 从0-10的范围内挑选一个随机数**
php > echo rand(0, 10);
![Get Random Number in PHP](http://www.tecmint.com/wp-content/uploads/2015/07/Get-Random-Number-in-PHP.png)
在PHP中获取随机数
**17. 获取某个指定字符串的md5sum和sha1sum例如让我们在PHP Shell中检查某个字符串比如说avi的md5sum和sha1sum并交叉检查这些带有bash shell生成的md5sum和sha1sum的结果。**
*在PHP中获取随机数*
**17. 获取某个指定字符串的md5校验和sha1校验例如让我们在PHP Shell中检查某个字符串比如说avi的md5校验和sha1校验并交叉校验bash shell生成的md5校验和sha1校验的结果。**
php > echo md5(avi);
3fca379b3f0e322b7b7967bfcfb948ad
@ -175,9 +182,10 @@ strlen函数用于获取指定字符串的长度。
8f920f22884d6fea9df883843c4a8095a2e5ac6f -
![Check md5sum and sha1sum in PHP](http://www.tecmint.com/wp-content/uploads/2015/07/Check-md5sum-and-sha1sum.png)
在PHP中检查md5sum和sha1sum
这里只是PHP Shell中所能获取的功能和PHP Shell的交互特性的惊鸿一瞥这些就是到现在为止我所讨论的一切。保持和tecmint的连线在评论中为我们提供你有价值的反馈吧。为我们点赞并分享帮助我们扩散哦。
*在PHP中检查md5校验和sha1校验*
这里只是PHP Shell中所能获取的功能和PHP Shell的交互特性的惊鸿一瞥这些就是到现在为止我所讨论的一切。保持连线在评论中为我们提供你有价值的反馈吧。为我们点赞并分享帮助我们扩散哦。
--------------------------------------------------------------------------------
@ -185,9 +193,9 @@ via: http://www.tecmint.com/execute-php-codes-functions-in-linux-commandline/
作者:[Avishek Kumar][a]
译者:[GOLinux](https://github.com/GOLinux)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/avishek/
[1]:http://www.tecmint.com/run-php-codes-from-linux-commandline/
[1]:https://linux.cn/article-5906-1.html

View File

@ -1,127 +0,0 @@
Translating by DongShuaike
How to Provision Swarm Clusters using Docker Machine
================================================================================
Hi all, today we'll learn how we can deploy Swarm Clusters using Docker Machine. It serves the standard Docker API, so any tool which can communicate with a Docker daemon can use Swarm to transparently scale to multiple hosts. Docker Machine is an application that helps to create Docker hosts on our computer, on cloud providers and inside our own data center. It provides easy solution for creating servers, installing Docker on them and then configuring the Docker client according the users configuration and requirements. We can provision swarm clusters with any driver we need and is highly secured with TLS Encryption.
Here are some quick and easy steps on how to provision swarm clusters with Docker Machine.
### 1. Installing Docker Machine ###
Docker Machine supports awesome on every Linux Operating System. First of all, we'll need to download the latest version of Docker Machine from the Github site . Here, we'll use curl to download the latest version of Docker Machine ie 0.2.0 .
For 64 Bit Operating System
# curl -L https://github.com/docker/machine/releases/download/v0.2.0/docker-machine_linux-amd64 > /usr/local/bin/docker-machine
For 32 Bit Operating System
# curl -L https://github.com/docker/machine/releases/download/v0.2.0/docker-machine_linux-i386 > /usr/local/bin/docker-machine
After downloading the latest release of Docker Machine, we'll make the file named docker-machine under /usr/local/bin/ executable using the command below.
# chmod +x /usr/local/bin/docker-machine
After doing the above, we'll wanna ensure that we have successfully installed docker-machine. To check it, we can run the docker-machine -v which will give output of the version of docker-machine installed in our system.
# docker-machine -v
![Installing Docker Machine](http://blog.linoxide.com/wp-content/uploads/2015/05/installing-docker-machine.png)
To enable Docker commands on our machines, make sure to install the Docker client as well by running the command below.
# curl -L https://get.docker.com/builds/linux/x86_64/docker-latest > /usr/local/bin/docker
# chmod +x /usr/local/bin/docker
### 2. Creating Machine ###
After installing Machine into our working PC or device, we'll wanna go forward to create a machine using Docker Machine. Here, in this tutorial we'll gonna deploy a machine in the Digital Ocean Platform so we'll gonna use "digitalocean" as its Driver API then, docker swarm will be running into that Droplet which will be further configured as Swarm Master and another droplet will be created which will be configured as Swarm Node Agent.
So, to create the machine, we'll need to run the following command.
# docker-machine create --driver digitalocean --digitalocean-access-token <API-Token> linux-dev
**Note**: Here, linux-dev is the name of the machine we are wanting to create. <API-Token> is a security key which can be generated from the Digital Ocean Control Panel of the account holder of Digital Ocean Cloud Platform. To retrieve that key, we simply need to login to our Digital Ocean Control Panel then click on API, then click on Generate New Token and give it a name tick on both Read and Write. Then we'll get a long hex key, thats the <API-Token> now, simply replace it into the command above.
Now, to load the Machine configuration into the shell we are running the comamands, run the following command.
# eval "$(docker-machine env linux-dev)"
![Docker Machine Digitalocean Cloud](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-digitalocean-cloud.png)
Then, we'll mark our machine as ACTIVE by running the below command.
# docker-machine active linux-dev
Now, we'll check whether its been marked as ACTIVE "*" or not.
# docker-machine ls
![Docker Machine Active List](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-active-list.png)
### 3. Running Swarm Docker Image ###
Now, after we finish creating the required machine. We'll gonna deploy swarm docker image in our active machine. This machine will run the docker image and will control over the Swarm master and node. To run the image, we can simply run the below command.
# docker run swarm create
![Docker Machine Swarm Create](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-swarm-create.png)
If you are trying to run swarm docker image using **32 bit Operating System** in the computer where Docker Machine is running, we'll need to SSH into the Droplet.
# docker-machine ssh
#docker run swarm create
#exit
### 4. Creating Swarm Master ###
Now, after our machine and swarm image is running into the machine, we'll now create a Swarm Master. This will also add the master as a node. To do so, here's the command below.
# docker-machine create \
-d digitalocean \
--digitalocean-access-token <DIGITALOCEAN-TOKEN>
--swarm \
--swarm-master \
--swarm-discovery token://<CLUSTER-ID> \
swarm-master
![Docker Machine Swarm Master Create](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-swarm-master-create.png)
### 5. Creating Swarm Nodes ###
Now, we'll create a swarm node which will get connected with the Swarm Master. The command below will create a new droplet which will be named as swarm-node and will get connected with the Swarm Master as node. This will create a Swarm cluster across the two nodes.
# docker-machine create \
-d digitalocean \
--digitalocean-access-token <DIGITALOCEAN-TOKEN>
--swarm \
--swarm-discovery token://<TOKEN-FROM-ABOVE> \
swarm-node
![Docker Machine Swarm Nodes](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-swarm-nodes.png)
### 6. Connecting to the Swarm Master ###
We, now connect to the Swarm Master so that we can deploy Docker containers across the nodes as per the requirement and configuration. To load the Swarm Master's Machine configuration into our environment, we can run the below command.
# eval "$(docker-machine env --swarm swarm-master)"
After that, we can run the required containers of our choice across the nodes. Here, we'll check if everything went fine or not. So, we'll run **docker info** to check the information about the Swarm Clusters.
# docker info
### Conclusion ###
We can pretty easily create Swarm Cluster with Docker Machine. This method is a lot productive because it reduces a lot of time of a system admin or users. In this article, we successfully provisioned clusters by creating a master and a node using a machine with Digital Ocean as driver. It can be created using any driver like VirtualBox, Google Cloud Computing, Amazon Web Service, Microsoft Azure and more according to the need and requirement of the user and the connection is highly secured with TLS Encryption. If you have any questions, suggestions, feedback please write them in the comment box below so that we can improve or update our contents. Thank you ! Enjoy :-)
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-how-to/provision-swarm-clusters-using-docker-machine/
作者:[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/

View File

@ -1,91 +0,0 @@
Translating by GOLinux!
Easy Backup, Restore and Migrate Containers in Docker
================================================================================
Today we'll learn how we can easily backup, restore and migrate docker containers out of the box. [Docker][1] is an open source platform that automates the deployment of applications with fast and easy way to pack, ship and run it under a lightweight layer of software called container. It makes the applications platform independent as it acts an additional layer of abstraction and automation of operating system level virtualization on Linux. It utilizes resource isolation features of Linux Kernel with its components cgroups and namespace for avoiding the overhead of virtual machines. It makes the great building blocks for deploying and scaling web apps, databases, and back-end services without depending on a particular stack or provider. Containers are those software layers which are created from a docker image that contains the respective linux filesystem and applications out of the box. If we have a docker container running in our box and need to backup those containers for future use or wanna migrate those containers, then this tutorial will help you how we can backup, restore and migrate docker containers in linux operating system.
Here are some easy steps on how we can backup, restore and migrate the docker containers in linux.
### 1. Backing up the Containers ###
First of all, in order to backup the containers in docker, we'll wanna see the list of containers that we wanna backup. To do so, we'll need to run docker ps in our linux machine running docker engine with containers already created.
# docker ps
![Docker Containers List](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-containers-list.png)
After that, we'll choose the containers we wanna backup and then we'll go for creating the snapshot of the container. We can use docker commit command in order to create the snapshot.
# docker commit -p 30b8f18f20b4 container-backup
![Docker Commit](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-commit.png)
This will generated a snapshot of the container as the docker image. We can see the docker image by running the command docker images as shown below.
# docker images
![Docker Images](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-images.png)
As we can see the snapshot that was taken above has been preserved as docker image. Now, inorder to backup that snapshot, we have two options, one is that we can login into the docker registry hub and push the image and the next is that we can backup the docker image as tarballs for further use.
If we wanna upload or backup the image in the [docker registry hub][2], we can simply run docker login command to login into the docker registry hub and then push the required image.
# docker login
![Docker Login](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-login.png)
# docker tag a25ddfec4d2a arunpyasi/container-backup:test
# docker push arunpyasi/container-backup
![Docker Push](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-push.png)
If we don't wanna backup to the docker registry hub and wanna save the image for future use in the machine locally then we can backup the image as tarballs. To do so, we'll need to run the following docker save command.
# docker save -o ~/container-backup.tar container-backup
![taking tarball backup](http://blog.linoxide.com/wp-content/uploads/2015/07/taking-tarball-backup.png)
To verify if the tarball has been generated or not, we can simply run docker ls inside the directory where we saved the tarball.
### 2. Restoring the Containers ###
Next, after we have successfully backed up our docker containers, we'll now go for restoring those contianers which are snapshotted as docker images. If we have pushed those docker images in the registry hub, then we can simply pull that docker image and run it out of the box.
# docker pull arunpyasi/container-backup:test
![Docker Pull](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-pull.png)
But if we have backed up those docker images locally as tarball file, then we can easy load that docker image using docker load command followed by the backed up tarball.
# docker load -i ~/container-backup.tar
Now, to ensure that those docker images have been loaded successfully, we'll run docker images command.
# docker images
After the images have been loaded, we'll gonna run the docker container from the loaded image.
# docker run -d -p 80:80 container-backup
![Restoring Docker Tarball](http://blog.linoxide.com/wp-content/uploads/2015/07/restoring-docker-tarballs.png)
### 3. Migrating the Docker Containers ###
Migrating the containers involve both the above process ie Backup and Restore. We can migrate any docker container from one machine to another. In the process of migration, first we take the backup of the container as snapshot docker image. Then, that docker image is either pushed to the docker registry hub or saved as tarball files in the locally. If we have pushed the image to the docker registry hub, we can easily restore and run the container using docker run command from any machine we want. But if we have saved the image as tarballs locally, we can simply copy or move the image to the machine where we want to load image and run the required container.
### Conclusion ###
Finally, we have learned how we can backup, restore and migrate the docker containers out of the box. This tutorial is exactly same for every platform of operating system where docker runs successfully. Really, docker is pretty simple and easy to use but very powerful tool. It has pretty easy to remember commands which are short enough with many simple but powerful flags and parameters. The above methods makes us comfortable to backup our containers so that we can restore them when needed in future. This can help us recover our containers and images even if our host system crashes or gets wiped out accidentally. If you have any questions, suggestions, feedback please write them in the comment box below so that we can improve or update our contents. Thank you ! Enjoy :-)
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-how-to/backup-restore-migrate-containers-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]:http://docker.com/
[2]:https://registry.hub.docker.com/

View File

@ -0,0 +1,72 @@
What is Logical Volume Management and How Do You Enable It in Ubuntu?
================================================================================
> Logical Volume Management (LVM) is a disk management option that every major Linux distribution includes. Whether you need to set up storage pools or just need to dynamically create partitions, LVM is probably what you are looking for.
### What is LVM? ###
Logical Volume Manager allows for a layer of abstraction between your operating system and the disks/partitions it uses. In traditional disk management your operating system looks for what disks are available (/dev/sda, /dev/sdb, etc.) and then looks at what partitions are available on those disks (/dev/sda1, /dev/sda2, etc.).
With LVM, disks and partitions can be abstracted to contain multiple disks and partitions into one device. Your operating systems will never know the difference because LVM will only show the OS the volume groups (disks) and logical volumes (partitions) that you have set up.
Because volume groups and logical volumes arent physically tied to a hard drive, it makes it easy to dynamically resize and create new disks and partitions. In addition, LVM can give you features that your file system is not capable of doing. For example, Ext3 does not have support for live snapshots, but if youre using LVM you have the ability to take a snapshot of your logical volumes without unmounting the disk.
### When Should You Use LVM? ###
The first thing your should consider before setting up LVM is what you want to accomplish with your disks and partitions. Some distributions, like Fedora, install with LVM by default.
If you are using Ubuntu on a laptop with only one internal hard drive and you dont need extended features like live snapshots, then you may not need LVM. If you need easy expansion or want to combine multiple hard drives into a single pool of storage then LVM may be what you have been looking for.
### Setting up LVM in Ubuntu ###
First thing to know about using LVM is there is no easy way to convert your existing traditional partitions to logical volumes. It is possible to move to a new partition that uses LVM, but that wont be something that we will cover in this article; instead we are going to take the approach of setting up LVM on a fresh installation of Ubuntu 10.10.
![](http://cdn3.howtogeek.com/wp-content/uploads/2010/12/ubuntu-10-banner.png)
To install Ubuntu using LVM you need to use the alternate install CD. Download it from the link below and burn a CD or [use unetbootin to create a USB drive][1].
![](http://cdn3.howtogeek.com/wp-content/uploads/2010/12/download-web.png)
Boot your computer from the alternate install disk and select your options up until the partition disks screen and select guided use entire disk and set up LVM.
*Note: This will format your entire hard drive so if you are trying to dual boot or have another installation select manual instead.*
![](http://cdn3.howtogeek.com/wp-content/uploads/2010/12/setup-1.png)
Select the main disk you want to use, typically your largest drive, and then go to the next step.
![](http://cdn3.howtogeek.com/wp-content/uploads/2010/12/setup-2.png)
You will immediately need to write the changes to disk so make sure you selected the right disk and then write the changes.
![](http://cdn3.howtogeek.com/wp-content/uploads/2010/12/setup-3.png)
Select the size you want the first logical volume to be and then continue.
![](http://cdn3.howtogeek.com/wp-content/uploads/2011/01/setup-4.png)
Confirm your disk partitions and continue with the installation.
![](http://cdn3.howtogeek.com/wp-content/uploads/2011/01/setup-5.png)
The final step will write the GRUB bootloader to the hard drive. It is important to note that GRUB cannot be on an LVM partition because computer BIOSes cannot directly read from a logical volume. Ubuntu will automatically create a 255 MB ext2 partition for your bootloader.
![](http://cdn3.howtogeek.com/wp-content/uploads/2011/01/setup-6.png)
After the installation is complete, reboot the machine and boot into Ubuntu as normal. There should be no perceivable difference between using LVM or traditional disk management with this type of installation.
![](http://cdn3.howtogeek.com/wp-content/uploads/2011/01/disk-manager.png)
To use LVM to its full potential, stay tuned for our upcoming article on managing your LVM installation.
--------------------------------------------------------------------------------
via: http://www.howtogeek.com/howto/36568/what-is-logical-volume-management-and-how-do-you-enable-it-in-ubuntu/
作者:[How-To Geek][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://plus.google.com/+howtogeek?prsrc=5
[1]:http://www.howtogeek.com/howto/13379/create-a-bootable-ubuntu-9.10-usb-flash-drive/

View File

@ -0,0 +1,125 @@
如何使用Docker Machine部署Swarm集群
================================================================================
大家好今天我们来研究一下如何使用Docker Machine部署Swarm集群。Docker Machine提供了独立的Docker API所以任何与Docker守护进程进行交互的工具都可以使用Swarm来透明地扩增到多台主机上。Docker Machine可以用来在个人电脑、云端以及的数据中心里创建Docker主机。它为创建服务器安装Docker以及根据用户设定配置Docker客户端提供了便捷化的解决方案。我们可以使用任何驱动来部署swarm集群并且swarm集群将由于使用了TLS加密具有极好的安全性。
下面是我提供的简便方法。
### 1. 安装Docker Machine ###
Docker Machine 在任何Linux系统上都被支持。首先我们需要从Github上下载最新版本的Docker Machine。我们使用curl命令来下载最先版本Docker Machine ie 0.2.0。
64位操作系统
# curl -L https://github.com/docker/machine/releases/download/v0.2.0/docker-machine_linux-amd64 > /usr/local/bin/docker-machine
32位操作系统
# curl -L https://github.com/docker/machine/releases/download/v0.2.0/docker-machine_linux-i386 > /usr/local/bin/docker-machine
下载了最先版本的Docker Machine之后我们需要对 /usr/local/bin/ 目录下的docker-machine文件的权限进行修改。命令如下
# chmod +x /usr/local/bin/docker-machine
在做完上面的事情以后我们必须确保docker-machine已经安装好。怎么检查呢运行docker-machine -v指令指令将会给出我们系统上所安装的docker-machine版本。
# docker-machine -v
![Installing Docker Machine](http://blog.linoxide.com/wp-content/uploads/2015/05/installing-docker-machine.png)
为了让Docker命令能够在我们的机器上运行必须还要在机器上安装Docker客户端。命令如下。
# curl -L https://get.docker.com/builds/linux/x86_64/docker-latest > /usr/local/bin/docker
# chmod +x /usr/local/bin/docker
### 2. 创建Machine ###
在将Docker Machine安装到我们的设备上之后我们需要使用Docker Machine创建一个machine。在这片文章中我们会将其部署在Digital Ocean Platform上。所以我们将使用“digitalocean”作为它的Driver API然后将docker swarm运行在其中。这个Droplet会被设置为Swarm主节点我们还要创建另外一个Droplet并将其设定为Swarm节点代理。
创建machine的命令如下
# docker-machine create --driver digitalocean --digitalocean-access-token <API-Token> linux-dev
**Note**: 假设我们要创建一个名为“linux-dev”的machine。<API-Token>是用户在Digital Ocean Cloud Platform的Digital Ocean控制面板中生成的密钥。为了获取这个密钥我们需要登录我们的Digital Ocean控制面板然后点击API选项之后点击Generate New Token起个名字然后在Read和Write两个选项上打钩。之后我们将得到一个很长的十六进制密钥这个就是<API-Token>了。用其替换上面那条命令中的API-Token字段。
现在运行下面的指令将Machine configuration装载进shell。
# eval "$(docker-machine env linux-dev)"
![Docker Machine Digitalocean Cloud](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-digitalocean-cloud.png)
然后我们使用如下命令将我们的machine标记为ACTIVE状态。
# docker-machine active linux-dev
现在我们检查是否它指machine被标记为了 ACTIVE "*"。
# docker-machine ls
![Docker Machine Active List](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-active-list.png)
### 3. 运行Swarm Docker镜像 ###
现在在我们创建完成了machine之后。我们需要将swarm docker镜像部署上去。这个machine将会运行这个docker镜像并且控制Swarm主节点和从节点。使用下面的指令运行镜像
# docker run swarm create
![Docker Machine Swarm Create](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-swarm-create.png)
If you are trying to run swarm docker image using **32 bit Operating System** in the computer where Docker Machine is running, we'll need to SSH into the Droplet.
如果你想要在**32位操作系统**上运行swarm docker镜像。你需要SSH登录到Droplet当中。
# docker-machine ssh
#docker run swarm create
#exit
### 4. 创建Swarm主节点 ###
在我们的swarm image已经运行在machine当中之后我们将要创建一个Swarm主节点。使用下面的语句添加一个主节点。这里的感觉怪怪的好像少翻译了很多东西是我把Master翻译为主节点的原因吗
# docker-machine create \
-d digitalocean \
--digitalocean-access-token <DIGITALOCEAN-TOKEN>
--swarm \
--swarm-master \
--swarm-discovery token://<CLUSTER-ID> \
swarm-master
![Docker Machine Swarm Master Create](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-swarm-master-create.png)
### 5. 创建Swarm结点群 ###
现在我们将要创建一个swarm结点此结点将与Swarm主节点相连接。下面的指令将创建一个新的名为swarm-node的droplet其与Swarm主节点相连。到此我们就拥有了一个两节点的swarm集群了。
# docker-machine create \
-d digitalocean \
--digitalocean-access-token <DIGITALOCEAN-TOKEN>
--swarm \
--swarm-discovery token://<TOKEN-FROM-ABOVE> \
swarm-node
![Docker Machine Swarm Nodes](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-machine-swarm-nodes.png)
### 6. Connecting to the Swarm Master ###
### 6. 与Swarm主节点连接 ###
现在我们连接Swarm主节点以便我们可以依照需求和配置文件在节点间部署Docker容器。运行下列命令将Swarm主节点的Machine配置文件加载到环境当中。
# eval "$(docker-machine env --swarm swarm-master)"
然后,我们就可以跨结点地运行我们所需的容器了。在这里,我们还要检查一下是否一切正常。所以,运行**docker info**命令来检查Swarm集群的信息。
# docker info
### Conclusion ###
### 总结 ###
我们可以用Docker Machine轻而易举地创建Swarm集群。这种方法有非常高的效率因为它极大地减少了系统管理员和用户的时间消耗。在这篇文章中我们以Digital Ocean作为驱动通过创建一个主节点和一个从节点成功地部署了集群。其他类似的应用还有VirtualBoxGoogle Cloud ComputingAmazon Web ServiceMicrosoft Azure等等。这些连接都是通过TLS进行加密的具有很高的安全性。如果你有任何的疑问建议反馈欢迎在下面的评论框中注明以便我们可以更好地提高文章的质量
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-how-to/provision-swarm-clusters-using-docker-machine/
作者:[Arun Pyasi][a]
译者:[DongShuaike](https://github.com/DongShuaike)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://linoxide.com/author/arunp/

View File

@ -0,0 +1,92 @@
无忧之道Docker中容器的备份、恢复和迁移
================================================================================
今天我们将学习如何快速地对docker容器进行快捷备份、恢复和迁移。[Docker][1]是一个开源平台用于自动化部署应用以通过快捷的途径在称之为容器的轻量级软件层下打包、发布和运行这些应用。它使得应用平台独立因为它扮演了Linux上一个额外的操作系统级虚拟化的自动化抽象层。它通过其组件cgroups和命名空间利用Linux内核的资源分离特性达到避免虚拟机开销的目的。它使得用于部署和扩展web应用、数据库和后端服务的大规模构建块无需依赖于特定的堆栈或供应者。
所谓的容器就是那些创建自Docker镜像的软件层它包含了独立的Linux文件系统和开箱即用的应用程序。如果我们有一个在盒子中运行着的Docker容器并且想要备份这些容器以便今后使用或者想要迁移这些容器那么本教程将帮助你掌握在Linux操作系统中备份、恢复和迁移Docker容器。
我们怎样才能在Linux中备份、恢复和迁移Docker容器呢这里为您提供了一些便捷的步骤。
### 1. 备份容器 ###
首先为了备份Docker中的容器我们会想看看我们想要备份的容器列表。要达成该目的我们需要在我们运行这Docker引擎并已创建了容器的Linux机器中运行 docker ps 命令。
# docker ps
![Docker Containers List](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-containers-list.png)
在此之后,我们要选择我们想要备份的容器,然后我们会去创建该容器的快照。我们可以使用 docker commit 命令来创建快照。
# docker commit -p 30b8f18f20b4 container-backup
![Docker Commit](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-commit.png)
该命令会生成一个作为Docker镜像的容器快照我们可以通过运行 docker images 命令来查看Docker镜像如下。
# docker images
![Docker Images](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-images.png)
正如我们所看见的上面做的快照已经作为Docker镜像保存了。现在为了备份该快照我们有两个选择一个是我们可以登陆进Docker注册中心并推送该镜像另一个是我们可以将Docker镜像打包成tarball备份以供今后使用。
如果我们想要在[Docker注册中心][2]上传或备份镜像,我们只需要运行 docker login 命令来登录进Docker注册中心然后推送所需的镜像即可。
# docker login
![Docker Login](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-login.png)
# docker tag a25ddfec4d2a arunpyasi/container-backup:test
# docker push arunpyasi/container-backup
![Docker Push](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-push.png)
如果我们不想备份到docker注册中心而是想要将此镜像保存在本地机器中以供日后使用那么我们可以将其作为tarball备份。要完成该操作我们需要运行以下 docker save 命令。
# docker save -o ~/container-backup.tar container-backup
![taking tarball backup](http://blog.linoxide.com/wp-content/uploads/2015/07/taking-tarball-backup.png)
要验证tarball时候已经生成我们只需要在保存tarball的目录中运行 ls 命令。
### 2. 恢复容器 ###
接下来在我们成功备份了我们的Docker容器后我们现在来恢复这些被快照成Docker镜像的容器。如果我们已经在注册中心推送了这些Docker镜像那么我们仅仅需要把那个Docker镜像拖回并直接运行即可。
# docker pull arunpyasi/container-backup:test
![Docker Pull](http://blog.linoxide.com/wp-content/uploads/2015/07/docker-pull.png)
但是如果我们将这些Docker镜像作为tarball文件备份到了本地那么我们只要使用 docker load 命令后面加上tarball的备份路径就可以加载该Docker镜像了。
# docker load -i ~/container-backup.tar
现在为了确保这些Docker镜像已经加载成功我们来运行 docker images 命令。
# docker images
在镜像被加载后我们将从加载的镜像去运行Docker容器。
# docker run -d -p 80:80 container-backup
![Restoring Docker Tarball](http://blog.linoxide.com/wp-content/uploads/2015/07/restoring-docker-tarballs.png)
### 3. 迁移Docker容器 ###
迁移容器同时涉及到了上面两个操作备份和恢复。我们可以将任何一个Docker容器从一台机器迁移到另一台机器。在迁移过程中首先我们将容器的备份作为快照Docker镜像。然后该Docker镜像或者是被推送到了Docker注册中心或者被作为tarball文件保存到了本地。如果我们将镜像推送到了Docker注册中心我们简单地从任何我们想要的机器上使用 docker run 命令来恢复并运行该容器。但是如果我们将镜像打包成tarball备份到了本地我们只需要拷贝或移动该镜像到我们想要的机器上加载该镜像并运行需要的容器即可。
### 尾声 ###
最后我们已经学习了如何快速地备份、恢复和迁移Docker容器本教程适用于各个成功运行Docker的操作系统平台。真的Docker是一个相当简单易用然而功能却十分强大的工具。它的命令相当易记这些命令都非常短带有许多简单而强大的标记和参数。上面的方法让我们备份容器时很是安逸使得我们可以在日后很轻松地恢复它们。这会帮助我们恢复我们的容器和镜像即便主机系统崩溃甚至意外地被清除。如果你还有很多问题、建议、反馈请在下面的评论框中写出来吧可以帮助我们改进或更新我们的内容。谢谢大家享受吧 :-)
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-how-to/backup-restore-migrate-containers-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]:http://docker.com/
[2]:https://registry.hub.docker.com/