新聞中心
變動(dòng)Redis端口號(hào)更改帶來(lái)的變化

成都創(chuàng)新互聯(lián)公司是專業(yè)的東海網(wǎng)站建設(shè)公司,東海接單;提供網(wǎng)站制作、成都網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行東海網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
在使用Redis作為緩存系統(tǒng)的過(guò)程中,有時(shí)候需要更改默認(rèn)的端口號(hào),以增加安全性。但是,更改端口號(hào)也會(huì)帶來(lái)一些變化。本文將介紹在更改Redis端口號(hào)后可能會(huì)出現(xiàn)的問(wèn)題及解決方案。
我們需要知道如何更改Redis的端口號(hào)。在Redis的配置文件redis.conf中,可以找到以下代碼:
# If not running redis-server with root privileges you may specify the
# user that should own the Redis process with the following option.
#
# Note that configuring a non-default user requires creating a Redis user
# with the same permissions as redis-server's default user (see above).
#
# user someusername
#
# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
# supervised no - no supervision interaction
# supervised upstart - signal upstart by "emit"ing the "redis" event
# supervised systemd - signal systemd by writing a "READY=1" message
# to the NOTIFY_SOCKET environment variable when
# the service is ready.
# supervised auto - detect upstart or systemd method based on
# UPSTART_JOB or SYSTEMD_UNIT environment variables.
# Note that setting "supervised" to "no" can be a good solution for debugging.
# NOTE: These supervision methods only signal "process is ready."
# They do not enable continuous liveness pings back to your supervisor.
#
# supervised systemd
#
# If you run Redis from another system account you may specify a path
# that contns the directory with the Unix socket used by Redis.
# The default value is /var/run/redis/redis.sock.
# unixsocket /tmp/redis.sock
# unixsocketperm 700
# Redis Port
#
# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
#
port 6379
可以看到,Redis的默認(rèn)端口號(hào)是6379。為了更改端口號(hào),只需要將port 6379行改為其他可用端口即可。例如,將端口號(hào)改為6380:
port 6380
然后,重新啟動(dòng)Redis即可生效。可以使用以下命令檢查Redis的狀態(tài):
$ sudo systemctl status redis
如果Redis正常運(yùn)行,則可以看到類(lèi)似以下的輸出:
● redis.service - Redis persistent key-value database
Loaded: loaded (/lib/systemd/system/redis.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2021-11-20 15:04:10 UTC; 10s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Process: 9107 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=0/SUCCESS)
Mn PID: 9108 (redis-server)
Tasks: 4 (limit: 2357)
CGroup: /system.slice/redis.service
└─9108 /usr/bin/redis-server 127.0.0.1:6380
可以看到,此時(shí)Redis的端口號(hào)已經(jīng)改為6380。
但是,在更改了端口號(hào)之后,可能會(huì)導(dǎo)致以下的問(wèn)題:
1. 連接錯(cuò)誤
如果使用了舊的端口號(hào)連接Redis,將會(huì)收到連接錯(cuò)誤的提示:
$ redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
這是因?yàn)镽edis服務(wù)器已經(jīng)不再監(jiān)聽(tīng)默認(rèn)的端口6379,需要將連接信息中的端口號(hào)改為新的端口號(hào)。例如,連接到端口號(hào)為6380的Redis:
$ redis-cli -p 6380
127.0.0.1:6380> ping
PONG
2. 集群配置
如果在Redis集群中更改了部分節(jié)點(diǎn)的端口號(hào),可能會(huì)導(dǎo)致集群配置錯(cuò)誤。例如,本來(lái)所有的節(jié)點(diǎn)都監(jiān)聽(tīng)了6379端口,但是在某一節(jié)點(diǎn)更改端口為6380后,集群配置就會(huì)發(fā)生變化。
解決此問(wèn)題的方法是使用集群命令reshard來(lái)重新分配槽位。但是,這個(gè)過(guò)程需要格外小心,避免數(shù)據(jù)丟失。
更改Redis的端口號(hào)雖然可以增加安全性,但也可能會(huì)帶來(lái)一些影響。在更改之前,需要對(duì)影響有足夠的準(zhǔn)備。同時(shí),如果遇到連接錯(cuò)誤或者集群配置錯(cuò)誤等問(wèn)題,需要及時(shí)進(jìn)行排查和解決。
香港服務(wù)器選創(chuàng)新互聯(lián),2H2G首月10元開(kāi)通。
創(chuàng)新互聯(lián)(www.cdcxhl.com)互聯(lián)網(wǎng)服務(wù)提供商,擁有超過(guò)10年的服務(wù)器租用、服務(wù)器托管、云服務(wù)器、虛擬主機(jī)、網(wǎng)站系統(tǒng)開(kāi)發(fā)經(jīng)驗(yàn)。專業(yè)提供云主機(jī)、虛擬主機(jī)、域名注冊(cè)、VPS主機(jī)、云服務(wù)器、香港云服務(wù)器、免備案服務(wù)器等。
分享題目:變動(dòng)Redis端口號(hào)更改帶來(lái)的變化(redis端口后數(shù)字)
文章URL:http://m.fisionsoft.com.cn/article/dheccje.html


咨詢
建站咨詢
