阿里云服務(wù)器Redis配置文件允許公網(wǎng)訪問

1. 想開多少個redis實例,就現(xiàn)在ECS的安全組配置入方向打開端口訪問限制:

image.png

2. redis配置文件推薦命名法:

redis.conf
redis-6370.conf
redis-6371.conf
redis-7372.conf

3. 編輯配置文件,設(shè)置連接密碼:

requirepass: redis-6371-password

4. 注釋登陸機器IP限制,允許所有IP訪問:

# bing 127.0.0.1

5. 關(guān)閉Redis3.2新增保護模式:

protected-mode no

6. 設(shè)置為守護進程方式啟動,更改日志文件位置/名字:

daemonize yes

logfile /var/log/redis/redis-6371.log

7. 服務(wù)端啟動/關(guān)閉Redis服務(wù)

redis-server /etc/redis-6371.conf

redis-cli -p 6371 shutdown

8. 多客戶端連接遠程Redis(失敗請查看6步驟中的日志文件)

redis-cli -h YOUR_IP -p 6371

9. 使用 info Clients 命令查看客戶端連接信息:

# Clients
connected_clients:2
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

下面是默認情況下不修改linux內(nèi)核參數(shù),遠程連接redis中常見的三個報錯,我將解釋原因并根據(jù)redis報錯提示逐個處理。注意:如果修改后遠程連接依舊和原來報錯一樣,請重啟redis服務(wù)。

可參考文章: https://blog.csdn.net/a491857321/article/details/52006376

WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

這個錯誤提示的原因是Linux中TCP連接隊列的長度需要設(shè)置大一些(redis設(shè)置的是511,但是linux內(nèi)核參數(shù)默認的是128)。解決辦法是修改/etc/sysctl.conf 文件添加 net.core.somaxconn = 1024,然后執(zhí)行 sysctl -p 生效即可。
參考地址: https://www.cnblogs.com/faunjoe88/p/7158484.html

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.

這個是因為默認centos7設(shè)置的內(nèi)存策略為0,同樣修改 /etc/sysctl.conf,添加 vm.overcommit_memory =1, 執(zhí)行 sysctl -p 生效即可。
參考地址: https://blog.csdn.net/whycold/article/details/21388455

WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

這是。執(zhí)行 echo never > /sys/kernel/mm/transparent_hugepage/enabled 可臨時解決該問題,永久解決需要在 /etc/rc.local 文件中添加一行 echo never > /sys/kernel/mm/transparent_hugepage/enabled,使每次開機自動執(zhí)行這條命令。
參考地址: https://blog.csdn.net/kk185800961/article/details/53326465

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容