CentOS7安装Reids

本文介绍如何在Linux环境下部署Redis服务,包括下载、安装、配置等步骤,并实现开机自启及远程连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、下载redis

切换到/usr/local目录下,下载最新稳定版

https://download.redis.io/redis-stable.tar.gz 

2、解压Redis

tar -zxvf redis-stable.tar.gz

3、进入解压目录

cd /usr/local/redis-stable

4、安装

make 或 make PREFIX=/usr/local/redis install #安装到指定目录中

5、如果编译失败安装gcc

yum install gcc

6、启动服务

进入解压目录

src/redis-server

出现以下界面,启动成功

                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 7.0.4 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 37166
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'      

7、本地连接

[root@localhost redis-stable]#  src/redis-cli
127.0.0.1:6379> select 1

8、修改配置文件支持后台运行和远程连接

#bind 127.0.0.1 -::1 #注释bind
daemonize no改为daemonize yes
protected-mode yes改为protected-mode no

设置密码

requirepass 密码

9、开机自启

复制配置文件 redis.conf /etc/redis/ ,改名6379.conf

cp -r redis.conf /etc/redis/6379.conf

复制配置文件

cp utils/redis_init_script /etc/init.d/redis

修改配置文件

vi /etc/init.d/redis
#修改到自己的安装执行目录
EXEC=/usr/local/redis-stable/src/redis-server
CLIEXEC=/usr/local/redis-stable/src/redis-cli

保存退出,修改权限

chmod 777 /etc/init.d/redis

开机自启动

chkconfig redis on

启动/停止服务

service redis start
service redis stop

开启防火墙端口

firewall-cmd --zone=public --add-port=6379/tcp --permanent
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值