如何使redis允许远程访问
小编给大家分享一下如何使redis允许远程访问,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
导语:
我们都知道redis默认只允许本地访问,那么我们如果要使redis可以远程访问该如何做呢?
具体方法:
打开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
解决办法:注释掉bind 127.0.0.1可以使所有的ip访问redis
若是想指定多个ip访问,但并不是全部的ip访问,可以bind
注意
下面还有个说明
#Protectedmodeisalayerofsecurityprotection,inordertoavoidthat#Redisinstancesleftopenontheinternetareaccessedandexploited.##Whenprotectedmodeisonandif:##1)Theserverisnotbindingexplicitlytoasetofaddressesusingthe#"bind"directive.#2)Nopasswordisconfigured.##Theserveronlyacceptsconnectionsfromclientsconnectingfromthe#IPv4andIPv6loopbackaddresses127.0.0.1and::1,andfromUnixdomain#sockets.##Bydefaultprotectedmodeisenabled.Youshoulddisableitonlyif#youaresureyouwantclientsfromotherhoststoconnecttoRedis#evenifnoauthenticationisconfigured,noraspecificsetofinterfaces#areexplicitlylistedusingthe"bind"directive.protected-modeyes
在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.
以上是“如何使redis允许远程访问”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。