Linux Enterprise-redis as a cache server for MySQL

Source: Internet
Author: User
Tags install php




I. Configuring the Environment



redhat6.5



Server1:lump PHP Module 172.25.50.1



Server2:redis 172.25.50.2



Server3:mysql 172.25.50.3650) this.width=650; "Src=" https://s5.51cto.com/oss/201710/23/ 4798dd724f358d754d0840713a37edcd.png "title=" screenshot from 2017-10-23 22-19-55.png "alt=" 4798dd724f358d754d0840713a37edcd.png "/>



Two. Installing the LNMP Environment



1. Install PHP








2. Configure Nginx








3. Configure Nginx PHP Default publishing file








4. Start Nginx and PHP services









5. Re-Server3 installation Mysql-server








Three. Installing Redis in Server2



1. Installation







2. Configure, bind all ports





3. Start the service














Four. Installing the Redis Extension for PHP



1. Installing the module








Linux system, after the successful installation of PHP, in the bin directory will generate a name phpize executable script, the purpose of this script is to dynamically install the PHP extension module. The benefit of installing PHP extensions with the Phpize script: There are no extensions installed when PHP is installed and can be installed at any later time without having to reinstall PHP.










2. Configuring the Module








Loading the Redis module





3. See if PHP is loading the Redis module Restart Service







Five. Test test.php Web page



1. Place the following test.php page in the Nginx default publishing directory










2. Start MySQL on Server3 and create an authorized Redis user








3. Pass the test test page's database to MySQL on Server3 and import the data into MySQL








Server3: Import test page data MySQL < Test.sql







4. Testing








Read data from Server2 's Redis








Database modification data on Server3








Data on Redis can not be changed in time, but also read the cache, can only be modified to change





Six. trigger Gearman for data synchronization



Here, we have implemented Redis as the MySQL cache server, but if the update Mysql,redis still have the corresponding KEY, the data will not be updated, there will be MySQL and redis data inconsistencies. So the next step is to sync the changed data to Redis via MySQL triggers. Configuring Gearman for Data synchronization
Gearman is a distributed task Distribution framework: The Gearman Job Server:gearman core program that needs to be compiled and installed and run in the background as a daemon. Gearman Client: Can be understood as a requester of a task. Gearman worker: The real performer of the task, generally need to write their own specific logic and run through the daemon process, Gearman Worker receives Gearman Client to pass the task content, will be processed sequentially.






Approximate process: The following MySQL trigger to write is equivalent to the Gearman client. modifying tables, inserting tables is equivalent to directly
issued a task. The relational data is then mapped to JSON format through the Lib_mysqludf_json UDF library function, then the task is added to the Gearman task queue through the GEARMAN-MYSQL-UDF plug-in, and finally through the redis_worker.php, which is Gearman the worker side to complete the Redis database update.






1. Installing the Gearmand module







2. Installing the PHP gearman extension








3. Configuring the Gearman Module




4. Restart PHP service, Gearman already installed











Seven. Installing the Lib_mysqludf_json module



The Lib_mysqludf_json UDF library function maps relational data to JSON format. Typically, the data in the database is mapped
To the JSON format, which is converted by a program.






1.server3 installation Mysql-devel








2. Unzip and install the Lib_mysqludf_json library function







GCC compiles lib_mysqludf_json library 650) this.width=650; "Src=" https://s4.51cto.com/oss/201710/23/ 37bcb6fe8b99f8eecc08d5ac363f2936.png "style=" Float:none; "title=" screenshot from 2017-10-21 21-30-58.png "alt=" 37bcb6fe8b99f8eecc08d5ac363f2936.png "/>








3. Copy the lib_mysqludf_json.so module into the MySQL module








4. View the MySQL module directory and register the UDF function








Eight. Installing the GEARMAN-MYSQL-UDF Plugin
This plugin is used to manage the distributed queue that calls Gearman






1. Installing GEARMAN-MYSQL-UDF modules and package dependencies





View Plugins






2. Register UDF function 





3. Specify service information for Gearman













Nine. write the worker side of the Gearman and start the background




10. Write the MySQL trigger (based on the actual situation), Mysql.sql



1. And import the database MySQL < mysql.sql









2. View triggers











11. Testing



The number of database updates entered on the Server3





Server query:







Linux Enterprise-redis as a cache server for MySQL


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.