您的位置:首页 > 数据库 > Redis

VM-centos安装redis各种坑和具体步骤

2018-05-04 11:33 183 查看

一、安装redis

在菜鸟教程里有具体的教程,这里只有linux安装教程

 

Linux 下安装

下载地址:http://redis.io/download,下载最新文档版本。

本教程使用的最新文档版本为 2.8.17,下载并安装:

[code]$ 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
如果报 GCC命令找不到的错误时 执行这条命令 安装GCC yum -y install gcc automake autoconf libtool make 编译报致命错误:jemalloc/jemalloc.h:没有那个文件或目录 那就不要运行 make 命令编译 使用这个命令 make MALLOC=libc [/code]

make完后 redis-2.8.17目录下会出现编译后的redis服务程序redis-server,还有用于测试的客户端程序redis-cli,两个程序位于安装目录 src 目录下:

下面启动redis服务.

[code]$ cd src
$ ./redis-server
./redis-server[/code]

注意这种方式启动redis 使用的是默认配置。也可以通过启动参数告诉redis使用指定配置文件使用下面命令启动。

[code]$ cd src
$ ./redis-server redis.conf
./redis-server redis.conf[/code]

redis.conf是一个默认的配置文件。我们可以根据需要使用自己的配置文件。

启动redis服务进程后,就可以使用测试客户端程序redis-cli和redis服务交互了。 比如:

[code]$ cd src
$ ./redis-cli
redis> set foo bar
OK
redis> get foo
"bar"
./redis-cli redis> set foo bar OK redis> get foo "bar"[/code]

安装成功后 开启远程:

CentOS中查看ip

然后就是远程这个服务器:

本机上启动redis客户端:redis-cli.exe -h 192.168.131.131

 

接着问题就来了:ping一下 报错了

 

[code]192.168.131.131:6379> ping
(error) DENIED Redis is running in protected mode because protected mode is enab
led, no bind address was specified, no authentication password is requested to c
lients. 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 acc
essible from internet if you do so. Use CONFIG REWRITE to make this change perma
nent. 2) Alternatively you can just disable the protected mode by editing the Re
dis 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, r
estart it with the '--protected-mode no' option. 4) Setup a bind address or an a
uthentication password. NOTE: You only need to do one of the above things in ord
er for the server to start accepting connections from the outside.

 

 

查了好多资料后总结并找到原因解决:

   Redis protected-mode 是3.2 之后加入的新特性,在Redis.conf的注释中,我们可以了解到,他的具体作用和启用条件

链接redis 时只能通过本地localhost (127.0.0.1)这个来链接,而不能用网络ip(192.168..)这个链接,不然会报上面错误,

是说处于保护模式,只能本地链接,我们需要修改配置文件../redis.conf

 

1、打开配置文件把下面对应的注释掉

[code]# bind 127.0.0.1
  • 1

2、Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程,设置为no

[code]daemonize no

3、保护模式

[code]protected-mode no //原本是yes

最后是重启redis-server和客户端

[code]./redis-server ../redis.conf

 

可以看到  建立连接成功了

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: