启动redis服务器
/usr/local/redis/bin/redis-server
关闭redis服务器
/usr/local/redis/bin/redis-cli shutdown
根据配置文件启动redis
/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
客户端登陆
/usr/local/redis/bin/redis-cli
查看redis运行端口号,默认是6379端口
netstat -anp | grep redis
在Linux防火墙添加6379端口
测试链接,还是报错,原因是redis在protected mode下运行,需要关闭保护模式 ./redis-cli 打开客户端后输入:
CONFIG SET protected-mode no
jedis导包
<!--测试linux redis连接情况-->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
</dependency>
测试成功链接linux上运行的redis
Mac在 Redis Desktop Manager 上查看
redis提示关闭protected mode的四种方法:
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:
-
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.
-
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.
-
If you started the server manually just for testing, restart it with the '--protected-mode no' option.
-
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.