In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how mysql implements lnmp architecture caching in redis environment. The content of the article is carefully selected and edited by the author. It has certain pertinence and is of great significance to everyone's reference. Let's learn with the author how mysql implements lnmp architecture caching in redis environment.
Configuration environment: centos 7.2
Server1:redis (172.25.254.1)
Server2:php (172.25.254.2)
Server3:mysql (172.25.254.3)
Configuration steps:
Server2:
1. Server2 installs the redis corresponding module of php
2. Nginx installation
?
123456789101112131415 [root@server2 php-fpm.d] # rpm-ivh nginx-1.8.0-1.el6.ngx.x86_64.rpmwarning: nginx-1.8.0-1.el6.ngx.x86_64.rpm: header v4 rsa/sha1 signature, key id 7bd9bf62: nokeypreparing... # [100%] 1:nginx #- -thanks for using nginx! Please find the official documentation for nginx here:* https://nginx.org/en/docs/commercial subscriptions for nginx are available on:* https://nginx.com/products/-[root@server2 php-fpm. D] # id nginxuid=498 (nginx) gid=499 (nginx) groups=499 (nginx)
3. Nginx and php configuration
1. Php configuration
?
12345678910111213 [root@server2 php-fpm.d] # cd / etc/php-fpm.d/ [root@server2 php-fpm.d] # id nginxuid=498 (nginx) gid=499 (nginx) groups=499 (nginx) [root@server2 php-fpm.d] # vim www.conf 39 user = nginx 41 group = nginx [root@server2 php-fpm.d] # vim / etc/php.ini 946 date.timezone = asia/shanghai [root@server2 php-fpm.d] # / etc/init.d/php-fpm startstarting php- Fpm: [ok] [root@server2 php-fpm.d] # netstat-antlp | grep phptcp 00 127.0.0.1 root@server2 php-fpm.d 9000 0.0.0.0 netstat * listen 1125/php-fpm [root@server2 php-fpm.d] # vim / etc/php.ini
2. Nginx configuration
?
123456789101112131415161718 [root@server2] # cd / etc/nginx/conf.d/ [root@server2 conf.d] # lsdefault.conf example_ ssl.confession [root @ server2 conf.d] # vim default.conf 10 index index.php index.html index.htm; 30 location ~. Php$ {31 root html; 32 fastcgi_pass 127.0.0.1 fastcgi_pass 9000; 33 fastcgi_index index.php; 34 fastcgi_param script_filename / usr/share/nginx/html$fastcgi_script _ name; 35 include fastcgi_params 36} [root@server2 conf.d] # nginx-tnginx: the configuration file / etc/nginx/nginx.conf syntax is oknginx: configuration file / etc/nginx/nginx.conf test is successful [root@server2 conf.d] # nginx [root@server2 conf.d] # netstat-anplt | grep nginxtcp 0 0. 0. 0. 0. 0.
Php Test:
?
123456789 [root@server2 conf.d] # cd / usr/share/nginx/html/ [root@server2 html] # vim index.php [root@server2 html] # cat index.php [root@server2 html] # / etc/init.d/php-fpm reloadreloading php-fpm: [14-jul-2018 01:09:13] notice: configuration file / etc/php-fpm.conf test is successful [ok]
Physical machine access:
4. Php configure redis+mysql
?
123456789101112131415161718192021222324262728293031333435363738394041 [root@server2] # cd / usr/share/nginx/html/ [root@server2 html] # vim test.php connect ('172.25.254.1 select from test limit 9 ") or die (" could net connect redi s server "); $query =" select * from test "; for ($key = 1; $key)
< 10; $key++) { if (!$redis->Get ($key) {$connect = mysql_connect ('172.25.254.3); mysql_select_db (test); $result = mysql_query ($query); / / if no $key is found, cache the results of the query sql to redis while ($row = mysql_fetch_assoc ($result)) {$redis- > set ($row [' id'], $row ['name']);} $myserver =' mysql'; break;} else {$myserver = "redis" $data [$key] = $redis- > get ($key);}} echo $myserver; echo ""; for ($key = 1; $key)
< 10; $key++) { echo "number is $key"; echo ""; echo "name is $data[$key]" ; echo ""; }>5. Add redis modules supported by php
?
1234567891011121314151617181920212232425272829303132 [root@server2] # unzip phpredis-master.zip [root@server2] # cd phpredis-master [root@server2 phpredis-master] # phpizeconfiguring for:php api version: 20090626zend module api no: 20090626zend extension api no: 220090626 [root@server2 phpredis-master] # lsacinclude.m4 config.sub library.c readme.markdownaclocal.m4 configure library.h redis.cautom4te.cache configure.in ltmain.sh redis_session.cbuild credits makefile.global redis_session.hcommon.h debian missing run-tests.phpconfig.guess debian.control mkdeb- Apache2.sh serialize.listconfig.h.in igbinary mkinstalldirs testsconfig.m4 install-sh php_ redis.hh [root @ server2 phpredis-master] #. / configure [root@server2 phpredis-master] # make & & make install [root@server2 ~] # cd / etc/php.d/ [root@server2 php.d] # lscurl.ini json.ini mysql.ini pdo_sqlite.ini zip.inifileinfo.ini mbstring.ini pdo.ini phar.inigd.ini mysqli.ini pdo_mysql.ini sqlite3.ini [root@server2 php .d] # cp mysql.ini redis.ini [root@server2 php.d] # vim redis.ini 2 extension=redis.so [root@server2 php.d] # / etc/init.d/php-fpm reloadreloading php-fpm: [14-jul-2018 01:21:56] notice: configuration file / etc/php-fpm.conf test is successful [ok] [root@server2 php.d] # php- m | grep redisredisserver3:mysql configuration
1. Install mysql-server
?
1234567891011121314 [root@server3 ~] # rpm-qa | grep mysqlmysql-community-common-5.7.17-1.el6.x86_64mysql-community-client-5.7.17-1.el6.x86_64mysql-community-libs-compat-5.7.17-1.el6.x86_64mha4mysql-node-0.56-0.el6.noarchmysql-community-libs-5.7.17-1.el6.x86_64mysql-community-server-5.7.17-1.el6.x86_64 [root @ server3 ~] # rpm-e `rpm-qa | grep mysql`-- nodeps # # delete mysqlwarning: / etc/my.cnf saved as / etc/my.cnf.rpmsave [root@server3 ~] # rpm-qa | grep mysql [root@server3 ~] # cd / var/lib/mysql/ [root@server3 mysql] # rm-fr * [root@server3 mysql] # ls [root@server3 mysql] # yum install-y mysql-server # # install
2. Open mysql and import the test database
?
123456789101112 [root@server3] # / etc/init.d/mysqld start [root@server3] # mysql
< test.sql[root@server3 ~]# mysql < test.sql[root@server3 ~]# cat test.sqluse test;create table `test` (`id` int(7) not null auto_increment, `name` char(8) default null, primary key (`id`)) engine=innodb default charset=utf8;insert into `test` values (1,'test1'),(2,'test2'),(3,'test3'),(4,'test4'),(5,'test5'),(6,'test6'),(7,'test7'),(8,'test8'),(9,'test9');#delimiter $$#create trigger datatoredis after update on test for each row begin# set @recv=gman_do_background('synctoredis', json_object(new.id as `id`, new.name as `name`));# end$$#delimiter ; 3、数据库授权 ? 123456789101112131415161718[root@server3 ~]# mysqlmysql>Grant all on test.* to redis@'%' identified by 'westos';query ok, 0 rows affected (0.00 sec) mysql > select * from test.test;+----+-+ | id | name | +-- +-+ | 1 | test1 | | 2 | test2 | | 3 | test3 | 4 | test4 | | 5 | test5 | 6 | test6 | 7 | test7 | 8 | test8 | | 9 | test9 | +-+-+ 9 rows in set (0.00 sec)
Testing: accessing 172.25.254.2/test.php
1. Php acquires data from redis by default. The first time redis has no cache, php requests data from mysql'.
No cache for the first time
After the second request for data:
The redis node can also be viewed
?
123 [root@server1 redis-4.0.1] # redis-cli127.0.0.1:6379 > get 2 "test2"
2. Update the content of the database server3 node and delete the node, then php requests the updated content of the data node from the database
?
123456789101112131415161718mysql > update test.test set name='westos' where id=1;query ok, 1 row affected (0.05sec) rows matched: 1 changed: 1 warnings: 0mysql > select * from test.test +-+-- +-+ | id | name | +-+ + | 1 | westos | | 2 | test2 | | 3 | test3 | | 4 | test4 | | 5 | test5 | | 6 | test6 | | 7 | test7 | | 8 | test8 | 9 | test9 | +-+-+ 9 rows in set (0.00 sec)
Redis's master host deletes node content
?
1234567 [root@server1 redis-4.0.1] # redis-cli127.0.0.1:6379 > get 2 "test2" 127.0.0.1 test2 6379 > del 1 (integer) 1127.0.1 purl 6379 > get 1 (nil)
Refresh the page and visit again
After reading the above about how mysql implements lnmp architecture caching in redis environment, many readers must have some understanding. If you need more industry knowledge and information, you can continue to follow our industry information column.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.