Ali cloud built using the WordPress Website - management and database cache

WordPress is a very popular blog site platform, can also be used as a content management system (CMS) to use, is one of the world's most widely used blog system. There are many excellent WordPress plugin that makes this open-source product very easily scale to meet different needs.
I am ready to take advantage of a series of articles, to show a variety of products (elastic computing, database, security, etc.) If you use Ali cloud, build a complete WordPress site. content include:

Fourth, database management and cache

When the site traffic increasing, the database is often the first component of the overall system performance bottlenecks encountered. This time needs to be optimized and managed by the database to improve the throughput of the database.
For site-type applications, reading and writing less is normal, therefore targeted for database read and write separation is often a good way. Separate read and write functions provided aliyun RDS data may provide external read and write a single database entry, the system of small invasive, is a very desirable solution. In addition, the industry's most commonly used method should be to increase memory database throughout the architecture for data cache, Redis databases in general will choose to implement. Accordingly, the data portion of the system becomes more complex, and therefore also need to use tools for this management DMS easy operation and maintenance.
This part of the organization chart below, based on a version adds:

  • MySQL database to read and write separation: store the user to upload attachments to WordPress
  • CDN: reading static file attachments accelerated by caching mechanism CDN edge node

image

DMS data management background

Ali cloud DMS data management products ( https://www.aliyun.com/product/dms ) official website slogan is "more powerful than phpMyAdmin, Navicat easier to use than" quite domineering. Its main role is of course all aggregation management database (whether in the cloud is not Ali), DBA library table to facilitate various operations and maintenance. Also compare appealing feature is the use of DSQL cross-database queries (by Dlink), when data validation service in the micro-architecture applications often use. Here a brief presentation about the basic features of the free version, Professional Edition and Enterprise Edition require additional purchase, but also to remove some restrictions and some additional features, see: https://help.aliyun.com/document_detail/48109.html

The easiest way is to log in DMS RDS top click "Login Database", enter the user name and password. To facilitate the presentation, I'll just use the highly privileged root account previously set.

image

Yesterday interface you can see a list of database selection and data table, where we can find by WordPress data structure is very simple, basically you can guess the purpose of the table by table name, such as "wp_posts" naturally it is stored posts . Note that "wp_" prefix can be customized Oh, if you do not know how to do students pay attention to look back at the first article of this series.
Try to write a SELECT statement to see what's inside, it's easy to find po WordPress default when you install the first piece hello world post.

image
image

Back to modify the contents of the page look, save, and then go back to re-run a DMS SQL, you can see the new content has been written into the data table.

image
image

MySQL separate read and write

MySQL读写分离这个功能,如果是自建数据库的话,需要利用Mycat做主从同步,做心跳检测,还得自己运维,还是比较麻烦的。阿里云MySQL直接提供这个功能还是很贴心,在数据库实例的“数据库代理”标签就可以打开了。首先选择添加只读实例,稍等一会儿,一个新的只读实例就创建好了。创建只读实例时会从备实例复制数据,数据与主实例一致,主实例的数据更新也会在主实例完成操作后立即自动同步到所有只读实例,完美。
image
image
image
在实例列表中会发现增加了一个打着“R”标的数据库实例。只读实例数量有限制,<64GB的主实例最多挂5个,≥64GB的主实例最多挂10个,一般中小网站挂3个就差不多了。
image
只读实例有自己的内网地址,可以用程序控制什么时候使用主实例,什么时候使用只读实例。当然大多数情况下,让MySQL自己决定就好了。我们回到主实例中,设置读写分离,将所有的读权重都给只读实例好了。这样就可以得到主实例的读写分离地址啦。

image
image
获得读写分离地址后,我们需要回到WordPress的配置文件wp-content/wp-config.php中,将之前填写的主库内网地址替换成刚刚获得的读写分析地址,并重启。
image
完成后在网页上浏览一下,从后端只读实例的监控可以看到IOPS和连接数等数据的变化,可以确定读写分离已经起作用了。
image

MySQL读写分离

Redis database ( https://www.aliyun.com/product/kvstore ) as one of the most commonly used cache database, the application can be seen in almost all walks of life. In order to use Redis up system programs need to have some transformation, WordPress is supported via plug-ins. In general availability needs to be done in order to avoid failure of Redis avalanche effect caused by the collapse of the entire system. So in most cases you should choose a multi-node cluster version to ensure high availability of the cache. Note that when the actual purchase of VPC and set a password.
image
And MySQL like to open the white list before use. This security mechanism Ali cloud database is basically a standard, basically the same configuration, the ECS server is added to the list on it.
image
image
image
image
After the whitelist is configured, record the internal network address, will be used later.
image
Then install the plug Redis Object Cache in WordPress. After installing the open configuration items, you can find this plugin need to modify the configuration before you can use. However, this configuration plug-in is not actually visualize, also need to modify the configuration file from the background, bad review.
image
image
Plug-in configuration information is placed in the configuration file wp-content / wp-config.php in. Need to add / edit the following code (where WP_REDIS_PASSWORD setting up a password to be set when creating Redis Example):

/** setup for Redis Object Cache **/
define('WP_REDIS_CLIENT', 'pecl');
define('WP_REDIS_SCHEME', 'tcp');
define('WP_REDIS_HOST', 'Redis实例的内网地址');
define('WP_REDIS_DATABASE', '0');
define('WP_REDIS_PASSWORD', '创建Redis实例时候设置的密码');
define('WP_CACHE_KEY_SALT', 'wp_');
define('WP_REDIS_MAXTTL', '86400');

image
After configuration is complete, return to plug-in configuration item on the page speaking about Redis configuration, if correct, then select "Enable Object Cache", in the status bar should show "Connected" says the configuration is complete.
image
image
Try to use about WordPress, then we use the DMS data management look at the effect of Redis. Select is also a "landing Database" in the above example the page Redis, then we should see a lot of metrics and Key-Value for CPU, memory, and other hits, which means Redis has begun to provide caching for the website service it.
image
image

Guess you like

Origin yq.aliyun.com/articles/706322