20150515-1 选题

This commit is contained in:
DeadFire 2015-05-15 16:16:05 +08:00
parent 21b6ccad58
commit 13a63f2765
2 changed files with 294 additions and 0 deletions

View File

@ -0,0 +1,106 @@
Basic Networking Commands with Docker Containers
================================================================================
Hi everybody, today we'll learn some basic networking with Docker Containers. Docker is an Open Source project that provides an open platform to pack, ship and run any application as a lightweight container. It has no boundaries of Language support, Frameworks or packaging system and can be run anywhere, anytime from a small home computers to high-end servers. It makes them great building blocks for deploying and scaling web apps, databases, and back-end services without depending on a particular stack or provider. Docker is meant for networking as it is gradually used in data-centers, ISPs and much more networked servers.
So, here are some basic networking commands that you can use on managing Docker Containers.
### 1. Finding the Docker Interface ###
Docker by default creates a bridge interface named docker0 which basically connects with the outside world. The docker containers running is directly connected with the bridge interface docker0. By default, docker assigns ip address 172.17.42.1/16 to the bridge interface docker0 which acts as a subnet for all the ip addresses of the running containers. It is pretty easy to get the Docker Interface's IP Address. To find out our docker0 bridge interface and the docker containers connected with the bridge we can simply run ip a command inside a terminal or a shell where Docker is installed.
# ip a
![Docker Interface](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-interface.png)
### 2. Getting the Docker Container's IP Address ###
As we read above, docker creates a bridge interface named docker0 in the host machine. As we create a new docker container, it is automatically assigned with a new dynamic IP Address by default which is followed within the subnet range of the interface. So, to check the IP Address of the running Docker container, we'll need to get into a running container and check out the ip address as shown below. First, we'll run a new container and get into the container. If you have got a container running already, you may skip the first command below.
# docker run -it ubuntu
Now, we'll be able to run ip a in order to get the ip address of the running container.
# ip a
![Docker Container IP](http://blog.linoxide.com/wp-content/uploads/2015/05/docker-container-ip.png)
### 3. Mapping the Expose port ###
To map the exposed port configured in the Dockerfile for the container to the high port, we'll simply need to follow the docker command with -P flag. This will open the random port of the Docker Container to the port defined by the Dockerfile. So, here's an example of using the flag -P to open/expose the defined port.
# docker run -itd -P httpd
![Mapping Expose Port](http://blog.linoxide.com/wp-content/uploads/2015/05/mapping-expose-port.png)
The above command will map container's port to port 80 as its defined in the Dockerfile of httpd. We can check the exposed port by viewing the running container using the following command.
# docker ps
And can use curl to check by running the below command.
# curl http://localhost:49153
![Curl Exposed Port](http://blog.linoxide.com/wp-content/uploads/2015/05/curl-exposed-port-e1431034586219.png)
### 4. Mapping to the Specific Port ###
We can also map the expose port or docker container port to the port we specify or define. In order to map the container to a specific port of our choice, we'll need to define the port of our desire with the flag -p . Here's an example on how we can do that.
# docker run -itd -p 8080:80 httpd
The above command will map the port 8080 to port 80. We can check it by running curl to that port.
# curl http://localhost:8080
![Mapping Specific Port](Curl Exposed Port)
### 5. Creating own Bridge ###
To assign a custom IP Address to the containers, we'll need to create a new bridge interface named bro in this tutorial. To assign a desired IP Address, we'll need to run the following command in the host machine running docker.
# stop docker.io
# ip link add br0 type bridge
# ip addr add 172.30.1.1/20 dev br0
# ip link set br0 up
# docker -d -b br0
![Creating Bridge Interface](http://blog.linoxide.com/wp-content/uploads/2015/05/creating-bridge-interface.png)
After creating the docker bridge, we'll want to let the Docker Daemon know about it.
# echo 'DOCKER_OPTS="-b=br0"' >> /etc/default/docker
# service docker.io start
![Adding Interface to Docker](http://blog.linoxide.com/wp-content/uploads/2015/05/adding-interface-to-docker.png)
Here, the bridged interface will range the docker containers with the ip address followed by bridge ip subnet .
### 6. Linking one Container to another ###
We can connect one container with the another container with Docker. We can run different apps on different containers and connect or link with each other. Links allow containers to connect with each other and securely transfer information about one container to another container. To do so, we'll use the --link flag. First, we'll use flag --name so that it will be easy to denote training/postgres image.
# docker run -d --name db training/postgres
![Running db Container](http://blog.linoxide.com/wp-content/uploads/2015/05/running-db-container.png)
After done, we'll gonna link training/webapp with the container db that we create earlier forming a new container named web.
# docker run -d -P --name web --link db:db training/webapp python app.py
![linking two containers](http://blog.linoxide.com/wp-content/uploads/2015/05/linking-two-containers.png)
### Conclusion ###
Networking with Docker is fun and amazing cause there are many stuffs we can do with Docker Containers. These were some easy and basic networking commands that we can play with Docker. Networking with docker is really advanced. We can do many stuffs with it. 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/networking-commands-docker-containers/
作者:[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

@ -0,0 +1,188 @@
How to Install Percona Server on CentOS 7
================================================================================
In this article we are going to learn about percona server, an opensource drop-in replacement for MySQL and also for MariaDB. The InnoDB database engine make it very attractive and a good alternative if you need performance, reliability and a cost efficient solution
In the following sections I am going to cover the installation of the percona server on the CentOS 7, I will also cover the steps needed to make backup of your current data, configuration and how to restore your backup.
### Table of contents ###
1. What is and why use percona
1. Backup your databases
1. Remove previous SQL server
1. Installing Percona binaries
1. Configuring Percona
1. Securing your environment
1. Restore your backup
### 1. What is and why use Percona ###
Percona is an opensource alternative to the MySQL and MariaDB databases, it's a fork of the MySQL with many improvements and unique features that makes it more reliable, powerful and faster than MySQL, and yet is fully compatible with it, you can even use replication between Oracle's MySQL and Percona.
#### Features exclusive to Percona ####
- Partitioned Adaptive Hash Search
- Fast Checksum Algorithm
- Buffer Pool Pre-Load
- Support for FlashCache
#### MySQL Enterprise and Percona specific features ####
- Import Tables From Different Servers
- PAM authentication
- Audit Log
- Threadpool
Now that you are pretty excited to see all these good things together, we are going show you how to install and do basic configuration of Percona Server.
### 2. Backup your databases ###
The following, command creates a mydatabases.sql file with the SQL commands to recreate/restore salesdb and employeedb databases, replace the databases names to reflect your setup, skip if this is a brand new setup
mysqldump -u root -p --databases employeedb salesdb > mydatabases.sql
Copy the current configuration file, you can also skip this in fresh setups
cp my.cnf my.cnf.bkp
### 3. Remove your previous SQL Server ###
Stop the MySQL/MariaDB if it's running.
systemctl stop mysql.service
Uninstall MariaDB and MySQL
yum remove MariaDB-server MariaDB-client MariaDB-shared mysql mysql-server
Move / Rename the MariaDB files in **/var/lib/mysql**, it's a safer and faster than just removing, it's like a 2nd level instant backup. :)
mv /var/lib/mysql /var/lib/mysql_mariadb
### 4. Installing Percona binaries ###
You can choose from a number of options on how to install Percona, in a CentOS system it's generally a better idea to use yum or RPM, so these are the way that are covered by this article, compiling and install from sources are not covered by this article.
Installing from Yum repository:
First you need to set the Percona's Yum repository with this:
yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
And then install Percona with:
yum install Percona-Server-client-56 Percona-Server-server-56
The above command installs Percona server and clients, shared libraries, possibly Perl and perl modules such as DBI::MySQL, if that are not already installed, and also other dependencies as needed.
Installing from RPM package:
We can download all rpm packages with the help of wget:
wget -r -l 1 -nd -A rpm -R "*devel*,*debuginfo*" \ http://www.percona.com/downloads/Percona-Server-5.5/Percona-Server-5.5.42-37.1/binary/redhat/7/x86_64/
And with rpm utility, you install all the packages once:
rpm -ivh Percona-Server-server-55-5.5.42-rel37.1.el7.x86_64.rpm \ Percona-Server-client-55-5.5.42-rel37.1.el7.x86_64.rpm \ Percona-Server-shared-55-5.5.42-rel37.1.el7.x86_64.rpm
Note the backslash '\' on the end of the sentences on the above commands, if you install individual packages, remember that to met dependencies, the shared package must be installed before client and client before server.
### 5. Configuring Percona Server ###
#### Restoring previous configuration ####
As we are moving from MariaDB, you can just restore the backup of my.cnf file that you made in earlier steps.
cp /etc/my.cnf.bkp /etc/my.cnf
#### Creating a new my.cnf ####
If you need a new configuration file that fit your needs or if you don't have made a copy of my.cnf, you can use this wizard, it will generate for you, through simple steps.
Here is a sample my.cnf file that comes with Percona-Server package
# Percona Server template configuration
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
After making your my.cnf file fit your needs, it's time to start the service:
systemctl restart mysql.service
If everything goes fine, your server is now up and ready to ready to receive SQL commands, you can try the following command to check:
mysql -u root -p -e 'SHOW VARIABLES LIKE "version_comment"'
If you can't start the service, you can look for a reason in **/var/log/mysql/mysqld.log** this file is set by the **log-error** option in my.cnf's **[mysqld_safe]** session.
tail /var/log/mysql/mysqld.log
You can also take a look in a file inside **/var/lib/mysql/** with name in the form of **[hostname].err** as the following example:
tail /var/lib/mysql/centos7.err
If this also fail in show what is wrong, you can also try strace:
yum install strace && systemctl stop mysql.service && strace -f -f mysqld_safe
The above command is extremely verbous and it's output is quite low level but can show you the reason you can't start service in most times.
### 6. Securing your environment ###
Ok, you now have your RDBMS ready to receive SQL queries, but it's not a good idea to put your precious data on a server without minimum security, it's better to make it safer with mysql_secure_instalation, this utility helps in removing unused default features, also set the root main password and make access restrictions for using this user.
Just invoke it by the shell and follow instructions on the screen.
mysql_secure_install
### 7. Restore your backup ###
If you are coming from a previous setup, now you can restore your databases, just use mysqldump once again.
mysqldump -u root -p < mydatabases.sql
Congratulations, you just installed Percona on your CentOS Linux, your server is now fully ready for use; You can now use your service as it was MySQL, and your services are fully compatible with it.
### Conclusion ###
There is a lot of things to configure in order to achieve better performance, but here is some straightforward options to improve your setup. When using innodb engine it's also a good idea to set the **innodb_file_per_table** option **on**, it gonna distribute table indexes in a file per table basis, it means that each table have it's own index file, it makes the overall system, more robust and easier to repair.
Other option to have in mind is the **innodb_buffer_pool_size** option, InnoDB should have large enough to your datasets, and some value **between 70% and 80%** of the total available memory should be reasonable.
By setting the **innodb-flush-method** to **O_DIRECT** you disable write cache, if you have **RAID**, this should be set to improved performance as this cache is already done in a lower level.
If your data is not that critical and you don't need fully **ACID** compliant transactions, you can adjust to 2 the option **innodb_flush_log_at_trx_commit**, this will also lead to improved performance.
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-how-to/percona-server-centos-7/
作者:[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/