溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何啟動(dòng)redis

發(fā)布時(shí)間:2020-09-23 10:05:46 來(lái)源:億速云 閱讀:156 作者:小新 欄目:關(guān)系型數(shù)據(jù)庫(kù)

小編給大家分享一下如何啟動(dòng)redis,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

redis的啟動(dòng)方式

1.直接啟動(dòng)

進(jìn)入redis根目錄,執(zhí)行命令:

 #加上‘&’號(hào)使redis以后臺(tái)程序方式運(yùn)行
./redis-server &

或者

修改redis.conf參數(shù)

daemonize yes

2.通過(guò)指定配置文件啟動(dòng)

可以為redis服務(wù)啟動(dòng)指定配置文件,例如配置為/etc/redis/6379.conf

進(jìn)入redis根目錄,輸入命令:

./redis-server /etc/redis/6379.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)腳本開頭添加如下注釋來(lái)修改運(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

以上是如何啟動(dòng)redis的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI