Hadoop学习笔记之常用命令

Hdfs命令

hdfs dfs -cat /urlba/url/url.txt|tail -55行
hdfs dfs -cat /urlba/url/url.txt|head -55行
hdfs dfs -cat /urlba/url/url.txt| shuf -n 5 随机5行。
hdfs dfs -cat /urlba/url/url.txt|wc -l 查看hdfs上文件行数。
hdfs dfs -du -h /data/1027 //查看1027文件夹下的子文件夹的具体大小
hdfs dfs -ls
hdfs dfs -cat /xm/102602/result/part-r-00000 | head //查看前十行,不加|head查看文件全部内容
hdfs dfs -tail /xm/102602/result/part-r-00000 //查看最后多少行
hdfs dfs -mkdir
hdfs dfs -text
hdfs dfs -get
hdfs dfs -put
hdfs dfs -mv
hdfs bfs -cp  //复制
hdfs dfs -rm  //删除单个文件
hdfs dfs -rm -r //递归删除,可以跟多个目录,批量删除,可以跟/result*这样的参数,意思是删除所有以result开头的文件夹

-du [-s] [-h] [-x] … :
Show the amount of space, in bytes, used by the files that match the specified
file pattern. The following flags are optional:
-s Rather than showing the size of each individual file that matches the
pattern, shows the total (summary) size.
-h Formats the sizes of files in a human-readable fashion rather than a number
of bytes.
-x Excludes snapshots from being counted.
Note that, even without the -s option, this only shows size summaries one level
deep into a directory.
The output is in the form
size disk space consumed name(full path)
大小 磁盘空间消耗 全路径名

Hadoop命令

hadoop jar <jar> [mainClass] args… //执行jar
hadoop jar <jar> [mainClass] args… //执行jar
hadoop namenode -format  //namenode格式化
hadoop job -kill job_1505886401930_0217  //kill某个正在运行的job,后面的job_什么的是job的id,这个id也可以在web管理界面看到,就是application_后面的数字集合
// 以下命令和上面的hdfs命令功能一样
hadoop fs -ls //查看当前目录下所有文件
hadoop fs -cat //查看某一个文件具体内容
hadoop fs -mkdir //创建目录,添加-p可以创建叠加目录
hadoop fs -text //显示文件内容,类似于cat,不过如果path的文件内容是压缩文件的话,那么就执行的是解压的操作
hadoop fs -get //取文件,或者说下载文件
hadoop fs -put //上传文件到hdfs
hadoop fs -mv //移动文件或目录 也可以对文件进行重命名操作
ls -l //查看文件权限 参考[这里](http://www.linuxidc.com/Linux/2014-10/108114.htm)
drwxr-xr-x 2 root root 4096 09-22 17:19 test 
第一个字符代表文件类型。d代表目录,-代表非目录;接下来每三个字符为一组权限,分为三组,依次代表所有者权限,同组用户权限,其它用户权限
每组权限的三个字符依次代表是否可读,是否可写,是否可执行;r 表示拥有读的权限
w 表示拥有写的权限
x 表示拥有可执行的权限
- 表示没有该权限
chmod 754 test
4代表读权限,2代表写权限,1代表执行权限
7=4 + 2 + 1,表示拥有可读可写可执行权限
5=4 + 1,表示拥有可读可执行权限,但是没有写权限
0 代表没有任何权限

Hbase命令

http://localhost:16010/ 此乃hbase的web管理界面

这里写图片描述

看到的表:

这里写图片描述

start-hbase.sh //执行之前确保hadoop所有组件均已成功启动
stop-hbase.sh
hbase shell // 进入shell命令模式
exit // 退出hbase shell
list //查看所有表
create 't1', {NAME => 'f1', VERSIONS => 1}, {NAME => 'f2', VERSIONS => 1}, {NAME => 'f3', VERSIONS => 1} //创建表t1
put 't1', 'r1', 'f1', 'v1' // 导入数据到t1表,r1代表第一行,f1代表字段列名,v1代表值
deleteall 't1','r7' // 删除第7行整行数据
flush 't1' // 写到hfile文件中
disable 't1' , drop 't1' // 删除表
desc 't1'// 查看表结构
alter 'test1',{NAME=>'body',TTL=>'15552000'},{NAME=>'meta', TTL=>'15552000'} // 修改表结构,需要先disable 然后才能alter,最后还得enable
get 't1','r1' // 查询t1表下r1列得值
count 't1' // 查询表的记录条数
truncate 't1' // 清空表中所有数据,包括索引,其实就是删除后重建
scan 't1' // 查看t1表里数据

HBase 常用Shell命令
HBase教程
高可用Hadoop平台-HBase集群搭建

实际应用

批量重命名一些文件

#!/usr/bin/bash

day=1
for((day=1;day<=30;day++))
do
        if [[ $day -lt 10 ]]; then
                hadoop fs -mv /output/partitioner/2018030101/part-r-0000${day} /partitioner/2018030101/2017-11-0${day}-xm.txt;
        else
                hadoop fs -mv /output/partitioner/2018030101/part-r-000${day} /partitioner/2018030101/2017-11-${day}-xm.txt;
        fi
        echo $day;
done

其实这段命令属于linux的shell命令,具体用到了for循环和if条件判断的命令,特别注意命令格式问题,有这样几个注意点:
1, if 与[ 之间必须有空格,[ ]与判断条件之间也必须有空格,]与; 之间不能有空格
2,gt代表大于,lt代表小于,只用于数字间的比较,字符串比较还是用大于号>
3,if语句必须以fi结尾
shell的if和else

其他命令

jps // 这个命令是查看当前已经启动了哪些节点,正常情况下应该有以下几个NodeManager,ResourceManager,NameNode,DataNode,SecondrayNameNode,Jps
start-all.sh //启动hadoop
stop-all.sh //停止hadoop
yarn logs -applicationId <applicationId> >> error1.txt //这是把某一个job的日志输出到error1.txt这个文件里
hadoop jar app.jar -D mapreduce.job.queuename=root.etl.distcp -D mapreduce.job.priority=HIGH //开始执行jar时调整优先级
yarn application -appId application_1478676388082_963529 -updatePriority VERY_HIGH //动态调整已经在执行job的优先级
hadoop job -list //作业列表
hadoop job -status job_201503171201_0003 //查看作业状态

hdfs多文件合并,参考文献

hdfs dfs -cat /sms/2018-01-22-sms*.txt | hdfs dfs -copyFromLocal - /sms/2018-01-22-sms-new.txt

http://blog.csdn.net/zhaojw_420/article/details/53161624 这里有一份详细命令介绍,仅供参考

其他

wc -l 123.txt   查看文件多少行

ssh-keygen -t rsa -C “xmliu@raipeng.com”

cat id_dsa.pub >> ~/.ssh/authorized_keys

chmod 600 authorized_keys 

ssh-copy-id -i id_rsa.pub root@192.168.1.148

猜你喜欢

转载自blog.csdn.net/diyangxia/article/details/78361507