解決redis連接數,最大連接數和NOAUTH Authentication問題

連接數與最大連接數

1、Redis (error) NOAUTH Authentication required.解決方法

127.0.0.1:6379> auth "yourpassword"

修改redis參數時:

> redis-cli

> auth "password"

2、連接redis數據庫時突然報錯:MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.

究其原因是因爲強制把redis快照關閉了導致不能持久化的問題,在網上查了一些相關解決方案,

通過stop-writes-on-bgsave-error值設置爲no即可避免這種問題。

有兩種修改方法,一種是通過redis命令行修改,另一種是直接修改redis.conf配置文件

命令行修改方式示例:

127.0.0.1:6379> config set stop-writes-on-bgsave-error no

查看:

方法1:在redis-cli命令行使用:info clients可以查看當前的redis連接數

127.0.0.1:6379> info clients
#Clients
connected_clients:621
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
127.0.0.1:6379>

方法2:config get maxclients 可以查詢redis允許的最大連接數

127.0.0.1:6379> CONFIG GET maxclients
    ##1) "maxclients"
    ##2) "10000"
127.0.0.1:6379>

設置:

1. 在2.6之後版本,可以修改最大連接數配置,默認10000,可以在redis.conf配置文件中修改

...
# maxclients 10000
...

2.config set maxclients num 可以設置redis允許的最大連接數

127.0.0.1:6379> CONFIG set maxclients 10
OK
127.0.0.1:6379>


3.啓動redis.service服務時加參數--maxclients 100000來設置最大連接數限制

redis-server --maxclients 100000 -f /etc/redis.conf

獲取客戶端信息命令

CLIENT LIST 獲取客戶端列表

CLIENT SETNAME 設置當前連接點redis的名稱

CLIENT GETNAME 查看當前連接的名稱

CLIENT KILL ip:port 殺死指定連接

CLIENT LIST
    ##id=3 addr=127.0.0.1:36588 fd=5 name= age=7 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client
CLIENT SETNAME js
    ##OK
CLIENT LIST
    ##id=3 addr=127.0.0.1:36588 fd=5 name=js age=37 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client
CLIENT GETNAME
    ##"js"
CLIENT KILL id 3
    ##(integer) 0

釋放超時鏈接配置

查看超時配置
config get timeout

設置超時配置
config set timeout 600
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章