这篇文章主要介绍了Redis3.2如何开启远程访问,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。

redis默认只允许本地访问,要使redis可以远程访问可以修改redis.conf
打开redis.conf文件在NETWORK部分有说明

##################################NETWORK######################################Bydefault,ifno"bind"configurationdirectiveisspecified,Redislistens#forconnectionsfromallthenetworkinterfacesavailableontheserver.#Itispossibletolistentojustoneormultipleselectedinterfacesusing#the"bind"configurationdirective,followedbyoneormoreIPaddresses.##Examples:##bind192.168.1.10010.0.0.1#bind127.0.0.1::1##~~~WARNING~~~IfthecomputerrunningRedisisdirectlyexposedtothe#internet,bindingtoalltheinterfacesisdangerousandwillexposethe#instancetoeverybodyontheinternet.Sobydefaultweuncommentthe#followingbinddirective,thatwillforceRedistolistenonlyinto#theIPv4lookbackinterfaceaddress(thismeansRediswillbeableto#acceptconnectionsonlyfromclientsrunningintothesamecomputerit#isrunning).##IFYOUARESUREYOUWANTYOURINSTANCETOLISTENTOALLTHEINTERFACES#JUSTCOMMENTTHEFOLLOWINGLINE.#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~bind127.0.0.1

使redis可以远程访问只要注释掉redis.conf配置文件中的 bind 127.0.0.1 即可以使所有的ip访问redis

若是想指定多个ip访问,但并不是全部的ip访问,可以bind多个IP

注意

在redis3.2之后,redis增加了protected-mode,在这个模式下,即使注释掉了bind 127.0.0.1,再访问redisd时候还是报错,如下

(error)DENIEDRedisisrunninginprotectedmodebecauseprotectedmodeisenabled,nobindaddresswasspecified,noauthenticationpasswordisrequestedtoclients.Inthismodeconnectionsareonlyacceptedfromtheloopbackinterface.IfyouwanttoconnectfromexternalcomputerstoRedisyoumayadoptoneofthefollowingsolutions:1)Justdisableprotectedmodesendingthecommand'CONFIGSETprotected-modeno'fromtheloopbackinterfacebyconnectingtoRedisfromthesamehosttheserverisrunning,howeverMAKESURERedisisnotpubliclyaccessiblefrominternetifyoudoso.UseCONFIGREWRITEtomakethischangepermanent.2)AlternativelyyoucanjustdisabletheprotectedmodebyeditingtheRedisconfigurationfile,andsettingtheprotectedmodeoptionto'no',andthenrestartingtheserver.3)Ifyoustartedtheservermanuallyjustfortesting,restartitwiththe'--protected-modeno'option.4)Setupabindaddressoranauthenticationpassword.NOTE:Youonlyneedtodooneoftheabovethingsinorderfortheservertostartacceptingconnectionsfromtheoutside.

解决方法是修改原protected-mode yes为protected-mode no

保存配置文件重启redis即可

感谢你能够认真阅读完这篇文章,希望小编分享的“Redis3.2如何开启远程访问”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!