2.1 配置单独节点运行MariaDB
*@DB01*
yum install mariadb-server -y
systemctl enable --now mariadb
mysql_secure_installation
2.2 备份原始数据导入新数据库服务器
*@Web01*
mysqldump -uroot -pcentos -A > all.sql
scp all.sql root@192.168.99.101:/root/.
*@DB01*
mysql -uroot -psziit < all.sql
mysql -uroot -psziit -e "show databases;"
2.3 配置Wordpress使用新的数据库服务器
a) 防火墙放行mysql端口
@DB01
firewall-cmd --add-service=mysql
firewall-cmd --add-service=mysql rmanent
b) Selinux允许http网络连接
@Web01
setsebool -P httpd_can_network_connect on
c) 创建数据库用户并对Wordpress数据库授权
mysql -uroot -pcentos
MariaDB [(none)]> grant all on wordpress.* to 'wordpress'@'192.168.99.%' identified by 'centos';
MariaDB [(none)]> flush privileges;
d) 修改wp-config.php指向新的数据库服务器
vim /var/www/html/wp-config.php
/** The name of the database for Press */
define( 'DB_NAME', 'wordpress' );
/** MySQL database username */
define( 'DB_USER', 'wordpress' );
/** MySQL database password */
define( 'DB_PASSWORD', 'centos' );
/** MySQL hostname */
define( 'DB_HOST', '192.168.99.101' );
2.4 效果评测
访问Web01,发布测试文章,查看DB01上的wordpress数据库,能够查询到记录
DB01
MariaDB [wordpress]> use wordpress
MariaDB [wordpress]> select * from wp_posts\G;
post_title: 测试
post_excerpt:
post_status: inherit
comment_status: closed
ping_status: closed
post_password:
post_name: 17-revision-v1
to_ping:
pinged:
post_modified: 2021-12-06 12:10:51