CentOS 7 下 MongoDB 分片副本集群日志切割测试

CentOS 7 下 MongoDB 分片副本集群日志切割测试

文章目录

  • CentOS 7 下 MongoDB 分片副本集群日志切割测试
      • 测试说明
      • 环境搭建
      • 测试方案
          • 处理 config 服务日志
          • 处理 shard 服务日志
          • 处理 mongos 服务日志
      • 测试结果
      • 参考

测试说明

# 操作系统
- CentOS 7.9 2009

# MongoDB 版本
- v3.4.24

# 测试方法
- kill -SIGUSR1 ${port}

# 测试服务
- mongodb config
- mongodb shard
- mongodb mongos

环境搭建

10.10.200.205 10.10.200.206 10.10.200.207
config config config
shard1 shard1 shard1
shard2 shard2 shard2
shard3 shard3 shard3
mongos mongos mongos

测试方案

处理 config 服务日志
  • 查看 config 服务日志
[root@node2 log]# tail -2 config.log 
2023-01-16T10:17:44.205+0800 I NETWORK  [conn913] received client metadata from 10.10.200.207:36786 conn913: { driver: { name: "NetworkInterfaceASIO-RS", version: "3.4.24" }, os: { type: "Linux", name: "CentOS Linux release 7.9.2009 (Core)", architecture: "x86_64", version: "Kernel 3.10.0-1160.el7.x86_64" } }
2023-01-16T10:19:01.287+0800 I -        [conn913] end connection 10.10.200.207:36786 (27 connections now open)
  • 查看 config 服务 pid
[root@node2 log]# cat configsrv.pid 
16072
  • 执行 kill 命令
[root@node2 log]# kill -SIGUSR1 16072
  • 验证执行结果
# 查看 config.log 日志 -- 日志重新写入
[root@node2 log]# cat config.log
2023-01-16T10:20:04.486+0800 I CONTROL  [signalProcessingThread] pid=16072 port=21000 64-bit host=node2
2023-01-16T10:20:04.486+0800 I CONTROL  [signalProcessingThread] Replica Set Config: { _id: "config", version: 1, configsvr: true, protocolVersion: 1, members: [ { _id: 0, host: "10.10.200.205:21000", arbiterOnly: false, buildIndexes: true, hidden: false, priority: 1.0, tags: {}, slaveDelay: 0, votes: 1 }, { _id: 1, host: "10.10.200.206:21000", arbiterOnly: false, buildIndexes: true, hidden: false, priority: 1.0, tags: {}, slaveDelay: 0, votes: 1 }, { _id: 2, host: "10.10.200.207:21000", arbiterOnly: false, buildIndexes: true, hidden: false, priority: 1.0, tags: {}, slaveDelay: 0, votes: 1 } ], settings: { chainingAllowed: true, heartbeatIntervalMillis: 2000, heartbeatTimeoutSecs: 10, electionTimeoutMillis: 10000, catchUpTimeoutMillis: 60000, getLastErrorModes: {}, getLastErrorDefaults: { w: 1, wtimeout: 0 }, replicaSetId: ObjectId('63bce0291c862cccdb2cedbc') } }
2023-01-16T10:20:04.486+0800 I CONTROL  [signalProcessingThread] Replica Set Member State: PRIMARY
2023-01-16T10:20:04.486+0800 I CONTROL  [signalProcessingThread] db version v3.4.24
2023-01-16T10:20:04.486+0800 I CONTROL  [signalProcessingThread] git version: 865b4f6a96d0f5425e39a18337105f33e8db504d
2023-01-16T10:20:04.486+0800 I CONTROL  [signalProcessingThread] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2023-01-16T10:20:04.486+0800 I CONTROL  [signalProcessingThread] allocator: tcmalloc
2023-01-16T10:20:04.486+0800 I CONTROL  [signalProcessingThread] modules: none
2023-01-16T10:20:04.486+0800 I CONTROL  [signalProcessingThread] build environment:
2023-01-16T10:20:04.486+0800 I CONTROL  [signalProcessingThread]     distmod: rhel70
2023-01-16T10:20:04.486+0800 I CONTROL  [signalProcessingThread]     distarch: x86_64
2023-01-16T10:20:04.486+0800 I CONTROL  [signalProcessingThread]     target_arch: x86_64
2023-01-16T10:20:04.486+0800 I CONTROL  [signalProcessingThread] options: { config: "/usr/local/mongodb/conf/config.conf", net: { bindIp: "0.0.0.0", port: 21000 }, processManagement: { fork: true, pidFilePath: "/usr/local/mongodb/data/config/log/configsrv.pid" }, replication: { replSetName: "config" }, sharding: { clusterRole: "configsvr" }, storage: { dbPath: "/usr/local/mongodb/data/config/data", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/usr/local/mongodb/data/config/log/config.log" } }
# 日志文件查看
  # 生成新 config.log
  # 备份生成 config.log.xxxx-xx-xx 
[root@node2 log]# ll
total 16
-rw-r--r--. 1 root root 2882 Jan 16 10:20 config.log
-rw-r--r--. 1 root root 7468 Jan 16 10:20 config.log.2023-01-16T02-20-04
-rw-r--r--. 1 root root    6 Jan 10 11:46 configsrv.pid
处理 shard 服务日志
  • 查看 shard 服务 pid
[root@node2 log]# cat shard1.pid 
16226
  • 执行 kill 命令
[root@node2 log]# kill -SIGUSR1 16226
  • 验证执行结果
[root@node2 log]# ll
total 36
-rw-r--r--. 1 root root  2478 Jan 16 10:22 shard1.log
-rw-r--r--. 1 root root 28448 Jan 16 10:22 shard1.log.2023-01-16T02-22-46
-rw-r--r--. 1 root root     6 Jan 10 11:53 shard1.pid
处理 mongos 服务日志
  • 查看 shard 服务 pid
[root@node2 log]# cat mongos.pid 
22730
  • 执行 kill 命令
[root@node2 log]# kill -SIGUSR1 22730
  • 验证执行结果
[root@node2 log]# ll
total 16
drwxr-xr-x. 2 root root   71 Jan 16 10:24 mongos.diagnostic.data
-rw-r--r--. 1 root root 1393 Jan 16 10:24 mongos.log
-rw-r--r--. 1 root root 7268 Jan 16 10:24 mongos.log.2023-01-16T02-24-21
-rw-r--r--. 1 root root    6 Jan 16 09:43 mongos.pid

测试结果

使用方法 是否影响服务 是否影响日志写入 是否方便简洁 是否可自动化
kill sigusr pid 否(连接未断) 否(备份、轮转) 是(一条命令) 是(计划任务)

参考

  • MongoDB – Forcing a Log Rotation with SIGUSR1

你可能感兴趣的:(服务器配置,MongoDB,mongodb,centos)