LAMP+Redis模型

1、LAMP + Redis环境配置(准备两台服务器)
1)LAMP服务器:192.168.31.236
2)Redis服务器:192.168.31.72
3)LAMP服务器:安装Apache服务、MySQL数据库服务、PHP服务、 PHPRedis连接驱动服务。(LAMP安装不做介绍)
Redis服务器:安装Redis服务
4)apache安装路径:/usrlocal/apache
5)mysql安装路径:/usrlocal/mysql
6)php安装路径:/usrlocal/php5
7)apache、mysql、php下载解压路径/usrlocal/src
仅供参考!!!!!!!!!!!
2、Redis服务器:安装Redis服务
1)下载Redis服务redis-2.8.13.tar.gz

    [root@jack31 ~]# wget -c -P /src  http://download.redis.io/releases/redis-2.8.13.tar.gz

2)解压redis-2.8.13.tar.gz

[root@jack31 ~]#tar zxvf redis-2.8.13.tar.gz 

3)解析安装

[root@jack31 ~]#cd /src/redis-2.8.13
[root@jack31 redis-2.8.13]#make PREFIX=/usr/local/redis install
~~~~~~~~~~~~~~~~~~
Hint: To run 'make test' is a good idea ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: 离开目录“/root/redis-2.8.13/src”
[root@jack31 redis-2.8.13]# 

4)复制配置文件到安装目录下/usr/local/redis

[root@jack31 redis-2.8.13]#cp /redis-2.8.13/redis.conf  /usr/local/redis/

5)添加环境变量
/etc/profile文件加入:export PATH=/usr/local/redis/bin:$PATH ;如下图:

[root@jack31 ~]#vim /etc/profile
[root@jack31 ~]#source /etc/profile

这里写图片描述

6)启动Redis服务命令

[root@jack31 redis]# nohup /usr/local/redis/bin/redis-server /usr/local/redis/redis.conf &
[1] 6504
nohup: 忽略输入并把输出追加到"nohup.out"
[root@jack31 redis]# 

7)停止Redis服务命令

[root@jack31 ~]#/usr/local/redis/bin/redis-cli -p 6379 shutdown
[1]+  完成                  nohup /usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
[root@jack31 redis]# 

8)本地登录测试

[root@jack31 ~]#/usr/local/redis/bin/redis-cli
127.0.0.1:6379> 

强调内容:Redis默认有16个库,从0-15,默认使用0库,可以通过select 切换:select 1 进入第1个库,select 15 进入第15个库

3、LAMP服务器:安装PHP-Redis连接驱动
1)下载PHP-Redis连接驱动

[root@jack31 ~]#wget https://github.com/phpredis/phpredis/archive/3.1.2.tar.gz
~~~~~~~~~~~~~~~~~~~~
正在保存至: “3.1.2.tar.gz”
[            <=>    ] 206,129     4.26KB/s 用时 51s    
2018-09-07 13:31:11 (3.97 KB/s) - “3.1.2.tar.gz” 已保存 [206129]
[root@jack31 ~]# 

2)解压3.1.2.tar.gz

[root@jack31 ~]#tar zxvf 3.1.2.tar.gz
~~~~~~~~~~~~~~~ 
phpredis-3.1.2/tests/TestSuite.php
phpredis-3.1.2/tests/make-cluster.sh
phpredis-3.1.2/tests/mkring.sh
[root@jack31 ~]# 

3)编译安装

[root@jack31 ~]#cd phpredis-3.1.2
[root@jack31 phpredis-3.1.2]#/usr/local/php5/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
为ok
[root@jack31 phpredis-3.1.2]#./configure --with-php-config=/usr/local/php5/bin/php-config --enable-redis
~~~~~~~~~~
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
为ok
[root@jack31 phpredis-3.1.2]# 
[root@jack31 phpredis-3.1.2]#make && make install
~~~~~~~~~~~~
---------------------------------------------------------------
Build complete.
Don't forget to run 'make test'.
Installing shared extensions:     */usr/local/php5/lib/php/extensions/no-debug-zts-20131226/*
[root@jack31 phpredis-3.1.2]# 
注意:/usr/local/php5/lib/php/extensions/no-debug-zts-20131226/模块路径

4)修改php的配置文件/usr/local/php/etc/php.ini
1)如果没有此文件去PHP源码包复制:
[root@jack31 ~]#cp /usr/local/src/php-5.6.37/php.ini-production /usr/local/php5/etc/php.ini
2)在/usr/local/php/etc/php.ini配置文件添加下面两行代码

extension_dir=”/usr/local/php5/lib/php/extensions/no-debug-zts-20131226
extension=redis.so


[root@jack31 ~]#vim /usr/local/php5/etc/php.ini
(1)
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir ; extension_dir = “./”
; On windows:
; extension_dir = “ext”
extension_dir = “/usr/local/php5/lib/php/extensions/no-debug-zts-20131226”
(2)
; If you wish to have an extension loaded automatically, use the following
; extension=modulename.extension
extension=redis.so #上两个为添加redis.so模块

5)重启apache服务,写入phpinfo测试页面
有下面的就说明添加成功:
这里写图片描述

6)LAMP+Redis缓存测试
在LAMP服务器,修改Discuz PHP网站发布/usr/local/apache/htdocs/config目录全局配置
文件config_global.php,查找

$_config['memory']['redis']['server'] = '';

将redis server后改为Redis主服务器的IP 192.168.31.72
这里写图片描述

4、测试Redis缓存
1)浏览器访问Apache PHP论坛网站,同时登录Redis服务器进行如下操作

[root@jack31 redis]# /usr/local/redis/bin/redis-cli
127.0.0.1:6379> keys *
 1) "6oqE8B_announcements"
 2) "6oqE8B_onlinerecord"
 3) "6oqE8B_fields_required"
 4) "6oqE8B_forumlinks"
 5) "6oqE8B_fields_optional"
 6) "6oqE8B_userapp"
 7) "6oqE8B_historyposts"
 8) "6oqE8B_diytemplatename"
 9) "6oqE8B_stamptypeid"
10) "6oqE8B_creditrule"
11) "6oqE8B_usergroup_7"
12) "6oqE8B_pluginlanguage_script"
13) "6oqE8B_onlinelist"
14) "6oqE8B_userstats"
15) "6oqE8B_style_default"
16) "6oqE8B_diytemplatenamehome"
17) "6oqE8B_common_member_2"
18) "6oqE8B_usergroups"
19) "6oqE8B_ipctrl"
20) "6oqE8B_ipbanned"
21) "6oqE8B_common_member_status_2"
22) "6oqE8B_setting"
23) "6oqE8B_fields_register"
24) "6oqE8B_seccodedata"
25) "6oqE8B_common_member_field_home_2"
26) "6oqE8B_pluginlanguage_system"
27) "6oqE8B_heats"
28) "6oqE8B_common_member_count_2"
29) "6oqE8B_diytemplatenameforum"
30) "6oqE8B_plugin"
31) "6oqE8B_magic"
32) "6oqE8B_usergroup_10"
33) "6oqE8B_cronnextrun"
34) "6oqE8B_modreasons"
127.0.0.1:6379> 

执行命令redis-cli进入Redis命令行,运行命令keys
*,如下图所示,存在2ewbrw_开头的key,则证明Redis成功缓存LAMP+Discuz网站信息数据。

2)测试Redis缓存是否生效
1)访问LAMP+Discuz网站,创建论坛测试用户chenliang1038,密码123456,此时用户数据第一次注册,用户名和密码会写入到MySQL数据库表中,同时也会将该数据写入至Redis缓存中,如图所示:
这里写图片描述

2)将test用户信息从MySQL Discuz库pre_common_member中删除,通过chenliang1038用户依然可以正常登录WEB网站,则证明此数据读取的是Redis缓存服务器。

[root@jack31 ~]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 5.6.39 Source distribution
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
| ultrax  #这位Discuz网站数据库            |
+--------------------+
5 rows in set (0.08 sec)
mysql> use ultrax    #使用ultrax库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select uid,email,username,password from pre_common_member;  #查询用户数据,含有chenliang1038用户
+-----+------------------+---------------+----------------------------------+
| uid | email            | username      | password                         |
+-----+------------------+---------------+----------------------------------+
|   1 | admin@admin.com  | admin         | e80bd19030e54b59f51dd34cc3a768eb |
|   2 | 869072134@qq.com | chenliang1038 | e92a41b28e3c3a9fa6fdc72adf91f498 |
+-----+------------------+---------------+----------------------------------+
2 rows in set (0.00 sec)
mysql> delete from pre_common_member where username='chenliang1038'
mysql> select uid,email,username,password from pre_common_member;
+-----+------------------+---------------+----------------------------------+
| uid | email            | username      | password                         |
+-----+------------------+---------------+----------------------------------+
|   1 | admin@admin.com  | admin         | e80bd19030e54b59f51dd34cc3a768eb |
|   2 | 869072134@qq.com | chenliang1038 | e92a41b28e3c3a9fa6fdc72adf91f498 |
+-----+------------------+---------------+----------------------------------+
2 rows in set (0.00 sec)

mysql> delete from pre_common_member where username='chenliang1038';  #删除chenliang1038用户数据
Query OK, 1 row affected (0.01 sec)
mysql> select uid,email,username,password from pre_common_member;    #在查询用户数据,已经没有chenliang1038用户了
+-----+-----------------+----------+----------------------------------+
| uid | email           | username | password                         |
+-----+-----------------+----------+----------------------------------+
|   1 | admin@admin.com | admin    | e80bd19030e54b59f51dd34cc3a768eb |
+-----+-----------------+----------+----------------------------------+
1 row in set (0.00 sec)
mysql> 

3)退出登录,在以chenliang1038登录,结果是可以登录的
这里写图片描述
这里写图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值