博文背景:
由於發現眾多同學,在使用雲服務器時,安裝的redis3.0+版本都關閉了protected-mode,因而都遭遇了挖礦病毒的攻擊,使得服務器99%的占用率!!
因此我們在使用redis時候,最好更改默認端口,並且使用redis密碼登錄。
(1)redis沒有用戶概念,redis只有密碼
(2)redis默認在工作在保護模式下。不允許遠程任何用戶登錄的(protected-mode)
redis.conf設置
protected-mode yes #打開保護模式 port 6380 #更改默認啟動端口 requirepass xxxxxx #設置redis啟動密碼,xxxx是自定義的密碼
啟動redis服務端
redis-server /opt/redis-4.0.10/redis.conf & #指定配置文件啟動redis,且后台啟動
使用密碼登錄redis,使用6380端口
方法1,使用這個
[root@oldboy_python ~ 09:48:41]#redis-cli -p 6380 127.0.0.1:6380> auth xxxx OK
方法2,此方案不安全,容易暴露密碼
[root@oldboy_python ~ 09:49:46]#redis-cli -p 6380 -a xxxx Warning: Using a password with '-a' option on the command line interface may not be safe. 127.0.0.1:6380> ping PONG
補充
檢查redis是否設置了密碼
127.0.0.1:6380> CONFIG get requirepass
1) "requirepass"
2) "xxxxxx"
如果沒有,也可以給redis設置密碼(命令方式)
CONFIG set requirepass "xxxxxx"
因此你的redis就不容易被黑客入侵了。
我的博客即將搬運同步至騰訊雲+社區,邀請大家一同入駐:https://cloud.tencent.com/developer/support-plan?invite_code=1a36zff5cc86l