連redis 連不上怎么辦!


網上很多,你應該已經查了一溜夠了!我這里只強調config 配置文件!

而配置里,兩個配置起決定性作用,bind屬性和protected-mode屬性(protected-mode有沒有是要看版本,老版本沒有的)。我為什么把注釋都放進來呢,因為人家已經寫得很清楚了,好好看!

 

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1
# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode yes

如果鏈接不上,我看很多都讓把 protected-mode 修改為 no  並且 將 bind屬性注釋掉 (老版本只注釋掉bind),但是,這樣,不就誰都可以鏈接redis數據庫了?那就不安全了啊

所以,protected-mode屬性根本不用改,bind屬性不要注釋,只需要在bind 后添加你想要鏈接此數據庫的地址就好了 如:

bind 192.168.1.100 10.0.0.1 就代表192.168.1.100和10.0.0.1是可以鏈接到數據庫的,人家寫的很清楚了!而且這也是安全並被推薦使用的!

下面說一下windows 下啟動redis服務的問題!

如下圖,是windows安裝完的文件

 

通常,我們會雙擊redis-server.exe啟動服務,但是默認服務使用的並不是這里的conf配置文件,如圖:

這個/path/to/redis.conf才是redis-server.exe啟動時指定的redis.conf配置,理論上我們修改這個redis.conf里的屬性,重新啟動服務也行,然而,我並沒找到這個redis.conf

所以我修改了redis.windows-service.conf 配置(當然你可以修改redis.windows.conf我認為也沒問題),並指定修改好的配置文件 如:

這時候再啟動redis-cli.exe 運行命令:config get * 查看一下你的conf配置就ok了

 

至於linux下,如果鏈接不上redis也是這個思路:修改下配置文件,然后指定配置文件重新啟動服務就好了!

 

關閉服務
  redis-cli -h 127.0.0.1 -p 6379 shutdown
  1.訪問redis根目錄    cd  /usr/local/redis-2.8.19
  2.登錄redis:redis-cli -h 127.0.0.1 -p 6379
  3.查看所有key值:keys *
  4.刪除指定索引的值:del key
  5.清空整個 Redis 服務器的數據:flushall
  6.清空當前庫中的所有 key:flushdb
linux下redis操作指令
查詢redis
   ps aux|grep redis
關閉redis服務
   redis-cli shutdown
指定conf啟動redis-server
   redis-server etc/redis/redis.conf

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM