20150612-3 选题

This commit is contained in:
DeadFire 2015-06-12 15:36:37 +08:00
parent 1ca6167f0f
commit ee107f6081
3 changed files with 560 additions and 0 deletions

View File

@ -0,0 +1,282 @@
How to Configure Apache Containers with Docker on Fedora 22
================================================================================
In this article we are going to learn about Docker, how to use it to deploy Apache httpd and how can you share it on Docker Hub. First we are going to learn how to pull and use images hosted on Docker Hub, and then install Apache on an image of Fedora 22 interactively, after that we are going to learn how to use a Dockerfile to make an image in a faster and more elegant way, finally we are going to publish the image we've created in Docker Hub, so anyone will be able download and use it later.
### Installing Docker and saying hello world ###
**Requirements**
You will need atleast these things to run Docker:
- You need a 64bit Kernel version 3.10 or higher
- Iptables 1.4 - This will be used by Docker to make the network wizardry, such as Network Address Translation.
- Git 1.7 - Docker uses Git to make it transactions to repositories, like Docker Hub
- ps - This utility is present in most environments and is provided in the procps package.
- root - despite normal users can run docker client by TCP and other means, we will assume that you are root, for sake of simplicity
#### Install docker using dnf ####
The following commands will install Docker
dnf update && dnf install docker
**Note**: You can still use Yum in Fedora 22, but it's deprecated in favor of DNF and is not present in a clean install.
#### Check your install ####
The first command we are going to use is docker info, this give you many information:
docker info
Also try **docker version**:
docker version
#### Starting Docker as daemon ####
You should start a docker instance that will take care of our requests.
docker -d
Now set docker to start with the system, so you don't need to run the previous command every time you reboot.
chkconfig docker on
Let's say hello world with Busybox:
docker run -t busybox /bin/echo "hello world"
In this command, we tell Docker to execute /bin/echo "hello world" in an instance/container of the Busybox image, which is a minimal POSIX environment based in a single binary and links to it.
If Docker can't find a local image of Busybox on your system, it will pull the image automatically from Docker Hub, as you can see in the following screenshot:
![Hello world with Busybox](http://blog.linoxide.com/wp-content/uploads/2015/06/docker-hello-world-busybox-complete.png)
Hello world with Busybox
Try the same command again, this time as Docker already have the Busybox image locally, all you will see is the output of echo:
docker run -t busybox /bin/echo "hello world"
Try also the following to enter in the container environment:
docker run -it busybox /bin/sh
To leave and stop the container use the **exit** command
### Dockerizing Apache interactively ###
Pull/Download the Fedora image:
docker pull fedora:22
Run a container dettached from the console:
docker run -d -t fedora:22 /bin/bash
List running containers and identify by name as follows
docker ps
![listing with docker ps and attaching with docker attach](http://blog.linoxide.com/wp-content/uploads/2015/06/docker-ps-with-docker-attach-highlight.png)
listing with docker ps and attaching with docker attach
The name angry_nobel was given to our instance, so let's attach:
docker attach angry_nobel
Note: Every time you run a container a new name will be given, if you need a constant name for you container you should use the -name parameter to docker run command.
#### Installing Apache ####
The following command will update DNF database, download install Apache (httpd package) and clean DNF cache to make the image small
dnf -y update && dnf -y install httpd && dnf -y clean all
Configuring Apache
The only thing we are going to change httpd.conf is the ServerName, this makes Apache stops to complain.
sed -i.orig 's/#ServerName/ServerName/' /etc/httpd/conf/httpd.conf
**Set the environment**
To make Apache run in standalone mode, you must provide some information in the form of enviroenment variables, and also you will need the directories set in these variables, so we are going to make this with a small shell script that will also start Apache
vi /etc/httpd/run_apache_foreground
----------
#!/bin/bash
#set variables
APACHE_LOG_DI=R"/var/log/httpd"
APACHE_LOCK_DIR="/var/lock/httpd"
APACHE_RUN_USER="apache"
APACHE_RUN_GROUP="apache"
APACHE_PID_FILE="/var/run/httpd/httpd.pid"
APACHE_RUN_DIR="/var/run/httpd"
#create directories if necessary
if ! [ -d /var/run/httpd ]; then mkdir /var/run/httpd;fi
if ! [ -d /var/log/httpd ]; then mkdir /var/log/httpd;fi
if ! [ -d /var/lock/httpd ]; then mkdir /var/lock/httpd;fi
#run Apache
httpd -D FOREGROUND
**Alternatively**, you can past and run this snippet on the container shell:
dnf -y install git && git clone https://github.com/gaiada/run-apache-foreground.git && cd run-apach* && ./install && dnf erase git
The inline script above will, install Git, clone [this repository][1], put the script in place and ask you if you want uninstall Git.
**Saving your container state**
Your container is now ready to run Apache, now it is time to save the current state of this container in an image to be able use whenever you need.
To leave the container environment, you must press **Ctrl+p** followed by **Ctrl+q**, if you just call exit in the shell, you will also stop the container and lost what you have done so far.
Once you are back to the Docker host, use **docker commit** followed by the container and the repository name/tag you desire:
docker commit angry_nobel gaiada/apache
Now that you saved the container status into a image, you can use **docker stop** on the running container:
docker stop angry_nobel
**Run and test your image**
Finally, run a container from your new image and redirect connections on port 80 to it with:
docker run -p 80:80 -d -t gaiada/apache /etc/httpd/run_apache_foreground
At this point, you are already running Apache in your container, open your browser to access the service in [http://localhost][2] and you will see the Apache default page as follows
![Apache default page running from Docker container](http://blog.linoxide.com/wp-content/uploads/2015/06/docker-apache-running.png)
Apache default page running from Docker container
### Dockerizing Apache with a Dockerfile ###
Now we are going to create a new Apache image, this time the steps will be written in a Dockerfile, that will be processed to form the image.
First, create a directory on which we will put the Dockerfile and enter this directory:
mkdir apachedf; cd apachedf
And then create a file named Dockerfile with the following content:
FROM fedora:22
MAINTAINER Carlos Alberto
LABEL version="0.1"
RUN dnf -y update && dnf -y install httpd && dnf -y clean all
RUN [ -d /var/log/httpd ] || mkdir /var/log/httpd
RUN [ -d /var/run/httpd ] || mkdir /var/run/httpd
RUN [ -d /var/lock/httpd ] || mkdir /var/lock/httpd
RUN sed -i.orig 's/#ServerName/ServerName/' /etc/httpd/conf/httpd.conf
ENV APACHE_RUN_USER apache
ENV APACHE_RUN_GROUP apache
ENV APACHE_LOG_DIR /var/log/httpd
ENV APACHE_LOCK_DIR /var/lock/httpd
ENV APACHE_RUN_DIR /var/run/httpd
ENV APACHE_PID_FILE /var/run/httpd/httpd.pid
EXPOSE 80
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
Let's see what is on this Dockerfile:
**FROM** - This tells docker that we are going to use Fedora 22 as base image
**MANTAINER** and **LABEL** - these commands are informative and have no direct influence on the image
**RUN** - Automate the steps we've done interactively, install Apache, create directories and edit httpd.conf
**ENV** - Set the environment variables, now we don't need the run_apache_foreground script anymore.
**EXPOSE** - Expose the port 80 to the world
**CMD** - Set the default command to httpd, so we don't need to do this every time we start a new container
**Build the image**
Now we are going to build the image and put the TAG gaiada/apachedf on it:
docker build -t gaiada/apachedf:0.1 .
![docker build complete](http://blog.linoxide.com/wp-content/uploads/2015/06/docker-build-complete.png)
docker build complete
Use **docker images** list the local images and see if your new image is there:
docker images
And then run you new image:
docker run -t -p 80:80 gaiada/apachedf
That is it for the Dockerfile, using this feature make things much easier, faster and reproducible.
### Publishing your images ###
Until now, you just pulled images from Docker Hub, but you can also push you image and pull them later as needed. In fact other can also download your image and use it in their systems without the need of change anything and now we are going to learn how to make our image available for others worldwide.
**Creating account**
For you to be able to push your image on Docker Hub, you need to create an account. Access [https://hub.docker.com/account/signup/][3] and fill the following form:
![Docker Hub signup page](http://blog.linoxide.com/wp-content/uploads/2015/06/docker-hub-signup.png)
Docker Hub signup page
**Login**
Enter the following command and proceed with the login name, password and email you provided in your account creation
docker login
After you do the first login, your account information will be recorded in **~/.dockercfg**
**Pushing**
Push the page to the server with the **docker push [registry/]your_login/repository_name[:tag]**
docker push docker.io/gaiada/apachedf
You might see something like this on your console:
![Docker push Apache image complete](http://blog.linoxide.com/wp-content/uploads/2015/06/docker-pushing-apachedf-complete.png)
Docker push Apache image complete
### Conclusion ###
Now that you know how to Dockerize Apache, try to include some modules, Perl, PHP, proxy, HTTPS, or whatever you need. I hope you guys liked it, and push your own images on Docker Hub.
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-how-to/configure-apache-containers-docker-fedora-22/
作者:[Carlos Alberto][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/carlosal/
[1]:https://github.com/gaiada/run-apache-foreground
[2]:http://localhost/
[3]:https://hub.docker.com/account/signup/

View File

@ -0,0 +1,95 @@
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,183 @@
Linux_Logo A Command Line Tool to Print Color ANSI Logos of Linux Distributions
================================================================================
linuxlogo or linux_logo is a Linux command line utility that generates a color ANSI picture of Distribution logo with a few system information.
![Linux_Logo - Prints Color ANSI Logs of Linux Distro](http://www.tecmint.com/wp-content/uploads/2015/06/Linux_Logo.png)
Linux_Logo Prints Color ANSI Logs of Linux Distro
This utility obtains System Information from /proc Filesystem. linuxlogo is capable of showing color ANSI image of various logos other than the host distribution logo.
The System information associated with logo includes Linux Kernel Version, Time when Kernel was last Compiled, Number/core of processor, Speed, Manufacturer and processor Generation. It also show information about total physical RAM.
It is worth mentioning here that screenfetch is another tool of similar kind, which shows distribution logo and a more detailed and formatted system inform http://www.tecmint.com/screenfetch-system-information-generator-for-linux/ation. We have already covered screenfetch long ago, which you may refer at:
- [ScreenFetch Generates Linux System Information][15]
linux_logo and Screenfetch should not be compared to each other. While the output of screenfetch is more formatted and detailed, where linux_logo produce maximum number of color ANSI diagram, and option to format the output.
linux_logo is written primarily in C programming Language, which displays linux logo in an X Window System and hence User Interface X11 aka X Window System should be installed. The software is released under GNU General Public License Version 2.0.
For the purpose of this article, were using following testing environment to test the linux_logo utility.
Operating System : Debian Jessie
Processor : i3 / x86_64
### Installing Linux Logo Utility in Linux ###
**1. The linuxlogo package (stable version 5.11) is available to install from default package repository under all Linux distributions using apt, yum or dnf package manager as shown below.**
# apt-get install linux_logo [On APT based Systems]
# yum install linux_logo [On Yum based Systems]
# dnf install linux_logo [On DNF based Systems]
OR
# dnf install linux_logo.x86_64 [For 64-bit architecture]
**2. Once linuxlogo package has been installed, you can run the command `linuxlogo` to get the default logo for the distribution you are using..**
# linux_logo
OR
# linuxlogo
![Get Default OS Logo](http://www.tecmint.com/wp-content/uploads/2015/06/Get-Default-OS-Logo.png)
Get Default OS Logo
**3. Use the option `[-a]`, not to print any fancy color. Useful if viewing linux_logo over black and white terminal.**
# linux_logo -a
![Black and White Linux Logo](http://www.tecmint.com/wp-content/uploads/2015/06/Black-and-White-Linux-Logo.png)
Black and White Linux Logo
**4. Use option `[-l]` to print LOGO only and exclude all other System Information.**
# linux_logo -l
![Print Distribution Logo](http://www.tecmint.com/wp-content/uploads/2015/06/Print-Distribution-Logo.png)
Print Distribution Logo
**5. The `[-u]` switch will display system uptime.**
# linux_logo -u
![Print System Uptime](http://www.tecmint.com/wp-content/uploads/2015/06/Print-System-Uptime.png)
Print System Uptime
**6. If you are interested in Load Average, use option `[-y]`. You may use more than one option at a time.**
# linux_logo -y
![Print System Load Average](http://www.tecmint.com/wp-content/uploads/2015/06/Print-System-Load-Average.png)
Print System Load Average
For more options and help on them, you may like to run.
# linux_logo -h
![Linuxlogo Options and Help](http://www.tecmint.com/wp-content/uploads/2015/06/linuxlogo-options.png)
Linuxlogo Options and Help
**7. There are a lots of built-in Logos for various Linux distributions. You may see all those logos using option `-L list` switch.**
# linux_logo -L list
![List of Linux Logos](http://www.tecmint.com/wp-content/uploads/2015/06/List-of-Linux-Logos.png)
List of Linux Logos
Now you want to print any of the logo from the list, you may use `-L NUM` or `-L NAME` to display selected logo.
- -L NUM will print logo with number NUM (deprecated).
- -L NAME will print the logo with name NAME.
For example, to display AIX Logo, you may use command as:
# linux_logo -L 1
OR
# linux_logo -L aix
![Print AIX Logo](http://www.tecmint.com/wp-content/uploads/2015/06/Print-AIX-Logo.png)
Print AIX Logo
**Notice**: The `-L 1` in the command where 1 is the number at which AIX logo appears in the list, where `-L aix` is the name at which AIX logo appears in the list.
Similarly, you may print any logo using these options, few examples to see..
# linux_logo -L 27
# linux_logo -L 21
![Various Linux Logos](http://www.tecmint.com/wp-content/uploads/2015/06/Various-Linux-Logos.png)
Various Linux Logos
This way, you can use any of the logos just by using the number or name, that is against it.
### Some Useful Tricks of Linux_logo ###
**8. You may like to print your Linux distribution logo at login. To print default logo at login you may add the below line at the end of `~/.bashrc` file.**
if [ -f /usr/bin/linux_logo ]; then linux_logo; fi
**Notice**: If there isnt any` ~/.bashrc` file, you may need to create one under user home directory.
**9. After adding above line, just logout and re-login again to see the default logo of your Linux distribution.**
![Print Logo on User Login](http://www.tecmint.com/wp-content/uploads/2015/06/Print-Logo-on-Login.png)
Print Logo on User Login
Also note, that you may print any logo, after login, simply by adding the below line.
if [ -f /usr/bin/linux_logo ]; then linux_logo -L num; fi
**Important**: Dont forget to replace num with the number that is against the logo, you want to use.
**10. You can also print your own logo by simply specifying the location of the logo as shown below.**
# linux_logo -D /path/to/ASCII/logo
**11. Print logo on Network Login.**
# /usr/local/bin/linux_logo > /etc/issue.net
You may like to use ASCII logo if there is no support for color filled ANSI Logo as:
# /usr/local/bin/linux_logo -a > /etc/issue.net
**12. Create a Penguin port A set of port to answer connection. To create Penguin port Add the below line to file /etc/services file.**
penguin 4444/tcp penguin
Here 4444 is the port number which is currently free and not used by any resource. You may use a different port.
Also add the below line to file /etc/inetd.conf file.
penguin stream tcp nowait root /usr/local/bin/linux_logo
Restart the service inetd as:
# killall -HUP inetd
Moreover linux_logo can be used in bootup script to fool the attacker as well as you can play a prank with your friend. This is a nice tool and I might use it in some of my scripts to get output as per distribution basis.
Try it once and you wont regret. Let us know what you think of this utility and how it can be useful for you. Keep Connected! Keep Commenting. Like and share us and help us get spread.
--------------------------------------------------------------------------------
via: http://www.tecmint.com/linux_logo-tool-to-print-color-ansi-logos-of-linux/
作者:[Avishek Kumar][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://www.tecmint.com/author/avishek/
[1]:http://www.tecmint.com/screenfetch-system-information-generator-for-linux/