redis server management (redis server papers)

Server Management

Commands and Tools

Check the connection is normal

PING
sends a PING Redis server to use the client, if the connection between the client and the server properly, and also the normal operation of the server, then the command returns a PONG.
Is generally used to test network connectivity and status of the server, or for measuring the retardation values.

 redis> PING
 PONG
 redis> PING
 Could not connect to Redis at 127.0.0.1:6379: Connection refused
Viewing Server Information

INFO [section]
to view a variety of information and Redis server statistic. Optional section by a given parameter, you can specify the information content of the command to return.

 redis> INFO
 # Server
 redis_version:2.9.11
 redis_git_sha1:937384d0
 redis_git_dirty:0
 redis_build_id:8e9509442863f22
 redis_mode:standalone
 ..........
SECTION parameter value (1/2)

Here Insert Picture Description

SECTION parameter value (2/2)

Here Insert Picture Description

Command to view the server being executed

MONITOR
real time to print out the received command Redis server, the format of "timestamp [Database IP address and port number] command is executed."

 redis> MONITOR
 OK
 1378822099.421623 [0 127.0.0.1:56604] "PING"
 1378822105.089572 [0 127.0.0.1:56604] "SET" "msg" "hello world"
 1378822109.036925 [0 127.0.0.1:56604] "SET" "number" "123"
 1378822140.649496 [0 127.0.0.1:56604] "SADD" "fruits" "Apple" "Banana" "Cherry"
 1378822154.117160 [0 127.0.0.1:56604] "EXPIRE" "msg" "10086"
 1378822257.329412 [0 127.0.0.1:56604] "KEYS" "*"
 1378822258.690131 [0 127.0.0.1:56604] "DBSIZE"
Find command slow

Slow queries

Record slow query log

Redis slow query function for a long execution time exceeds the specified command record it and show the user that commands are recorded, to facilitate users find slow to run the command, and targeted optimization.

Slow query function can be set by the following two configuration options:
slowlog-log-It would help-Within last
longer than microseconds microseconds command is recorded, the negative value indicates the set off slow query execution function.
The default value is 10000, that is, 1/100 seconds, 1 second = 1 million because microsecond.
slowlog-max-len
slow query log the maximum number of log records when more than this number, the new log will overwrite the old log (FIFO).
The default value is 128.

View slow query log

SLOWLOG GET [number]
返回服务器目前记录的慢查询日志。
如果给定可选的 number 参数,那么只返回最多 number 条日志;否则的话,返回所有慢查询日志。

# 为测试需要,将 slowlog-log-slower-than 设成了 10 微秒
 redis> SLOWLOG GET
 1) 1) (integer) 12 # 唯一的日志标识符
 2) (integer) 1324097834 # 被记录命令的执行时间,以 UNIX 时间戳格式表示
 3) (integer) 16 # 命令执行耗费的时长,以微秒为单位
 4) 1) "CONFIG" # 被执行的命令,以数组的形式排列
 2) "GET" # 这里完整的命令是 CONFIG GET slowlog-log-slower-than
 3) "slowlog-log-slower-than"
慢查询日志的其他命令

Here Insert Picture Description

redis> SLOWLOG LEN
 (integer) 14
 redis> SLOWLOG RESET
 OK
 redis> SLOWLOG LEN
 (integer) 0
服务器的加锁与解锁

通过配置选项 requirepass ,用户可以为服务器设置密码。当客户端连接一个带密码的服务器时,它必须执行 AUTH 命令来进行解锁,否则这个客户端就不能执行除 AUTH 以外的其他命令。

举个例子,如果我们在服务器启动时,用以下方式给服务器设置了密码:

$ redis-server --requirepass helloworld
 那么连接服务器的客户端必须在解锁之后才能执行其他命令:
 redis> PING
 (error) NOAUTH Authentication required.
 redis> AUTH helloworld
 OK
 redis> PING
 PONG
关闭服务器

SHUTDOWN [option]
在不给定 option 参数的情况下,服务器会先执行持久化操作:
• 如果打开了 AOF 持久化,那么调用 fdatasync ,确保之前执行的命令能够被写入到硬盘。
• 如果打开了 RDB 持久化并且数据库已经发生了变化,那么执行 SAVE 命令。
在以上操作都完成之后,服 务器关闭。

在打开了持久化功能的情况下,使用 SHUTDOWN 命令关闭服务器不会丢失任何数据。

option 选项的值可以是 save 或者 nosave :
• SHUTDOWN save 在关闭之前总是执行 SAVE 命令,用于在没有开启 RDB 持久化的情况下,创建一个 RDB 文件来保存数据;
• SHUTDOWN nosave 在关闭之前不执行 SAVE 命令,用于在数据库可能已经出错的情况下,避免将错误的数据保存到 RDB 文件里面。

现成的 Redis 管理工具

RedisLive、Redis-Commander 和 RedMon

RedisLive

使用 Python 编写的 Redis 实时监视工具

界面
Here Insert Picture Description
被监视的服务器地址和端口号。
内存占用、键的数量、客户端数量、
已执行命令数量、上线时间。
内存占用情况。
命令执行情况。
最常执行的命令。
最常被处理的键。
更多信息
安装方法和使用说明: http://www.nkrode.com/article/real-time-dashboard-for-redis

Redis Commander

Node.js 编写的 Redis 管理工具

界面
Here Insert Picture Description
查看服务器已有的键
Here Insert Picture Description
添加键功能
Here Insert Picture Description
目前只支持添加字符串、列表、集合和有序集合,不支持添加散列和 HyperLogLog 。

执行命令
Here Insert Picture Description
嵌入式文档
Here Insert Picture Description
更多信息
安装和使用简介: http://joeferner.github.io/redis-commander/
启动之后访问 http://localhost:8081/ 就可以看见界面。

Redmon

Ruby 编写的 Redis 管理工具

界面
Here Insert Picture Description
命令行
Here Insert Picture Description
查看和设置配置选项
Here Insert Picture Description

现有工具的缺点

不够强大 不够稳定
目前还没有强大并且稳定的工具被开源出来。
重度使用 Redis 的公司一般都会自己构建管理工具。

复习

服务器管理命令

PING - Check the network connection and whether the server is working properly.
INFO - View current server status information and statistics.
MONITOR - command to view the server being executed.
SLOWLOG - Record and view the chief executive of time exceeds the specified command.
requirepass option lock server, using the AUTH command to unlock.
SHUTDOWN - Turn off the server.

There is no strong and stable open source Redis management software, the need arises to make their own writing.

Published 252 original articles · won praise 151 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_39885372/article/details/104281589