CentOS redis shell Script _linux Shell

Source: Internet
Author: User
Tags redis redis server

Before you can use this script to manage, you need to configure the following kernel parameters, otherwise the Redis script will error when you restart or stop Redis, and you cannot automatically synchronize data to disk before stopping the service:

Copy Code code as follows:

# vi/etc/sysctl.conf

Vm.overcommit_memory = 1


Then the application takes effect:
Copy Code code as follows:
# sysctl-p

Then add the service and boot from:

Copy Code code as follows:

# chmod 755/etc/init.d/redis
# Chkconfig–add Redis
# chkconfig–level 345 Redis on
# chkconfig–list Redis

Script Source:

#!/bin/bash # # Redis-this script starts and stops the Redis-server daemon # chkconfig:-# Description:redis is a persistent key-value database # processname:redis-server # config:/usr/local/redis/etc/redis.conf # pidfile:/ Usr/local/redis/var/redis.pid source/etc/init.d/functions bin= "/usr/local/redis/bin" CONFIG= "/usr/local/redis/etc" /redis.conf "pidfile="/usr/local/redis/var/redis.pid "### Read configuration [-R" $SYSCONFIG "] && source" $SYS CONFIG "Retval=0 prog=" Redis-server desc= "Redis server" start () {if [-e $PIDFILE];then echo $desc Alrea
    Dy 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 "in Start" start;;
 stop) stop;;
 restart) restart;;
    Condrestart) [-e/var/lock/subsys/$prog] && restart retval=$?
 ;;
    Status $prog retval=$?
  ;; * echo $ "Usage: $ {start|stop|restart|condrestart|status}" retval=1 Esac exit $RETVAL

Note: Please modify the Redis boot file, configuration file and PID file location in your script according to the location you configured, and note that the file is stored in a UNIX-run mode, otherwise you will be prompted for errors when running under Linux/bin/bash^m:bad Interpreter:no such file or directory

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.