如何在 CentOS 7 上安装 Percona Server

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在 CentOS 7 上安装 Percona Server相关的知识,希望对你有一定的参考价值。

1.备份你的数据库
接下来,在命令行下使用SQL命令创建一个mydatabases.sql文件,来重建或恢复salesdb和employeedb数据库,根据你的设置替换数据库名称,如果没有安装mysql则跳过此步:
mysqldump -u root -p --databases employeedb salesdb > mydatabases.sql

2.复制当前的配置文件,如果你没有安装MYSQL也可跳过:
cp my.cnf my.cnf.bkp

3.删除之前的SQL服务器
停止MYSQL/MariaDB,如果它们还在运行:
systemctl stop mysql.service

3.卸载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
参考技术A 1、安装数据库源
# yum install percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm1

2、安装Percona 5.7
# yum install Percona-Server-server-571

3、启动数据库并设置开机启动
# service mysqld restart
# chkconfig mysqld on12

4、初始化数据库
[root@localhost Percona-db]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:

The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new password:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Dropping test database...
Success.

- Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

Centos 安装Percona Toolkit工具集

1、下载

下载地址:   https://www.percona.com/downloads/percona-toolkit/LATEST/

 

技术分享图片

[[email protected] ~]# wget https://www.percona.com/downloads/percona-toolkit/3.0.13/binary/redhat/7/x86_64/percona-toolkit-3.0.13-re85ce15-el7-x86_64-bundle.tar

2、安装

[[email protected] ~]# rpm -ivh percona-toolkit-3.0.13-1.el7.x86_64.rpm 
warning: percona-toolkit-3.0.13-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 8507efa5: NOKEY
error: Failed dependencies:
        perl(DBI) >= 1.13 is needed by percona-toolkit-3.0.13-1.el7.x86_64
        perl(DBD::mysql) >= 1.0 is needed by percona-toolkit-3.0.13-1.el7.x86_64
        perl(IO::Socket::SSL) is needed by percona-toolkit-3.0.13-1.el7.x86_64

缺少 perl-DBI   perl-DBD-MySQL  perl-IO-Socket-SSL 依赖包,通过yum安装即可

再次安装 percona-toolkit-3.0.13-1.el7.x86_64.rpm 

[[email protected] ~]# rpm -ivh percona-toolkit-3.0.13-1.el7.x86_64.rpm 
warning: percona-toolkit-3.0.13-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 8507efa5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:percona-toolkit-3.0.13-1.el7     ################################# [100%]

3、检验安装结果

[[email protected] ~]# pt-duplicate-key-checker --help
pt-duplicate-key-checker examines MySQL tables for duplicate or redundant
indexes and foreign keys.  Connection options are read from MySQL option files.
For more details, please use the --help option, or try perldoc
/usr/bin/pt-duplicate-key-checker for complete documentation.

Usage: pt-duplicate-key-checker [OPTIONS] [DSN]

Options:

  --all-structs         Compare indexes with different structs (BTREE, HASH,
                        etc)
  --ask-pass            Prompt for a password when connecting to MySQL
  --charset=s       -A  Default character set
  --[no]clustered       PK columns appended to secondary key is duplicate (
                        default yes)
  --config=A            Read this comma-separated list of config files; if
                        specified, this must be the first option on the command
                        line
  --databases=h     -d  Check only this comma-separated list of databases
  --defaults-file=s -F  Only read mysql options from the given file
  --engines=h       -e  Check only tables whose storage engine is in this comma-
                        separated list
  --help                Show help and exit
  --host=s          -h  Connect to host
  --ignore-databases=H  Ignore this comma-separated list of databases
  --ignore-engines=H    Ignore this comma-separated list of storage engines
  --ignore-order        Ignore index order so KEY(a,b) duplicates KEY(b,a)
  --ignore-tables=H     Ignore this comma-separated list of tables
  --key-types=s         Check for duplicate f=foreign keys, k=keys or fk=both (
                        default fk)
  --password=s      -p  Password to use when connecting
  --pid=s               Create the given PID file
  --port=i          -P  Port number to use for connection
  --set-vars=A          Set the MySQL variables in this comma-separated list of
                        variable=value pairs
  --socket=s        -S  Socket file to use for connection
  --[no]sql             Print DROP KEY statement for each duplicate key (
                        default yes)
  --[no]summary         Print summary of indexes at end of output (default yes)
  --tables=h        -t  Check only this comma-separated list of tables
  --user=s          -u  User for login if not current user
  --verbose         -v  Output all keys and/or foreign keys found, not just
                        redundant ones
  --version             Show version and exit
  --[no]version-check   Check for the latest version of Percona Toolkit, MySQL,
                        and other programs (default yes)

Option types: s=string, i=integer, f=float, h/H/a/A=comma-separated list, d=DSN, z=size, m=time

Rules:

  This tool accepts additional command-line arguments. Refer to the SYNOPSIS and usage information for details.

DSN syntax is key=value[,key=value...]  Allowable DSN keys:

  KEY  COPY  MEANING
  ===  ====  =============================================
  A    yes   Default character set
  D    yes   Default database
  F    yes   Only read default options from the given file
  P    yes   Port number to use for connection
  S    yes   Socket file to use for connection
  h    yes   Connect to host
  p    yes   Password to use when connecting
  u    yes   User for login if not current user

  If the DSN is a bareword, the word is treated as the h key.

Options and values after processing arguments:

  --all-structs         FALSE
  --ask-pass            FALSE
  --charset             (No value)
  --clustered           TRUE
  --config              /etc/percona-toolkit/percona-toolkit.conf,/etc/percona-toolkit/pt-duplicate-key-checker.conf,/root/.percona-toolkit.conf,/root/.pt-duplicate-key-checker.conf
  --databases           (No value)
  --defaults-file       (No value)
  --engines             (No value)
  --help                TRUE
  --host                (No value)
  --ignore-databases    
  --ignore-engines      
  --ignore-order        FALSE
  --ignore-tables       
  --key-types           fk
  --password            (No value)
  --pid                 (No value)
  --port                (No value)
  --set-vars            
  --socket              (No value)
  --sql                 TRUE
  --summary             TRUE
  --tables              (No value)
  --user                (No value)
  --verbose             FALSE
  --version             FALSE
  --version-check       TRUE

 

以上是关于如何在 CentOS 7 上安装 Percona Server的主要内容,如果未能解决你的问题,请参考以下文章

如何在 CentOS 7 上安装 Percona Server

CentOS 7.2 安装配置 Percona Server

CentOS 7 安装 Percona XtraDB Cluster 5.7

如何在 CentOS 7 上安装和安全配置 MariaDB 10

Centos 安装Percona Toolkit工具集

CentOS 7 下 MySQL 5.7 配置 Percona Xtrabackup