Redis設定為開機自啟動

2022-03-11 13:58:55 字數 1866 閱讀 9809

vim /etc/init.d/redis
#!/bin/sh

#chkconfig: 2345 90 10

#description: redis is a persistent key-value database

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_6379.pid

conf="/myredis/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

fi

if [ "$?"="0" ]

then

echo "redis is running..."

fi

;;

stop)

if [ ! -f $pidfile ]

then

echo "$pidfile does not exist, process is not running"

else

pid=$(cat $pidfile)

echo "stopping ..."

$redis_cli -p $redisport shutdown

while [ -x $ ]

do

echo "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

redisport=6379 # 埠號

exec=/usr/local/bin/redis-server # 執行指令碼的位址

redis_cli=/usr/local/bin/redis-cli # 客戶端執行指令碼的位址

pidfile=/var/run/redis_6379.pid # 程序id檔案位址,啟動redis後才能看見

conf="/myredis/redis.conf" #配置檔案位址

chmod 755 /etc/init.d/redis
/etc/init.d/redis start
starting redis server...

redis is running...

chkconfig --add /etc/init.d/redis

chkconfig redis on

檢視第一步的配置檔案資訊,是否和第二步的檔案資訊一致,vim貼上會出現貼上不全的問題

redis設定開機自啟動

1 拷貝 redis 安裝目前下的 usr local redis 4.0.8 utils redis init script 到 etc init.d redis檔案中 cp usr local redis 4.0.8 utils redis init script etc init.d redi...

redis配置為開機自啟動

將redis設定為系統服務,並且開機自啟動。需要完成以下指令碼。bin sh chkconfig 2345 10 90 description start and stop redis path usr local bin sbin usr bin bin redisport 6379 exec u...

設定redis服務開機自啟動

今天周一,一大早來公司開完會,就聽到開發的同學說本地專案起不來了,叫我查下原因。想了下,他們本地專案只跟我們公司的一台內網伺服器有關,那台伺服器他們要用到的呢,也就只有mysql和redis這兩個服務,於是就去查了下這兩個服務的狀態。mysql是啟動狀態的,redis是關閉的,想起來了,週末園區說會...