#显示命令帮助信息
[root@node1 ~]# hadoop fs -help rm
#查看目录信息(hdfs dfs与hadoop fs基本相同)
[root@node1 ~]# hdfs dfs -ls /
Found 10 items
drwxrwxrwx - yarn hadoop 0 2020-06-03 18:41 /app-logs
#...省略部分输出...
[root@node1 ~]# hadoop fs -ls /
Found 10 items
drwxrwxrwx - yarn hadoop 0 2020-06-03 18:41 /app-logs
#...省略部分输出...
#hadoop fs (-cat,-appendToFile,-chgrp,-chmod,-chown,-copyFromLocal,-copyToLocal,-cp,-du,-find,-move,-mkdir等,见名知意不在解释)
#2个集群同步文件
[root@node1 ~]# hadoop distcp <srcurl> <desturl>
#输出集群的配置目录与lib目录
[root@node1 ~]# hadoop classpath
/usr/hdp/2.6.5.0-292/hadoop/conf:/usr/hdp/2.6.5.0-292/hadoop/lib/*:/usr/hdp/2.6.5.0-292/hadoop/.//*:/usr/hdp/2.6.5.0-292/hadoop-hdfs/./:/usr/hdp/2.6.5.0-292/hadoop-hdfs/lib/*:/usr/hdp/2.6.5.0-292/hadoop-hdfs/.//*:/usr/hdp/2.6.5.0-292/hadoop-yarn/lib/*:/usr/hdp/2.6.5.0-292/hadoop-yarn/.//*:/usr/hdp/2.6.5.0-292/hadoop-mapreduce/lib/*:/usr/hdp/2.6.5.0-292/hadoop-mapreduce/.//*::mysql-connector-java-5.1.49-bin.jar:/usr/hdp/2.6.5.0-292/tez/*:/usr/hdp/2.6.5.0-292/tez/lib/*:/usr/hdp/2.6.5.0-292/tez/conf
#查看当前支持的库(hadoop支持的压缩加密等库)
[root@node1 ~]# hadoop checknative
20/06/04 19:39:36 INFO bzip2.Bzip2Factory: Successfully loaded & initialized native-bzip2 library system-native
20/06/04 19:39:36 INFO zlib.ZlibFactory: Successfully loaded & initialized native-zlib library
Native library checking:
hadoop: true /usr/hdp/2.6.5.0-292/hadoop/lib/native/libhadoop.so.1.0.0
zlib: true /lib64/libz.so.1
snappy: true /usr/hdp/2.6.5.0-292/hadoop/lib/native/libsnappy.so.1
lz4: true revision:99
bzip2: true /lib64/libbz2.so.1
openssl: true /lib64/libcrypto.so
###hdfs命令比较重要,包含,fsck文件系统检查,balancer均衡集群文件数据,haadmin 高可用等,dfsadmin文件系统管理命令。
###hdfs管理集群在cdh的cm管理下和hdp的ambari之下用到的机会比较少。
yarn命令主要用来管理yarn集群,查看任务队列,日志,管理集群节点等功能
[hdfs@node1 ~]$ yarn node -list -all
20/06/04 19:51:56 INFO client.RMProxy: Connecting to ResourceManager at node2.work.com/192.168.31.133:8050
20/06/04 19:51:56 INFO client.AHSProxy: Connecting to Application History server at node2.work.com/192.168.31.133:10200
Total Nodes:3
Node-Id Node-State Node-Http-Address Number-of-Running-Containers
node4.work.com:45454 RUNNING node4.work.com:8042 1
node5.work.com:45454 RUNNING node5.work.com:8042 0
node3.work.com:45454 RUNNING node3.work.com:8042 0
#列出集群运行的任务
[hdfs@node1 ~]$ yarn application -list
#杀死某个任务
[hdfs@node1 ~]$ yarn application -kill <ID>
help查看帮助文档
hbase(main):003:0> help
HBase Shell, version 1.1.2.2.6.5.0-292, r897822d4dd5956ca186974c10382e9094683fa29, Fri May 11 08:00:59 UTC 2018
Type 'help "COMMAND"', (e.g. 'help "get"' -- the quotes are necessary) for help on a specific command.
Commands are grouped. Type 'help "COMMAND_GROUP"', (e.g. 'help "general"') for help on a command group.
COMMAND GROUPS:
Group name: general
Commands: status, table_help, version, whoami
Group name: ddl
Commands: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, locate_region, show_filters
Group name: namespace
Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables
Group name: dml
Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve
Group name: tools
Commands: assign, balance_switch, balancer, balancer_enabled, catalogjanitor_enabled, catalogjanitor_run, catalogjanitor_switch, close_region, compact, compact_rs, flush, major_compact, merge_region, move, normalize, normalizer_enabled, normalizer_switch, split, splitormerge_enabled, splitormerge_switch, trace, unassign, wal_roll, zk_dump
Group name: replication
Commands: add_peer, append_peer_tableCFs, disable_peer, disable_table_replication, enable_peer, enable_table_replication, list_peers, list_replicated_tables, remove_peer, remove_peer_tableCFs, set_peer_tableCFs, show_peer_tableCFs
Group name: snapshots
Commands: clone_snapshot, delete_all_snapshot, delete_snapshot, list_snapshots, restore_snapshot, snapshot, snapshot_all, snapshot_restore
Group name: configuration
Commands: update_all_config, update_config
Group name: quotas
Commands: list_quota_snapshots, list_quota_table_sizes, list_quotas, set_quota
Group name: security
Commands: grant, revoke, user_permission
Group name: procedures
Commands: abort_procedure, list_procedures
Group name: visibility labels
Commands: add_labels, clear_auths, get_auths, list_labels, set_auths, set_visibility
Group name: rsgroup
Commands: add_rsgroup, balance_rsgroup, get_rsgroup, get_server_rsgroup, get_table_rsgroup, list_rsgroups, move_rsgroup_servers, move_rsgroup_tables, remove_rsgroup
SHELL USAGE:
Quote all names in HBase Shell such as table and column names. Commas delimit
command parameters. Type <RETURN> after entering a command to run it.
Dictionaries of configuration used in the creation and alteration of tables are
Ruby Hashes. They look like this:
{'key1' => 'value1', 'key2' => 'value2', ...}
and are opened and closed with curley-braces. Key/values are delimited by the
'=>' character combination. Usually keys are predefined constants such as
NAME, VERSIONS, COMPRESSION, etc. Constants do not need to be quoted. Type
'Object.constants' to see a (messy) list of all constants in the environment.
If you are using binary keys or values and need to enter them in the shell, use
double-quote'd hexadecimal representation. For example:
hbase> get 't1', "key\x03\x3f\xcd"
hbase> get 't1', "key\003\023\011"
hbase> put 't1', "test\xef\xff", 'f1:', "\x01\x33\x40"
The HBase shell is the (J)Ruby IRB with the above HBase-specific commands added.
For more on the HBase Shell, see http://hbase.apache.org/book.html
可以看到hbase的命令分为几类:general、ddl、namespace、dml、tools、replication、snapshots、security等
查看服务器
#查看集群状态
hbase(main):004:0> status
1 active master, 0 backup masters, 3 servers, 0 dead, 0.6667 average load
#查看版本
hbase(main):005:0> version
1.1.2.2.6.5.0-292, r897822d4dd5956ca186974c10382e9094683fa29, Fri May 11 08:00:59 UTC 2018
表操作
#列出表
hbase(main):006:0> list
TABLE
0 row(s) in 0.0450 seconds
=> []
#创建表, create ‘表名称’, ‘列族名称1’,‘列族名称2’,‘列名称N’,创建一张名为Student的表,包含基本信息(baseInfo)、学校信息(schoolInfo)两个列族
hbase(main):007:0> create 'Student','baseInfo','schoolInfo'
0 row(s) in 2.5290 seconds
=> Hbase::Table - Student
#查看表信息
hbase(main):008:0> describe 'Student'
Table Student is ENABLED
Student
COLUMN FAMILIES DESCRIPTION
{NAME => 'baseInfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'F
ALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKC
ACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
{NAME => 'schoolInfo', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS =>
'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOC
KCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
2 row(s) in 0.1200 seconds
# 禁用表
disable 'Student'
# 检查表是否被禁用
is_disabled 'Student'
# 启用表
enable 'Student'
# 检查表是否被启用
is_enabled 'Student'
#表是否存在
exists 'Student'
# 删除表前需要先禁用表
disable 'Student'
# 删除表
drop 'Student'
#插入数据
put 'Student', 'rowkey1','baseInfo:name','tom'
put 'Student', 'rowkey1','baseInfo:birthday','1990-01-09'
# 获取指定行中所有列的数据信息
get 'Student','rowkey3'
# 获取指定行中指定列族下所有列的数据信息
get 'Student','rowkey3','baseInfo'
# 获取指定行中指定列的数据信息
get 'Student','rowkey3','baseInfo:name'
# 删除指定行
delete 'Student','rowkey3'
# 删除指定行中指定列的数据
delete 'Student','rowkey3','baseInfo:name'
beeline通过jdbc链接hiveserver2的thrift端口
[hdfs@node1 ~]$ beeline -u jdbc:hive2://node2.work.com:10000
Connecting to jdbc:hive2://node2.work.com:10000
Connected to: Apache Hive (version 1.2.1000.2.6.5.0-292)
Driver: Hive JDBC (version 1.2.1000.2.6.5.0-292)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 1.2.1000.2.6.5.0-292 by Apache Hive
0: jdbc:hive2://node2.work.com:10000>
在集群配置kerberos时需要先kinit认证身份,再用beeline链接
[hdfs@node1 ~]$ beeline -u "jdbc:hive2://node2.work.com:10000/default;principal=hive/_HOST@example.com"
注意:本人在cdh集群中principal=hive/node2.work.com@example.com这样可以链接,在hdp中必须用_HOST代替node2.work.com才能连接。我也没搞懂到底哪里出了问题。