在CentOS6.5下安装Redis v3.03

[[email protected] ~]# wget http://download.redis.io/releases/redis-3.0.3.tar.gz
[[email protected] ~]# tar xzf redis-3.0.3.tar.gz
[[email protected] 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
[[email protected] redis-3.0.3]# make
[[email protected] 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
[[email protected] 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

[[email protected] 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

[[email protected] 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,显示如下已经成功。

[[email protected] ~]# ./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下配置文件

[[email protected] redis-3.0.3]# nano redis.conf
找到 daemonize no 这项修改为 yes
使服务端运行在后台
新建 redis service脚本
[[email protected] 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目录执行下面操作

[[email protected] src]# mkdir /usr/redis
[[email protected] src]# cp redis-server  /usr/redis
[[email protected] src]# cp redis-benchmark /usr/redis
[[email protected] src]# cp redis-cli  /usr/redis
[[email protected] src]# cp redis.conf  /usr/redis
cp: cannot stat 'redis.conf': No such file or directory
[[email protected] src]# cd ..
[[email protected] 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
[[email protected] redis-3.0.3]# cp redis.conf /usr/redis
[[email protected] redis-3.0.3]#

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

[[email protected] rc.d]# chkconfig --add redis
service redis does not support chkconfig
[[email protected] rc.d]# vim /etc/init.d/redis
如果没加#chkconfig: 2345 86 14就会出现上面的错误。
[[email protected] rc.d]# chkconfig --add redis
[[email protected] rc.d]# chkconfig --level 2345 redis on
[[email protected] rc.d]# chkconfig --list redis
redis           0:off   1:off   2:on    3:on    4:on    5:on    6:off
[[email protected] rc.d]#
Copyright © OneZos all right reserved,powered by Gitbook本书发布时间: 2021-06-09 09:53:38

results matching ""

    No results matching ""