zoukankan      html  css  js  c++  java
  • php切换版本之后 redis 安装使用

    一:redis安装
    Download, extract and compile Redis with:

        $ wget http://download.redis.io/releases/redis-3.0.4.tar.gz
        $ tar xzf redis-3.0.4.tar.gz
        $ cd redis-3.0.4
        $ make

    编译完成将:redis-server  redis-cli 和上级目录redis.conf  复制到 /usr/local/redis目录下 并将daemonize改为yes

    启动redis: ./redis-server redis.conf


    The binaries that are now compiled are available in the src directory. Run Redis with:

        $ redis-server

    You can interact with Redis using the built-in client:

        $ redis-cli

    redis> set name ruanqin
    OK
    redis> get name
    "ruanqin"
    这里无法启动:

    错误信息如下:

    PHP Warning: php Startup: redis: Unable to initialize module
    Module compiled with module API=20050922
    PHP compiled with module API=20090626
    These options need to match in Unknown on line 0
    

    首先先说下这种错误出现的原因:

    执行编译源码包执行phpize的版本与当前php环境中phpize的版本不一致造成的,也有可能和你切换的php版本有关系,我就是切换版本之后重新安装的解决办法:

    1、删除编译过的源码包phpredis-master以及对应目录中的redis.so重新解压phpredis-master

    2、检测/usr/sbin目录下是否存在php php-config php-cgi phpize文件,如果存在删除这些文件 重新建立对应的软连接到这个目录。

    ln -s php /usr/local/php/bin/php
    ln -s php-cgi /usr/local/php/bin/php-cgi
    ln -s php-config /usr/local/php/bin/php-config
    ln -s phpize /usr/local/php/bin/phpize
    

    以上目录请以php的当前安装目录为准。

    3、重新进入phpredis-master目录进行安装即可。


    More:http://www.redis.io/download

    二、php扩展:
    更多版本:http://pecl.php.net/package/redis

        wget http://pecl.php.net/get/redis-2.2.5.tgz
        #解压
        tar zxvf redis-2.2.5.tgz
        #进入安装目录
        cd redis-2.2.5
        /usr/local/php/bin/phpize
        #配置
        ./configure --with-php-config=/usr/local/php/bin/php-config
        #编译安装
        make && make install

    安装完成之后,出现下面的安装路径
    /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/

    配置php支持
    #编辑配置文件,在最后一行添加以下内容

        vim /usr/local/php/etc/php.ini
        extension="redis.so"

    这个时候phpinfo()就可以看到redis扩展了。

    redis 服务器重启自启动命令 

    在/etc/init.d/目录下创建redis  复制内容

    #!/bin/sh
    #
    # redis - this script starts and stops the redis-server daemon
    #
    # chkconfig:   - 85 15 
    # description:  Redis is a persistent key-value database
    # processname: redis-server
    # config:      /etc/redis/redis.conf
    # config:      /etc/sysconfig/redis
    # pidfile:     /var/run/redis.pid
    
    # Source function library.
    . /etc/rc.d/init.d/functions
    
    # Source networking configuration.
    . /etc/sysconfig/network
    
    # Check that networking is up.
    [ "$NETWORKING" = "no" ] && exit 0
    
    redis="/usr/local/redis/redis-server"
    prog=$(basename $redis)
    
    REDIS_CONF_FILE="/usr/local/redis/redis.conf"
    
    [ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis
    
    lockfile=/var/lock/subsys/redis
    
    start() {
        echo "start test!"
        [ -x $redis ] || exit 5
        [ -f $REDIS_CONF_FILE ] || exit 6
        echo "test successful!"
        echo -n $"Starting $prog: "
        daemon $redis $REDIS_CONF_FILE
        retval=$?
        echo
        [ $retval -eq 0 ] && touch $lockfile
        return $retval
    }
    
    stop() {
        echo -n $"Stopping $prog: "
        killproc $prog -QUIT
        retval=$?
        echo
        [ $retval -eq 0 ] && rm -f $lockfile
        return $retval
    }
    
    restart() {
        stop
        start
    }
    
    reload() {
        echo -n $"Reloading $prog: "
        killproc $redis -HUP
        RETVAL=$?
        echo
    }
    
    force_reload() {
        restart
    }
    
    rh_status() {
        status $prog
    }
    
    rh_status_q() {
        rh_status >/dev/null 2>&1
    }
    
    case "$1" in
        start)
            rh_status_q && exit 0
            $1
            ;;
        stop)
            rh_status_q || exit 0
            $1
            ;;
        restart|configtest)
            $1
            ;;
        reload)
            rh_status_q || exit 7
            $1
            ;;
        force-reload)
            force_reload
            ;;
        status)
            rh_status
            ;;
        condrestart|try-restart)
            rh_status_q || exit 0
            ;;
        *)
            echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
            exit 2
    esac

    最后记得给他个权限 755就可以了

    特殊情况下redis启动失败可以加个脚本文件:

    #!/bin/bash
    # Source function library.
    . /etc/rc.d/init.d/functions
    
    # Source networking configuration.
    . /etc/sysconfig/network
    
    ret=$(ps aux|grep redis|awk '{print $2,$11}'|grep redis|head -1|awk '{print $1}')
    
    if [ -z $ret ]
    then
        echo 'ready to start'
        echo "service redis start"
        eval "service redis start"
    else
        echo 'fk,'
    fi

    crontab 中写入:     */1 * * * * /bin/bash /www/shell/redis.sh > /var/log/redis_err.log 2>&1 &

  • 相关阅读:
    easyExcel入门
    UML-从需求到设计--迭代进化
    UML-操作契约总结
    102. Binary Tree Level Order Traversal
    98. Validate Binary Search Tree
    95. Unique Binary Search Trees II
    96. Unique Binary Search Trees
    94. Binary Tree Inorder Traversal
    84. Largest Rectangle in Histogram
    92. Reverse Linked List II
  • 原文地址:https://www.cnblogs.com/ruanqin/p/6098991.html
Copyright © 2011-2022 走看看