最近想详细学习下redis,利用vagrant复制了个linux系统,把安装过程及遇到的问题记录下来,以备后用.

一.在其中一台linux服务器上安装redis服务.

1.下载某版本的安装包:wget http://download.redis.io/releases/redis-4.0.8.tar.gz

解压:tar -zvxf redis-4.0.8.tar.gz

2.安装

cd redis-4.0.8
make
cd src
make install PREFIX=/usr/local/redis //安装到指定目录
//移动配置文件到安装目录
mkdir /usr/local/redis/etc
mv redis.conf /usr/local/redis/etc

3.配置

//配置redis为后台启动
vim /usr/local/redis/etc/redis.conf //将daemonize no 改成daemonize yes
//允许除本机外的其他机器访问
bind 192.168.66.59(redis服务器的某块网卡的地址:即其他服务器访问改redis服务器时访问对应访问该服务器的ip地址)
protected-mode no
//以上不做设置时,用其他服务器访问redis服务器时会被拒绝
//将redis加入到开机启动
vi /etc/rc.local
//在里面添加内容:
/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf (意思就是开机调用这段开启redis的命令)

4.开启服务

/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
//开启客户端
/usr/local/redis/bin/redis-cli 

5.redis 支持 string,hash(用户存储对象),list,set(包括无序和有序)四种类型;

二.再另外一台lnmp服务器上安装php redis扩展

通过wget获取并安装phpredis-2.2.4 phpize后make&&make install出错,报:error: ext/standard/php_smart_str.h: No such file or directory#include <ext/standard/php_smart_str.h>

查了下原因,因为php是7.1+,最新的 phpredis 分了几大分支,针对最新的PHP稳定发行版 php7 有专门为php7的分支,所以从github拉下phpredis 源码.

1.下载安装:

git clone phpredis/phpredis,此时clone失败报:error: Peer reports incompatible or unsupported protocol version. while accessing https://github.com/nicolasff/phpredis/info/refs
解决:https请求的原因更新curl libcurl库。
yum update -y nss curl libcurl
然后重新克隆
cd phpredis
which phpize
//用phpize生成configure配置文件 执行
usr/bin/phpize
./configure --with-php-config=/usr/bin/php-config //此处为php-config的路径,可用whereis php-config查看路径 或者 find / -name phpize 得到路径
make && make install
vim php.ini
//在最后添加:
extension=redis.so;
重启php service php-fpm restart
报错:
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/redis.so' - /usr/lib64/php/modules/redis.so: undefined symbol: php_json_decode_ex in Unknown on line 0这是因为和json扩展加载顺序冲突导致的解决方法:不要在php.ini里加入extension=redis.so这行,可在php.d文件夹下创建新文件redis.ini,在redis.ini里加入extension=redis.so这行.
重启php
php -m 发现redis扩展加载上了源码安装的redis开启关闭服务操作:
1.redis关闭
redis-cli -h 127.0.0.1 -p 6379 shutdown
2.redis启动
redis-server
如果上述方式都没有成功停止redis,则可以使用终极武器 kill -9
$ ps -ef | grep redis | awk ‘{print $2}’ | xargs kill -9

三.一个简单的redis连接封装类:

<?php
class redisServer{private $redis;private $attr=["dbId"=>0];//默认dbid;protected $dbId=0;private $expireTime;private $host;private $port;public function __construct($config=[],$attr=[]){$this->redis=new Redis();$this->attr=array_merge($this->attr,$attr);$this->host=$config["host"];$this->port=$config["port"] ? $config["port"]: 6379;$this->dbId=$attr["dbId"] ?$attr["dbId"]: 0;//$this->redis->connect($config["host"],$config["port"],$this->attr["timeout"]);$this->redis->connect($config["host"],$config["port"]);$this->redis->select($this->dbId);//$this->expireTime=time()+$this->attr["timeout"];}public   function getRedis($config=[],$attr=[]){return $this->redis;}}
?>
//调用:
<?php
require_once("redisServer.php");
$redisConfig=["host"=>"192.168.66.59","port"=>6379];
$attr=["dbId"=>0];$redisServer=new redisServer($redisConfig,$attr);
$redis=$redisServer->getRedis();
$redis->set("say","hello");
var_dump($redis->get("say"));exit;
?>

四.一个简单的memcached连接封装类:

<?php
class memcachedServer{private $host;private $port;private $memcache;public function __construct($config,$attr=[]){$this->memcache= new Memcached();$this->memcache->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);$this->host=$config["host"]??'127.0.0.1';$this->port=$config["port"]??11211;//避免单个php-fpm在建立完以persistent_id命名的长连接后不再重复建立长连接if(!count( $this->memcache->getServerList())){$this->memcache->addServer($this->host,$this->port);}}public function getMem(){return $this->memcache;}
}
?>
//调用;
<?php
include_once("memcacheServer.php");
$config=["host"=>"192.168.66.59","11211"];
$memServer=new memcachedServer($config);
$mem=$memServer->getMem();
$mem->set("say","hello memcacheService1");
var_dump($mem->get("say"));exit;
?>

linux 安装redis_Linux安装redis及安装php-redis扩展相关推荐

  1. Linux下redis的安装(适用centos)

    转自:https://www.cnblogs.com/_popc/p/3684835.html 第一部分:安装redis  希望将redis安装到此目录 1 /usr/local/redis 希望将安 ...

  2. Redis 入门安装(Linux)

    Redis 入门安装(Linux) 备注:该案例讲解基于CentOS6.5.Reids3.2.8 Redis 官网 中文地址:http://www.redis.cn/ 英文地址:https://red ...

  3. linux 安装redis4.0.6,Redis(4.0.6)在Linux(CentOS7)下的安装

    构建 Redis redis 目前没有官方 RPM 安装包,需要从源代码编译,编译需要安装 Make 和 GCC. yum install gcc make 从官网下载 tar 压缩包. curl h ...

  4. Linux下redis的安装

    原文出处:http://www.cnblogs.com/_popc/p/3684835.html 第一步:redis的安装 希望将redis安装到此目录 1 /usr/local/redis 希望将安 ...

  5. linux redis数据库安装配置,Linux系统中redis的安装配置步骤

    Linux系统中redis的安装配置步骤 发布时间:2020-06-23 10:13:36 来源:亿速云 阅读:87 作者:Leah 这篇文章将为大家详细讲解有关Linux系统中redis的安装配置步 ...

  6. 七、redis的安装(linux)

    1.系统环境 [root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.8.2003 (Core) 2.Linux安装yum ...

  7. redis linux 文件位置,Linux下Redis的安装和部署

    一.Redis介绍 Redis是当前比较热门的NOSQL系统之一 它是一个key-value存储系统.和Memcache类似,但很大程度补偿了Memcache的不足,它支持存储的value类型相对更多 ...

  8. 【Redis】Linux下Redis安装与redis-desktop-manager使用(无法连接Redis服务器解决方法)...

    新手小白开始学习nosql数据库Redis,首先从安装入手. 全文分两部分:Linux下安装redis,可视化工具redis desktop manager的简单使用. 一.安装 下载,解压缩和编译R ...

  9. php redis 扩展 编译安装,Linux 下 PHP 扩展 redis 编译安装

    Linux环境为 CentOS6.5 64位 安装redis 比较简单,也没什么说的,看官网就行,链接:http://redis.io/download 主要看底部的东西. 安装好 redis 好之后 ...

最新文章

  1. EXT3与EXT4的主要区别
  2. Gut:华中科大蔺蓉组开发简单便捷无创肠道生物信息获取方法
  3. html学习文档-3、HTML元素
  4. 解决Tomcat启动时出现的The APR based Apache Tomcat Native library异常
  5. PPT学习资源(总)
  6. 计算机c盘哪些东西可以清理,细说电脑c盘哪些文件可以删除
  7. android学习日记13--数据存储之ContentProvide
  8. thinkpython2e电子书下载_《Think Python 2e》中译版电子书分享
  9. 【OpenCV】IplImage和char *的相互转换,以及极易忽视的细节
  10. 比较算盘和计算机的优点,UPD4526BC 二进制与十进制相比较的优点
  11. 谈谈作为DBA我对MySQL数据库优化的理解
  12. zookeeper学习一-ZK简介
  13. [报错解决]CondaSSLError: OpenSSL appears to be unavailable on this machine. OpenSSL is required to downl
  14. 《Miss Talk》第08期:对话桥吧英语联合创始人兼CTO 于双印
  15. 从同花顺获取涨停数据,视图化分析优质板,方便投资。
  16. text-overflow属性的使用
  17. mysql查询数据库版本
  18. STM32配置DAC输出固定电压和方波
  19. 校园网限速引起网络知识:网络配置ipconfig /release ipconfig /renew
  20. spring的IOC容器

热门文章

  1. 中国工商银行的 Service Mesh 探索与实践
  2. 如何提升软件交付效能?答案未必如你所想
  3. maven nexus 说明
  4. 当前监管面比较关注的企业征信模型
  5. Linux信号实践(2) --信号分类
  6. 异常处理:try-catch-finally与throws的区别及使用情况
  7. Java 中 @Autowired与@Resource的区别
  8. python操作haproxy配置文件实例
  9. Social Emotional Computing -价值观的运算
  10. libevent和基于libevent的网络编程