1.安装redis数据库
yum install redis
2.下载fedora的epel仓库
yum install epel-release
3.启动redis服务
systemctl start redis
4.查看redis状态
systemctl status redis
停止服务
systemctl stop redis
重启服务
systemctl restart redis

5.查看redis进程
ps -ef |grep redis
6.设置开机自启动
systemctl enable redis
7.开放端口号 (若端口已开放此步可省略,可先8后7)
linux 操作防火墙: linux开放防火墙端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=6379/tcp --permanent
注意:80端口是必须要开放的
重启防火墙:
systemctl restart firewalld
8.查看端口 (若此命令无效可百度自行安装)
netstat -lnp|grep 6379
9.设置redis 远程连接和密码
输入命令进入编辑模式
vi /etc/redis.conf
9.1 将这部注释掉,否则只有本机才能访问 bind 127.0.0.1
################################## NETWORK #####################################
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#bind 127.0.0.1
# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
9.2 保护模式修改为no
#bind 127.0.0.1
# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
# "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no
9.3 如果修改端口号,修改这里就可以了,本文默认6379端口
protected-mode no
# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379
9.4 修改密码为 111111
这个密码为登陆redis所需要的密码,请记好
################################## SECURITY ###################################
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
requirepass 111111
10.保存并退出编辑重启redis
systemctl restart redis
11.进入redis
11.1:命令:
redis-cli -h 127.0.0.1 -p 6379
11.2:输入用户名和密码 auth 111111
返回OK
11.3:然后再输入 info
12.获取当前的db数
config get databases
或者
empty list or set 代表的是当前数据为空,不影响
13.切换指定db select 1 (可为0-15)
如上,切换到正确的会显示OK。错误的会显示ERR