redis 遠端 訪問 安全配置

2022-03-06 05:24:00 字數 1948 閱讀 1431

朋友總結很好,就**了-> 站長部落格

假設兩台redis伺服器,ip分別為:192.168.1.101和192.168.1.103,如果在101上通過redis-cli訪問103上的redis呢?

在遠端連線103直線,先講下redis-cli的幾個關鍵引數:

用法:redis-cli [options] [cmd [arg [arg ...]]]

-h 《主機ip>,預設是127.0.0.1

-p 《埠》,預設是6379

-a 《密碼》,如果redis加鎖,需要傳遞密碼

--help,顯示幫助資訊

通過對rendis-cli用法介紹,在101上連線103應該很簡單:

[root@xsf001 ~]# redis-cli -h 192.168.1.103 -p 6379  

redis 192.168.1.103:6379>   

在101上對103設定個個string值 user.1.name=zhangsan

redis 192.168.1.103:6379> set user.1.name zhangsan  

ok  

看到ok,表明設定成功了。然後直接在103上登陸,看能不能獲取到這個值。

[root@xsf003 utils]# redis-cli   

redis 127.0.0.1:6379> get user.1.name  

"zhangsan"  

木錯吧,確實是zhangsan,這說明101上連的是103上的redis伺服器。當然能夠成功連線103是有基本條件的,101上可以喝103上的6379埠通訊。

人人都可以連線redis伺服器是很危險的,我們需要給103上的redis設定個密碼,怎麼設定呢,需要編輯redis的配置檔案/etc/redis/6379.conf

[root@xsf003 utils]# vim /etc/redis/6379.conf   

找到# requirepass foobared 去掉前面的注釋#,並把foobared 替換為你自己的密碼:hi, coder

requirepass "hi, coder"  

儲存配置檔案之後,重啟redis服務

[root@xsf003 utils]# /etc/init.d/redis_6379 stop  

stopping ...  

waiting for redis to shutdown ...  

redis stopped  

[root@xsf003 utils]# /etc/init.d/redis_6379 start  

starting redis server...  

101上重新連線103並獲取user.1.name的值

[root@xsf001 ~]# redis-cli -h 192.168.1.103 -p 6379  

redis 192.168.1.103:6379> get user.1.name  

(error) err operation not permitted  

redis 192.168.1.103:6379>   

為什麼是error呢,當然是因為連線103時沒傳遞密碼了,退出重新連

redis 192.168.1.103:6379> quit  

[root@xsf001 ~]# redis-cli -h 192.168.1.103 -p 6379 -a "hi, coder"  

redis 192.168.1.103:6379> get user.1.name  

"zhangsan"  

看到zhangsan,說明你已經連線成功了。

遠端訪問安全 SSH

ssh安全與配置 secure shell ssh 的目的在於在通過網路遠端訪問另乙個主機時提供最大的保護。它通過提供更好的身份驗證工具和secure copy scp secure file transfer protocal sftp x會話 和埠 等功能來加密網路交換,從而增加其他非安全協議的...

Redis遠端訪問配置修改

若遠端主機需要訪問redis伺服器,可以修改redis.conf配置檔案 bind欄位預設為 bind 127.0.0.1 這樣只能本機訪問redis 若允許遠端主機訪問,可注釋掉bind行 或者 將bind 127.0.0.1改為 bind 0.0.0.0 開放埠 6379 編輯防火強配置檔案 v...

Redis遠端訪問

1.redis繫結的主機位址是本地 需要進入配置檔案進行修改 root vm 0 16 centos vim usr local redis redis.conf 注釋掉bind 127.0 0.1 bind 127.0.0.1 或者 bind 0.0.0.0 更改protected mode ye...