centos 7 安装和配置redis

centos 7 安装和配置redis

1.通过yum方式安装redis

切换用户至root

执行命令:

yum install redis -y

2.查看安装的情况

 whereis redis
redis: /etc/redis.conf

这里可以看到默认存放配置文件的地方

3.简单启动redis

命令:

redis-server

启动界面如下表示成功:


这里只是采用默认的方式启动最基本的服务,通常使用中并不这么玩。

4.一些常用的配置项

vi打开/etc/redis.conf文件

4.1>取消 bind 127.0.0.1


通过vi找到bind地址,注释掉

4.2>正如上面所见,Redis默认不是以守护进程的方式运行,修改daemonize值为yes使其后台运行


通过vi查找到daemonize,将后面的值改为yes

4.3>取消保护模式,默认情况下redis启动了保护模式,只能在本地访问不能远程访问。如果不取消将会报错:

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.

用vi找到protected-mode修改值为no

4.4>添加密码认证,默认情况redis是没有密码的但是实际使用中一般都会配置


通过vi查找到requirepass,可以发现默认有一行requirepass foobared被注释掉了。上面还有警告说明。将注释取消,后面跟的字符foobared便是密码改成自己需要的即可

5.通过指定配置文件的方式启动redis使其配置信息生效

虽然在第四步中我们配置了很多的信息,但是如果启动的时候不指定配置文件将不会生效

指定配置文件启动命令如下:

redis-server /etc/redis.conf




从上不难看出已经后台运行了

至此redis的安装配置实用说明结束,其他复杂配置后续补充。

centos 7 安装和配置redis

相关文章:

你感兴趣的文章:

标签云: