Redis STARTUP script on centos Linux

Source: Internet
Author: User

The redis management script is based on the Ubuntu release. For Ubuntu users, you can refer to this Article. Ubuntu installation and startup of redis are not available on centos Linux. The following script can be used for centos:

Before using this script for management, you must configure the following kernel parameters. Otherwise, an error will be reported when the redis script restarts or stops redis, data cannot be automatically synchronized to the disk before the service is stopped:

# Vi/etc/sysctl. conf

VM. overcommit_memory = 1

Then the application takes effect:

# Sysctl-P

Create a redis STARTUP script:

 

# Vim/etc/init. d/redis

#! /Bin/bash
#
# Init file for redis
#
# Chkconfig:-80 12
# Description: redis daemon
#
# Processname: redis
# Config:/etc/redis. conf
# Pidfile:/var/run/redis. PID
Source/etc/init. d/functions
# Bin = "/usr/local/bin"
Bin = "/usr/local/bin"
Config = "/etc/redis. conf"
Pidfile = "/var/run/redis. PID"
### Read Configuration
[-R "$ sysconfig"] & source "$ sysconfig"
Retval = 0
Prog = "redis-server"
Desc = "redis server"
Start (){
If [-e $ pidfile]; then
Echo "$ DESC already running ...."
Exit 1
Fi
Echo-N $ "Starting $ Desc :"
Daemon $ bin/$ prog $ config
Retval =$?
Echo
[$ Retval-EQ 0] & Touch/var/lock/subsys/$ prog
Return $ retval
}
Stop (){
Echo-N $ "Stop $ Desc :"
Killproc $ prog
Retval =$?
Echo
[$ Retval-EQ 0] & Rm-F/var/lock/subsys/$ prog $ pidfile
Return $ retval
}
Restart (){
Stop
Start
}
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Restart)
Restart
;;
Condrestart)
[-E/var/lock/subsys/$ prog] & restart
Retval =$?
;;
Status)
Status $ prog
Retval =$?
;;
*)
Echo $ "Usage: $0 {START | stop | restart | condrestart | status }"
Retval = 1
Esac
Exit $ retval

Then add the service and start it automatically:

# Chmod 755/etc/init. d/redis
# Chkconfig -- add redis
# Chkconfig -- level 345 redis on
# Chkconfig -- list 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.