Yum安裝Redis及設定遠端通過密碼通路
一、安裝redis
[[email protected] ~]# yum install redis -y
......
二、修改配置檔案
1、查找配置檔案
[[email protected] ~]# whereis redis.config
redis: /etc/redis.conf
補充:一般配置檔案在/etc/目錄下
2、處理配置檔案
(1)做好備份
[[email protected] ~]# cp /etc/redis.conf /etc/redis.conf_bak
(2)去除注釋行和空行
[[email protected] ~]# cat /etc/redis.conf_bak | grep -v "#" | grep -v ^$ > /etc/redis.conf
[[email protected] ~]# cat /etc/redis.conf
補充:
cat /etc/redis.conf_bak | grep -v "#" | grep -v ^$ > /etc/redis.conf
第一步grep -v "#":去除#行(-v表示反選)
第二步grep -v ^$:去除空行
第三部> /etc/redis.conf:将處理好的内容覆寫寫入/etc/redis.conf
3、開啟遠端和設定密碼
(1)開啟遠端通路
#開啟遠端通路
#bind 127.0.0.1
#關閉保護
protected-mode no
(2) 設定密碼
預設此行是被注釋了,是以要開啟密碼要自己将此行插入。
requirepass yourpasswd
3、 開啟redis服務
1、安裝redis服務會給預設建立redis使用者(預設是nologin)
2、 修改配置檔案權限
(1) 修改redis.conf所屬使用者及所屬組
[[email protected] /]# chown redis:redis /etc/redis.conf
(2) 給予redis.conf所屬使用者及組x(執行)權限
[[email protected] /]# chmod u+x,g+x /etc/redis.conf
(3) 開啟服務并設定開機自啟動
這裡我直接使用root使用者開啟的,大家可以自行切換到redis使用者操作
[[email protected] ~]# systemctl start redis
[[email protected] ~]# systemctl enable redis
[[email protected] ~]# systemctl status redis
4、 測試遠端使用密碼連接配接
netstat -ntpl
下圖可以看到端口已經開啟(大家測試時可以先将防火牆關閉,如果是阿裡雲伺服器請配置安全規則)
使用用戶端工具連接配接
總結:
其實yum安裝redis很簡單,但是本篇寫的很備援,或者說廢話很多。
這裡隻是想寫的詳細一點,望諸位見諒。
最後,感謝大家支援。