CentOS Steam 9安装 Redis
1. 安装Redis服务
shell
yum install redis
2. 启动/关闭/重启 Redis 服务
-
启动 Redis 服务命令:
shellsystemctl start redis.service
-
关闭 Redis 服务命令:
shellsystemctl stop redis.service
-
重启 Redis 服务命令:
shellsystemctl restart redis.service
-
注意:Redis 启动成功后如下
3. 设置开机启动
shell
systemctl enable redis.service
4. 设置 Redis 密码
-
编辑配置文件
shellvi /etc/redis/redis.conf
-
找到 "# requirepass foobared",去掉前面的 "#",并把 "foobared" 改成你的密码。
-
保存文件,重启 Redis 服务
shellsystemctl restart redis.service
-
验证密码
5. 开启远程连接
-
编辑配置文件
shellvi /etc/redis/redis.conf
-
找到
bind 127.0.0.1
将其注释
-
找到
protected-mode yes
将其改为protected-mode no
-
保存文件,重启 Redis 服务
shellsystemctl restart redis.service
-
开放 6379 端口
重点
注意:CentOS Stream系统默认开启了防火墙,若需要远程能登录,需开放6379端口。
shellfirewall-cmd --zone=public --add-port=6379/tcp --permanent
shellfirewall-cmd --reload
-
若为云服务器需设置
安全组
,若未设置依旧无法远程连接。