DXP BLOG
首页
  • JDk
  • Spring系列
  • 微服务
  • Json
  • Netty
  • Bug
  • Mysql
  • Postgresql
  • 达梦
  • activemq
  • rabbitmq
  • rocketmq
  • redis
  • Vue
  • React
  • Angular
  • Javascript
  • Typescript
linux
  • 协议
  • 加解密
  • 分类
  • 标签
  • 归档
Gitee (opens new window)

董新平

一个普普通通的代码程序猿
首页
  • JDk
  • Spring系列
  • 微服务
  • Json
  • Netty
  • Bug
  • Mysql
  • Postgresql
  • 达梦
  • activemq
  • rabbitmq
  • rocketmq
  • redis
  • Vue
  • React
  • Angular
  • Javascript
  • Typescript
linux
  • 协议
  • 加解密
  • 分类
  • 标签
  • 归档
Gitee (opens new window)
  • Redis

    • Redis基础
    • Windows下Redis安装
    • 编译安装Redis
      • Redis数据类型
    • 中间件
    • Redis
    dongxinping
    2023-12-27
    目录

    编译安装Redis

    # 编译安装Redis

    ubuntu 22.04.3

    # 1. 下载redis源码包

    redis官网 (opens new window)

    下载最新的稳定版本。 (7.2)

    # 2.编译安装

    将 redis.tar.gz解压到 linxu下的 /usr/local/src 下,用make命令编译。需要一下依赖

    • pkg-config
    • gcc

    如果报错缺失 cc 和 pkg-config, 则需要安装对应的依赖

    sudo apt-get install pkg-config
    sudo apt-get install gcc
    
    1
    2

    将redis安装到指定的目录下:

    make PREFIX=/opt/redis install
    
    1

    此时会在 /opt/redis/bin 下生成相关的启动程序

    • redis-server 服务
    • redis-cli 客户端
    • redis-benchmark 性能测试工具
    • redis-check-aof
    • redis-check-rdb

    复制一份 redis.conf文件到 /opt/redis/conf下

    mkdir /opt/redis/conf
    cp /usr/local/src/redis.conf /opt/redis/conf
    
    1
    2

    # 3.启动程序

    前台启动

    ./redis-server ../conf/redis.conf 
    
    1

    后台启动

    方式一:nohup

    nohup redis-server &
    
    1

    方式二: 配置后台启动

    修改 redis.conf配置文件 中的 daemonize属性值改为 yes即可

    ./redis-server ../conf/redis.conf
    
    1

    # 4. 注册service服务

    将 redis注册为linxu服务,可开机启动

    在我们的源码文件夹 /usr/local/src/redis/utils下有对应的工具包。 通过脚本 install_server.sh来注册服务。是交互式的,通过端口来区分实例,不过在新版linxu服务器上,建议使用 systemd 来管理服务,所以redis上会提示:

    Welcome to the redis service installer
    This script will help you easily set up a running redis server
    
    This systems seems to use systemd.
    Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!
    
    1
    2
    3
    4
    5

    可以通过修改安装的脚本来跳过校验, 注释下面的校验行就行了

    #bail if this system is managed by systemd
    _pid_1_exe="$(readlink -f /proc/1/exe)"
    if [ "${_pid_1_exe##*/}" = systemd ]
    then
            echo "This systems seems to use systemd."
            echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
            exit 1
    fi
    unset _pid_1_exe
    
    1
    2
    3
    4
    5
    6
    7
    8
    9

    不过不建议采用以上的方案, 应遵循新的linux管理方式, 采用 systemd

    # 5. 注册为systemd服务

    将 systemd-redis_server.service 文件拷贝到 /etc/systemd/system 下

    sudo cp systemd-redis_server.service /etc/systemd/system/redis_server.service
    
    1

    根据自己需求定制化。 如下:

    # 修改redis.conf
    # 改为后台启动
    daemoninze yes
    # pid文件存放位置
    pidfile /opt/redis/redis_6379.pid
    # 日志存放位置
    logfile /opt/redis/redis.log
    # redis数据存放位置
    dir /opt/redis
    
    
    #  修改 redis_server.service 文件的启动文件
    # 启动
    ExecStart=/opt/redis/bin/redis-server /opt/redis/conf/redis.conf
    # 停止
    ExecStop=/opt/redis/bin/redis-cli shutdown
    # 因为上面redis的配置 daemon 是 yes, 所以这里必须采用 forking
    Type=forking
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    上次更新: 2023/12/27, 20:04:43
    Windows下Redis安装
    Redis数据类型

    ← Windows下Redis安装 Redis数据类型→

    最近更新
    01
    Redis数据类型
    01-20
    02
    Atomic
    12-27
    03
    Windows下Redis安装
    11-16
    更多文章>
    dongxinping | Copyright © 2022-2024 Dongxinping | MIT License
    • 跟随系统
    • 浅色模式
    • 深色模式
    • 阅读模式