1、脚本:名字,redis
vi /etc/init.d/redis
#!/bin/sh
#chkconfig: 2345 80 90
#description:auto_run
PATH=/usr/local/bin:/usr/local/redis/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
REDIS_CLI=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/usr/local/redis/etc/redis.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
2、把上述代码存为redis,放到/etc/init.d/下面
chmod 755 /etc/init.d/redis
3、开机启动
chkconfig redis on
4、启动,停止redis
1. service redis start #或者 /etc/init.d/redis start
2. service redis stop #或者 /etc/init.d/redis stop
redis开机启动设置
最新推荐文章于 2024-08-14 17:47:03 发布