标签搜索

在 CentOS 7 CPanel 服务器上安装 MariaDB 10

冰封一夏
2021-08-05 09:35:08 / 2 阅读 / 正在检测是否收录...

MariaDB 是一个增强版的、开源的 MySQL 替代品。它主要由 MariaDB 社区在维护,采用 GPL v2 授权许可。软件的安全性是 MariaDB 开发者的主要焦点。他们保持为 MariaDB 的每个版本发布安全补丁。当有任何安全问题被发现时,开发者会尽快修复并推出 MariaDB 的新版本。

MariaDB 的优势

  • 完全开源
  • 快速且透明的安全版本
  • 与 MySQL 高度兼容
  • 性能更好
  • 比 MySQL 的存储引擎多

在这篇文章中,我将谈论关于如何在 CentOS7 CPanel 服务器上升级 MySQL5.5 到最新的 MariaDB 。在安装前先完成以下步骤。

先决条件:

1. 停止当前 MySQL 服务

  1. root@server1[/var/]#mysql
  2. Welcometo theMySQLmonitor.Commandsendwith;org.
  3. YourMySQLconnectionidis5859
  4. Serverversion:5.5.47-cllMySQLCommunityServer(GPL)
  5. Copyright(c)2000,2015,Oracleand/orits affiliates.Allrights reserved.
  6. Oracleisa registered trademark ofOracleCorporationand/orits
  7. affiliates.Othernames may be trademarks of their respective
  8. owners.
  9. Type'help;'or'h'forhelp.Type'c'toclearthe current input statement.
  10. root@server1[~]#systemctlstop mysql
  11. root@server1[~]#systemctlstatus mysql
  12. mysql.service-LSB:startandstopMySQL
  13. Loaded:loaded(/etc/rc.d/init.d/mysql)
  14. Active:failed(Result:exit-code)sinceSun2016-01-3110:00:02UTC;1min31sago
  15. Docs:man:systemd-sysv-generator(8)
  16. MainPID:23430(code=exited,status=203/EXEC)
  17. Jan3110:00:02server1.centos7-test.comsystemd[1]:StartedMySQLServer.
  18. Jan3110:00:02server1.centos7-test.comsystemd[1]:StartingMySQLServer...
  19. Jan3110:00:02server1.centos7-test.comsystemd[1]:mysql.service:main process exited,code=exited,status=203/EXEC
  20. Jan3110:00:02server1.centos7-test.comsystemd[1]:Unitmysql.service entered failed state.
  21. Jan3110:00:02server1.centos7-test.comsystemd[1]:mysql.service failed.

2. 在升级之前将所有配置文件和数据库转移

转移数据库的存储路径和 MySQL 的配置文件

  1. root@server1[~]#cp-Rf/var/lib/mysql/var/lib/mysql-old
  2. root@server1[/var/lib/mysql]#cat/etc/my.cnf
  3. [mysqld]
  4. default-storage-engine=MyISAM
  5. innodb_file_per_table=1
  6. max_allowed_packet=268435456
  7. open_files_limit=10000
  8. root@server1[~]#mv/etc/my.cnf/etc/my.cnf-old

3. 从服务器上删除和卸载 MySQL 所有的 RPM 包

运行以下命令来禁用 MySQL RPM 的目标target。通过运行此命令,cPanel 将不再处理 MySQL 的更新,并在系统上将这些 RPM 版本标记为已卸载。

  1. /scripts/update_local_rpm_versions--edit target_settings.MySQL50uninstalled
  2. /scripts/update_local_rpm_versions--edit target_settings.MySQL51uninstalled
  3. /scripts/update_local_rpm_versions--edit target_settings.MySQL55uninstalled
  4. /scripts/update_local_rpm_versions--edit target_settings.MySQL56uninstalled

现在运行以下命令:

  1. /scripts/checkcpanelrpms--fix--targets=MySQL50,MySQL51,MySQL55,MySQL56

移除服务器上所有已有的 MySQL RPM 来为 MariaDB 的安装清理环境。请看下面的输出:

  1. root@server1[/var/lib/mysql]#/scripts/check_cpanel_rpms--fix--targets=MySQL50,MySQL51,MySQL55,MySQL56
  2. [2016-01-3109:53:59+0000]
  3. [2016-01-3109:53:59+0000]Problemswere detectedwithcPanel-provided files which are RPM controlled.
  4. [2016-01-3109:53:59+0000]Ifyou didnotmakethese changes intentionally,you can correct them by running:
  5. [2016-01-3109:53:59+0000]
  6. [2016-01-3109:53:59+0000]>/usr/local/cpanel/scripts/check_cpanel_rpms--fix
  7. [2016-01-3109:53:59+0000]
  8. [2016-01-3109:53:59+0000]ThefollowingRPMsare unneeded on your systemandshould be uninstalled:
  9. [2016-01-3109:53:59+0000]MySQL55-client-5.5.47-1.cp1148
  10. [2016-01-3109:53:59+0000]MySQL55-devel-5.5.47-1.cp1148
  11. [2016-01-3109:53:59+0000]MySQL55-server-5.5.47-1.cp1148
  12. [2016-01-3109:53:59+0000]MySQL55-shared-5.5.47-1.cp1148
  13. [2016-01-3109:53:59+0000]MySQL55-test-5.5.47-1.cp1148
  14. [2016-01-3109:53:59+0000]compat-MySQL50-shared-5.0.96-4.cp1136
  15. [2016-01-3109:53:59+0000]compat-MySQL51-shared-5.1.73-1.cp1150
  16. [2016-01-3109:53:59+0000]Removing0broken rpms:
  17. [2016-01-3109:53:59+0000]rpm:nopackages givenforerase
  18. [2016-01-3109:53:59+0000]NonewRPMS neededforinstall
  19. [2016-01-3109:53:59+0000]Disablingservice monitoring.
  20. [2016-01-3109:54:01+0000]Uninstallingunneeded rpms:MySQL55-testMySQL55-serverMySQL55-client compat-MySQL51-shared compat-MySQL50-sharedMySQL55-sharedMySQL55-devel
  21. [2016-01-3109:54:04+0000]Removedsymlink/etc/systemd/system/multi-user.target.wants/mysql.service.
  22. [2016-01-3109:54:04+0000]Restoringservice monitoring.

通过这些步骤,我们已经卸载了现有的 MySQL RPM,并做了标记来防止 MySQL的更新,服务器的环境已经清理,然后准备安装 MariaDB。

开始安装吧,我们需要根据 CentOS 和 MariaDB 的版本为 MariaDB 创建一个 yum 软件库。下面是我的做法!

安装步骤:

第1步:创建 YUM 软件库。

  1. root@server1[~]#vim/etc/yum.repos.d/MariaDB.repo
  2. [mariadb]
  3. name=MariaDB
  4. baseurl=http://yum.mariadb.org/10.0/centos7-amd64/
  5. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  6. gpgcheck=1
  7. root@server1[/etc/yum.repos.d]#cat/etc/yum.repos.d/MariaDB.repo
  8. [mariadb]
  9. name=MariaDB
  10. baseurl=http://yum.mariadb.org/10.0/centos7-amd64/
  11. gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
  12. gpgcheck=1

第2步:打开 /etc/yum.conf 并修改如下行:

删除这一行:

  1. exclude=courier*dovecot*exim*filesystem httpd*mod_ssl*mydns*mysql*nsd*php*proftpd*pure-ftpd*spamassassin*squirrelmail*

替换为:

  1. exclude=courier*dovecot*exim*filesystem httpd*mod_ssl*mydns*nsd*proftpd*pure-ftpd*spamassassin*squirrelmail*

重要

需要确保我们已经从 exclude 列表中移除了 MySQL 和 PHP。

第3步:运行以下命令来安装 MariaDB 和相关的包。

  1. root@server1[~]#yuminstallMariaDB-serverMariaDB-clientMariaDB-devel php-mysql
  2. DependenciesResolved
  3. ===============================================================================================================================================
  4. PackageArchVersionRepositorySize
  5. ===============================================================================================================================================
  6. Installing:
  7. MariaDB-client x86_6410.0.23-1.el7.centosmariadb10M
  8. MariaDB-devel x86_6410.0.23-1.el7.centosmariadb6.3M
  9. MariaDB-server x86_6410.0.23-1.el7.centosmariadb55M
  10. php-mysql x86_645.4.16-36.el7_1base99k
  11. Installingfordependencies:
  12. MariaDB-common x86_6410.0.23-1.el7.centosmariadb43k
  13. MariaDB-shared x86_6410.0.23-1.el7.centosmariadb1.2M
  14. libzip x86_640.10.1-8.el7base48k
  15. php-common x86_645.4.16-36.el7_1base563k
  16. php-pdo x86_645.4.16-36.el7_1base97k
  17. TransactionSummary
  18. ===============================================================================================================================================
  19. Install4Packages(+5Dependentpackage)

第4步:重新启动,并确保 MySQL 服务已启动。

  1. root@server1[~]#systemctlstart mysql
  2. root@server1[~]#
  3. root@server1[~]#
  4. root@server1[~]#systemctlstatus mysql
  5. mysql.service-LSB:startandstopMySQL
  6. Loaded:loaded(/etc/rc.d/init.d/mysql)
  7. Active:active(exited)sinceSun2016-01-3110:01:46UTC;3sago
  8. Docs:man:systemd-sysv-generator(8)
  9. Process:23717ExecStart=/etc/rc.d/init.d/mysql start(code=exited,status=0/SUCCESS)
  10. MainPID:23430(code=exited,status=203/EXEC)
  11. Jan3110:01:46server1.centos7-test.comsystemd[1]:StartingLSB:startandstopMySQL...
  12. Jan3110:01:46server1.centos7-test.com mysql[23717]:StartingMySQLSUCCESS!
  13. Jan3110:01:46server1.centos7-test.comsystemd[1]:StartedLSB:startandstopMySQL.

第5步:运行 mysql_upgrade 命令。

它将检查所有数据库中的所有表与当前安装的版本是否兼容,并在必要时会更新系统表,以赋予当前版本新增加的权限或能力。

  1. root@server1[~]#mysql_upgrade
  2. MySQLupgrade detected
  3. Phase1/6:Checkingandupgrading mysql database
  4. Processingdatabases
  5. mysql
  6. mysql.columns_priv OK
  7. mysql.db OK
  8. mysql.event OK
  9. mysql.func OK
  10. mysql.help_category OK
  11. mysql.help_keyword OK
  12. mysql.help_relation OK
  13. mysql.help_topic OK
  14. mysql.host OK
  15. mysql.ndb_binlog_index OK
  16. mysql.plugin OK
  17. mysql.proc OK
  18. mysql.procs_priv OK
  19. mysql.proxies_priv OK
  20. mysql.servers OK
  21. mysql.tables_priv OK
  22. mysql.time_zone OK
  23. mysql.time_zone_leap_second OK
  24. mysql.time_zone_name OK
  25. mysql.time_zone_transition OK
  26. mysql.time_zone_transition_type OK
  27. mysql.user OK
  28. Phase2/6:Fixingviewsfrommysql
  29. Phase3/6:Running'mysql_fix_privilege_tables'
  30. Phase4/6:Fixingtableanddatabase names
  31. Phase5/6:Checkingandupgrading tables
  32. Processingdatabases
  33. cphulkd
  34. cphulkd.auths OK
  35. cphulkd.blacklist OK
  36. cphulkd.brutes OK
  37. cphulkd.good_logins OK
  38. cphulkd.ip_lists OK
  39. cphulkd.known_netblocks OK
  40. cphulkd.login_track OK
  41. cphulkd.logins OK
  42. cphulkd.report OK
  43. cphulkd.whitelist OK
  44. eximstats
  45. eximstats.defers OK
  46. eximstats.failures OK
  47. eximstats.sends OK
  48. eximstats.smtp OK
  49. information_schema
  50. leechprotect
  51. leechprotect.hits OK
  52. modsec
  53. modsec.hits OK
  54. performance_schema
  55. roundcube
  56. roundcube.cache OK
  57. roundcube.cache_index OK
  58. roundcube.cache_messages OK
  59. roundcube.cache_shared OK
  60. roundcube.cache_thread OK
  61. roundcube.contactgroupmembers OK
  62. roundcube.contactgroups OK
  63. roundcube.contacts OK
  64. roundcube.cp_schema_version OK
  65. roundcube.dictionary OK
  66. roundcube.identities OK
  67. roundcube.searches OK
  68. roundcube.session OK
  69. roundcube.system OK
  70. roundcube.usersOK
  71. saheetha_test
  72. saheetha_test.authors OK
  73. whmxfer
  74. whmxfer.sessions OK
  75. Phase6/6:Running'FLUSH PRIVILEGES'
  76. OK

第6步:再次重新启动 MySQL 的服务,以确保一切都运行完好。

  1. root@server1[~]#systemctlrestart mysql
  2. root@server1[~]#
  3. root@server1[~]#systemctlstatus mysql
  4. mysql.service-LSB:startandstopMySQL
  5. Loaded:loaded(/etc/rc.d/init.d/mysql)
  6. Active:active(running)sinceSun2016-01-3110:04:11UTC;9sago
  7. Docs:man:systemd-sysv-generator(8)
  8. Process:23831ExecStop=/etc/rc.d/init.d/mysql stop(code=exited,status=0/SUCCESS)
  9. Process:23854ExecStart=/etc/rc.d/init.d/mysql start(code=exited,status=0/SUCCESS)
  10. MainPID:23430(code=exited,status=203/EXEC)
  11. CGroup:/system.slice/mysql.service
  12. ├─23861/bin/sh/usr/bin/mysqld_safe--datadir=/var/lib/mysql--pid-file=/var/lib/mysql/server1.centos7-test.com.pid
  13. └─23933/usr/sbin/mysqld--basedir=/usr --datadir=/var/lib/mysql--plugin-dir=/usr/lib64/mysql/plugin--user=mysql--log-error=/v...
  14. Jan3110:04:10server1.centos7-test.comsystemd[1]:StartingLSB:startandstopMySQL...
  15. Jan3110:04:11server1.centos7-test.com mysql[23854]:StartingMySQL.SUCCESS!
  16. Jan3110:04:11server1.centos7-test.comsystemd[1]:StartedLSB:startandstopMySQL.

第7步:运行 EasyApache,重建 Apache/PHP 以支持 MariaDB,并确保所有 PHP 的模块保持不变。

  1. root@server1[~]#/scripts/easyapache--build

重要

如果你在安装 MariaDB 之后忘记重建 Apache/PHP,将会报如下库错误:

  1. root@server1[/etc/my.cnf.d]#php-v
  2. php:errorwhileloading shared libraries:libmysqlclient.so.18:cannot open shared objectfile:Nosuchfileordirectory

第8步:现在验证安装的程序和数据库。

  1. root@server1[/var/lib/mysql]#mysql
  2. Welcometo theMariaDBmonitor.Commandsendwith;org.
  3. YourMariaDBconnectionidis15
  4. Serverversion:10.0.23-MariaDBMariaDBServer
  5. Copyright(c)2000,2015,Oracle,MariaDBCorporationAbandothers.
  6. Type'help;'or'h'forhelp.Type'c'toclearthe current input statement.
  7. MariaDB[(none)]>show storage engines;
  8. +--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
  9. |Engine|Support|Comment|Transactions|XA|Savepoints|
  10. +--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
  11. |CSV|YES|CSV storage engine|NO|NO|NO|
  12. |MRG_MyISAM|YES|Collectionof identicalMyISAMtables|NO|NO|NO|
  13. |MEMORY|YES|Hashbased,storedinmemory,usefulfortemporary tables|NO|NO|NO|
  14. |BLACKHOLE|YES|/dev/nullstorage engine(anything youwriteto it disappears)|NO|NO|NO|
  15. |MyISAM|YES|MyISAMstorage engine|NO|NO|NO|
  16. |InnoDB|DEFAULT|Percona-XtraDB,Supportstransactions,row-level locking,andforeign keys|YES|YES|YES|
  17. |ARCHIVE|YES|Archivestorage engine|NO|NO|NO|
  18. |FEDERATED|YES|FederatedXpluggable storage engine|YES|NO|YES|
  19. |PERFORMANCE_SCHEMA|YES|PerformanceSchema|NO|NO|NO|
  20. |Aria|YES|Crash-safe tableswithMyISAMheritage|NO|NO|NO|
  21. +--------------------+---------+----------------------------------------------------------------------------+--------------+------+------------+
  22. 10rowsinset(0.00sec)

原文发布时间为:2016-06-14

本文来自云栖社区合作伙伴“Linux中国”


0

评论

博主关闭了所有页面的评论