I have introduced redis in previous articles. The following content is my record of installing Redis on CentOS. For later improvements.
1. Support environment required for installation
Before installing Redis, you must first install the Unix Tcl tool. If it is not installed, you will not be able to test Redis later. The following error message is returned when You execute make test later: You need tcl 8. xuyao de5 or newer in order to run the Redis test. the specific process is as follows:
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. Install redis
The process of installing redis is very simple. The tutorials are also available on the official website. The details are as follows:
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 can be omitted. If this parameter is omitted, redis will be installed in the/usr/local/bin directory by default.
3. Test Redis
Cd src
Make test
Through the above commands, you must be able to perform a larger test on redis.
4. Configure redis
A. Copy and modify the configuration document
Cp./redis. conf/usr/local/redis/
Vim/usr/local/redis. conf
I only modified the following two items:
Daemonize yes # redis will run as a daemprocess. By default, no will temporarily use your terminal.
Timeout 300 # How long does it take to close the connection when the client is idle? If 0 is specified, this function is disabled.
More configuration content will be released after sorting.
B. Set automatic start.
Vim/etc/init. d/redis
Save the following content in the file:
#! /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. 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
C. Start or close the service
Service redis start
Service redis stop
5. Use redis
[Root @ localhost redis] # cd/usr/local/redis/bin
[Root @ localhost bin] #./redis-cli
Wagner. 0.0.1: 6379> set foo bar
OK
127.0.0.1: 6379> get foo
"Bar"
Wagner. 0.0.1: 6379>
-EOF-