本文主要記錄在船新的CentOS 8中安裝配置.NET Core運行環境以及配合使用的Redis,Redis的安裝配置相對比較簡單,綜合了網上的教程進行實踐,並最終完成配置正常使用。廢話不多說,開始!
一、安裝Redis
1、安裝
yum install redis
2、查詢本次安裝的版本(主要用於查看Redis所有文件位置)
rpm -qa|grep redis
結果:redis-5.0.3-1.module_el8.0.0+6+ab019c03.x86_64
3、查詢安裝位置
rpm -ql redis-5.0.3-1.module_el8.0.0+6+ab019c03.x86_64
4、開啟Redis Server
cd /usr/bin
redis-server
至此,Redis Server已經可以啟動了!
5、客戶端連接 Redis Server
開啟一個新的Linux連接窗口。此處為連接本地的Redis,故無需帶上ip以及端口參數
cd /usr/bin
redis-cli
本地客戶端連接也是正常的!
二、遠程連接Redis
1、配置
完成以上步驟,僅僅是在本地連接上能夠使用,一旦使用外部調用,則無法使用。此處外部設備操作系統為win10,其他的根據自身情況度娘設置。其次,在外部連接之前,先配置阿里雲ESC 安全組配置,添加Redis端口安全組,默認端口為6379
問題①:在不進行配置的情況下,直接連接遠程端Redis Server會報如下錯誤:
(error) DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified,
no authentication password is requested to clients. In this mode connections are only accepted from the loopback
interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1)
Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by
connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible
from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable
the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then
restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode
no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things
in order for the server to start accepting connections from the outside.
此處大致意思為:配置中 protected-mode屬性為yes,即當前處於保護模式下,無法連接。我們需要設置其為no
問題②:無法操作遠程Redis,進行Redis操作報錯:
Error: 在驅動器 %1 上插入軟盤。
此處問題進行密碼設置即可。
以上問題的解決方法
在本地客戶端連接情況下,進行如下操作:
a、打開Redis配置文件Redis.conf
cd /etc
vim redis.conf
按下鍵盤i進入編輯模式
找到如下參數,並修改:
針對問題①的修改:
bind 127.0.0.1 //行數:69 =》修改為#bind 127.0.0.1
protected-mode yes //行數:89 =》修改為protected-mode no
daemonize yes //行數:137 =》修改為daemonize no //設置為no則不作為后台運行,否則后台運行
針對問題②的修改:
# requirepass foobared //行數:508 =》在508行下添加與行,內容為requirepass code6076..
b、保存配置文件並退出
按下鍵盤esc退出編輯模式,然后按shift + : 鍵,再錄入wq,回車即可。
c、重新啟動Redis Server
redis-server /etc/redis.conf
此處進行Redis服務器啟動並指定配置文件,以應用我們改的配置。
注:如果上面設置daemonize參數
為no時,回車后,效果如下:(為空白,實則已經非后台執行,當前控制台已被占用)
為yes時:回車后,效果如下:(后台執行,可繼續操作)
2、連接
以Windows 10 為例,連接方式如下:
D:\WorkSpace\Redis\redis-cli -h x.x.x.x -p 6379 -a code6076..
3、設置開機自啟
啟動服務
systemctl start redis
如果開啟服務出現任何輸出,則需要根據提示,根據日志進行配置,我就遇到了redis日志權限不足。有類似情況使用如下命令: chown redis:redis /var/log/redis/redis.log
報錯如下圖:
設置自啟
systemctl enable redis
然后重啟服務器
reboot
重啟完成后,查看狀態:
systemctl stutas redis
大功告成!