标签:
redis 是一个基于内存的高性能key-value数据库,数据都保存在内存中定期刷新到磁盘,以极高的读写效率而备受关注。他的特点是支持各种数据结构,stirng,hashes, list,set,和sorted sets
1、下载安装
wget http://download.redis.io/redis-stable.tar.gz
tar -zxvf redis-stable.tar.gz
cd redis-stable
make
make test 检查一下是否正常,遇到2个错误
[root@localhost redis-stable]# make test
cd src && make test
make[1]: Entering directory `/usr/local/src/redis-stable/src‘
which: no tclsh8.5 in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/geffzhang/bin)
You need ‘tclsh8.5‘ in order to run the Redis test
make[1]: *** [test] 错误 1
make[1]: Leaving directory `/usr/local/src/redis-stable/src‘
make: *** [test] 错误 2
[root@localhost redis-stable]#
没安装tcl
按照官网http://www.linuxfromscratch.org/blfs/view/cvs/general/tcl.html 上的安装(也可以使用:yum install tcl 命令安装)
make install
mkdir -p /usr/local/bin
cp -pf redis-server /usr/local/bin
cp -pf redis-benchmark /usr/local/bin
cp -pf redis-cli /usr/local/bin
cp -pf redis-check-dump /usr/local/bin
cp -pf redis-check-aof /usr/local/bin
make[1]: Leaving directory `/usr/local/src/redis-stable/src‘
[root@localhost redis-stable]#
好了,现在redis就安装成功了
Redis 由四个可执行文件:redis-benchmark、redis-cli、redis-server、redis-stat 这四个文件,加上一个redis.conf就构成了整个redis的最终可用包。它们的作用如下:
现在就可以启动redis了,redis只有一个启动参数,就是他的配置文件路径。
redis-server /etc/redis.conf
注意,默认复制过去的redis.conf文件的daemonize参数为no,所以redis不会在后台运行,这时要测试,我们需要重新开一个终端。修改为yes则为后台运行redis。另外配置文件中规定了pid文件,log文件和数据文件的地址,如果有需要先修改,默认log信息定向到stdout.
下面是redis.conf的主要配置参数的意义:
这时你可以打开一个终端进行测试了,配置文件中默认的监听端口是6379
2、建立用户和日志目录
第一次启动时建议为Redis建立用户和日志目录
[root@localhost redis-stable]# useradd redis
[root@localhost redis-stable]# mkdir -p /var/lib/redis
#db文件放在这里,需要修改redis.conf
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the ‘dbfilename‘ configuration directive.
#
# Also the Append Only File will be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis
[root@localhost redis-stable]# mkdir -p /var/log/redis
# Specify the log file name. Also ‘stdout‘ can be used to force
# Redis to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile /var/log/redis/redislog
[root@localhost redis-stable]# chown redis.redis /var/lib/redis
[root@localhost redis-stable]# chown redis.redis /var/log/redis
3、配置Init脚本
Redis管理脚本基于Ubuntu 的发行版上的,Ubuntu的可以看这篇文章ubuntu安装启动redis,在Centos linux 上并不能用,下面有个脚本可以用于CentOS 。
用这个脚本管理之前,需要先配置下面的内核参数,否则Redis脚本在重启或停止redis时,将会报错,并且不能自动在停止服务前同步数据到磁盘上:
# vi /etc/sysctl.conf
vm.overcommit_memory = 1
然后应用生效:
# sysctl –p
建立redis启动脚本:
# vim /etc/init.d/redis
#!/bin/bash
#
# Init file for redis
#
# chkconfig: - 80 12
# description: redis daemon
#
# processname: redis
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
#BIN="/usr/local/bin"
BIN="/usr/local/bin"
CONFIG="/etc/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=0
prog="redis-server"
desc="Redis Server"
start() {
if [ -e $PIDFILE ];then
echo "$desc already running...."
exit 1
fi
echo -n $"Starting $desc: "
daemon $BIN/$prog $CONFIG
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}
stop() {
echo -n $"Stop $desc: "
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
[ -e /var/lock/subsys/$prog ] && restart
RETVAL=$?
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=1
esac
exit $RETVAL
然后增加服务并开机自启动:
# chmod 755 /etc/init.d/redis
# chkconfig --add redis
# chkconfig --level 345 redis on
# chkconfig --list redis
[root@localhost redis-stable]# service redis start
Starting Redis Server: [确定]
[root@localhost redis-stable]# cat /var/log/redis/redislog
[14250] 14 Jul 22:23:15 * Server started, Redis version 2.4.15
[14250] 14 Jul 22:23:15 * The server is now ready to accept connections on port 6379
[14250] 14 Jul 22:23:15 - 0 clients connected (0 slaves), 717512 bytes in use
[14250] 14 Jul 22:23:20 - 0 clients connected (0 slaves), 717512 bytes in use
[14250] 14 Jul 22:23:25 - 0 clients connected (0 slaves), 717512 bytes in use
[14250] 14 Jul 22:23:30 - 0 clients connected (0 slaves), 717512 bytes in use
[14250] 14 Jul 22:23:35 - 0 clients connected (0 slaves), 717512 bytes in use
[root@localhost redis-stable]#
centos 6.3 server 安装redis-2.4.15
标签:
原文地址:http://www.cnblogs.com/zhengah/p/4976573.html