在阿里云服务器上安装redis流程及常见错误

在阿里云服务器上部署redis,首先需要登陆远程登陆自己购买的阿里云服务器,购买及认证的过程就不说了,当时也是一个新手,啥都不懂,也不懂服务器,一步步按照说明才完成的,现在需要在阿里云服务器上安装redis,具体过程如下:

1,找到redis官网https://redis.io/的下载页面

在阿里云服务器上安装redis流程及常见错误_第1张图片

复制链接地址,这里我下载的是最新的稳定版,然后进入服务器,在你想要放文件的目录下,使用wget命令进行下载

wget http://download.redis.io/releases/redis-4.0.9.tar.gz

tar xzf redis-4.0.9.tar.gz

cd redis-4.0.9 

执行完上面操作后执行输入make指令,等待编译安装,晚装完成后就可以使用了

进入src目录  执行  ./redis-server 启动

在阿里云服务器上安装redis流程及常见错误_第2张图片

这样就表示启动成功了,另外再开一个窗口,同样进入该目录

 在阿里云服务器上安装redis流程及常见错误_第3张图片

这样就完成了redis的读写操作了

另外我使用java api来操作这个redis

首先使用IDEA来建立一个MAVEN工程,在pom文件添加依赖

在阿里云服务器上安装redis流程及常见错误_第4张图片

然后编写java测试方法链接redis

在阿里云服务器上安装redis流程及常见错误_第5张图片

输出结果:

在阿里云服务器上安装redis流程及常见错误_第6张图片

在此过程中java远程操作redis时会出现一下小问题:

运行的时候报错:

(error) 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.

错误原因:默认情况下redis运行在保护模式(这种模式下,访问不需要密码),但是这种模式只允许本地回路访问。按照第二种方式修改。

1.修改redis.conf配置文件,将绑定的ip地址端口号给注释见下图 

在阿里云服务器上安装redis流程及常见错误_第7张图片

2.将daemonize yes 改为 daemonize no

在阿里云服务器上安装redis流程及常见错误_第8张图片

 

3.停止redis,重新启动,加载配置项就可以了   ./redis-server ../redis.conf

 

 

 
   

 

 

转载于:https://www.cnblogs.com/linlinyu/p/8748121.html

你可能感兴趣的:(在阿里云服务器上安装redis流程及常见错误)