Merge pull request #2918 from FatJoe123/patch-1

Patch 1
This commit is contained in:
Xingyu.Wang 2015-06-11 22:57:23 +08:00
commit 2341ddaba5
2 changed files with 220 additions and 188 deletions

View File

@ -1,188 +0,0 @@
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/

View File

@ -0,0 +1,220 @@
如何在CentOS 7上安装Percona Server
================================================================================
在这篇文章中我们将了解关于Percona Server一个开源简易的MySQLMariaDB的替代。InnoDB的数据库引擎使得Percona Server非常有吸引力如果你需要的高性能高可靠性和高性价比的解决方案它将是一个很好的选择。
在下文中将介绍在CentOS 7上Percona的服务器的安装以及备份当前数据,配置的步骤和如何恢复备份。
###目录###
1.什么是Percona为什么使用它
2.备份你的数据库
3.删除之前的SQL服务器
4.使用二进制包安装Percona
5.配置Percona
6.保护你的数据
7.恢复你的备份
### 1.什么是Percona为什么使用它 ###
Percona是一个开源简易的MySQLMariaDB数据库的替代它是MYSQL的一个分支相当多的改进和独特的功能使得它比MYSQL更可靠性能更强速度更快它与MYSQL完全兼容你甚至可以在Oracle的MYSQL与Percona之间使用复制命令。
#### 在Percona中独具特色的功能 ####
-分段自适应哈希搜索
-快速校验算法
-缓冲池预加载
-支持FlashCache
#### MySQL企业版和Percona的特定功能 ####
-从不同的服务器导入表
-PAM认证
-审计日志
-线程池
现在你肯定很兴奋地看到这些好的东西整理在一起我们将告诉你如何安装和做些的Percona Server的基本配置。
### 2. 备份你的数据库 ###
接下来在命令行下使用SQL命令创建一个mydatabases.sql文件来重建/恢复salesdb和employeedb数据库重命名数据库以便反映你的设置如果没有安装MYSQL跳过此步
mysqldump -u root -p --databases employeedb salesdb > mydatabases.sql
复制当前的配置文件如果你没有安装MYSQL也可跳过
cp my.cnf my.cnf.bkp
### 3.删除之前的SQL服务器 ###
停止MYSQL/MariaDB如果它们还在运行
systemctl stop mysql.service
卸载MariaDB和MYSQL
yum remove MariaDB-server MariaDB-client MariaDB-shared mysql mysql-server
移动重命名在/var/lib/mysql当中的MariaDB文件这比仅仅只是移除更为安全快速这就像2级即时备份。:)
mv /var/lib/mysql /var/lib/mysql_mariadb
### 4.使用二进制包安装Percona ###
你可以在众多Percona安装方法中选择在CentOS中使用Yum或者RPM包安装通常是更好的主意所以这些是本文介绍的方式下载源文件编译后安装在本文中并没有介绍。
从Yum仓库中安装:
首先你需要设置的Percona的Yum库:
yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm
接下来安装Percona:
yum install Percona-Server-client-56 Percona-Server-server-56
上面的命令安装Percona的服务器和客户端共享库可能需要Perl和Perl模块以及其他依赖的需要。如DBI::MySQL的如果这些尚未安装
使用RPM包安装:
我们可以使用wget命令下载所有的rpm包:
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/
使用rpm工具一次性安装所有的rpm包
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
注意在上面命令语句中最后的反斜杠'\',如果您安装单独的软件包,记住要解决依赖关系,在安装客户端之前要先安装共享包,在安装服务器之前请先安装客户端。
### 5.配置Percona服务器 ###
#### 恢复之前的配置 ####
当我们从MariaDB迁移过来时你可以将之前的my.cnf的备份文件恢复回来。
cp /etc/my.cnf.bkp /etc/my.cnf
#### 创建一个新的my.cnf文件 ####
如果你需要一个适合你需求的新的配置文件或者你并没有备份配置文件,你可以使用以下方法,通过简单的几步生成新的配置文件。
下面是Percona-server软件包自带的my.cnf文件
# 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
根据你的需要配置好my.cnf后就可以启动该服务了
systemctl restart mysql.service
如果一切顺利的话它已经准备好执行SQL命令了你可以用以下命令检查它是否已经正常启动
mysql -u root -p -e 'SHOW VARIABLES LIKE "version_comment"'
如果你不能够正常启动它,你可以在**/var/log/mysql/mysqld.log**中查找原因该文件可在my.cnf的[mysql_safe]的log-error中设置。
tail /var/log/mysql/mysqld.log
你也可以在/var/lib/mysql/文件夹下查找格式为[hostname].err的文件就像下面这个例子样
tail /var/lib/mysql/centos7.err
如果还是没找出原因你可以试试strace
yum install strace && systemctl stop mysql.service && strace -f -f mysqld_safe
上面的命令挺长的,输出的结果也相对简单,但绝大多数时候你都能找到无法启动的原因。
### 6.保护你的数据 ###
好了你的关系数据库管理系统已经准备好接收SQL查询但是把你宝贵的数据放在没有最起码安全保护的服务器上并不可取为了更为安全最好使用mysql_secure_instalation这个工具可以帮助删除未使用的默认功能还设置root的密码并限制使用此用户进行访问。
只需要在shell中执行并参照屏幕上的说明。
mysql_secure_install
### 7.还原备份 ###
如果您参照之前的设置现在你可以恢复数据库只需再用mysqldump一次。
mysqldump -u root -p < mydatabases.sql
恭喜你你刚刚已经在你的CentOS上成功安装了Percona你的服务器已经可以正式投入使用你可以像使用MYSQL一样使用它你的服务器与他完全兼容。
### 总结 ###
为了获得更强的性能你需要对配置文件做大量的修改,但这里也有一些简单的选项来提高机器的性能。当使用InnoDB引擎时将innodb_file_per_table设置为on它将在一个文件中为每个表创建索引表这意味着每个表都有它自己的索引文件它使系统更强大和更容易维修。
可以修改innodb_buffer_pool_size选项InnoDB应该有足够的缓存池来应对你的数据集大小应该为当前可用内存的70%到80%。
过将innodb-flush-method设置为O_DIRECT关闭写入高速缓存如果你使用了RAID这可以提升性能因为在底层已经完成了缓存操作。
如果你的数据并不是十分关键并且并不需要对数据库事务正确执行的四个基本要素完全兼容可以将innodb_flush_log_at_trx_commit设置为2这也能提升系统的性能。
--------------------------------------------------------------------------------
via: http://linoxide.com/linux-how-to/percona-server-centos-7/
作者:[Carlos Alberto][a]
译者:[FatJoe123](https://github.com/FatJoe123)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:http://linoxide.com/author/carlosal/