最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

redis服務(wù)器環(huán)境下mysql實現(xiàn)lnmp架構(gòu)緩存

 更新時間:2018年07月18日 11:31:05   作者:weixin_41789003  
這篇文章主要介紹了redis系統(tǒng)環(huán)境下mysql實現(xiàn)lnmp架構(gòu)緩存,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下

配置環(huán)境:redhat6.5

server1:redis(172.25.254.1)

server2:php(172.25.254.2)

server3:mysql(172.25.254.3)

配置步驟:

server2:

1、server2安裝php的redis相應(yīng)模塊

2、nginx安裝

[root@server2 php-fpm.d]# rpm -ivh nginx-1.8.0-1.el6.ngx.x86_64.rpm 
warning: nginx-1.8.0-1.el6.ngx.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 7bd9bf62: NOKEY
Preparing...        ########################################### [100%]
  1:nginx         ########################################### [100%]
----------------------------------------------------------------------
 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 nginx
uid=498(nginx) gid=499(nginx) groups=499(nginx)

3、nginx和php配置

1、php配置

[root@server2 php-fpm.d]# cd /etc/php-fpm.d/
[root@server2 php-fpm.d]# id nginx
uid=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 start
Starting php-fpm:                     [ OK ]
[root@server2 php-fpm.d]# netstat -antlp | grep php
tcp    0   0 127.0.0.1:9000       0.0.0.0:*          LISTEN   1125/php-fpm    
[root@server2 php-fpm.d]# vim /etc/php.ini

2、nginx配置

[root@server2 ~]# cd /etc/nginx/conf.d/
[root@server2 conf.d]# ls
default.conf example_ssl.conf
[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: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 -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@server2 conf.d]# nginx 
[root@server2 conf.d]# netstat -anplt |grep nginx
tcp    0   0 0.0.0.0:80         0.0.0.0:*          LISTEN   1141/nginx

php測試:

[root@server2 conf.d]# cd /usr/share/nginx/html/
[root@server2 html]# vim index.php
[root@server2 html]# cat index.php 
<!--php
phpinfo()
-->
[root@server2 html]# /etc/init.d/php-fpm reload
Reloading php-fpm: [14-Jul-2018 01:09:13] NOTICE: configuration file /etc/php-fpm.conf test is successful
                              [ OK ]

物理機(jī)訪問:

4、php配置redis+mysql

[root@server2 ~]# cd /usr/share/nginx/html/
[root@server2 html]# vim test.php 
  <!--php
      $redis = new Redis();
      $redis--->connect('172.25.254.1',6379) or die ("could net connect redi  s server");
   #   $query = "select * from test limit 9";
      $query = "select * from test";
      for ($key = 1; $key < 10; $key++)
      {
          if (!$redis->get($key))
          {
             $connect = mysql_connect('172.25.254.3','redis','wes  tos');
             mysql_select_db(test);
             $result = mysql_query($query);
             //如果沒有找到$key,就將該查詢sql的結(jié)果緩存到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、添加php支持的redis模塊

[root@server2 ~]# unzip phpredis-master.zip 
[root@server2 ~]# cd phpredis-master
[root@server2 phpredis-master]# phpize 
Configuring for:
PHP Api Version:     20090626
Zend Module Api No:   20090626
Zend Extension Api No:  220090626
[root@server2 phpredis-master]# ls
acinclude.m4  config.sub   library.c     README.markdown
aclocal.m4   configure    library.h     redis.c
autom4te.cache configure.in  ltmain.sh     redis_session.c
build      CREDITS     Makefile.global  redis_session.h
common.h    debian     missing      run-tests.php
config.guess  debian.control mkdeb-apache2.sh serialize.list
config.h.in   igbinary    mkinstalldirs   tests
config.m4    install-sh   php_redis.h
[root@server2 phpredis-master]# ./configure 
[root@server2 phpredis-master]# make && make install 
[root@server2 ~]# cd /etc/php.d/
[root@server2 php.d]# ls
curl.ini   json.ini   mysql.ini   pdo_sqlite.ini zip.ini
fileinfo.ini mbstring.ini pdo.ini    phar.ini
gd.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 reload
Reloading 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 redis
redis
server3:mysql配置

1、安裝mysql-server

[root@server3 ~]# rpm -qa | grep mysql
mysql-community-common-5.7.17-1.el6.x86_64
mysql-community-client-5.7.17-1.el6.x86_64
mysql-community-libs-compat-5.7.17-1.el6.x86_64
mha4mysql-node-0.56-0.el6.noarch
mysql-community-libs-5.7.17-1.el6.x86_64
mysql-community-server-5.7.17-1.el6.x86_64
[root@server3 ~]# rpm -e `rpm -qa|grep mysql` --nodeps  ##不考慮依賴性刪除mysql
warning: /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 ##安裝

2、開啟mysql,并導(dǎo)入測試數(shù)據(jù)庫

[root@server3 ~]# /etc/init.d/mysqld start
[root@server3 ~]# mysql < test.sql
[root@server3 ~]# mysql < test.sql 
[root@server3 ~]# cat test.sql 
use 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、數(shù)據(jù)庫授權(quán)

[root@server3 ~]# mysql
mysql> 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)

測試:訪問172.25.254.2/test.php

1、php默認(rèn)從redis 索取數(shù)據(jù),第一次redis無緩存,則php從mysql'索取數(shù)據(jù)

第一次無緩存

第二次索取數(shù)據(jù)后:

redis節(jié)點也可查看

[root@server1 redis-4.0.1]# redis-cli
127.0.0.1:6379> get 2
"test2"

2、將數(shù)據(jù)庫server3節(jié)點內(nèi)容更新并刪除節(jié)點,則php從數(shù)據(jù)庫索取數(shù)據(jù)節(jié)點更新內(nèi)容

mysql> update test.test set name='westos' where id=1;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> 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的master主機(jī)刪除節(jié)點內(nèi)容

[root@server1 redis-4.0.1]# redis-cli
127.0.0.1:6379> get 2
"test2"
127.0.0.1:6379> del 1
(integer) 1
127.0.0.1:6379> get 1
(nil)

刷新頁面,再次訪問

以上redis 作為 mysql 的緩存服務(wù)器,但是如果更新了 mysql,redis中仍然會有對應(yīng)的 KEY,數(shù)據(jù)就不會更新,此時就會出現(xiàn) mysql 和 redis 數(shù)據(jù)不一致的情況。

總結(jié)

以上所述是小編給大家介紹的redis服務(wù)器環(huán)境下mysql實現(xiàn)lnmp架構(gòu)緩存,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • mysql_connect(): Connection using old (pre-4.1.1) authentication protocol refused

    mysql_connect(): Connection using old (pre-4.1.1) authentica

    MySQL錯誤提示:Connection using old (pre-4.1.1) authentication protocol refused (client option ‘secure_auth’ enabled)解決辦法,需要的朋友可以參考下
    2014-04-04
  • MySQL基礎(chǔ)教程之事務(wù)異常情況

    MySQL基礎(chǔ)教程之事務(wù)異常情況

    事務(wù)(Transaction)是訪問和更新數(shù)據(jù)庫的程序執(zhí)行單元;事務(wù)中可能包含一個或多個sql語句,這些語句要么都執(zhí)行,要么都不執(zhí)行,下面這篇文章主要給大家介紹了關(guān)于MySQL基礎(chǔ)教程之事務(wù)異常情況的相關(guān)資料,需要的朋友可以參考下
    2022-10-10
  • 學(xué)習(xí)mysql?如何行轉(zhuǎn)列與列傳行

    學(xué)習(xí)mysql?如何行轉(zhuǎn)列與列傳行

    這篇文章主要介紹了mysql行轉(zhuǎn)列與列傳行的使用方法,幫助大家更好的理解和學(xué)習(xí)MySQL的使用,語句不難,但有一定的知識參考價值,需要的朋友可以參考一下,希望給你的學(xué)習(xí)帶來幫助
    2022-02-02
  • mysql中find_in_set()函數(shù)的使用及in()用法詳解

    mysql中find_in_set()函數(shù)的使用及in()用法詳解

    這篇文章主要介紹了mysql中find_in_set()函數(shù)的使用以及in()用法詳解,需要的朋友可以參考下
    2018-07-07
  • MySQL存儲過程的創(chuàng)建和使用示例詳解

    MySQL存儲過程的創(chuàng)建和使用示例詳解

    文章介紹了MySQL存儲過程的概念、創(chuàng)建與刪除、調(diào)用、變量使用、參數(shù)、流程控制、管理和案例,存儲過程可以封裝SQL指令,提高執(zhí)行效率,但也有一定局限性,感興趣的朋友跟隨小編一起看看吧
    2025-02-02
  • mysql中url時區(qū)的陷阱該如何規(guī)避詳解

    mysql中url時區(qū)的陷阱該如何規(guī)避詳解

    最近在工作中發(fā)現(xiàn)一個問題,是關(guān)于mysql中url時區(qū)的,發(fā)現(xiàn)這個陷阱如果大家不注意可能都會遇到,所以給大家總結(jié)下,這篇文章主要給大家介紹了關(guān)于mysql中url時區(qū)的陷阱該如何規(guī)避的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-08-08
  • MySql 空間索引的實現(xiàn)

    MySql 空間索引的實現(xiàn)

    MySQL空間索引是一種用于優(yōu)化地理空間數(shù)據(jù)查詢的數(shù)據(jù)結(jié)構(gòu),通過為幾何數(shù)據(jù)類型創(chuàng)建空間索引,可以高效地對空間數(shù)據(jù)進(jìn)行查詢和操作,感興趣的可以了解一下
    2024-11-11
  • MySQL遷移中explicit_defaults_for_timestamp參數(shù)影響

    MySQL遷移中explicit_defaults_for_timestamp參數(shù)影響

    在MySQL數(shù)據(jù)庫遷移過程中,explicit_defaults_for_timestamp參數(shù)設(shè)置為off可能導(dǎo)致數(shù)據(jù)寫入行為變化,本文就來介紹一下explicit_defaults_for_timestamp參數(shù)影響,感興趣的可以了解一下
    2024-09-09
  • 詳解如何在MySQL中自動生成和更新時間戳

    詳解如何在MySQL中自動生成和更新時間戳

    在數(shù)據(jù)庫設(shè)計中,時間戳字段(如 create_time 和 update_time)是非常常見的需求,它們通常用于記錄數(shù)據(jù)的創(chuàng)建時間和最后更新時間,以便于數(shù)據(jù)追蹤和分析,本文將深入探討如何在 MySQL 中設(shè)置自動生成和更新時間戳字段,需要的朋友可以參考下
    2025-02-02
  • window10系統(tǒng)下mysql5.7安裝審計插件(親測有用)

    window10系統(tǒng)下mysql5.7安裝審計插件(親測有用)

    mysql有沒oracle這樣的審計功能,突然想在mysql做審計怎么辦,下面帶大家從零開始給mysql安裝審計插件,親測絕對可用哦,需要的朋友可以參考下
    2022-09-09

最新評論

诏安县| 都兰县| 瑞丽市| 前郭尔| 施甸县| 多伦县| 临沂市| 凌源市| 阿拉善左旗| 济阳县| 昭苏县| 西城区| 绿春县| 浠水县| 西吉县| 文昌市| 淅川县| 抚远县| 莱州市| 永定县| 剑河县| 金门县| 宣汉县| 星子县| 宝坻区| 迁安市| 靖西县| 义乌市| 香格里拉县| 晴隆县| 惠东县| 昭觉县| 阳信县| 济阳县| 佛学| 张北县| 达拉特旗| 长武县| 电白县| 清镇市| 孟村|