CentOS Setup opens the way to automatically start Redis

Source: Internet
Author: User
Tags redis server

Prerequisite: Set daemonize in redis.conf to Yes to ensure the daemon is turned on.

First step: Create a startup script named Redis under the/etc/init.d/directory

Writing the boot-up script (Vi/etc/init.d/redis)

The script (Redis) is as follows:

# chkconfig:2345 90 10

# Description:redis is a persistent key-value database


#PATH =/usr/local/bin:/sbin:/usr/bin:/bin


redisport=6379

Exec=/usr/local/bin/redis-server

Redis_cli=/usr/local/bin/redis-cli


Pidfile=/var/run/redis.pid

conf= "/etc/redis.conf"

Auth= "123456"

Case "$" 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 was not running"

Else

pid=$ (Cat $PIDFILE)

echo "Stopping ..."

$REDIS _cli-p $REDISPORT-a $AUTH 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

Step Two: Set this file as an executable file

chmod 755 Redis

Chown Root:root Redis

Step three: Set up the boot execution Redis script

Chkconfig Redis on

Note: The first and second comments in the Redis script must be added, or you will be prompted when the settings start automatically

Service Redis does not support Chkconfig

The error message

Fourth step: Start the Redis service

Service Redis Start

Of course you can also stop and restart the service

#重启redis服务

Service Redis Restart

#关闭redis服务

Service Redis Stop


CentOS Setup opens the way to automatically start Redis

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.