1. XenForo 1.5.14 中文版——支持中文搜索!现已发布!查看详情
  2. Xenforo 爱好者讨论群:215909318 XenForo专区

centos7 编译 redis

本帖由 admin2016-02-25 发布。版面名称:应用交流

  1. admin

    admin 管理员 管理成员

    注册:
    2011-11-01
    帖子:
    3,665
    赞:
    2,423
    下载安装编译:
    代码:
    wget http://download.redis.io/releases/redis-stable.tar.gz
    tar xzf redis-stable.tar.gz
    cd redis-stable
    make
    make install
    设置配置文件路径:
    代码:
    mkdir -p /usr/local/redis/bin  #命令目录
    mkdir -p /usr/local/redis/etc  #配置文件目录
    mv ./redis.conf /usr/local/redis/etc/
    cd src
    mv   mkreleasehdr.sh   redis-benchmark   redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server redis-trib.rb  /usr/local/redis/bin/
    修改配置文件:
    # vim /usr/local/redis/etc/redis.conf
    修改为: daemonize yes

    最后将其注册为系统服务
    在/etc/init.d/目录下建立redis 文件
    vim /etc/init.d/redis
    代码:
    ###########################
    #!/bin/sh
    #chkconfig: 2345 10  90
    #description:auto_run
    PATH=/usr/local/bin:/sbin:/usr/bin:/bin
    
    REDISPORT=6379
    EXEC=/usr/local/redis/bin/redis-server
    REDIS_CLI=/usr/local/redis/bin/redis-cli
    
    PIDFILE=/var/run/redis_${REDISPORT}.pid
    CONF="/usr/local/redis/etc/redis.conf"
    
    case "$1" in
        start)
            if [ -f $PIDFILE ]
            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=$(cat $PIDFILE)
                    echo "Stopping ..."
                    $REDIS_CLI -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
    ###########################
    设置权限
    chmod +x /etc/init.d/redis
    设置自动启动:
    chkconfig redis on
    启动Redis:
    # /usr/local/bin/redis-server /usr/local/redis/etc/redis.conf
    #关闭服务
    redis-cli shutdown
    或者在cli中执行shutdown
    redis 127.0.0.1:6379> shutdown
    清除缓存
    redis-cli flushall
    查看状态 :
    # ps -ef | grep redis

    下面介绍为PHP添加redis插件

    从官网下载最新的拓展,地址:http://pecl.php.net/package/redis或者https://github.com/phpredis/phpredis
    代码:
    wget http://pecl.php.net/get/redis-4.0.1.tgz
    tar xzf redis-4.0.1.tgz
    cd redis-4.0.1
    /usr/local/php/bin/phpize
    ./configure --prefix=/usr/local/redis/ --enable-redis --with-php-config=/usr/local/php/bin/php-config
    #make && make install
    把拓展添加至php.ini,重启php
    代码:
    extension=redis.so
    
    session.save_handler = redis
    session.save_path = "tcp://localhost:6379"
     
    最后编辑: 2018-04-24
正在加载...