小白学习安装redis

获取redis

下载到centos指定目录

shell 复制代码
cd /home/download

wget https://download.redis.io/releases/redis-7.0.2.tar.gz

解压、编译、安装

  • 解压
shell 复制代码
tar -zxf redis-7.0.2.tar.gz -C /opt
  • 编译
shell 复制代码
cd /opt/redis-7.0.2

make
  • 安装
shell 复制代码
cd /opt/redis-7.0.2

make install

进入/usr/local/bin查看

shell 复制代码
ll /usr/local/bin

启动

  • 配置环境变量启动
shell 复制代码
vi /etc/profile

添加如下内容:

vi 复制代码
REDIS_HOME=/opt/redis-7.0.2
PATH=$PATH:$REDIS_HOME/bin

使变量生效

shell 复制代码
source /etc/profile

启动:

shell 复制代码
#实际是去找/usr/local/bin的这个启动语句,并使用redis配置文件
redis-server $REDIS_HOME/redis.conf

停止:

shell 复制代码
#/usr/local/bin的这个进行停止
redis-cli shutdown
  • 直接启动
shell 复制代码
redis-server
  • 编辑redis.conf,根据配置启动
shell 复制代码
cd $REDIS_HOME

cp redis.conf redis.conf.bck
vi redis.conf

修改如下内容:

vi 复制代码
# 监听地址,0.0.0.0使可以在任意网络访问
bind 0.0.0.0
# 守护进程,设置成yes即可后台运行
daemonize yes
# 密码,设置后,访问redis需要密码
requirepass 1234
logfile "redis.log"

根据你自己的进程号,停止redis

shell 复制代码
 redis-server redis.conf
 ps -ef | grep redis
 kill -9 73155
  • 使用系统服务启动

进入/etc/systemd/system,新建redis.service

shell 复制代码
cd /etc/systemd/system

vi redis.service

内容如下:

vi 复制代码
[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /opt/redis-7.0.2/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

启动:

shell 复制代码
systemctl start redis

查看状态:

shell 复制代码
systemctl status redis

开机自启动:

shell 复制代码
systemctl enable redis

测试

使用RDM测试连接如下图

参考

相关推荐
即将进化成人机21 分钟前
验证码生成 + Redis 暂存 + JWT 认证
数据库·redis·笔记
hgz07101 小时前
Redis:安装配置、核心概念与实践应用
redis
无盐海4 小时前
Redis 哨兵模式
数据库·redis·缓存
古月฿5 小时前
大学生素质测评系统设计与实现
java·vue.js·redis·mysql·spring·毕业设计
Billow_lamb5 小时前
redis 中 redisTemplate 的所有操作与函数
数据库·redis·缓存
不穿格子的程序员6 小时前
Redis篇8——Redis深度剖析:揭秘 Redis 高性能
数据库·redis·缓存·nio·io多路复用
curd_boy7 小时前
【AI】利用语义缓存,优化AI Agent性能
人工智能·redis·缓存
Li_7695329 小时前
Redis —— (四)
数据库·redis
ttthe_MOon10 小时前
Redis Cluster集群模式和各种常见问题
数据库·redis·缓存