大数据常用命令(持续更新)
hdfs:
1.查看目录 hdfs dfs -ls /
2.查看目录大小 hdfs dfs -du -h /
3.删除目录或文件 hdfs dfs -rm -r -skipTrash /dir_to_delete
4.上传文件 hdfs dfs -put 本地目录 hdfs目录
5.下载文件 hdfs dfs -get hdfs目录 本地目录
6.查看文件详情 hdfs fsck /XXX -files -blocks -locations -racks
7.查看/进入/离开安全模式状态 hdfs dfsadmin -safemode get/enter/leave
8.查看NameNode主备节点 hdfs haadmin -getAllServiceState
9.查看DataNode的统计信息 hdfs dfsadmin -report
10.检查坏块 hdfs fsck /
11.删除坏块 hdfs fsck / -delete "/file"
hdfs 快照:
1.hdfs dfsadmin -allowSnapshot 路径 (功能描述:开启指定目录的快照功能)
2.hdfs dfsadmin -disallowSnapshot 路径 (功能描述:禁用指定目录的快照功能,默认是禁用)
3.hdfs dfs -createSnapshot 路径 (功能描述:对目录创建快照)
4.hdfs dfs -createSnapshot 路径 名称 (功能描述:指定名称创建快照)
5.hdfs dfs -renameSnapshot 路径 旧名称 新名称 (功能描述:重命名快照)
6.hdfs lsSnapshottableDir (功能描述:列出当前用户所有可快照目录)
7.hdfs snapshotDiff 路径1 路径2 (功能描述:比较两个快照目录的不同之处)
8.hdfs dfs -deleteSnapshot path snapshotName (功能描述:删除快照)
9.hdfs dfs -ls -t /backup_dayu/hdfs/.snapshot(ls)
Yarn:
1. 查看yarn上运行的任务
yarn application -list
2. 杀死任务 yarn application -kill ${application-Id}
#杀死所有任务
yarn application -list | grep -w RUNNING | awk '{print $1}' | grep application_ | xargs yarn application -kill
3.查看yarn上队列资源使用情况 yarn queue -status QueueName
4.查看yarn上资源情况,以及每个任务使用的内存情况 yarn top
5.查看resourceManager主节点 yarn rmadmin -getAllServiceState
6.查看所有历史日志yarn application -list -appStates ALL
7.查看service状态
yarn rmadmin -getAllServiceState
Spark:
${spark_root}/bin/spark-submit --class org.apache.spark.examples.streaming.HdfsWordCount --name spark-task-example --num-executors 4 --master yarn --deploy-mode cluster --queue QueueName ${spark_root}/jars/spark-examples*.jar
定位问题常用命令
查找类所在jar包
Caused by : java.lang.ClassNotFoundExcetion之类的问题
find . -iname "*.jar" | while read jarfile; do
unzip -l $jarfile | grep okio/Buffer
if [ $? -eq 0 ]
then
echo "find class in jar : "$jarfile
fi
done
curl命令使用方法:
# 获取https资源:
curl -k --cacert ${cert_dir}/trust.cer --cert ${cert_dir}/server.cer:${pwd} --key ${cert_dir}/server_key.pem -X GET --location -o logo.png https://${host_name}:port/static/spark-logo-77x50px-hd.png
# 获取http服务:
curl --cert /var/run/secrets/kubernetes.io/serviceaccount/ca.crt -H "Content-Type: application/json" -X GET --location "${host_name}:port"
# 密文密码解密方法
curl -i --unix-socket ${sidecar_dir}/http.sock -X POST -H "xx-local-forward:true" "http://localhost/rest/plat/secretbox/v1/keys" -H "Content-Type: application/json" -d "{ "action": "decrypt", "cipherText": "${密文密码}"}"
echo "${上一步返回内容}" | base64 -d
# 查看是否启用ssl认证
openssl s_client -connect <hostname> : <port>
k8s常用命令
# 获取pod所在namespace
ns=`kubectl get pods -o wide -A|grep ${pod_name} |awk '{print $1}' |head -1`
# get node list
kubectl get node -o wide -n $ns
# get sts list
kubectl get sts -nmae
# 修改pod对应的sts,k8s将自动重启pod
kubectl edit sts -n $ns ndp-spark-thrift
# get pod list
kubectl get pod -o wide -n $ns
# 进入pod
kubectl exec -it -n $ns ${pod_name} -- bash
# 根据标签删除多个pod
kubectl delete pod -l spark-role=driver -n $ns
# describe pod
kubectl describe -n $ns pod
# get pod yaml
kubectl get -o wide -n $ns -o yaml pod ${pod_name}
# get 自定义资源 list
kubectl get ${resource_name} -n $ns
# describe自定义资源
kubectl describe -n $ns ${resource_name}
# 进入pod挂载的宿主机路径,pod进不去时可以用来查看日志
read -p 'Like Pod Name: ' pod;kubectl get pods $(kubectl get pod -n $ns | grep -i $pod | awk '{print $1}' | head -n 1) -n $ns -o jsonpath='{.metadata.uid}'
ssh ${pod_install_node_ip}
cd /var/lib/kubelet/pods/${POD_ID}/volumes/kubernetes.io~csi/
# 拷贝文件夹到容器
kubectl cp dir/ $ns/${pod_name}:/dir
# 拷贝容器文件夹到节点
kubectl cp $ns/${pod_name}:/dir dir/
# 拷贝容器文件到节点(k8s拷贝时,要指定文件名称,很蠢有没有)
kubectl cp $ns/${pod_name}:/dir/***.jar ./***.jar
# 查看镜像ID
kubectl describe pod ${pod_name} -n $ns | grep wn_base_image