linux里安裝redis以及redis的安全設置


發表此篇文章是由於redis有一個小白式錯誤:redis默認匿名訪問,導致redis安全性堪憂。下面從redis安裝說起:

安裝Redis: 請參考這兒;https://redis.io/download

[plain]  view plain  copy
  1. <span style="font-family:Verdana;font-size:12px;color:#666666;">$ wget http://download.redis.io/releases/redis-3.2.7.tar.gz  
  2. $ tar xzf redis-3.2.7.tar.gz  
  3. $ cd redis-3.2.7  
  4. $ make  
  5.    
  6. $ src/redis-server</span>  

ps :如果以上有報錯,可能是你的服務器沒有安裝依賴:

CentOS7:

[plain]  view plain  copy
  1. yum install -y gcc-c++ tcl  

安裝完成后

在目錄 redis-3.2.7中有一個redis.conf的配置文件,按照默認習慣我們將其復制到/etc目錄下:

[plain]  view plain  copy
  1. [root@MyCloudServer ~]# cp redis-3.2.7/redis.conf /etc  

PS:請使用復制(cp)而不要使用移動(mv);畢竟你要弄錯了還可以再拷貝一份兒過去用不是?

使用vim編輯剛剛拷貝的redis.conf

[plain]  view plain  copy
  1. vim /etc/redis.conf  

PS:使用vim需要先安裝:

CentOS7:

[plain]  view plain  copy
  1. yum  install vim  

我們需要注意以下幾項:

1.注釋掉47行的bind 127.0.0.1(這個意思是限制為只能 127.0.0.1 也就是本機登錄)PS:個人更建議 將你需要連接Redis數據庫的IP地址填寫在此處,而不是注釋掉。這樣做會比直接注釋掉更加安全。

2.更改第84行port  6379 為你需要的端口號(這是Redis的默認監聽端口)PS:個人建議務必更改

3.更改第128行 daemonize no 為 daemonize yes(這是讓Redis后台運行) PS:個人建議更改

4.取消第 480  # requirepass foobared 的#注釋符(這是redis的訪問密碼) 並更改foobared為你需要的密碼 比如 我需們需要密碼為123456 則改為  requirepass 123456。PS:密碼不可過長否則Python的redis客戶端無法連接

以上配置文件更改完畢,需要在防火牆放行:

[plain]  view plain  copy
  1. firewall-cmd --zone=public --add-port=xxxx/tcp --permanent  

請將xxxx更改為你自己的redis端口。

重啟防火牆生效:

[plain]  view plain  copy
  1. systemctl restart firewalld.service  
指定配置文件啟動redis:
[plain]  view plain  copy
  1. [root@MyCloudServer ~]# redis-3.2.7/src/redis-server /etc/redis.conf   
加入到開機啟動:
[plain]  view plain  copy
  1. echo "/root/redis-3.2.6/src/redis-server /etc/redis.conf" >> /etc/rc.local  

一個較為安全的redis配置完畢。

redis的桌面客戶端我推薦:RedisDesktopManager

去下面這個地址下載:https://github.com/uglide/RedisDesktopManager/releases


免責聲明!

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



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