1.下载(Download)、解压(extract)、完整性检查(How to verify files for integrity)
Redis uses a standard practice for its versioning: major.minor.patchlevel. Redis使用标准做法进行版本控制:主版本号.次版本号.修订版本号 An even minor marks a stable release, like 1.2, 2.0, 2.2, 2.4, 2.6, 2.8. 偶数次版本号表示一个稳定的发行版,如1.2,2.0,2.2,2.4,2.6,2.8。 Odd minors are used for unstable releases, for example 2.9.x releases are the unstable versions of what will be Redis 3.0 once stable.奇数次版本号被用于表示不稳定版本,例如2.9.x版本是不稳定版本,一旦稳定就是3.0
In order to install Redis binaries into /usr/local/bin just use:
% make install
You can use make PREFIX=/some/other/directory install if you wish to use a different destination. 如果你想安装二进制命令到不同的目录
Make install will just install binaries in your system, but will not configure init scripts and configuration files in the appropriate place. This is not needed if you want just to play a bit with Redis, but if you are installing it the proper way for a production system, we have a script doing this for Ubuntu and Debian systems:
Make install在系统中只会安装二进制文件,但不会在适当的位置配置init脚本和配置文件。 如果你只想玩一点Redis,这不是必需的。但如果你正在为生产系统安装它找一个更合适的方式, 针对Ubuntu和Debian系统,我们有一个脚本做这些:
% cd utils% ./install_server.sh
The script will ask you a few questions and will setup everything you need to run Redis properly as a background daemon that will start again on system reboots.
You'll be able to stop and start Redis using the script named /etc/init.d/redis_<portnumber>, for instance /etc/init.d/redis_6379.
# cd redis-3.2.8
# make PREFIX=/usr/local/redis install
Hint: It's a good idea to run 'make test' ;)
# make test...
...
\o/ All tests passed without errors!
Cleanup: may take some time... OK
# mkdir -pv /usr/local/redis/{etc,log,lib}mkdir: created directory ‘/usr/local/redis/etc’mkdir: created directory ‘/usr/local/redis/log’
# cd utils
# ./install_server.shWelcome to the redis service installer
This script will help you easily set up a running redis server
Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] /usr/local/redis/etc/6379.confPlease select the redis log file name [/var/log/redis_6379.log] /usr/local/redis/log/redis_6379.logPlease select the data directory for this instance [/var/lib/redis/6379] /usr/local/redis/lib/6379
Please select the redis executable path [] /usr/local/redis/bin/redis-server
Selected config:
Port : 6379
Config file : /usr/local/redis/etc/6379.confLog file : /usr/local/redis/log/redis_6379.logData dir : /usr/local/redis/lib/6379
Executable : /usr/local/redis/bin/redis-serverCli Executable : /usr/local/redis/bin/redis-cliIs this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
# cat /etc/init.d/redis_6379 #!/bin/sh#Configurations injected by install_server below....EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/usr/local/redis/etc/6379.conf"REDISPORT="6379"################ SysV Init Information# chkconfig: - 30 50# description: redis_6379 is the redis daemon.### BEGIN INIT INFO# Provides: redis_6379# Required-Start: $network $local_fs $remote_fs# Required-Stop: $network $local_fs $remote_fs# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Should-Start: $syslog $named# Should-Stop: $syslog $named# Short-Description: start and stop redis_6379# Description: Redis daemon### END INIT INFOcase "$1" in
start) if [ -f $PIDFILE ] then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
;;
stop) if [ ! -f $PIDFILE ] then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE) echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown while [ -x /proc/${PID} ] do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
status)
PID=$(cat $PIDFILE 2> /dev/null) # 原为PID=$(cat $PIDFILE) stop之后,文件不存在,抛出异常
if [ -z ${PID} ] # 原为if [ ! -x /proc/${PID} ] PID即使为空,但/proc仍然存在,最后还是会回到running状态
then
echo 'Redis is not running'
else
echo "Redis is running ($PID)"
fi
;;
restart) $0 stop $0 start
;;
*) echo "Please use start, stop, restart or status as first argument"
;;esac
4. 连接测试
(magedu) [iyunv@Webserver utils]# redis-cli -h localhost -p 6379localhost:6379> ping
PONG
localhost:6379> set foo bar
OK
localhost:6379> get foo"bar"localhost:6379> ping 'zcy'"zcy"
5. 关闭服务
# netstat -tlnp | grep 6379 127.0.0.1:6379 0.0.0.0:* LISTEN 67387/redis-server
# pkill -u root redis # 方法1# netstat -tlnp | grep 6379# service redis_6379 statusRedis is not running# service redis_6379 stoppid does not exist, process is not running# service redis_6379 startStarting Redis server...# redis-cli -h localhost -p 6379 get foo"bar"# redis-cli -h localhost -p 6379 shutdown #方法2 : 服务脚本用的是这一种。# service redis_6379 statusRedis is not running#无论哪种方式关闭服务,都会产生如下日志71428:M 25 Feb 22:06:09.131 # User requested shutdown... 关闭用户的请求71428:M 25 Feb 22:06:09.131 * Saving the final RDB snapshot before exiting. 在关闭之前保存最后的RDB快照71428:M 25 Feb 22:06:09.142 * DB saved on disk DB保存到磁盘上71428:M 25 Feb 22:06:09.142 * Removing the pid file. 移除PID文件71428:M 25 Feb 22:06:09.142 # Redis is now ready to exit, bye bye.. pkill ,kill 默认发送信号15 SINTERM
产生日志:67387:signal-handler (1488031433) Received SIGTERM scheduling shutdown... 接收到终止信号安排关闭...