[data@lcoalhost-1 spark-2.4.0]$ ./sbin/stop-all.sh
localhost-1: no org.apache.spark.deploy.worker.Worker to stop
localhost-2: no org.apache.spark.deploy.worker.Worker to stop
原因分析
spark集群的停止是通过xxx.pid文件操作
查看stop-master,其中停止语句为
"${SPARK_HOME}/sbin"/spark-daemon.sh stop org.apache.spark.deploy.master.Master 1
查看spark-daemon.sh, SPARK_PID_DIR=/tmp pid文件默认在/tmp目录下
if [ "$SPARK_PID_DIR" = "" ]; then
SPARK_PID_DIR=/tmp
fi
# some variables
log="$SPARK_LOG_DIR/spark-$SPARK_IDENT_STRING-$command-$instance-$HOSTNAME.out"
pid="$SPARK_PID_DIR/spark-$SPARK_IDENT_STRING-$command-$instance.pid"
# Set default scheduling priority
if [ "$SPARK_NICENESS" = "" ]; then
export SPARK_NICENESS=0
fi
execute_command() {
if [ -z ${SPARK_NO_DAEMONIZE+set} ]; then
nohup -- "$@" >> $log 2>&1 < /dev/null &
newpid="$!"
echo "$newpid" > "$pid"
停止Spark集群
担心使用kill强制停止spark相关进程会破坏集群,因此考虑回复/tmp下的pid文件,再使用stop-all.sh来停止集群。
分析spark-daemon.sh脚本,看到pid文件命名规则如下:
pid=$SPARK_PID_DIR/spark-$SPARK_IDENT_STRING-$command-$instance.pid
其中
$SPARK_PID_DIR是/tmp
$SPARK_IDENT_STRING是登录用户$USER,我的集群中用户名是data
$command是调用spark-daemon.sh时的参数,有两个:
org.apache.spark.deploy.master.Master
org.apache.spark.deploy.worker.Worker
$instance也是调用spark-daemon.sh时的参数,我的集群中是1
因此pid文件名如下:
/tmp/spark-data-org.apache.spark.deploy.master.Master-1.pid
/tmp/spark-data-org.apache.spark.deploy.worker.Worker-1.pid
解决方法
# 修改spark-env.sh,增加
export SPARK_PID_DIR=/data/user/spark-2.4.0/pids
启动集群查看/data/user/spark-2.4.0/pids 目录下的文件
参考链接 https://www.cnblogs.com/simplestupid/p/4693513.html