CentOS下redis自啟動(dòng)shell腳本
用這個(gè)腳本管理之前,需要先配置下面的內(nèi)核參數(shù),否則Redis腳本在重啟或停止redis時(shí),將會(huì)報(bào)錯(cuò),并且不能自動(dòng)在停止服務(wù)前同步數(shù)據(jù)到磁盤上:
# vi /etc/sysctl.conf
vm.overcommit_memory = 1
然后應(yīng)用生效:
然后增加服務(wù)并開機(jī)自啟動(dòng):
# chmod 755 /etc/init.d/redis
# chkconfig –add redis
# chkconfig –level 345 redis on
# chkconfig –list redis
腳本源碼:
#!/bin/bash # # redis - this script starts and stops the redis-server daemon # # chkconfig: - 80 12 # 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 "$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
注意:請(qǐng)將腳本中redis的啟動(dòng)文件、配置文件和pid文件存放位置按你配置的位置做相應(yīng)修改,文件保存的時(shí)候注意是unix下可運(yùn)行的模式,否則在linux下運(yùn)行的時(shí)候會(huì)提示錯(cuò)誤,/bin/bash^M: bad interpreter: No such file or directory
相關(guān)文章
linux 環(huán)境 mysql寫入中文報(bào)錯(cuò)
本篇文章主要介紹了linux 環(huán)境 mysql寫入中文報(bào)錯(cuò)的相關(guān)知識(shí)。具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-04-04putty實(shí)現(xiàn)自動(dòng)登錄的方法(ssh和ssh2)
這篇文章主要介紹putty實(shí)現(xiàn)自動(dòng)登錄的方法,需要的朋友可以參考下2013-02-02Linux下使用Shell腳本實(shí)現(xiàn)ftp的自動(dòng)上傳下載的代碼小結(jié)
如何實(shí)現(xiàn)在ftp自動(dòng)上傳下載文件腳本呢?想必還有很多朋友都不太了解吧,下面是ftp自動(dòng)上傳下載文件腳本方法,希望對(duì)朋友們有些幫助2013-02-02Shell腳本實(shí)現(xiàn)的一個(gè)簡(jiǎn)易Web服務(wù)器例子分享
這篇文章主要介紹了Shell腳本實(shí)現(xiàn)的一個(gè)簡(jiǎn)易Web服務(wù)器例子分享,本文實(shí)現(xiàn)的Web服務(wù)器非常簡(jiǎn)單實(shí)用,可以在你不想安裝nginx、apache等大型WEB服務(wù)器時(shí)使用,需要的朋友可以參考下2014-12-12linux下防火墻開啟某個(gè)端口號(hào)及防火墻常用命令使用(詳解)
下面小編就為大家?guī)?lái)一篇linux下防火墻開啟某個(gè)端口號(hào)及防火墻常用命令使用(詳解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-01-01