redis的啟動(dòng)方式操作詳解
redis的啟動(dòng)方式
1.直接啟動(dòng)
進(jìn)入redis根目錄,執(zhí)行命令:
#加上‘&’號(hào)使redis以后臺(tái)程序方式運(yùn)行
./redis-server &
2.通過指定配置文件啟動(dòng)
可以為redis服務(wù)啟動(dòng)指定配置文件,例如配置為/etc/redis/6379.conf
進(jìn)入redis根目錄,輸入命令:
redis-server redis.windows.conf
#如果更改了端口,使用redis-cli客戶端連接時(shí),也需要指定端口,例如:
redis-cli -p 6380
3.使用redis啟動(dòng)腳本設(shè)置開機(jī)自啟動(dòng)
啟動(dòng)腳本 redis_init_script 位于位于Redis的 /utils/ 目錄下,redis_init_script腳本代碼如下:
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
#redis服務(wù)器監(jiān)聽的端口
REDISPORT=6379
#服務(wù)端所處位置
EXEC=/usr/local/bin/redis-server
#客戶端位置
CLIEXEC=/usr/local/bin/redis-cli
#redis的PID文件位置,需要修改
PIDFILE=/var/run/redis_${REDISPORT}.pid
#redis的配置文件位置,需將${REDISPORT}修改為文件名
CONF="/etc/redis/${REDISPORT}.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
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac根據(jù)啟動(dòng)腳本,將修改好的配置文件復(fù)制到指定目錄下,用root用戶進(jìn)行操作:
mkdir /etc/redis cp redis.conf /etc/redis/6379.conf
將啟動(dòng)腳本復(fù)制到/etc/init.d目錄下,本例將啟動(dòng)腳本命名為redisd(通常都以d結(jié)尾表示是后臺(tái)自啟動(dòng)服務(wù))。
cp redis_init_script /etc/init.d/redisd
設(shè)置為開機(jī)自啟動(dòng),直接配置開啟自啟動(dòng) chkconfig redisd on 發(fā)現(xiàn)錯(cuò)誤: service redisd does not support chkconfig
解決辦法,在啟動(dòng)腳本開頭添加如下注釋來修改運(yùn)行級(jí)別:
#!/bin/sh # chkconfig: 2345 90 10
再設(shè)置即可
#設(shè)置為開機(jī)自啟動(dòng)服務(wù)器 chkconfig redisd on #打開服務(wù) service redisd start #關(guān)閉服務(wù) service redisd stop
到此這篇關(guān)于redis的啟動(dòng)方式操作詳解的文章就介紹到這了,更多相關(guān)redis啟動(dòng)方式內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
深入理解redis_memcached失效原理(小結(jié))
這篇文章主要介紹了深入理解redis_memcached失效原理(小結(jié)),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-08-08
redis分布式設(shè)計(jì)的實(shí)現(xiàn)示例
Redis 的分布式設(shè)計(jì)主要通過三種模式實(shí)現(xiàn),每種模式解決不同的問題,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2026-05-05

