redis新增開機啟動

2021-08-01 09:20:55 字數 1500 閱讀 2551

參看

1.將redis編譯檔案目錄下的redis.conf 複製到/etc/redis/目錄下面

daemonize為yes,確保守護程序開啟

2、編寫開機自啟動指令碼

vim /etc/init.d/redis 

# chkconfig: 2345 90 10

# description: start and stop redis

path=/usr/local/bin:/sbin:/usr/bin:/bin

redisport=6379

exec=/usr/local/bin/redis-server

redis_cli=/usr/local/bin/redis-cli

pidfile=/var/run/redis.pid

conf="/etc/redis/redis.conf"

case "$1" in

start)

if [ -f $pidfile ]

then

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

else

echo "starting redis server..."

$exec $conf

fiif [ "$?"="0" ]

then

echo "redis is running..."

fi;;

stop)

if [ ! -f $pidfile ]

then

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

else

pid=$(cat $pidfile)

echo "stopping..."

$redis_cli -p $redisport shutdown

sleep 2

while [ -x $pidfile ]

doecho "waiting for redis to shutdown..."

sleep 1

done

echo "redis stopped"

fi;;

restart|force-reload)

$ stop

$ start

;;*)

echo "usage: /etc/init.d/redis " >&2

exit 1

esac

指令碼許可權修改:chmod 755 redis

3.啟動指令碼

/etc/init.d/redis start

或者service redis start 也可以

4.開機啟動

chkconfig redis on 

由於ubuntu可能沒有chkconfig ,可以使用 sysv-rc-conf

sysv-rc-conf redis on 

Linux新增開機啟動

修改 etc rc.local 下面是rc.local的乙個例子 touch var lock subsys local modprobe bonding nohup home rsync.sh rsync daemon home cmcc nrpe bin nrpe c home cmcc nrp...

UBUNTU 新增開機啟動程式

1.在 etc init.d 目錄下新建指令碼檔案 jr bin sh begin init info provides binfmt support required start local fs remote fs required stop local fs remote fs default...

linux新增開機啟動服務

修改 etc rc.local 下面是rc.local的乙個例子 touch var lock subsys local modprobe bonding nohup home rsync.sh rsync daemon home cmcc nrpe bin nrpe c home cmcc nrp...