Linux(Centos)下Redis開機自啟設定

2021-08-25 13:54:45 字數 2018 閱讀 2765

1、設定redis.conf中daemonize為yes,確保守護程序開啟。

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

vi /etc/init.d/redis
指令碼內容如下:

# chkconfig: 2345 10 90  

# description: start and stop redis

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

# redis埠號

redisport=6379

# redis-server所在目錄的絕對路徑

exec=/usr/apk/redis-2.8.17/redis-server

# redis-cli所在目錄的絕對路徑

redis_cli=/usr/apk/redis-2.8.17/redis-cli

pidfile=/var/run/redis.pid

# redis.conf所在目錄的絕對路徑

conf="/usr/apk/redis-2.8.17/redis.conf"

auth="nginx"

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 exists, process is not running."

else

pid=$(cat $pidfile)

echo "stopping..."

$redis_cli -p $redisport shutdown

sleep 2

while [ -x $pidfile ]

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

3、寫完後儲存退出vi

4、設定許可權

chmod 755 redis
5、啟動測試

/etc/init.d/redis start
啟動成功會提示如下資訊:

starting redis server...

redis is running...

使用redis-cli測試:

[root@rk ~]# /usr/redisbin/redis-cli

127.0.0.1:6379> set foo bar

ok127.0.0.1:6379> get foo

"bar"

127.0.0.1:6379> exit

6、設定開機自啟動

chkconfig redis on
7、關機重啟測試

reboot
然後在用redis-cli測試即可。

Linux centos7 下安裝配置redis

剛開始redis安裝的最新版本6.0.1,導致後面會出現gcc的版本問題弄了好久,建議安裝舊點的版本 wget建議將redis安裝包放到opt目錄下 mv redis 5.0.8.tar.gz opt移動完成進入opt目錄 cd opt二 解壓安裝包tar zxvf redis 5.0.8.tar....

Linux centos下檢視硬體型號

檢視cpu資訊 型號 cat proc cpuinfo grep name cut f2 d uniq c 8 intel r xeon r cpu e5410 2.33ghz 看到有8個邏輯cpu,也知道了cpu型號 cat proc cpuinfo grep physical uniq c 4 ...

linux(centos)下安裝boost庫及使用

一 安裝 剛剛使用linux系統,對很多系統命令和操作方式還不是很熟悉。想裝個boost庫,在網上看了幾篇教程根本沒弄明白,終於,用三行命令解決了。yum install boost yum install boost devel yum install boost doc 二 使用 對於我這樣的小...