美文网首页
redis安装

redis安装

作者: ZemelZhu | 来源:发表于2018-12-30 10:16 被阅读0次

    下载redis

    1.https://redis.io/download 下载redis上传到 /usr/local下

    安装

    cd /usr/local/redis-4.0.2
    make

    提取配置文件

    mkdir -p /usr/redis
    cp /usr/local/redis-4.0.2/src/redis-server /usr/local/redis/
    cp /usr/local/redis-4.0.2/src/redis-cli /usr/local/redis/
    cp /usr/local/redis-4.0.2/redis.conf /usr/local/redis/

    修改配置文件

    vim /usr/local/redis/redis.conf

    • 在bind 127.0.0.1前加“#”将其注释掉
    • 默认为保护模式,把 protected-mode yes 改为 protected-mode no
    • 默认为不守护进程模式,把daemonize no 改为daemonize yes
    • 将 requirepass foobared前的“#”去掉,密码改为你想要设置的密码

    编辑redis开机启动redis脚本

    !/bin/sh

    chkconfig: 2345 80 90

    description: Start and Stop redis

    PATH=/usr/local/bin:/sbin:/usr/bin:/bin

    REDISPORT=6379
    EXEC=/usr/local/redis/redis-server
    REDIS_CLI=/usr/local/redis/redis-cli
    PIDFILE=/var/run/redis_6379.pid
    CONF="/usr/local/redis/redis.conf"
    AUTH="1234"

    case "1" in start) if [ -fPIDFILE ]
    then
    echo "PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..."EXEC CONF fi if [ "?"="0" ]
    then
    echo "Redis is running..."
    fi
    ;;
    stop)
    if [ ! -f PIDFILE ] then echo "PIDFILE does not exist, process is not running"
    else
    PID=(catPIDFILE)
    echo "Stopping ..."
    REDIS_CLI -aAUTH -p REDISPORT SHUTDOWN while [ -x{PIDFILE} ]
    do
    echo "Waiting for Redis to shutdown ..."
    sleep 1
    done
    echo "Redis stopped"
    fi
    ;;
    restart|force-reload)
    {0} stop{0} start
    ;;
    *)
    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
    exit 1
    esac

    添加开机启动服务

    vim /etc/rc.local
    最后加入
    service redis start

    设置权限

    chmod 755 /etc/init.d/redis

    注册系统服务

    chkconfig --add redis

    测试redis服务

    service redis start
    service redis stop

    创建redis命令软连接

    ln -s /usr/local/redis/redis-cli /usr/bin/redis

    测试redis

    redis

    配置防火墙即可

    相关文章

      网友评论

          本文标题:redis安装

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