tar命令安装

$ wget http://download.redis.io/releases/redis-2.8.17.tar.gz
$ tar xzf redis-2.8.17.tar.gz
$ cd redis-2.8.17
$ make

可以出现的错误:

/bin/sh: cc: 未找到命令 make[1]: *** [adlist.o] 错误 127

解决办法:

#yum安装gcc
[root@VM_255_centos redis-2.8.17]# yum install gcc-c++ 
#清空上次编译失败残留文件
[root@VM_255_centos redis-2.8.17]# make distclean 
#执行编译及安装 
[root@VM_255_centos redis-2.8.17]# make && make install

启动redis服务端:

[root@VM_255_centos src]# pwd
/usr/myproject/redis-2.8.17/src
[root@VM_255_centos src]# ./redis-server

启动redis客户端:

[root@VM_255_145_centos src]# pwd
/usr/myproject/redis-2.8.17/src
[root@VM_255_145_centos src]# ./redis-cli

设置密码:

[root@VM_255_145_centos src]# config get requirepass
[root@VM_255_145_centos src]# config set requirepass 123456
[root@VM_255_145_centos src]#./ redis-cli-h 127.0.0.1-p 6379 -a 123456

或直接在redis.conf配置文件中配置密码

[root@VM_255_145_centos redis-2.8.17]# pwd
/usr/myproject/redis-2.8.17
[root@VM_255_145_centos redis-2.8.17]# vi redis.conf

配置内容:

requirepass 123456

配置文件的修改:

dbfilename /usr/myproject/redis-2.8.17/data/dump.rdb
dir /usr/myproject/redis-2.8.17/data/redis_data
bind 139.199.38.31
port 6379

Linux通过yum安装redis

yum install redis 
或
yum install -y http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
yum --enablerepo=remi install redis
重启redis
service redis start
或者
systemctl start redis或
直接使用命令:
redis-server
redis-cli

查看redis状态

[root@VM_255_centos myproject]# systemctl status redis.service




redis 安装 报错 redis编译安装报错_6 redis 编译失败


jedis连接Redis可以出现的异常:

Exception in thread "main" redis.clients.jedis.exceptions.JedisException: Could not get a resource from the pool
 at redis.clients.util.Pool.getResource(Pool.java:51)
 at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226)
 at com.sd.util.redis.JedisUtil.getJedis(JedisUtil.java:61)
 at com.sd.util.redis.JedisUtil$Strings.set(JedisUtil.java:1164)
 at com.sd.util.redis.JedisUtil$Strings.set(JedisUtil.java:1141)
 at com.sd.controller.pc.Test.main(Test.java:205)
Caused by: java.util.NoSuchElementException: Unable to validate object
 at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:506)
 at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363)
 at redis.clients.util.Pool.getResource(Pool.java:49)
 ... 5 more


redis 安装 报错 redis编译安装报错_redis_02


原因分析:

1、防火墙屏蔽了6379端口

2、redis的保护模式默认为yes

3、域名绑定的问题

4、同一台机器中安装了两个版本的redis

常规解决办法:

[root@VM_255_145_centos redis-2.8.17]# pwd
/usr/myproject/redis-2.8.17
[root@VM_255_145_centos redis-2.8.17]# vi redis.conf

配置内容:

protected-mode no


redis 安装 报错 redis编译安装报错_6 redis 编译失败_03


最后,开通6379端口

[root@VM_255_145_centos redis-2.8.17]# vi /etc/sysconfig/iptables-config

添加内容

-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT


redis 安装 报错 redis编译安装报错_redis 安装 报错_04


查看当前系统中是否安装了多个版本的redis

[root@VM_255__centos ~]# find / |grep redis


redis 安装 报错 redis编译安装报错_redis_05


如果有多个版本,卸载一个版本即可;