• linux下安装redis及其中遇到的问题的解决方法


    1.将下载好的压缩包放到/usr/local目录下
    # tar xzf redis-3.0.2.tar.gz # cd redis-3.0.2 # make
    提示错误 make: cc: Command not found make: *** [adlist.o] Error 127
    没有安装gcc环境,需要安装gcc
    # yum install gcc
    安装后检查是否安装成功
    # rpm -qa |grep gcc
    之后重新make
    2.编译完成后,在Src目录下,有四个可执行文件redis-server、redis-benchmark、redis-cli和redis.conf将其拷贝到一个目录下。
    # mkdir /usr/redis
    # cp redis-server  /usr/redis
    # cp redis-benchmark /usr/redis
    # cp redis-cli  /usr/redis
    # cp redis.conf  /usr/redis
    # cd /usr/redis

    3.启动服务
    # redis-server   redis.conf
    提示错误 -bash :redis-server:command not found

    建立软连接
    # ln -s /usr/redis/redis-server /usr/bin/redis-server
    # ln -s /usr/redis/redis-cli /usr/bin/redis-cli
    重新启动
    # redis-server /usr/redis/redis.conf

    启动成功

    4.设置开机自启动

     (1)先将redis.conf中daemonize设置为yes,确保守护进程开启。

     (2)编写开机自启动脚本

    # vi /etc/init.d/redis

    PATH=/usr/local/bin:/sbin:/usr/bin:/bin   
    REDISPORT=6379  
    EXEC=/usr/redis/redis-server   
    REDIS_CLI=/usr/redis/redis-cli   
     
    PIDFILE=/var/run/redis.pid   
    CONF="/usr/redis/redis.conf"  
    AUTH="1234"  
    
    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 exists, process is not running."  
                    else  
                            PID=$(cat $PIDFILE)   
                            echo "Stopping..."  
                           $REDIS_CLI -p $REDISPORT  SHUTDOWN    
                            sleep 2  
                           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
    注: redis设置AUTH命令
    redis 127.0.0.1:6379> AUTH PASSWORD
    (error) ERR Client sent AUTH, but no password is set
    redis 127.0.0.1:6379> CONFIG SET requirepass "1234"
    OK
    redis 127.0.0.1:6379> AUTH 1234
    Ok

    (3)设置权限
    # chmod 755 redis
    (4)启动
    # /etc/init.d/redis start  
    提示错误 /etc/init.d/redis:permission denied

    # chmod a+x /etc/init.d/redis
    a+x 是给所有人加上可执行权限,包括所有者,所属组,和其他人 o+x 只是给其他人加上可执行权限

    重新启动后显示
    Starting Redis server...
    Redis is running ...

    (5)设置开机自启动
    # chkconfig redis on
    提示错误 service redis does not support chkconfig

    把下面两行注释放在/etc/init.d/redis文件靠前的注释中:

    # chkconfig:   2345 90 10

    # description:  Redis is a persistent key-value database

    (6)关机重启测试








     




     
  • 相关阅读:
    codevs 1576 最长严格上升子序列
    codevs 3415 最小和
    codevs 2102 石子归并 2
    洛谷 P1040 加分二叉树
    BZOJ 3038 上帝造题的七分钟二
    codevs 线段树练习ⅠⅡⅢ
    启动Tomcat提示:指定的服务未安装
    poj 1061 青蛙的约会 (扩展欧几里得模板)
    POJ 3449 Geometric Shapes(判断几个不同图形的相交,线段相交判断)
    HDU 5251 矩形面积(二维凸包旋转卡壳最小矩形覆盖问题) --2015年百度之星程序设计大赛
  • 原文地址:https://www.cnblogs.com/wyy123/p/6141236.html
Copyright © 2020-2023  润新知