方法1: SAVE 命令是“壅闭式”生存,Redis 不会创建子历程,而是直接由主历程把内存数据写到 RDB 文件里。
[root@Rocky9.4 redis]#( redis-cli
-a 123456 save & );pstree -p | grep redis-server;ls /apps/redis/data/ -lhWarning: Using a password with '-a' or '-u' option on the command line interface may not be safe. |-redis-server(28847)-+-{redis-server}(28854) | |-{redis-server}(28855) | |-{redis-server}(28856) | |-{redis-server}(28857) | `-{redis-server}(28858)total 180M-rw-r--r-- 1 redis redis 180M Dec 23 18:48 dump_6379.rdb-rw-r--r-- 1 redis redis 48K Dec 23 21:45 temp-28847.rdb
-a 123456Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.127.0.0.1:6379> bgsaveBackground saving started127.0.0.1:6379># 生产临时文件,fork 子历程 pid是920,从temp-920.rdb也可以看出是历程920在备份[root@Rocky9.4 data]#pstree -p | grep redis-server;ls /apps/redis/data/ -lh |-redis-server(638)-+-redis-server(920) | |-{redis-server}(666) | |-{redis-server}(667) | |-{redis-server}(668) | |-{redis-server}(669) | `-{redis-server}(671)total 128M-rw-r--r-- 1 redis redis 67M Dec 24 14:43 temp-920.rdb# 备份竣事以后,将文件重命名[root@Rocky9.4 data]#pstree -p | grep redis-server;ls /apps/redis/data/ -lh |-redis-server(638)-+-{redis-server}(666) | |-{redis-server}(667) | |-{redis-server}(668) | |-{redis-server}(669) | `-{redis-server}(671)total 180M-rw-r--r-- 1 redis redis 180M Dec 24 14:43 dump_6379.rdb# 也可以查察日志[root@Rocky9.4 data]#tail -f ../log/redis-6379.log# bgsave的日志,会显示出具体的子历程编号638:M 24 Dec 2024 15:15:14.746 * Background saving started by pid 10371037:C 24 Dec 2024 15:15:22.016 * DB saved on disk1037:C 24 Dec 2024 15:15:22.026 * Fork CoW for RDB: current 0 MB, peak 0 MB, average 0 MB638:M 24 Dec 2024 15:15:22.095 * Background saving terminated with success# save的日志638:M 24 Dec 2024 15:20:09.364 * DB saved on disk
on 或 off:启用或禁用用户。
>password:设置用户的密码,可以有多个密码。
~pattern:指定用户可以访问的键的模式(可选)。
+permissions 和 -permissions:授予或打消用户的权限,可以利用命令类别或具体命令。
# 假设您希望创建一个名为 alice 的用户,设置密码为 123456,而且授予她所有权限但禁用 FLUSHALL 命令。可以按照以下方式配置:[root@Rocky9.4 etc]#vim redis_6379.confuser alice on >123456 ~* +@all -FLUSHALL -FLUSHDBuser default on >123456 ~* +@all +get +set -FLUSHALL -FLUSHDB -keys -config# 重启服务systemctl restart redis# 连接到Redis[root@Rocky9.4 etc]#redis-cli
-u redis://alice:123456@127.0.0.1:6379Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.127.0.0.1:6379> FLUSHALL(error) NOPERM User alice has no permissions to run the 'flushall' command127.0.0.1:6379> exit