这篇文章主要介绍了HDFS中PID示例分析,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
前言:
Linux中可以通过PID找到对相应的进程号和进程目录,ps -ef|grep pid可以单独kill想要的pid;如果生产上想通过shell脚本直接kill `ps -ef|grep 服务名 ,会把服务下所有多个进程和其他进程kill掉, 已hadoop为例可以读文件里进程号指定kill掉‘;
Hodoop的PID默认存储路径为/tmp,PID内容为进程号;
为什么说PID内容为进程号:
[hadoop@hadoop001 hadoop]$ jps
7857 DataNode
7748 NameNode
8774 Jps
8061 SecondaryNameNode
[hadoop@hadoop001 tmp]$ pwd
/tmp
[hadoop@hadoop001 tmp]$ cat hadoop-hadoop-datanode.pid
7857
[hadoop@hadoop001 tmp]$ cat hadoop-hadoop-namenode.pid
7748
[hadoop@hadoop001 tmp]$ cat hadoop-hadoop-secondarynamenode.pid
8061
观察hadoop停止的脚本,发现通过调用hadoop-daemons.sh停止脚本,
[hadoop@hadoop001 sbin]$ cat stop-dfs.sh
#---------------------------------------------------------
# namenodes
NAMENODES=$($HADOOP_PREFIX/bin/hdfs getconf -namenodes)
echo "Stopping namenodes on [$NAMENODES]"
"$HADOOP_PREFIX/sbin/hadoop-daemons.sh" \
--config "$HADOOP_CONF_DIR" \
--hostnames "$NAMENODES" \
--script "$bin/hdfs" stop namenode
#---------------------------------------------------------
# datanodes (using default slaves file)
if [ -n "$HADOOP_SECURE_DN_USER" ]; then
echo \
"Attempting to stop secure cluster, skipping datanodes. " \
"Run stop-secure-dns.sh as root to complete shutdown."
else
"$HADOOP_PREFIX/sbin/hadoop-daemons.sh" \
--config "$HADOOP_CONF_DIR" \
--script "$bin/hdfs" stop datanode
fi
#---------------------------------------------------------
# 进入查看hadoop-daemons.sh脚本
[hadoop@hadoop001 sbin]$ cat hadoop-daemon.sh |grep pid
# HADOOP_PID_DIR The pid files are stored. /tmp by default.
pid=$HADOOP_PID_DIR/hadoop-$HADOOP_IDENT_STRING-$command.pid
if [ -f $pid ]; then
if kill -0 `cat $pid` > /dev/null 2>&1; then
echo $command running as process `cat $pid`. Stop it first.
echo $! > $pid
if [ -f $pid ]; then
TARGET_PID=`cat $pid`
rm -f $pid
感谢你能够认真阅读完这篇文章,希望小编分享的“HDFS中PID示例分析”这篇文章对大家有帮助,同时也希望大家多多支持编程网,关注编程网行业资讯频道,更多相关知识等着你来学习!