当前位置 博文首页 > 弈凌:Centos8快速安装Redis6

    弈凌:Centos8快速安装Redis6

    作者:[db:作者] 时间:2021-06-10 21:16

    环境准备

    执行gcc -v命令检查gcc版本是否>=8.x,如果不存在或者小于8.x,需自行安装或升级gcc,正确输出结果如下:

    Using built-in specs.
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
    OFFLOAD_TARGET_NAMES=nvptx-none
    OFFLOAD_TARGET_DEFAULT=1
    Target: x86_64-redhat-linux
    Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
    Thread model: posix
    gcc version 8.3.1 20191121 (Red Hat 8.3.1-5) (GCC) 
    

    安装Redis

    # 切换到opt目录下进行安装redis
    cd /opt
    # 下载redis源码压缩包
    wget https://download.redis.io/releases/redis-6.2.4.tar.gz
    # 解压redis源码压缩包
    tar -zxvf redis-6.2.4.tar.gz
    # 切换到解压目录
    cd redis-6.2.4
    # gcc编译redis源码
    make
    

    启动Redis

    修改配置文件:vi redis.conf

    # 设置密码(养成良好习惯,无论任何环境不使用弱密码)
    requirepass 700b71fb4f02491790e78bb8bf0825fa
    # 后台启动
    daemonize yes
    # 绑定访问IP(配置自己的IP,不配置的话就只能以`localhost:6379`链接Redis)
    bind 192.168.6.6
    

    配置systemd.service:vi /lib/systemd/system/redis.service

    [Unit]
    Description=Redis
    After=network.target
    
    [Service]
    Type=forking
    PIDFile=/var/run/redis_6379.pid
    ExecStart=/opt/redis-6.2.4/src/redis-server /opt/redis-6.2.4/redis.conf
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/bin/kill -s QUIT $MAINPID
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
    

    刷新系统服务

    systemctl daemon-reload
    

    使用systemctl命令来管理redis

    // 启动
    systemctl start redis.service
    // 停止
    systemctl stop redis.service
    // 重启
    systemctl restart redis.service
    // 查看状态
    systemctl status redis.service
    // 开机自启
    systemctl enable redis.service
    
    下一篇:没有了