• Linux Install redis


    1.将下载好的压缩包放到/usr/local目录下
    # tar xzf redis-3.0.2.tar.gz # cd redis-3.0.2 # make
    //--------------------------------------------------------------
    $ wget http://download.redis.io/releases/redis-4.0.8.tar.gz
    $ tar xzf redis-4.0.8.tar.gz
    $ cd redis-4.0.8
    $ make

    //最新版的redis

    //-------------------------------------------------------------
    提示错误 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)关机重启测试







    ps:此为本人安装过程及遇到的一些问题的总结,其中借鉴了很多帖子的经验,在此感谢大家。
  • 相关阅读:
    python学习之列表和字典
    python学习之字符串(下)
    python学习之数字
    python学习之核心数据类型
    android 学习Layout布局的使用
    android学习SeekBar的使用
    android学习Gallery和ImageSwitch的使用
    android学习ScrollView的使用
    android学习ViewFlipper的使用
    C#怎么判断传入int值是否是枚举里面的值
  • 原文地址:https://www.cnblogs.com/zengpeng/p/8421379.html
Copyright © 2020-2023  润新知