美文网首页
Centos7安装Redis

Centos7安装Redis

作者: 王国的荣耀 | 来源:发表于2021-09-02 18:53 被阅读0次

    安装redis

    安装gcc依赖
    yum install -y gcc

    下载安装

    wget http://download.redis.io/releases/redis-5.0.3.tar.gz
    tar -zxvf redis-5.0.3.tar.gz**
    
    cd redis-5.0.3**
    make
    make install PREFIX=/usr/local/redis
    

    启动服务

    前台启动

    cd /usr/local/redis/bin/
    ./redis-server
    

    后台启动

     cp /home/xxx/redis-5.0.3/redis.conf /usr/local/redis/bin/
    # 修改 redis.conf 文件,
    # 把 daemonize no 改为 daemonize yes
    ./redis-server redis.conf**
    

    设置开机启动

    添加开机启动服务
    vi /etc/systemd/system/redis.service
    复制粘贴以下内容:

    [Unit]
    Description=redis-server
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    

    注意:ExecStart配置成自己的路径

    设置开机启动
    [root@localhost bin]# systemctl daemon-reload
    [root@localhost bin]# systemctl start redis.service
    [root@localhost bin]# systemctl enable redis.service
    创建 redis 命令软链接
    [root@localhost ~]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis

    redis服务操作

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

    redis 外网可以访问

    修改redis.conf
    主要是两个地方:
    注释绑定的主机地址
    bind 127.0.0.1 ,或修改为 bind 0.0.0.0 原理都一样。
    原状态只允许本地访问
    修改redis的保护模式为no
    protected-mode no

    相关文章

      网友评论

          本文标题:Centos7安装Redis

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