美文网首页
CentOS8 安装Redis

CentOS8 安装Redis

作者: 深入浅出 | 来源:发表于2021-09-26 15:49 被阅读0次

    1 下载

    Redis官方下载地址:http://redis.io/download,下载最新稳定版本。

    2 安装

    #下载并解压安装包
    [root@pre ~]# cd /opt/src/
    [root@pre ~]# wget https://download.redis.io/releases/redis-6.2.5.tar.gz
    [root@pre src]# tar -zxvf redis-6.2.5.tar.gz
    [root@pre src]# mv redis-6.2.5 /opt/
    [root@pre opt]# cd redis-6.2.5/
    #cd切换到redis解压目录下,执行编译
    [root@pre opt]# make
    #安装并指定安装目录
    [root@pre opt]# make install PREFIX=/opt/redis
    

    3 启动服务

    3.1前台启动

    [root@pre opt]# cd /opt/redis/bin
    [root@pre bin]# ./redis-server
    

    3.2 后台启动

    #从 redis 的源码目录中复制 redis.conf 到 redis 的安装目录
    [root@pre redis-6.2.5]# cp /opt/redis-6.2.5/redis.conf /opt/redis/bin/
    
    #修改 redis.conf 文件
    #将 requirepass foobared 前面的注释去掉,改成你的密码,如 requirepass 123456
    #将 daemonize no 改为 daemonize yes
    
    #启动
    [root@pre bin]# ./redis-server redis.conf
    

    3.3 设置开机启动

    #添加开机启动服务
    vi /etc/systemd/system/redis.service
    
    [Unit]
    Description=redis-server
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/opt/redis/bin/redis-server /opt/redis/bin/redis.conf
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    
    #设置开机启动
    [root@pre bin]# systemctl daemon-reload
    [root@pre bin]# systemctl start redis.service
    [root@pre bin]# systemctl enable redis.service
    
    #创建 redis 命令软链接
    [root@iZm5e7zks238u7wqud0v75Z bin]# ln -s /opt/redis/bin/redis-cli /usr/bin/redis
    
    #测试 redis
    [root@pre bin]# redis
    127.0.0.1:6379> ping
    PONG
    127.0.0.1:6379>
    

    4 服务操作命令

    systemctl start redis.service #启动服务
    systemctl stop redis.service #停止服务
    systemctl restart redis.service #重启服务
    systemctl status redis.service #查看服务状态
    systemctl enable redis.service #设置开机自启动
    systemctl disable redis.service #停止开机自启动
    

    相关文章

      网友评论

          本文标题:CentOS8 安装Redis

          本文链接:https://www.haomeiwen.com/subject/luuqnltx.html