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
原文链接:/centos/374936.html