1.安裝依賴
yum install -y wget gcc make tcl
2.下載源碼並安裝 進入redis官網
https://redis.io/download/
下載最新版
wget http://download.redis.io/releases/redis-4.0.6.tar.gz
tar xzf redis-4.0.6.tar.gz
cd redis-4.0.6
make
make test
make install
3.修改配置 建立設定檔目錄,dump file 目錄,進程pid目錄,log目錄等
dump file、進程pid、log目錄等,一般放在/var/目錄下,
mkdir -p /var/redis/data
設定檔一般放在/etc/下
cp redis.conf /etc/
修改/etc/redis.conf如下:
daemonize yes
dir /var/redis/data
pidfile /var/run/redis.pid
logfile /var/log/redis.log
宏變數設定
上述安裝將會將redis相關的可執行檔redis-server,redis-cli等存放到/usr/local/bin下面
為了方便,可將其加入系統路徑中
vim /etc/profile
修改
export PATH=/usr/local/bin:$PATH
儲存退出,執行下面的命令生效
source /etc/profile
4.設定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"
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
5.啟動
簡單啟動測試
/usr/local/bin/redis-server /etc/redis.conf
作為系統服務啟動
service redis status
service redis start
chkconfig redis on
chkconfig --list redis
6.參考文獻
[1].https://www.cnblogs.com/visec479/p/5148744.html 簡潔好
[2].https://www.cnblogs.com/caoguo/p/4625662.html 不錯,系統服務指令碼可供參考
[3].http://blog.csdn.net/ludonqin/article/details/47211109