• redis 安装配置(开机启动)


    1、安装wget

        yum -y install wget

    2、下载redis安装包(版本3.0以上)

    wget http://download.redis.io/releases/redis-3.0.4.tar.gz

    3、安装redis

       1)解压:tar -zxvf redis-3.0.4.tar.gz

       2)进入src目录

       3)make MALLOC=libc

       4)make install(执行完后,会在/usr/local/下面出现redis-cli、redis-server等文件,方便操作

    4、创建数据和日志文件

      sudo useradd redis 

      sudo mkdir -p /var/lib/redis 

      sudo mkdir -p /var/log/redis 

      sudo chown redis.redis /var/lib/redis #db文件放在这里,要修改redis.conf 

      sudo chown redis.redis /var/log/redis 

    5、修改redis.conf

         vi /redis3.0.4/redis.conf

         修改:daemonize yes

    6、编写脚本,vim /etc/init.d/redis:

    # chkconfig: 2345 10 90
    # description: Start and Stop redis
     
    PATH=/usr/local/bin:/sbin:/usr/bin:/bin
     
    REDISPORT=6379 #实际环境而定
    EXEC=/usr/local/redis/src/redis-server #实际环境而定
    REDIS_CLI=/usr/local/redis/src/redis-cli #实际环境而定
     
    PIDFILE=/var/run/redis.pid
    CONF="/usr/local/redis/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 exists, 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
    

     7、执行权限:

      chmod +x /etc/init.d/redis
    8、开机自启动:
      
      # 尝试启动或停止redis
      service redis start
      service redis stop
     
      # 开启服务自启动
      chkconfig redis on

        

  • 相关阅读:
    PAT B1045 快速排序 (25 分)
    PAT B1042 字符统计 (20 分)
    PAT B1040 有几个PAT (25 分)
    PAT B1035 插入与归并 (25 分)
    PAT B1034 有理数四则运算 (20 分)
    PAT B1033 旧键盘打字 (20 分)
    HDU 1231 最大连续子序列
    HDU 1166 敌兵布阵
    HDU 1715 大菲波数
    HDU 1016 Prime Ring Problem
  • 原文地址:https://www.cnblogs.com/handongdong/p/4997672.html
Copyright © 2020-2023  润新知