环境:
centos6.5
redis2.8.19
使用非root用户安装
一、安装
1、下载redis
Java代码
wget http://download.redis.io/releases/redis-2.8.19.tar.gz
2、安装前需要安装make、gcc、tcl
Java代码
sudo yum install make
sudo yum install gcc
sudo yum install -y tcl
3、解压、编译、安装
Java代码
$ tar -xzvf redis-2.8.19.tar.gz
$ cd redis-2.8.19
$ make MALLOC=libc
$make test
注:make会在目录下生成四个可执行文件:redis-benchmark、redis-cli、redis-server、redis-stat
Java代码
$sudo make install
注:这个操作会将生成的可执行文件复制到/usr/local/bin中
二、启动
1、直接启动(适用于开发环境)
Java代码
切换到redis-2.8.17/src目录下
$redis-server
2、通过初始化脚本启动(适用于生产环境)
(1)配置init脚本:
Java代码
wget ps://github.com/ijonas/dotfiles/raw/master/etc/init.d/redis-server">https://github.com/ijonas/dotfiles/raw/master/etc/init.d/redis-server
wget https://github.com/ijonas/dotfiles/raw/master/etc/redis.conf
sudo mv redis-server /etc/init.d/redis-server
sudo chmod +x /etc/init.d/redis-server
sudo mv redis.conf /etc/redis.conf
将/etc/init.d/redis-server文件里的内容替换成以下内容:
Java代码
#!/bin/sh
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis.conf
# config: /etc/sysconfig/redis
# pidfile: /var/run/redis.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
redis="/usr/local/bin/redis-server"
prog=$(basename $redis)
REDIS_CONF_FILE="/etc/redis.conf"
[ -f /etc/sysconfig/redis ] && . /etc/sysconfig/redis
lockfile=/var/lock/subsys/redis
start() {
[ -x $redis ] || exit 5
[ -f $REDIS_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $redis $REDIS_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
echo -n $"Reloading $prog: "
killproc $redis -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit 2
esac
(2)初始化用户和日志路径
Java代码
sudo useradd redis
sudo mkdir -p /var/lib/redis
sudo mkdir -p /var/log/redis
sudo chown redis.redis /var/lib/redis
sudo chown redis.redis /var/log/redis
(3)将redis加入自启动服务
Java代码
sudo chkconfig --add /etc/init.d/redis-server
Java代码
sudo chkconfig redis-server --level 345 on
使用chkconfig --list查看添加的服务
(4)启动服务
Java代码
sudo service redis-server start
三、使用
Java代码
redis-cli
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379> keys *
(empty list or set)