Redis 安装

目 录

  • [一.Ubuntu 20 里安装 Redis](#一.Ubuntu 20 里安装 Redis)
  • 二.Centos

一.Ubuntu 20 里安装 Redis

使用 apt 安装

xml 复制代码
 apt install redis -y

支持远程连接

修改 /etc/redis/redis.conf

  • 修改 bind 127.0.0.1bind 0.0.0.0
  • 修改 protected-mode yesprotected-mode no
xml 复制代码
1 # By default, if no "bind" configuration directive is specified, Redis listens
2 # for connections from all the network interfaces available on the server.
3 # It is possible to listen to just one or multiple selected interfaces using
4 # the "bind" configuration directive, followed by one or more IP addresses.
5 #
6 # Examples:
7 #
8 # bind 192.168.1.100 10.0.0.1
9 # bind 127.0.0.1 ::1
10 #
11 # ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
12 # internet, binding to all the interfaces is dangerous and will expose the
13 # instance to everybody on the internet. So by default we uncomment the
14 # following bind directive, that will force Redis to listen only into
15 # the IPv4 loopback interface address (this means Redis will be able to
16 # accept connections only from clients running into the same computer it
17 # is running).
18 #
19 # IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
20 # JUST COMMENT THE FOLLOWING LINE.
21 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 # bind 127.0.0.1 # 注释掉这⾏
23 bind 0.0.0.0 # 添加这⾏
24
25 protected-mode no # 把 yes 改成 no

控制 Redis 启动

启动 Redis 服务

xml 复制代码
 service redis-server start

停止 Redis 服务

xml 复制代码
service redis-server stop

重启 Redis 服务

xml 复制代码
service redis-server restart

二.Centos

如果是 Centos8 , yum 仓库中默认的 redis 版本就是5.直接yum install 即可

Centos7

使用 yum 安装

首先安装 scl 源, 再安装 redis

xml 复制代码
yum install centos-release-scl-rh
xml 复制代码
yum install rh-redis5-redis

创建符号链接

默认安装的目录为 /opt/rh/rh-redis5/root/usr/bin/ , 藏的太深了, 不方便使用. 我们通过符号链接, 把需要用到的关键内容设置到方便使用的目录中.

  1. 针对可执行程序设置符号链接
xml 复制代码
cd /usr/bin
ln -s /opt/rh/rh-redis5/root/usr/bin/redis-server ./redis-server
ln -s /opt/rh/rh-redis5/root/usr/bin/redis-sentinel ./redis-sentinel
ln -s /opt/rh/rh-redis5/root/usr/bin/redis-cli ./redis-cli
  1. 针对配置文件设置符号链接
xml 复制代码
cd /etc/
ln -s /etc/opt/rh/rh-redis5/ ./redis

修改配置文件

  1. 设置 ip 地址
xml 复制代码
 bind 0.0.0.0
  1. 关闭保护模式
xml 复制代码
protected-mode no
  1. 启动守护进程
xml 复制代码
daemonize yes
  1. 设置工作目录

先创建工作目录

xml 复制代码
mkdir -p /var/lib/redis

再在配置文件中, 设置工作目录

xml 复制代码
dir /var/lib/redis
  1. 设置日志目录

先创建日志目录

xml 复制代码
mkdir -p /var/log/redis/

再在配置文件中, 设置日志目录

xml 复制代码
logfile /var/log/redis/redis-server.log

启动 redis

xml 复制代码
 redis-server /etc/redis/redis.conf

停止 redis

先查看到 redis-server 的 pid

xml 复制代码
ps aux | grep redis

然后通过 kill 命令直接杀死 redis 进程

xml 复制代码
kill 进程 id
相关推荐
AAA修煤气灶刘哥3 小时前
别让Redis「歪脖子」!一次搞定数据倾斜与请求倾斜的捉妖记
redis·分布式·后端
AAA修煤气灶刘哥3 小时前
后端人速藏!数据库PD建模避坑指南
数据库·后端·mysql
RestCloud8 小时前
揭秘 CDC 技术:让数据库同步快人一步
数据库·api
得物技术11 小时前
MySQL单表为何别超2000万行?揭秘B+树与16KB页的生死博弈|得物技术
数据库·后端·mysql
christine-rr15 小时前
linux常用命令(4)——压缩命令
linux·服务器·redis
可涵不会debug15 小时前
【IoTDB】时序数据库选型指南:工业大数据场景下的技术突围
数据库·时序数据库
ByteBlossom15 小时前
MySQL 面试场景题之如何处理 BLOB 和CLOB 数据类型?
数据库·mysql·面试
麦兜*15 小时前
MongoDB Atlas 云数据库实战:从零搭建全球多节点集群
java·数据库·spring boot·mongodb·spring·spring cloud
Slaughter信仰15 小时前
深入理解Java虚拟机:JVM高级特性与最佳实践(第3版)第十章知识点问答(10题)
java·jvm·数据库
麦兜*15 小时前
MongoDB 在物联网(IoT)中的应用:海量时序数据处理方案
java·数据库·spring boot·物联网·mongodb·spring