Navigation

    DDBB

    • Register
    • Login
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    CentOS6.5下Redis v3.03安装

    Linux
    1
    1
    74
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      admin last edited by

      在CentOS6.5下安装Redis v3.03

      [root@li1473-187 ~]# wget http://download.redis.io/releases/redis-3.0.3.tar.gz
      [root@li1473-187 ~]# tar xzf redis-3.0.3.tar.gz
      [root@li1473-187 redis-3.0.3]# ls
      00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README      runtest          runtest-sentinel  src    utils
      BUGS             COPYING       INSTALL  MANIFESTO  redis.conf  runtest-cluster  sentinel.conf     tests
      [root@li1473-187 redis-3.0.3]# make
      [root@li1473-187 redis-3.0.3]# cd src && make install
      
      Hint: It's a good idea to run 'make test' 😉
      
       INSTALL install
       INSTALL install
       INSTALL install
       INSTALL install
       INSTALL install
      [root@li1473-187 src]# make test
      You need tcl 8.5 or newer in order to run the Redis test
      make: *** [test] Error 1
      

      提示需要安装tcl8.5

      # wget http://downloads.sourceforge.net/tcl/tcl8.5.9-src.tar.gz
      # tar -zxvf tcl8.5.9-src.tar.gz
      # cd /tcl8.5.9-src/unix
      
      ./configure
      make
      make install
      

      再重新执行make test

      [root@li1473-187 src]# make test
      \o/ All tests passed without errors!
      
      Cleanup: may take some time... OK
      make[1]: Leaving directory '/root/redis-3.0.3/src'
      

      输入./src/redis-server启动 redis

      [root@li1473-187 redis-3.0.3]# ./src/redis-server
      11304:C 15 Feb 15:58:37.819 # Warning: no config file specified, using the default config. In order to specify a config file use ./src/redis-server /path/to/redis.conf
                      _._
                 _.-``__ ''-._
            _.-``    `.  `_.  ''-._           Redis 3.0.3 (00000000/0) 64 bit
        .-`` .-```.  ```\/    _.,_ ''-._
       (    '      ,       .-`  | `,    )     Running in standalone mode
       |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
       |    `-._   `._    /     _.-'    |     PID: 11304
        `-._    `-._  `-./  _.-'    _.-'
       |`-._`-._    `-.__.-'    _.-'_.-'|
       |    `-._`-._        _.-'_.-'    |           http://redis.io
        `-._    `-._`-.__.-'_.-'    _.-'
       |`-._`-._    `-.__.-'    _.-'_.-'|
       |    `-._`-._        _.-'_.-'    |
        `-._    `-._`-.__.-'_.-'    _.-'
            `-._    `-.__.-'    _.-'
                `-._        _.-'
                    `-.__.-'
      

      打开另一个SSH,显示如下已经成功。

      [root@li1473-187 ~]# ./redis-3.0.3/src/redis-cli
      127.0.0.1:6379> set foo bar
      OK
      127.0.0.1:6379> get foo
      "bar"
      127.0.0.1:6379>
      

      修改 redis-3.0.3下配置文件

      [root@li1473-187 redis-3.0.3]# nano redis.conf
      找到 daemonize no 这项修改为 yes
      使服务端运行在后台
      新建 redis service脚本
      [root@li1473-187 redis-3.0.3]# touch /etc/rc.d/init.d/redis
      

      编辑/etc/rc.d/init.d/redis

      #!/bin/sh
      #chkconfig: 2345 86 14
      #description: Startup and shutdown script for Redis
      
      PROGDIR=/usr/redis #安装路径
      PROGNAME=redis-server
      DAEMON=$PROGDIR/$PROGNAME
      CONFIG=/usr/redis/redis.conf
      PIDFILE=/var/run/redis.pid
      DESC="redis daemon"
      SCRIPTNAME=/etc/rc.d/init.d/redis
      
      start()
      {
       if test -x $DAEMON
       then
       echo -e "Starting $DESC: $PROGNAME"
       if $DAEMON $CONFIG
       then
       echo -e "OK"
       else
       echo -e "failed"
       fi
       else
       echo -e "Couldn't find Redis Server ($DAEMON)"
       fi
      }
      
      stop()
      {
       if test -e $PIDFILE
       then
       echo -e "Stopping $DESC: $PROGNAME"
       if kill `cat $PIDFILE`
       then
       echo -e "OK"
       else
       echo -e "failed"
       fi
       else
       echo -e "No Redis Server ($DAEMON) running"
       fi
      }
      
      restart()
      {
       echo -e "Restarting $DESC: $PROGNAME"
       stop
       start
      }
      
      list()
      {
       ps aux | grep $PROGNAME
      }
      
      case $1 in
       start)
       start
       ;;
       stop)
       stop
       ;;
       restart)
       restart
       ;;
       list)
       list
       ;;
      
       *)
       echo "Usage: $SCRIPTNAME {start|stop|restart|list}" >&2
       exit 1
       ;;
      esac
      exit 0
      

      进入redis-3.0.3的src目录执行下面操作

      [root@li1473-187 src]# mkdir /usr/redis
      [root@li1473-187 src]# cp redis-server  /usr/redis
      [root@li1473-187 src]# cp redis-benchmark /usr/redis
      [root@li1473-187 src]# cp redis-cli  /usr/redis
      [root@li1473-187 src]# cp redis.conf  /usr/redis
      cp: cannot stat 'redis.conf': No such file or directory
      [root@li1473-187 src]# cd ..
      [root@li1473-187 redis-3.0.3]# ls
      00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README      runtest          runtest-sentinel  src    utils
      BUGS             COPYING       INSTALL  MANIFESTO  redis.conf  runtest-cluster  sentinel.conf     tests
      [root@li1473-187 redis-3.0.3]# cp redis.conf /usr/redis
      [root@li1473-187 redis-3.0.3]#
      

      增加服务并设置开机启动。

      [root@li1473-187 rc.d]# chkconfig --add redis
      service redis does not support chkconfig
      [root@li1473-187 rc.d]# vim /etc/init.d/redis
      如果没加#chkconfig: 2345 86 14就会出现上面的错误。
      [root@li1473-187 rc.d]# chkconfig --add redis
      [root@li1473-187 rc.d]# chkconfig --level 2345 redis on
      [root@li1473-187 rc.d]# chkconfig --list redis
      redis           0:off   1:off   2:on    3:on    4:on    5:on    6:off
      [root@li1473-187 rc.d]#
      
      1 Reply Last reply Reply Quote 0
      • First post
        Last post