CentOS 7下安装、配置Redis

操作系统:CentOS-7-x86_64-Minimal-1804.iso

Redis客户端:redis-desktop-manager-0.9.3.817

  • 安装

1.由于CentOS官方yum源里面没有Redis,这里我们需要安装一个第三方的yum源,这里用了Fedora的epel仓库

yum install epel-release

安装过程中会有让你确认的,输入y按回车就可以了

2.安装Redis

yum install redis

安装过程中会有让你确认的,输入y按回车就可以了

3.启动Redis

service redis start

  • 配置

1.修改端口号/密码等配置

vim /etc/redis.conf

2.注释掉ip绑定(这个只允许本地调试,不注释掉这个,你远程这个redis的时候会提示:

redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect

)

CentOS 7下安装、配置Redis

3.

关闭保护模式(不关闭的话远程这个redis会提示:

redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode

)

CentOS 7下安装、配置Redis

除了以上配置,系统的防火墙也导致了客户端连不上Redis服务:

  • 服务器防火墙安装

新装的centos系统,防火墙默认是被禁掉的,因此不会有iptables文档。

注意,别手动去创建,通过几个命令让它生成:

解决办法:

1、随便写一条iptables命令配置个防火墙规则:如:

iptables -P OUTPUT ACCEPT

2,进行保存

service iptables save

3,service iptables restart

如果出现下列异常

The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.

With RHEL 7 / CentOS 7, firewalld was introduced to manage iptables. IMHO, firewalld is more suited for workstations than for server environments.

It is possible to Go back to a more classic iptables setup. First, stop and mask the firewalld service:

请连续输入下列命令:

systemctl stop firewalld 

systemctl mask firewalld 

yum install iptables-services

systemctl enable iptables

systemctl stop iptables   

systemctl start iptables 

systemctl |restart iptables 

service iptables save

至此,iptables文件就会存在了。接下来对文档进行编辑,可以使用vim也可以直接用桌面(桌面支持从windows直接复制到iptables文档里面,比较方便)

  • iptables配置

进入修改

[root@localhost ~]#vi /etc/sysconfig/iptables

在“COMMIT”前加入

-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT

[root@localhost ~]#service iptables save
[root@localhost ~]#service iptables restart

以上全部成功后,客户端即可成功访问Redis。

PS:

查看IP命令

[root@localhost ~]# ip a

 Redis服务端命令

[root@localhost ~]# redis-cli
127.0.0.1:6379> PING
PONG
127.0.0.1:6379> quit
[root@localhost ~]#

转载自:

Linux公社的《CentOS使用yum安装Redis的方法》

Linux公社的《CentOS 7下Redis安装配置与Redis Desktop Manager工具连接注意点》

相关推荐