Lamp+redis Cache Database Consolidation

Source: Internet
Author: User
Tags apache php php redis php website redis server

LAMPIn an enterprise production environment, in addition to theMYSQLdeployed separately on other servers, due toMYSQLthe database will be very stressful and willMYSQLmaster-slave replication and read/write separation, whilePHPThe site is tuned, usuallyPHPthe optimization methods include:PHPThe code itself optimizes,PHPconfiguration file optimization, forPHPAdd a cache module toPHPsite data is cached, and so on.

In order to relieve the pressure of MySQL database, the Redis cache database service was used.

Lamp+redisworking mechanism: User access via browserLAMPwebsite, and login to the website with a username and password, the defaultRedisThere is no list of this user name and password in the cache .PHPThe program will readMYSQLuser name and password in the database, and then caches the user name and password toRedis, the next time the user logs on to the website again using the same user name and password through the browser,PHPno need to read the user and password information from the database, but directly take precedence from theRedisRead and return in the cache, thereby mitigatingMYSQLthe pressure on the database.

Redis In addition to caching the user name, password, you can also change PHP Forum Various data, such as user posts, user dynamics, etc., such as as shown:

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/03/4b94114b3ae994486c48ab03099a7963.png-wh_500x0-wm_3 -wmp_4-s_63241279.png "title=" Qq20171103130942.png "alt=" 4b94114b3ae994486c48ab03099a7963.png-wh_ "/>

to implement the LAMP PHP website related Data deposit Redis , you need a Redis servers, Php-redis Connection Driver, PHP Code Connection modification, and so on.

Lamp+redisOperation Case

LAMP php Connection Redis, first need to install the Redis server, install the connection driver, and then modify the PHP website configuration file, the following steps:

(1) Lamp+redis actual combat environment configuration

LAMP Server: 192.168.149.128

Redis Database: 192.168.149.129


(2)            server Installation deployment redis service, the code is as follows

wget     /http download.redis.io/releases/redis-2.8.13.tar.gz  

tar       ZXF                 redis-2.8.13.tar.gz

CD          redis-2.8.13

make     prefix=/usr/local/redis  Install

cp       redis.conf    /usr/local/redis/

will be /usr/local/redis/bin/ Add directory to environment variable configuration file /etc/profile end, and then Shell Terminal Execution Source/etc/profile make environment variables effective

Export Path=/usr/local/redis/bin: $PATH

Nohup background start and stop Redis Service Command:

Nohup/usr/local/redis/bin/redis-server/usr/local/redis/redis.conf &

/usr/local/redis/bin/redis-cli-p 6379 shutdown

(3) installation Php-redis Connection Driver

to ensure that PHP able to connect Redis cache server, add PHP Redis extension, that is, adding PHP Ann ext extension modules, add the following methods :

wget  https://github.com/phpredis/phpredis/archive/3.1.2.tar.gz

tar   xzf   3.1.2.tar.gz

/usr/local/php5/bin/phpize

cd   phpredis-3.1.2/

./configure   --with-php-config=/usr/local/php5/bin/php-config  --enable-redis

make

make install

Modify Vim/usr/local/php5/lib/php.ini configuration files, adding redis.so module, the code is as follows:

Extension_dir = "/usr/local/php5/lib/php/extensions/no-debug-zts-20090626"

Extension=redis.so

Restart Apache Services, writing Phpinfo test page, accessed through the browser, 12-9 as shown, check to be present Redis modules can:

650) this.width=650; "Src=" Https://s3.51cto.com/oss/201711/03/d8fb3b716c7a8aa62d2064947ead4b0c.png-wh_500x0-wm_3 -wmp_4-s_293481425.png "title=" Qq20171103131802.png "alt=" D8fb3b716c7a8aa62d2064947ead4b0c.png-wh_ "/>

(4) Lamp+redis Cache Test

Login192.168.149.128 WEBserver, modifyingDiscuz PHPwebsite Release/usr/local/apache2/htdcosDirectory global configuration fileconfig_global.php, findCONFIG MEMORYsegment, theRedis Serverafter insteadRedisof the primary serverIP192.168.149.129can, such asas shown:

650) this.width=650; "Src=" Https://s2.51cto.com/oss/201711/03/a1980f9e281c81d9d9be987d5c182023.png-wh_500x0-wm_3 -wmp_4-s_2493362533.png "title=" Qq20171103131937.png "alt=" A1980f9e281c81d9d9be987d5c182023.png-wh_ "/>

access via browserApache PHPForum website, simultaneous loginRedisserver, execute commandredis-cliEnterRediscommand line, Run commandKeys *, such asshown, there is aIoklanbegins withKey, it provesRedisSuccessful CacheLamp+discuzwebsite Information data.

650) this.width=650; "Src=" Https://s1.51cto.com/oss/201711/03/6c9ccc616b953fd747ada48e8fcbdac4.png-wh_500x0-wm_3 -wmp_4-s_1328627325.png "title=" Qq20171103132157.png "alt=" 6c9ccc616b953fd747ada48e8fcbdac4.png-wh_ "/>







This article is from the "Liu Shifan-technology sharing" blog, make sure to keep this source http://liusf.blog.51cto.com/13344518/1978703

Lamp+redis Cache Database Consolidation

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.