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

相关文章
|
监控 NoSQL 固态存储
【MongoDB】Secondary同步慢问题
【4月更文挑战第2天】【MongoDB】Secondary同步慢问题
|
canal SQL 关系型数据库
|
存储 IDE 程序员
揭秘 IPython 的 5 种最佳调试方法
一个好的集成开发环境(IDE)附带的调试器是开发人员能够拥有的最强大的工具之一,但并不是每个人都在使用一个带有很棒代码调试器的集成发环境(IDE)。
|
存储 前端开发 JavaScript
【前端学JAVA】有手就会!10min快速入门java的基础语法(2)
【8月更文挑战第8天】10min快速入门java的基础语法
528 2
【前端学JAVA】有手就会!10min快速入门java的基础语法(2)
|
安全 Linux 网络安全
OpenSSH漏洞修复(升级最新版本流程)
【5月更文挑战第27天】OpenSSH漏洞修复(升级最新版本流程)
2372 1
OpenSSH漏洞修复(升级最新版本流程)
|
关系型数据库 MySQL 数据库
SiteGround主机站点工具SITE TOOLS设置教程
当你使用SiteGround搭建WordPress或WooCommerce网站后,你会经常登录到两个不同的网站后台:一个是SiteGround的Site Tools后台,用于进行网站的安全、速度优化、FTP工具和网站备份等技术操作;另一个是WordPress网站后台,主要用于管理网站内容、调整前台显示样式和编辑网站功能。本文我们介绍了如何使用SiteGround SITE TOOLS主机站点工具管理网站。
839 0
SiteGround主机站点工具SITE TOOLS设置教程
|
运维 NoSQL
Cassandra 数据一致性修复 repair 来龙去脉
文章分3块:1.为什么需要repair?;2.repair大概流程?;3.repair可能的问题。
4499 0
Cassandra 数据一致性修复 repair 来龙去脉
|
Linux 网络安全 调度
DolphinScheduler 调度工作流报错 Host key verification failed.
DolphinScheduler调度任务失败,错误显示&quot;Host key verification failed.&quot;。问题可能在于SSH免密登录配置失效或租户不存在于Linux系统中。解决方案:检查SSH配置并确保调度用户有管理员权限;确认DolphinScheduler租户与Linux用户对应。如果日志仅显示主机键验证失败,可能忽略了租户与操作系统用户的对应关系。创建具备管理员权限的新租户可解决。此外,当失败策略设为&quot;继续&quot;时,可能无法查看失败日志,建议使用&quot;结束&quot;策略。
701 0
|
Linux 网络安全
实验:CentOS 7 编译安装最新版 OpenSSH 9.4p1
CentOS7 升级安装 OpenSSH 9.4p1 OpenSSL 3.0.10
2580 1
|
存储 运维 监控
【译】深入浅出 Cassandra 的删除和墓碑
深入浅出介绍 cassandra 作为一款分布式数据库如何支持删除操作
6212 0
【译】深入浅出 Cassandra 的删除和墓碑

热门文章

最新文章