zoukankan      html  css  js  c++  java
  • CentOS安装Redis

    Redis 安装步骤

    1. 下载Redis

    (1)获取权限:su root

    (2)规划好下载的目录:mkdir /usr/local/soft/

    (3)进入新建的目录,准备下载:cd /usr/local/soft/

    (4)下载redis最新稳定版:

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

    2.  解压并安装redis

    (1)解压tar包:tar zxvf redis-3.0.0.tar.gz

    (2)进入解压后出现的新目录:cd redis-3.0.0

    (3)编译源码:make

    (4)校验编译是否正确:make test

    3. 手工启动redis,测试redis是否运行正常

    (1)在当前redis目录中输入命令启动Redis:src/redis-server

    (2)检查进程是否有Redis了:ps aux | grep redis,可以看见进程列表中有一个叫“src/redis-server”的进程了

    (3)启动redis自带的客户端,进行测试:

           启动客户端并连接本地Redis:  src/redis-cli 

            > set foo bar     -- 提示 “ok”说明设置键值正常。

            > get foo           -- 能够提示返回正确的“bar”,说明运行正常。

            > quit               -- 退出客户端

    4. Redis加入开机自启动序列

    (1)redis.conf 配置文件里面的daemonize no 改成 daemonize yes 

    (2)编写脚本/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/soft/redis-3.0.0/src/redis-server #实际环境而定

        REDIS_CLI=/usr/local/soft/redis-3.0.0/src/redis-cli #实际环境而定

        PIDFILE=/var/run/redis.pid

        CONF="/usr/local/soft/redis-3.0.0/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 "Redis is 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

    ##############################

    (3)执行权限: chmod +x /etc/init.d/redis

    (4)开机启动 :

    # 尝试启动或停止redis

    service redis start

    service redis stop

    # 开启服务自启动

    sudo chkconfig redis on

  • 相关阅读:
    使用python发送(SMTP)qq邮件
    google hack
    python多线程爬取网页
    windows自带的颜色编辑器居中
    (转)如何在任务栏添加托盘图标
    c++ 字符串转数字或数字转字符串
    (转)null和NULL和nullptr和””区别
    Windows系统自带选择文件的对话重写和居中处理
    ANSII 与Unicode,Utf8之间的转换
    (转) Windows如何区分鼠标双击和两次单击
  • 原文地址:https://www.cnblogs.com/zhangzhi19861216/p/4711051.html
Copyright © 2011-2022 走看看