腾讯云或阿里云centos7安装Redis,并解决端口无法访问的问题

问题背景

最近自建的网站JeecgFlow在云环境安装redis时候,出现端口无法远程进行访问。

浪费好了好久时间进行排查, 记录一下Redis在云环境centos7环境下如何安装,并且远程访问。

Redis安装

shell 复制代码
//安装c++ 用于编译redis
yum install gcc-c++

//在/usr/local创建java目录
cd /usr/local
mkdir java

//在/usr/local/java创建redis服务
1.cd /usr/local/java

2. wget http://download.redis.io/releases/redis-5.0.7.tar.gz

3. tar -zxvf redis-5.0.7.tar.gz

4. cd redis-5.0.7

5. make

6. make install

在上面目录下执行一下命令,启动redis服务: redis-server redis.conf

复制代码
[root@root redis-5.0.7]# redis-server redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 12513
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

出现如上即表示执行成功,但是按ctrl+c将会关闭服务, 故而需要进行redis.conf配置

  • 配置redis

主要配置前台关闭,密码, bind

shell 复制代码
1. 打开redis.conf
vim redis.conf
//改这个属性daemonize yes

这个配置就表示在启动后不会收到前台ctrl+c影响,属于后台启动了服务。

shell 复制代码
1. vim redis.conf
2. /requirepass 搜索到设置密码的地方,将注释取消,并且设置自己的密码
shell 复制代码
1. vim redis.conf
2. /port 将IP地址从127.0.0.1改成0.0.0.0
//这一步很重要, 不配置将会导致应用无法连接redis服务
  • 服务端验证是否安装OK
shell 复制代码
//启动服务,cd /usr/local/java/redis-5.0.7
redis-server redis.conf

//进行终端命令
[root@root redis-5.0.7]# redis-cli -p 6379 -a xxx

防火墙

安装好redis之后,就是将服务器的防火墙进行设置

shell 复制代码
systemctl status firewalld

//启动
systemctl enable firewalld.service
systemctl start firewalld

//关闭
systemctl stop firewalld

//新增端口
firewall-cmd --zone=public --add-port=8084/tcp --permanent

//重启
firewall-cmd --reload
 
//查看规则 
firewall-cmd --list-all

云环境设置

  • 腾讯云-轻量服务器

找到云服务实例,点击详情->防火墙->添加规则

  • 阿里云


主要就是按绑定的安全组新增一条规则就可以啦。

复制代码
特别注意,redis监听端口要从bind 127.0.0.1改成0.0.0.0 否则连接不上, 在这浪费好久哦!
相关推荐
RainSerein1 小时前
Laravel8中调取腾讯云文字识别OCR
ocr·php·腾讯云·laravel
软件2052 小时前
【redis使用场景——缓存——数据淘汰策略】
数据库·redis·缓存
加勒比海涛3 小时前
Spring Cloud Gateway 实战:从网关搭建到过滤器与跨域解决方案
数据库·redis·缓存
大只鹅5 小时前
分布式部署下如何做接口防抖---使用分布式锁
redis·分布式
draymond71076 小时前
阿里云-spring boot 接入SLS日志
阿里云
MonkeyKing_sunyuhua9 小时前
Ehcache、Caffeine、Spring Cache、Redis、J2Cache、Memcached 和 Guava Cache 的主要区别
redis·spring·memcached
笨手笨脚の10 天前
Redis 源码分析-Redis 中的事件驱动
数据库·redis·缓存·select·nio·epoll·io模型
(:满天星:)10 天前
Redis哨兵模式深度解析与实战部署
linux·服务器·网络·数据库·redis·缓存·centos
weixin_4383354010 天前
Spring Boot:运用Redis统计用户在线数量
java·spring boot·redis
十六点五10 天前
Redis(2)——AOF持久化
java·redis·后端