cassandra nodetool常用命令介绍

简介: 简介 nodetool是cassandra自带的外围工具,通过JMX可以动态修改当前进程内存数据,注意cassandra是无主对等架构,默认的命令是操作本机当前进程,例如repair,如果需要做全集群修复,需要在每台机器上执行对应的nodetool命令。

简介

nodetool是cassandra自带的外围工具,通过JMX可以动态修改当前进程内存数据,注意cassandra是无主对等架构,默认的命令是操作本机当前进程,例如repair,如果需要做全集群修复,需要在每台机器上执行对应的nodetool命令。
执行nodetool help命令可获得详细帮助信息,如下:

[root@Cassandra8c32GTest005 cassandra]# bin/nodetool help
usage: nodetool [(-pwf <passwordFilePath> | --password-file <passwordFilePath>)]
        [(-h <host> | --host <host>)] [(-u <username> | --username <username>)]
        [(-pw <password> | --password <password>)] [(-p <port> | --port <port>)]
        <command> [<args>]

The most commonly used nodetool commands are:
    assassinate                  Forcefully remove a dead node without re-replicating any data.  Use as a last resort if you cannot removenode
    bootstrap                    Monitor/manage node's bootstrap process
    cleanup                      Triggers the immediate cleanup of keys no longer belonging to a node. By default, clean all keyspaces
    clearsnapshot                Remove the snapshot with the given name from the given keyspaces. If no snapshotName is specified we will remove all snapshots
    compact                      Force a (major) compaction on one or more tables or user-defined compaction on given SSTables
    compactionhistory            Print history of compaction
    compactionstats              Print statistics on compactions
    decommission                 Decommission the *node I am connecting to*
    describecluster              Print the name, snitch, partitioner and schema version of a cluster
    describering                 Shows the token ranges info of a given keyspace
    disableautocompaction        Disable autocompaction for the given keyspace and table
    disablebackup                Disable incremental backup
    disablebinary                Disable native transport (binary protocol)
    disablegossip                Disable gossip (effectively marking the node down)
    ......

命令非常多,本文中,我们也不会做简单英文翻译,重点说一些运维中常用到的命令工具,未涉及到的命令可以在日常工作中通过使用,会慢慢加深了解。

常用命令介绍

  • nodetool status:集群所有node 心跳状态
[root@Cassandra8c32GTest005 cassandra]# bin/nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address        Load       Tokens       Owns (effective)  Host ID                               Rack
UN  192.168.1.105  1.63 MiB   256          100.0%            0892685d-c79f-4e5b-b9ac-80ae1fb2a5f6  rack1
UN  192.168.1.106  1.65 MiB   256          100.0%            6520eeee-5802-48b2-8ff2-3f89d7ebd5e3  rack1
  • nodetool info: 当前节点进程全局信息
[root@Cassandra8c32GTest005 cassandra]# bin/nodetool info
ID                     : 0892685d-c79f-4e5b-b9ac-80ae1fb2a5f6
Gossip active          : true
Thrift active          : true
Native Transport active: true
Load                   : 1.63 MiB
Generation No          : 1565767843
Uptime (seconds)       : 159165
Heap Memory (MB)       : 630.35 / 7922.00
Off Heap Memory (MB)   : 0.01
Data Center            : datacenter1
Rack                   : rack1
Exceptions             : 0
Key Cache              : entries 172, size 19.91 KiB, capacity 100 MiB, 254 hits, 472 requests, 0.538 recent hit rate, 14400 save period in seconds
Row Cache              : entries 0, size 0 bytes, capacity 0 bytes, 0 hits, 0 requests, NaN recent hit rate, 0 save period in seconds
Counter Cache          : entries 0, size 0 bytes, capacity 50 MiB, 0 hits, 0 requests, NaN recent hit rate, 7200 save period in seconds
Chunk Cache            : entries 18, size 1.12 MiB, capacity 480 MiB, 1000 misses, 2706 requests, 0.630 recent hit rate, NaN microseconds miss latency
Percent Repaired       : 100.0%
Token                  : (invoke with -T/--tokens to see all 256 tokens)

加减机器,扩容,缩容

集群的扩容是非常常用的功能,加减机器了。
先看看加机器,如果配置正确,节点正常启动后,会自动加入集群
参考如下文章,加节点
https://docs.datastax.com/en/dse/6.7/dse-admin/datastax_enterprise/operations/opsAddNodeToCluster.html

  • nodetool cleanup:在老节点上,分别执行,删除非自己管理的数据

机器过保下线:

  • nodetool decommission:当前节点下线,会将当前节点数据拷贝到其他副本
  • nodetool removenode: 从其他副本节点拷贝数据到数据重分布后的目标节点,有数据不一致风险,用于当前节点不能重新拉起,提供数据读取服务。
  • nodetool assassinate:强制移除节点,无任何数据拷贝
    加减盘后,让sst重分布,rebalance磁盘
  • relocatesstables: 磁盘加减盘后,relocatesstables可让sst重新分布
  • nodetool netstats 监控数据迁移进度

数据安全,备份

  • nodetool enablebackup: 开启增量备份, data目录增加一个sstable文件的话,在backup目录会创建一个硬链接,可以异步备份到s3或者oss上
  • nodetool garbagecollect:主动做回收,用于磁盘空间告警场景。
  • nodetool snapshot:对全部的keyspace都做snapshot,按当前时间戳取快照名,在table的dataDir/snapshots/${ts}/存放数据文件
  • refresh: 上述备份后的sst如何restore呢,手动导入sstable到正确位置后,执行refresh,让进程可见

数据正确性及其他运维命令

  • repair:修数据用,让多副本数据一致
  • verify: 数据巡检,检查sst内数据和crc是不是一致。
  • resetlocalschema: 从集群其他节点同步schema, 各个节点上表schema数据必须是一致的。
  • nodetool flush: memtable刷至本地磁盘,生成sstable
  • nodetool compact:对指定的sstables做一次major compaction
    sstabledump工具往往需要上面工具生成的sst作为输入
  • rebuild_index: 如果二级索引与base表不一致,可重建

排查问题相关

  • getendpoints: 如果集群比较大,不可能扫描所有日志,可通过partitionKey找到后端的node,方便定位问题。
[root@Cassandra8c32GTest004 cassandra]# bin/nodetool getendpoints ycsb usertable user7562145027629296129
192.168.1.105
192.168.1.106
  • tablehistograms: 查看表partition数据统计,可检查出某partition是否过大
[root@Cassandra8c32GTest004 cassandra]# bin/nodetool tablehistograms ycsb usertable
ycsb/usertable histograms
Percentile  SSTables     Write Latency      Read Latency    Partition Size        Cell Count
                              (micros)          (micros)           (bytes)
50%             0.00              0.00              0.00              1109                10
75%             0.00              0.00              0.00              1109                10
95%             0.00              0.00              0.00              1109                10
98%             0.00              0.00              0.00              1109                10
99%             0.00              0.00              0.00              1109                10
Min             0.00              0.00              0.00               125                 0
Max             0.00              0.00              0.00              1109                10
  • toppartitions: 当节点负载比较高,输出一个top partitions可以拿到当前访问比较热的partition,前端可以降降压力。

结语

其他命令多为调整运行参数,不是那么常用,需要的时候,通过帮助手册,搜索关键字就能找到对应的命令,不再赘述了。

钉钉群交流

为了营造一个开放的 Cassandra 技术交流,我们建立了微信群和钉钉群,为广大用户提供专业的技术分享及问答,定期在国内开展线下技术沙龙,专家技术直播,欢迎大家加入。
image

钉钉群入群链接:https://c.tb.cn/F3.ZRTY0o

相关文章
|
API
vue3.0 router路由跳转传参(router.push)
vue3.0 router路由跳转传参(router.push)
1766 0
|
8月前
|
存储 数据采集 人工智能
先建“语义基座”,再谈运维智能!阿里云以 Operation Intelligence 定义 AIOps 新范式
通用大模型的到来与数据整合技术的突破,正在重塑 AIOps 的底层逻辑。
1420 58
|
4月前
|
SQL 运维 架构师
从DBA到数据架构师:数据库从业者的能力跃迁路径
本文剖析DBA转型数据架构师的跃迁路径:从单库运维到全局设计,从技术执行到业务驱动。聚焦2026年核心能力——数据建模、跨系统集成、AI工具应用等,助你突破成长瓶颈,成为定义数据体系的“价值工程师”。
|
机器学习/深度学习 存储 人工智能
Qlib:华尔街颤抖!微软开源金融AI量化投资神器,助力智能投研
Qlib是微软亚洲研究院推出的开源AI量化投资平台,提供从数据处理、模型训练到组合管理的全流程支持,内置高性能数据基础设施和多种机器学习模型。
6314 87
Qlib:华尔街颤抖!微软开源金融AI量化投资神器,助力智能投研
|
12月前
|
Java 测试技术 API
Java 跳出多层循环
本文详解Java中如何使用带标签的`break`语句跳出多层循环。通过实例展示其语法与应用场景,如图像黑屏检测,并对比传统方法与Stream API,帮助开发者在性能与可读性间做出权衡,提升代码效率与质量。(238字)
417 0
|
算法 安全 数据安全/隐私保护
Python随机数函数全解析:5个核心工具的实战指南
Python的random模块不仅包含基础的随机数生成函数,还提供了如randint()、choice()、shuffle()和sample()等实用工具,适用于游戏开发、密码学、统计模拟等多个领域。本文深入解析这些函数的用法、底层原理及最佳实践,帮助开发者高效利用随机数,提升代码质量与安全性。
1629 0
|
存储 NoSQL Redis
Redis 持久化揭秘:选择 RDB、AOF 还是混合持久化?
Redis 是一个内存数据库,意味着它主要将数据存储在内存中,从而能够提供极高的性能。然而,作为内存数据库,Redis 默认情况下的数据不会永久保存。为了确保数据在重启或故障后能够恢复,Redis 提供了几种 **持久化机制**。这些机制允许 Redis 将内存中的数据保存到硬盘上,从而实现数据持久化。
1748 22
Redis 持久化揭秘:选择 RDB、AOF 还是混合持久化?
|
关系型数据库 MySQL 数据库连接
DBeaver如何连接一个数据库
【10月更文挑战第27天】DBeaver 是一款功能强大的通用数据库管理工具,支持多种主流数据库。本文介绍了使用 DBeaver 连接数据库的基本步骤,包括下载安装、创建新连接、选择数据库类型、配置连接参数、测试连接以及最终连接到数据库。详细的操作指南帮助用户轻松管理和操作数据库。
6452 9
|
运维 NoSQL
Cassandra 数据一致性修复 repair 来龙去脉
文章分3块:1.为什么需要repair?;2.repair大概流程?;3.repair可能的问题。
4542 0
Cassandra 数据一致性修复 repair 来龙去脉

热门文章

最新文章