小白学习安装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测试连接如下图

参考

相关推荐
佛祖让我来巡山6 小时前
线上 Redis 突然“爆”了,怎么办?
redis·redis宕机·redis崩了·redis线上事故
三十..7 小时前
Redis 核心原理与高可用架构实践
运维·数据库·redis
叶小鸡8 小时前
Java 篇-项目实战-AI 天机学堂(从 0 到 1)-day5
数据库·redis·缓存
IT策士8 小时前
Redis 从入门到精通:Python 操作 Redis
redis·python·bootstrap
周杰伦的稻香9 小时前
Go + Redis:本地部署高性能图片主色调提取服务
开发语言·redis·golang
小二·11 小时前
Redis 7 分布式缓存架构实战
redis·分布式·缓存
lx1885486989613 小时前
Redis大Key阻塞:单线程CPU100%的致命陷阱
数据库·redis·缓存
IT策士13 小时前
Redis 从入门到精通:位图、HyperLogLog、GEO
数据库·redis·缓存
IT策士13 小时前
Redis 从入门到精通:Python 操作 Redis 进阶
数据库·redis·python
布局呆星13 小时前
Spring Boot + Redis 缓存实战:@Cacheable、序列化踩坑、缓存一致性,一次讲透
spring boot·redis·缓存