学习成长

提供在线文档,方便大家学习


redis(centos7)设置开机启动服务

<p><strong>编写配置脚本</strong> </p> <pre><code>vim /etc/init.d/redis</code></pre> <p><strong>文件内容如下</strong></p> <h1>!/bin/sh</h1> <pre><code># chkconfig: 2345 10 90 # description: redis .... REDISPORT=6379 EXEC=/usr/local/bin/redis/src/redis-server CLIEXEC=/usr/local/bin/redis/src/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid CONF="/usr/local/bin/redis/redis.conf" case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." nohup $EXEC $CONF &amp; fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $CLIEXEC -p $REDISPORT shutdown while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; *) echo "Please use start or stop as first argument" ;; esac</code></pre> <p><strong>修改redis.conf,打开后台运行选项</strong></p> <pre><code># By default Redis does not run as a daemon. Use 'yes' if you need it. # Note that Redis will write a pid file in /var/run/redis.pid when daemonized. daemonize yes</code></pre> <p><strong>修改文件执行权限</strong></p> <pre><code>chmod +x /etc/init.d/redis</code></pre> <p><strong>设置开机启动</strong></p> <pre><code> 尝试启动或停止 redis ./redis start ./redis stop # 开启服务自启动 chkconfig redis on</code></pre>

页面列表

ITEM_HTML