1.下載: wget? http://download.redis.io/releases/redis-3.2.9.tar.gz
2.解壓: tar zxvf redis-3.2.9.tar.gz
3.進(jìn)入目錄: cd redis-3.2.9
編譯并指定安裝目錄: make PREFIX=/usr/local/redis-3.2.9 install
4.創(chuàng)建軟鏈接: ln -s /usr/local/redis-3.2.9 /usr/local/redis
cp redis.conf /etc/redis.conf
5.編輯/etc/redis.conf
daemonize no? ==> daemonize yes? ? (設(shè)置redis為后臺daemon進(jìn)程)
6.創(chuàng)建redis用戶
[root@redis-server ~]# useradd -r -s /sbin/nologin -M redis
7.創(chuàng)建啟動腳本/etc/init.d/redis
#!/bin/sh
#
# redis? ? ? ? init file for starting up the redis daemon
#
# chkconfig:? - 20 80
# description: Starts and stops the redis daemon.
# Source function library.
#!/bin/sh
#
# redis? ? ? ? init file for starting up the redis daemon
#
# chkconfig:? - 20 80
# description: Starts and stops the redis daemon.
# Source function library.
. /etc/rc.d/init.d/functions
name="redis-server"
exec="/usr/local/redis/bin/$name"
pidfile="/var/run/redis/redis.pid"
REDIS_CONFIG="/etc/redis.conf"
[ -e /etc/sysconfig/redis ] && . /etc/sysconfig/redis
lockfile=/var/lock/subsys/redis
start() {
[ -f $REDIS_CONFIG ] || exit 6
[ -x $exec ] || exit 5
echo -n $"Starting $name: "
daemon --user ${REDIS_USER-redis} "$exec $REDIS_CONFIG"
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $name: "
killproc -p $pidfile $name
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
stop
start
}
reload() {
false
}
rh_status() {
status -p $pidfile $name
}
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)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}"
exit 2
esac
exit $?
8. 修改腳本文件權(quán)限
[root@redis-server ~]# chmod 755 /etc/init.d/redis
9. 添加進(jìn)service服務(wù)管理并設(shè)置開機(jī)啟動
[root@redis-server ~]# chkconfig --add redis
[root@redis-server ~]# chkconfig redis on
10. redis服務(wù)測試
service redis start
11. 連接測試(通過自帶redis-cli命令連接測試)
[root@redis-server ~]# /usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379