在Ubuntu Server 20 安装 Redis 记录
安装
安装 Redis
apt-get update
apt-get install redis-server
验证是否安装成功
service redis status
出现如下文案,表示redis正常运行
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2022-06-29 10:56:28 CST; 10min ago
...
外网访问
编辑/etc/redis/redis.conf
注释 bind 127.0.0.1 ::1
修改 requirepass foobared
将foobared
修改为自己的密码
重启
service redis restart
使用客户端链接验证,配置完毕。
遇到的问题
阿里云服务器安全组限制
所有步骤配置完之后,无法正常链接,经排查,是阿里云ESC的安全组策略限制了redis默认的6379端口,开放即可。
protected-mode yes
是否需要注释
网上有些安装教程中提到,需要将此配置改为no。验证了下,没有必要。
配置中的注释如下:
# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
# 保护模式是一层安全防护措施,是为了避免Redis实例在公网裸奔,被任意访问。
#
# 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.
#
# 当安全模式打开时,如果没有使用"bind"配置任何IP,或没有指定密码。
# 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.
# 默认情况下保护模式是打开的,当你确认你需要即使没配置密码也没有使用“bind”限制任何IP的情况下,
# 仍然接受来自任何访问时,可以关闭保护模式。
当你确认你需要即使没配置密码也没有使用“bind”限制任何IP的情况下,
仍然接受来自任何访问时,可以关闭保护模式。
如何设置了密码或者bind了IP,满足其中之一,就不需要管这个配置。