Redis joins CentOS Linux boot

Source: Internet
Author: User
Tags joins redis server

Redis joins CentOS Linux boot

There are many online Redis in Linux under the example of automatic startup, a lot of ways to achieve, many of them are referred to a foreigner to launch the example, in fact, the direct use is not, and there are a lot of places there are some grammatical errors, here I experiment, The successful Linux service Chkconfig configuration starts the method.

The following directly posted content, you download after the modification can be used, followed by detailed parameters:

# chkconfig:2345 90# Description:start and Stop redispath=/usr/local/bin:/sbin:/usr/bin:/binredisport=6379exec=/ Opt/redis-2.8.9/src/redis-serverredis_cli=/opt/redis-2.8.9/src/redis-clipidfile=/var/run/redis.pidconf= "/etc/ redis.conf "auth=" 1234 "case" "in Start" if [-f $PIDFILE] then echo "$PIDFILE exists, process is already RU    Nning 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 exists, and process is not running."      Else pid=$ (cat $PIDFILE) echo "Stopping ..." $REDIS _cli-p $REDISPORT-a $AUTH SHUTDOWN sleep 2 While [-X $PIDFILE] do echo "Waiting for Redis to shutdown ..." Sleep 1 done echo "Redis sto  Pped "FI;;  restart|force-reload) ${0} stop ${0} start; *) echo "Usage:/etc/init.d/redis {start|stop|restart|force-reload}" >& 2 Exit 1esac 

2. Save Exit VI after writing

3. Set permissions

chmod 755 Redis

4. Start test

/etc/init.d/redis start

Startup success prompts you for the following information:

Starting Redis Server ... Redis is running ...

Using the REDIS-CLI test:

[[email protected] ~]#/usr/redisbin/redis-cli127.0.0.1:6379> set foo barok127.0.0.1:6379> get foo "bar" 127.0.0.1:6379> exit

6. Set Boot from boot

Chkconfig Redis on

7, Shutdown restart test

Reboot

Then you can use the REDIS-CLI test.

  

# chkconfig:2345 10 90

Indicates that through the Chkconfig configuration, in Linux 2, 3, 4, 5 items start, this 2345 represents the Linux system boot sequence specific, the specific content is: Level 0 indicates: The shutdown, Level 1 means: Single user mode, Level 2 means: Multi-user command line mode without network connection, Level 3 means: Multi-user command line mode with network connection, level 4 means: Not available, Level 5 means: Multi-user mode with graphical interface, Level 6 means: reboot

If you do not understand, your own Baidu Chkconfig command detailed instructions.

# Description:start and Stop Redis

The above sentence is a description

Path=/usr/local/bin:/sbin:/usr/bin:/bin

Path is the search path for the shell used by the startup script

redisport=6379

Redisport refers to the Redis port, starting Redis use

Exec=/opt/redis-2.8.9/src/redis-server

Absolute path to Redis-server after installation of Redis, used when starting Redis

Redis_cli=/opt/redis-2.8.9/src/redis-cli

Redis connector Absolute path, used when Redis is turned off

Pidfile=/var/run/redis.pid

redis.conf configuration file specified in the PID path address, here, in the redis.conf configuration file need to set daemonize this parameter item to Yes will be generated at redis startup pid file, many new people do not know, did not generate PID file, So the script shuts down Redis based on the PID file and fails.

conf= "/etc/redis.conf"

Redis Boot configuration file, starting with

Auth= "1234"

If Redis has a login password, this configuration is required, see section on stop below for details

Start

# here to determine whether the PID file exists, if present, it means that reids boot or run an exception, because Redis will create a PID file after booting, if the normal shutdown will delete the PID file

If [-F $PIDFILE]

Then

echo "$PIDFILE exists, process is already running or crashed."

Else

# If the PID file does not exist, start Reids and Prompt "Redis is running ..." after successful startup

echo "Starting Redis server ..."

$EXEC $CONF

Fi

If ["$?" = "0"]

Then

echo "Redis is running ..."

Fi

;;

Stop

# when the Reids is off, if the PID file does not exist, it is determined that Redis does not start

if [!-F $PIDFILE]

Then

echo "$PIDFILE exists, process is not running."

Else

# #--If a PID file exists, get the PID number, then log in to Redis and enter shutdown to stop the Redis service

pid=$ (Cat $PIDFILE)

echo "Stopping ..."

# #--This section is an example of REDIS having a login password, and if there is no login password, the following command removes-a $AUTH: $REDIS _cli-p $REDISPORT SHUTDOWN

$REDIS _cli-p $REDISPORT-a $AUTH SHUTDOWN

Sleep 1

# #--loop to determine whether the PID file exists, here is whether it can be executed, the same reason, understood as whether the program is stopped, and until the PID file is deleted, it means that Redis closed.

While [-X $PIDFILE]

Do

echo "Waiting for Redis to shutdown ..."

Sleep 1

Done

echo "Redis stopped"

Fi

;;

Finally, say a few questions that you might encounter:

1. If the startup script indicates that a file cannot be found, it indicates that the contents of our file are incorrect: for example, Cat $ (pidfile)-X ${pidfile} If these are written in normal instructions or strings, but in the judgment expression [] will be an error

2. If the PID file cannot be found, you need to configure the option in the Redis.conf configuration to open.

In fact, so the problem is a little bit of troubleshooting check to finally correct. Be patient and careful.

Redis joins CentOS Linux boot

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.