mysql-based, supplemented by lnmp build redis architecture

Article Directory


In this article, we want to explain is how to use redis, do mysql cache.
Here Insert Picture Description The actual production environment, the client database read operation is to take data directly to redis redis cache if there is no data, they will go to get mysql data, and cache data in a redis redis to have two case can not be used: expired data or data in mysql updated when users read access redis, when users write access mysql. Actually read demand is great, redis happens to be among the data cached in memory, the response speed is fast, can also reduce the pressure on our back-end database mysql

Experimental background:

server1  nginx php 172.25.2.10
server2  数据库redis 172.25.2.11
真机  msql(mariadb数据库) 172.25.2.250
关闭3台主机的防火墙和selinux

Basic environment to build

1. The process redis on the original server1 are closed.

Here Insert Picture Description2. Configure nginx webserver do
Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description2. Edit the nginx configuration file
Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionOpen nginx
Here Insert Picture DescriptionPhp installed on server1
Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionWritten test page on server1:

Here Insert Picture DescriptionHere Insert Picture Description
Here Insert Picture DescriptionAllows users to access data when the first went to redis modules take data, if there is no data or data module redis has expired, the user will find mysql to get data

2. Install redis on server2
Here Insert Picture DescriptionDelete the original made from the master.
Here Insert Picture DescriptionOpen redis
Here Insert Picture DescriptionHere Insert Picture Description3. In the real machine (mounting mariadb 250)

First, empty the environment
Here Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture DescriptionHere Insert Picture Description
Authorization allows front-end server can call back the database
The test in the test data into the database

mysql -pwestos1234 < test.php

Here Insert Picture Description

When accessed in a browser (server1). Discover at this time the client access to the information mysql database
because the database redis there are no data, so the first would go to the mysql database to get data
Here Insert Picture Description
when you can see a second time to refresh the visit is to take data from the redis
Here Insert Picture Description

Published 263 original articles · won praise 12 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_45649763/article/details/104840371