新聞中心
Redis是一個(gè)開(kāi)源的高性能的Key-Value數(shù)據(jù)庫(kù),它支持多種數(shù)據(jù)類型的存儲(chǔ),如字符串、列表、哈希、集合等等。作為企業(yè)級(jí)應(yīng)用開(kāi)發(fā)中的關(guān)鍵組件之一,很多開(kāi)發(fā)者都會(huì)將Redis服務(wù)部署到自己的應(yīng)用環(huán)境中。但是,有些時(shí)候我們需要關(guān)閉Redis服務(wù),比如在應(yīng)用程序維護(hù)、故障排除或者系統(tǒng)升級(jí)等情況下。那么,如何以最小的代價(jià)來(lái)關(guān)閉Redis服務(wù)呢?

10年積累的網(wǎng)站設(shè)計(jì)制作、成都網(wǎng)站設(shè)計(jì)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先做網(wǎng)站后付款的網(wǎng)站建設(shè)流程,更有夏河免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
一、在shell中直接關(guān)閉Redis服務(wù)
最簡(jiǎn)單的方法是在shell中直接關(guān)閉Redis服務(wù)。以CentoS 7.8為例,我們需要進(jìn)入到Redis安裝目錄下的bin目錄,執(zhí)行下面的命令來(lái)關(guān)閉Redis服務(wù):
./redis-cli SHUTDOWN
這條命令將向Redis服務(wù)器發(fā)送關(guān)閉命令,Redis將會(huì)在安全的方式下結(jié)束自己的工作。
二、通過(guò)Redis配置文件關(guān)閉服務(wù)
如果Redis已經(jīng)在運(yùn)行但您希望更改配置,那么您可以修改Redis的配置文件。以Redis的默認(rèn)配置文件/etc/redis/redis.conf為例,下面是如何關(guān)閉Redis服務(wù)的幾行:
# Require clients to issue AUTH command before processing
# any other commands. This might be useful in environments
# where you do not trust others with access to the Redis
# server instance hosting your data.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# requirepass foobared
# Stop accepting new connections from clients.
#
# This command will immediately stop accepting new connections.
# You can use this option when you want to apply the configuration
# changes to a running Redis-server or if you want to gracefully
# shutdown it for mntenance.
#
# The clients connected to the Redis server will still be served
# for the number of seconds specified by the 'timeout' configuration
# directive.
#
# This command does not flush the database but just stops accepting
# new connections, so all the data remns saved in memory.
#
# By default Redis does not run as a daemon. Use 'daemonize yes' to
# fork the Redis process into the background.
#
# Note that Redis will not stop the server if clients are connected.
# Exit the client before shutting down the server.
stop-writes-on-bgsave-error no
# Close the connection to the client after a timeout.
#
# If the client is idle for the specified number of seconds, the connection is
# closed.
#
# The timeout value is given in seconds. In the example below, the timeout is set
# to 300 seconds (5 minutes).
#
# A value of 0 means that the timeout is disabled.
timeout 0
# Set the maximum number of connected clients.
#
# The default value is 10000.
#
# maxclients 10000
# Set the maximum number of connections Redis can handle.
#
# The default value is 100000.
#
# maxmemory 1000mb
在文件中找到下面這段代碼,將stop-writes-on-bgsave_error的值修改為yes:
# Stop accepting new connections from clients.
stop-writes-on-bgsave_error yes
然后重啟Redis服務(wù):
service redis restart
Redis將在shutdown后重啟,并在安全地方式下執(zhí)行。
三、通過(guò)命令行關(guān)閉Redis服務(wù)
在Redis服務(wù)運(yùn)行時(shí),您也可以在命令行模式下直接關(guān)閉服務(wù)。進(jìn)入redis-cli模式后,執(zhí)行shutdown命令即可:
redis-cli
shutdown
Redis將會(huì)在安全的方式下結(jié)束自己的工作。
總結(jié)
關(guān)閉Redis服務(wù)是一個(gè)非常容易的操作。您可以使用命令行操作、修改配置文件或者使用命令行模式下的命令來(lái)關(guān)閉Redis服務(wù)。無(wú)論采用何種方式,在關(guān)閉Redis之前請(qǐng)確保在關(guān)閉前已經(jīng)保存了所有的數(shù)據(jù),否則您將會(huì)失去寶貴的數(shù)據(jù)。
成都創(chuàng)新互聯(lián)科技有限公司,是一家專注于互聯(lián)網(wǎng)、IDC服務(wù)、應(yīng)用軟件開(kāi)發(fā)、網(wǎng)站建設(shè)推廣的公司,為客戶提供互聯(lián)網(wǎng)基礎(chǔ)服務(wù)!
創(chuàng)新互聯(lián)(www.cdcxhl.com)提供簡(jiǎn)單好用,價(jià)格厚道的香港/美國(guó)云服務(wù)器和獨(dú)立服務(wù)器。創(chuàng)新互聯(lián)成都老牌IDC服務(wù)商,專注四川成都IDC機(jī)房服務(wù)器托管/機(jī)柜租用。為您精選優(yōu)質(zhì)idc數(shù)據(jù)中心機(jī)房租用、服務(wù)器托管、機(jī)柜租賃、大帶寬租用,可選線路電信、移動(dòng)、聯(lián)通等。
網(wǎng)站題目:閉深入了解如何關(guān)閉Redis服務(wù)(redis服務(wù)怎么關(guān))
分享URL:http://m.fisionsoft.com.cn/article/cdsihpp.html


咨詢
建站咨詢
