centos安装redis3为系统服务

前端之家收集整理的这篇文章主要介绍了centos安装redis3为系统服务前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#无wget,请通过命令yuminstallwget安装
wgethttp://download.redis.io/releases/redis-3.0.1.tar.gztarxzfredis-3.0.1.tar.gz
cdredis-3.0.1make#如果无make命令,请下载yuminstallgccmakemaketestmakeinstall

安装好了redis后,须注意拷贝bin文件到usr/local/bin(这步很重要,无这步会报错)

cpredis-server/usr/local/bin/cpredis-cli/usr/local/bin

之后修改redis.conf,打开后台运行选项:

daemonizeyes

编写启动shell:vim/etc/init.d/redis(copy网上的)

#chkconfig:23451090#description:StartandStopredis
PATH=/usr/local/bin:/sbin:/usr/bin:/bin

REDISPORT=6379#实际环境而定EXEC=/usr/local/redis/src/redis-server#实际环境而定REDIS_CLI=/usr/local/redis/src/redis-cli#实际环境而定
PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis/redis.conf"#实际环境而定
case"$1"in
start)if[-f$PIDFILE]then
echo"$PIDFILEexists,processisalreadyrunningorcrashed."
else
echo"StartingRedisserver..."
$EXEC$CONF
fi
if["$?"="0"]then
echo"Redisisrunning..."
fi
;;
stop)if[!-f$PIDFILE]then
echo"$PIDFILEexists,processisnotrunning."
else
PID=$(cat$PIDFILE)echo"Stopping..."
$REDIS_CLI-p$REDISPORTSHUTDOWNwhile[-x$PIDFILE]do
echo"WaitingforRedistoshutdown..."
sleep1
done
echo"Redisstopped"
fi
;;
restart|force-reload)${0}stop${0}start
;;
*)echo"Usage:/etc/init.d/redis{start|stop|restart|force-reload}">&2
exit1esac

赋予权限chmod+x /etc/init.d/redis

设置开机启动:

#尝试启动或停止redisserviceredisstartserviceredisstop
#开启服务自启动chkconfigredison
原文链接:https://www.f2er.com/centos/382104.html

猜你在找的CentOS相关文章