赞
踩
redis版本: 6.0.16
配置数据单位换算关系
################## 该部分用于指定存储单位的大小换算关系,不区分大小写,只支持bytes,不支持bits
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
#
# units are case insensitive so 1GB 1Gb 1gB are all the same.
包含其它配置文件的信息 include path
对于公共部分配置,可以按以下方式配置引入
# include /path/to/local.conf
# include /path/to/other.conf
bind IP1 [IP2 …]
这项配置绑定的IP并不是远程访问的客户端的IP地址,而是本机的IP地址。
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
bind 127.0.0.1
本机的IP地址是和网卡(network interfaces)绑定在一起的,配置这项后,Redis只会接收来自指定网卡的数据包。比如我的主机有以下网卡:
root@VM-4-5-ubuntu:~# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.4.5 netmask 255.255.252.0 broadcast 10.0.7.255 inet6 fe80::5054:ff:fe0b:843 prefixlen 64 scopeid 0x20<link> ether 52:54:00:0b:08:43 txqueuelen 1000 (Ethernet) RX packets 283943 bytes 28027507 (28.0 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 280878 bytes 43033240 (43.0 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 35168 bytes 2582220 (2.5 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 35168 bytes 2582220 (2.5 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
如果我想要让Redis可以远程连接的话,就需要让Redis监听eht0
这块网卡,也就是要加上配置bind 127.0.0.1 10.0.4.5
,这样既可以本地访问,也能够远程访问。(主要bind
只能有一行配置,如果有多个网卡要监听,就配置多个ip
,用空格隔开,否者只有配置的最后一个bind
生效)。
保护模式 protected-mode
从注释信息就可以看到,如果protected-mode
是yes
的话,如果没有指定bind
或者没有指定密码,那么只能本地访问。
protected-mode yes
端口号 port
配置Redis监听的端口号,默认6379。
# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379
TCP半连接队列长度配置 tcp-backlog
在进行TCP/IP连接时,内核会维护两个队列
syns queue
用于保存已收到sync
但没有接收到ack
的TCP半连接请求。由/proc/sys/net/ipv4/tcp_max_syn_backlog
指定,我的系统(Ubuntu20.04)上是1024。accept queue
,用于保存已经建立的连接,也就是全连接。由/proc/sys/net/core/somaxconn
指定。根据配置里的注释,需要同时提高somaxconn
和tcp_max_syn_backlog
的值来确保生效。
tcp-backlog 511
**是否超时无操作关闭连接 timeout **
客户端经过多少时间(单位秒)没有操作就关闭连接,0代表永不关闭。
timeout 0
TCP连接保活策略 tcp-keepalive
TCP连接保活策略,可以通过tcp-keepalive配置项来进行设置,单位为秒,假如设置为60秒,则server端会每60秒向连接空闲的客户端发起一次ACK请求,以检查客户端是否已经挂掉,对于无响应的客户端则会关闭其连接。如果设置为0,则不会进行保活检测。
tcp-keepalive 300
**启动方式 daemonize **
是否以守护(后台)进程的方式启动,默认no。
daemonize yes
进程pid文件 pidfile
redis启动后会把pid写入到pidfile指定的文件中。
pidfile /var/run/redis_6379.pid
日志相关 loglevel logfile
loglevel
用于配置日志打印机别,默认notice
:
debug
:能设置的最高的日志级别,打印所有信息,包括debug信息。verbose
:打印除了debug
日志之外的所有日志。notice
:打印除了debug
和verbose
级别的所有日志。warning
:仅打印非常重要的信息。loglevel notice
logfile ""
指定数据库的数量 databse
redis默认有16个数据库,编号从0开始。
databases 16
启动是否显示logo
always-show-logo yes
################################## SECURITY ###################################
# Warning: since Redis is pretty fast, an outside user can try up to
# 1 million passwords per second against a modern box. This means that you
# should use very strong passwords, otherwise they will be very easy to break.
# Note that because the password is really a shared secret between the client
# and the server, and should not be memorized by any human, the password
# can be easily a long string from /dev/urandom or whatever, so by using a
# long and unguessable password no brute force attack will be possible.
大致意思就是redis很快,所以被破解密码时,性能也很好,如果你的密码太渣渣了,那么可能很快就被破解了,因此尽量使用长且不容易被猜到的密码作为redis的访问密码。
配置ACL
ACL
:访问控制列表。
有两种方法配置ACL:
redis.conf
中配置,也可以通过外部aclfile
配置。aclfile path
。配置语法:user <username> ... acl rules ...
,例如 user worker +@list +@connection ~jobs:* on >ffa9203c493aa99
redis默认有一个default
用户。如果default
具有nopass
规则(就是说没有配置密码),那么新连接将立即作为default
用户登录,无需通过AUTH
命令提供任何密码。否则,连接会在未验证状态下启动,并需要AUTH
验证才能开始工作。
描述用户可以做的操作的ACL规则如下:
on
启用用户,该用户可以验证身份登陆。off
禁用用户,该用户不允许验证身份登陆。+<command>
允许用户执行command
指示的命令✅-<command>
禁止用户执行command
指示的命令Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。