重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊(cè)、服務(wù)器等服務(wù)
這篇文章運(yùn)用簡(jiǎn)單易懂的例子給大家介紹啟動(dòng)redis服務(wù)器的步驟,代碼非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
創(chuàng)新互聯(lián)公司2013年成立,先為杭錦等服務(wù)建站,杭錦等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢(xún)服務(wù)。為杭錦企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。
redis的啟動(dòng)方式
1.直接啟動(dòng)
進(jìn)入redis根目錄,執(zhí)行命令:
#加上‘&’號(hào)使redis以后臺(tái)程序方式運(yùn)行 ./redis-server &
2.通過(guò)指定配置文件啟動(dòng)
可以為redis服務(wù)啟動(dòng)指定配置文件,例如配置為/etc/redis/6379.conf
進(jìn)入redis根目錄,輸入命令:
./redis-server /etc/redis/6379.conf
如果更改了端口,使用`redis-cli`客戶(hù)端連接時(shí),也需要指定端口,例如:
redis-cli -p 6380
3.使用redis啟動(dòng)腳本設(shè)置開(kāi)機(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)聽(tīng)的端口 REDISPORT=6379 #服務(wù)端所處位置 EXEC=/usr/local/bin/redis-server #客戶(hù)端位置 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用戶(hù)進(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è)置為開(kāi)機(jī)自啟動(dòng),直接配置開(kāi)啟自啟動(dòng) chkconfig redisd on 發(fā)現(xiàn)錯(cuò)誤: service redisd does not support chkconfig
解決辦法,在啟動(dòng)腳本開(kāi)頭添加如下注釋來(lái)修改運(yùn)行級(jí)別:
#!/bin/sh # chkconfig: 2345 90 10
再設(shè)置即可
#設(shè)置為開(kāi)機(jī)自啟動(dòng)服務(wù)器 chkconfig redisd on #打開(kāi)服務(wù) service redisd start #關(guān)閉服務(wù) service redisd stop
關(guān)于啟動(dòng)redis服務(wù)器的步驟就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。