yum安装
yum install redis -y
如出现以下错误
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.neusoft.edu.cn
No package redis available.
Error: Nothing to do
需要安装epel-release
root@localhost ~]# yum install epel-release -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.huaweicloud.com
* extras: mirrors.huaweicloud.com
* updates: mirrors.neusoft.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================
Package Arch Version Repository Size
=======================================================================================
Installing:
epel-release noarch 7-11 extras 15 k
Transaction Summary
=======================================================================================
Install 1 Package
Total download size: 15 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/extras/packages/epel-release-7-11.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for epel-release-7-11.noarch.rpm is not installed
epel-release-7-11.noarch.rpm | 15 kB 00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-2.1511.el7.centos.2.10.x86_64 (@anaconda)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : epel-release-7-11.noarch 1/1
Verifying : epel-release-7-11.noarch 1/1
Installed:
epel-release.noarch 0:7-11
Complete!
完成之后再重新装redis
启动
systemctl start redis.service
关闭
systemctl stop redis.service
查看状态
systemctl status redis.service
开机自启动
systemctl enable redis
开放端口和重启防火墙(如防火墙已关闭请忽略)
[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@localhost ~]# firewall-cmd --zone=public --add-port=6379/tcp --permanent
success
[root@localhost ~]# systemctl restart firewalld
配置redis.conf
cd /etc 目录下
vi redis.conf
#bind 127.0.0.1 # 这里要注释掉,否则只有本机能访问
protected-mode no # 这里由yes改为no
requirepass 123456 # 这里设置上密码
重启redis服务
systemctl restart redis.service
然后用Redis-cli去探探:
[root@localhost etc]# redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> info
NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> info
# Server
...
原文:https://www.cnblogs.com/zuoxiaodragon/p/12732764.html