centOS下安装redis及java远程连接redis中问题解决

来源:互联网 发布:linux高级运维面试题 编辑:程序博客网 时间:2024/06/05 06:58
近期工作没那么忙想自己搭建个redis服务器环境中途遇到很多问题在网上各种搜索
最后将安装步骤和安装过程中的问题进行整理归纳希望对大家能有所帮助。
一、安装redis
(1)下载redis安装文件https://redis.io/download
(2)将redis-4.0.1.tar.gz上传到linux服务器的/opt目录下。
(3)执行tar -zxvf redis-4.0.1.tar.gz将安装包解压。cd redis-4.0.1进入到redis-4.0.1下
执行make命令会报如下错误:如果没有错误则不必执行步骤(4)。

(4)安装GCC编译工具。yum install gcc
(5)进入到redis-4.0.1目录下执行make命令报下面错误:

(6)执行vi .make-settings 编辑src/.make-settings ,改为OPT=-O2 -march=x86-64
然后在/opt/redis-4.0.1下执行make命令会报如下错误
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1
(7)下载tcl8.6.1-src.tar.gz ,将文件上传到linux服务器/opt目录下执行tar -zxvf tcl8.6.1-src.tar.gz将安装包解压。
(8)cd /opt/tcl8.6.1/unix 进入到/opt/tcl8.6.1/unix目录下。
(9)执行配置 ./configure
(10)在目录下编译 make
(11)在目录下安装 make install
(12)进入到/opt/redis-4.0.1目录下执行make。redis安装完成。
(13)进入到/opt/redis-4.0.1/src目录启动redis服务./redis-server。

二、JAVA用Jedis连接redis。
(1)因为centOS默认是开启防火墙的所有要将redis的6379端口对外开放。需要执行iptables -I INPUT -p tcp --dport 6379 -j ACCEPT 和service iptables save命令。然后连接报下面错误:
Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
at redis.clients.jedis.Protocol.processError(Protocol.java:127)
at redis.clients.jedis.Protocol.process(Protocol.java:161)
at redis.clients.jedis.Protocol.read(Protocol.java:215)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340)
at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239)
at redis.clients.jedis.Jedis.set(Jedis.java:121)
at com.ebrun.mavenpro.utils.TestMain.main(TestMain.java:9)
需要为redis设置上密码,修改/opt/redis-4.0.1目录下的redis.conf文件。

参数的yes改为no。或者进入到/opt/redis-4.0.1/src目录下启动客户端执行./redis-cls进入客户端设置密码config set requirepass 123456设置密码。


本篇文章参考了多篇文章归纳总结的,参考地址:
http://blog.csdn.net/jiangxiaoge1023/article/details/51547856
http://www.cnblogs.com/langtianya/p/5189234.html



原创粉丝点击