Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write redis self-starting shell script under CentOS

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to write a redis self-startup shell script under CentOS". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to write a redis self-startup shell script under CentOS".

Before using this script to manage, you need to configure the following kernel parameters, otherwise the Redis script will report an error when restarting or stopping redis, and cannot automatically synchronize data to disk before stopping the service:

The code is as follows:

# vi / etc/sysctl.conf

Vm.overcommit_memory = 1

Then the application takes effect:

The code is as follows:

# sysctl-p

Then add services and boot up:

The code is as follows:

# chmod 755 / etc/init.d/redis

# chkconfig-add redis

# chkconfig-level 345 redis on

# chkconfig-list redis

Script source code:

#! / bin/bash## redis- this script starts and stops the redis-server daemon## chkconfig:-80 1 minutes description: Redis is a persistent key-value database# processname: redis-server# config: / usr/local/redis/etc/redis.conf# pidfile: / usr/local/redis/var/redis.pidsource / etc/init.d/functionsBIN= "/ usr/local/redis/bin" CONFIG= "/ usr/local/redis/etc/redis.conf" PIDFILE= "/ usr/local/redis / var/redis.pid "# Read configuration [- r" $SYSCONFIG "] & & source" $SYSCONFIG "RETVAL=0prog=" 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=1esacexit $RETVAL

Note: please modify the startup file, configuration file and pid file storage location of redis in the script according to the location you configured. When saving the file, pay attention to the runnable mode under unix, otherwise an error will be prompted when running under linux. / bin/ Bash ^ M: bad interpreter: No such file or directory

Thank you for your reading, the above is the content of "how to write redis self-startup shell script under CentOS". After the study of this article, I believe you have a deeper understanding of how to write redis self-startup shell script under CentOS, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report