"HyperDB" WordPress plugin for database redundancy and load balancing

My name is Ito and I am an infrastructure engineer
By using cloud services such as AWS, it is now possible to easily replicate servers and provide redundancy and load balancing for site access via a load balancer
In this state, the web servers are redundant and load balanced, but the databases are not
If there is a lot of access to the database,
the load on the web server may be fine, but the processing on the DB server may become clogged and the site may not be displayed.
This is a long introduction, but WordPress runs on a so-called LAMP environment.
This means that it uses a database, so even if you have redundant web servers, the database can get clogged...
503 Service Temporarily Unavailable
I get an error that I don't want to see
In such cases, it's a good idea to make the database redundant as well!
HyperDB , a plugin that enables database redundancy for Worddress .
In the case of AWS, it is easy to make RDS redundant.
All you have to do is create a "read replica" of the master RDS.
So I will skip the explanation here.
Install HyperDB
Installing the HyperDB plugin is a bit complicated
because although it can be installed from the WordPress admin screen,
the actual settings need to be written directly into the php file.
After installation, you should find the following file in WordPress' wp-content/plugins/hyperdb:
"db-config.php."
If you can connect to the server via SSH, you can do so. If you can only connect via FTP, you will need to configure it in advance and
upload it to the target directory.
First, write the following in wp-config.php: "The database configuration file is db-config.php."
# vim /pass/to/docroot/wp-config.php define('DB_CONFIG_FILE', ABSPATH . 'db-config.php');
Let's continue with the settings
Configuring HyperDB
Make the following settings for the installed db-config.php
First, configure the master server. (Around line 217, confirmed in v1.1)
# vim /pass/to/docroot/db-config.php $wpdb->add_database(array( 'host' => 'Enter RDS (master server) endpoint', 'user' => DB_USER, 'password' => DB_PASSWORD, 'name' => DB_NAME, 'write' => 1, 'read' => 2, ));
For host, enter the RDS endpoint. If you are using a port other than the default 3306,
you must enter the port number followed by a colon: <endpoint>:<port number>.
The key points are write and read
- write: DB write priority
- read: Priority of reading to DB
Setting it to "0" will disable writing and reading.
In the above case, the write priority to the master server is high, and the read priority is low.
Next, we will configure the slave server.
Add the following below the master server configuration.
# vim /pass/to/docroot/db-config.php $wpdb->add_database(array( 'host' => 'Enter RDS (slave server) endpoint', 'user' => DB_USER, 'password' => DB_PASSWORD, 'name' => DB_NAME, 'write' => 0, 'read' => 1, ));
Here too, write and read are effective
- write: 0 = Do not write to the server
- read: 1 = high priority for read, write is 0 so it is read only
With this setting, only reads will be sent to the slave server.
Similarly, if you register multiple slave servers, reads will only be sent to the slave servers.
Now, reads to the DB (i.e., normal access) are load-balanced among the slave servers.
In WordPress, writing to the database is mostly done from the admin screen, such as changing settings or adding articles.
This is not a problem because the master server has a high write priority.
So, now WordPress database is redundant and load balanced!
Now you can rest assured even if your site suddenly gets accessed!
HyperDB — WordPress Plugins
0