Redis之——CentOS 6.5安装配置redis
1、安装需要的支持环境
在安装Redis之前首要先做的是安装Unix的Tcl工具,如果不安装的话后期将无法对Redis进行测试。在后期执行make test的时候返回如下错误信息:You need tcl 8.xuyao de5 or newer in order to run the Redis test,具体的流程为:
[plain] view plain copy
- cd /usr/local/src
- wget http://downloads.sourceforge.net/tcl/tcl8.6.3-src.tar.gz
- tar -zxvf tcl8.6.3-src.tar.gz
- cd tcl8.6.3/unix/
- ./configure
- make
- make install
2、安装redis
安装redis的过程非常的简单,具体教程官网也有。具体如下:
[plain] view plain copy - cd /usr/local/src
- wget http://download.redis.io/releases/redis-2.8.19.tar.gz
- tar zxvf redis-2.8.19.tar.gz
- cd redis-2.8.19
- make
- make PREFIX=/usr/local/redis install
其中PREFIX=/usr/local/redis可以省略,省略情况下redis会默认安装到/usr/local/bin目录下。
3、测试Redis
[plain] view plain copy - cd src
- make test
通过以上命令就要可以对redis进行加大的测试。
4、配置redis
A、复制并修改配置文档
[plain] view plain copy - cp ./redis.conf /usr/local/redis/
- vim /usr/local/redis/redis.conf
我只修改了如下两项:
daemonize yes #redis将以守护进程的方式运行,默认为no会暂用你的终端
timeout 300 #当 客户端闲置多长时间后关闭连接,如果指定为0,表示关闭该功能
更多的配置内容,后续梳理完成后再发布出来。
B、设置自动启动
[plain] view plain copy - vim /etc/init.d/redis
[plain] view plain copy
#!/bin/sh
redis Startup script for Redis Server
chkconfig: - 80 12
description: Redis is an open source, advanced key-value store.
processname: redis-server
config: /etc/redis.conf
pidfile: /var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/redis/bin"
CONFIG="/usr/local/redis/redis.conf"
PIDFILE="/var/run/redis.pid"
Read configuration
[ -r “KaTeX parse error: Expected 'EOF', got '&' at position 14: SYSCONFIG" ] &̲& source "SYSCONFIG”
RETVAL=0
prog=“redis-server”
desc=“Redis Server”
start() {
if [ -e
P
I
D
F
I
L
E
]
;
t
h
e
n
e
c
h
o
"
PIDFILE ];then echo "
PIDFILE];thenecho"desc already running…"
exit 1
fi
echo -n $"Starting $desc: "
daemon
B
I
N
/
BIN/
BIN/prog
C
O
N
F
I
G
R
E
T
V
A
L
=
CONFIG RETVAL=
CONFIGRETVAL=?
echo
[ KaTeX parse error: Expected 'EOF', got '&' at position 16: RETVAL -eq 0 ] &̲& touch /var/lo…prog
return $RETVAL
}
stop() {
echo -n $"Stop $desc: "
killproc
p
r
o
g
R
E
T
V
A
L
=
prog RETVAL=
progRETVAL=?
echo
[ KaTeX parse error: Expected 'EOF', got '&' at position 16: RETVAL -eq 0 ] &̲& rm -f /var/lo…prog $PIDFILE
return $RETVAL
}
restart() {
stop
start
}
case "
1
"
i
n
s
t
a
r
t
)
s
t
a
r
t
;
;
s
t
o
p
)
s
t
o
p
;
;
r
e
s
t
a
r
t
)
r
e
s
t
a
r
t
;
;
c
o
n
d
r
e
s
t
a
r
t
)
[
−
e
/
v
a
r
/
l
o
c
k
/
s
u
b
s
y
s
/
1" in start) start ;; stop) stop ;; restart) restart ;; condrestart) [ -e /var/lock/subsys/
1"instart)start;;stop)stop;;restart)restart;;condrestart)[−e/var/lock/subsys/prog ] && restart
RETVAL=$?
;;
status)
status
p
r
o
g
R
E
T
V
A
L
=
prog RETVAL=
progRETVAL=?
;;
*)
echo $“Usage: $0 {start|stop|restart|condrestart|status}”
RETVAL=1
esac
exit $RETVAL
c、启动或关闭服务
[plain] view plain copy
- service redis start
- service redis stop
5、使用redis
[plain] view plain copy - [root@localhost redis]# cd /usr/local/redis/bin
- [root@localhost bin]# ./redis-cli
- 127.0.0.1:6379> set foo bar
- OK
- 127.0.0.1:6379> get foo
- “bar”
- 127.0.0.1:6379>