千家信息网

CentOS7 Linux yum安装Redis的方法

发表于:2024-09-25 作者:千家信息网编辑
千家信息网最后更新 2024年09月25日,这篇文章主要介绍了CentOS7 Linux yum安装Redis的方法的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇CentOS7 Linux yum安装Redis的方
千家信息网最后更新 2024年09月25日CentOS7 Linux yum安装Redis的方法

这篇文章主要介绍了CentOS7 Linux yum安装Redis的方法的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇CentOS7 Linux yum安装Redis的方法文章都会有所收获,下面我们一起来看看吧。

1. 安装redis

  • 下载fedora的epel仓库

yum install epel-release
  • 安装redis数据库

yum install redis
  • 安装完毕后,使用下面的命令启动redis服务

# 启动redisservice redis start# 停止redisservice redis stop# 查看redis运行状态service redis status# 查看redis进程ps -ef | grep redis
  • 设置redis为开机自动启动

chkconfig redis on
  • 进入redis服务

# 进入本机redisredis-cli# 列出所有keykeys *
  • 防火墙开放相应端口

# 开启6379/sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT# 保存/etc/rc.d/init.d/iptables save# centos 7下执行service iptables save

2.修改redis默认端口和密码

  • 打开配置文件

vi /etc/redis.conf
  • 修改默认端口,查找 port 6379 修改为相应端口即可

  • 修改默认密码,查找 requirepass 修你的密码

  • 停止redis服务并指定配置文件重新启动

service redis stopredis-server /etc/redis.conf &
  • 使用端口登陆

redis-cli -h 127.0.0.1 -p 6379
  • 使用密码验证

auth 123

3.远程连接redis

  • 需要修改/etc/redis.conf

# 打开redis配置文件vi /etc/redis.conf# 找到 bind 127.0.0.1 将其注释# 找到 protected-mode yes 将其改为protected-mode no
  • 重启服务

service redis stopredis-server /etc/redis.conf &

如果修改了如上配置还是无法远程连接,请检查端口是否开放,网络是否连通,密码是否正确

关于"CentOS7 Linux yum安装Redis的方法"这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对"CentOS7 Linux yum安装Redis的方法"知识都有一定的了解,大家如果还想学习更多知识,欢迎关注行业资讯频道。

0