Redis进阶-bind参数详解
文章目錄
- redis.conf
- 驗證bind
- bind 127.0.0.1
- bind 192.168.18.130
- bind 192.168.18.130 127.0.0.1
redis.conf
Redis Version: 5.0.3
毫無疑問,看官方的配置文件的解讀 .
bind 配置的是 redis server 網(wǎng)卡的地址 ,配置哪個網(wǎng)卡地址,你就可以通過哪個網(wǎng)卡地址訪問redis ,而不是外部訪問redis的ip 列表。
可以看到,我這個主機上有兩個網(wǎng)卡,1個是回環(huán)地址 127.0.0.1 ,另外一個是 eno16777736對應(yīng)的192.168.18.130 。
所以 bind 建議配置 : 127.0.0.1 192.168.18.130
驗證bind
bind 127.0.0.1
假設(shè)我們使用默認(rèn)的配置文件,即bind 127.0.0.1 .
啟動redis后 , 在redis server本機上訪問 redis server
[redis@artisan bin]$ ./redis-cli 127.0.0.1:6379> 127.0.0.1:6379> set artisanK artisanV OK 127.0.0.1:6379>redis server 本機客戶端 可以連接操作 。
我們嘗試使用代碼或者RedisDesktopManager訪問下 192.168.18.130
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.18.130:6379] with root cause外部通過 192.168.18.130 無法訪問,因為你配置了bind 127.0.0.1 這個回環(huán)網(wǎng)卡地址,redis server 只接收這個網(wǎng)卡過來的連接。
bind 192.168.18.130
外部通過 192.168.18.130 可以訪問,因為你配置了bind 192.168.18.130,redis server 只接收這個網(wǎng)卡過來的連接。
redis server 本機
停止redis 服務(wù)也要通過 -h 指定ip
那怎么訪問呢? 通過 -h 指定ip
本機訪問redis 居然不行。。。因為你配置了bind 192.168.18.130,redis server 只接收這個網(wǎng)卡過來的連接,沒有配置 127.0.0.1 這個網(wǎng)絡(luò)地址,redis server 自然不會接收這個回環(huán)地址發(fā)送過來的連接請求。
bind 192.168.18.130 127.0.0.1
[redis@artisan bin]$ ./redis-cli 127.0.0.1:6379> set artisanKey artisanValue OK 127.0.0.1:6379> get artisanKey "artisanValue" 127.0.0.1:6379> 127.0.0.1:6379>外部通過 192.168.18.130 可以訪問,本機通過127.0.0.1 可以訪問。 因為你配置了bind 127.0.0.1 192.168.18.130,redis server 只接收192.168.18.130 27.0.0.1 這兩個網(wǎng)卡過來的連接。
總結(jié)
以上是生活随笔為你收集整理的Redis进阶-bind参数详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Redis进阶-Redis使用建议一二事
- 下一篇: Redis进阶-如何发现和优雅的处理Bi