Skip to content

Commit 0dc868e

Browse files
sarutakpwendell
authored andcommitted
[SPARK-3584] sbin/slaves doesn't work when we use password authentication for SSH
Author: Kousuke Saruta <[email protected]> Closes apache#2444 from sarutak/slaves-scripts-modification and squashes the following commits: eff7394 [Kousuke Saruta] Improve the description about Cluster Launch Script in docs/spark-standalone.md 7858225 [Kousuke Saruta] Modified sbin/slaves to use the environment variable "SPARK_SSH_FOREGROUND" as a flag 53d7121 [Kousuke Saruta] Merge branch 'master' of git://git.apache.org/spark into slaves-scripts-modification e570431 [Kousuke Saruta] Added a description for SPARK_SSH_FOREGROUND variable 7120a0c [Kousuke Saruta] Added a description about default host for sbin/slaves 1bba8a9 [Kousuke Saruta] Added SPARK_SSH_FOREGROUND flag to sbin/slaves 88e2f17 [Kousuke Saruta] Merge branch 'master' of git://git.apache.org/spark into slaves-scripts-modification 297e75d [Kousuke Saruta] Modified sbin/slaves not to export HOSTLIST
1 parent ff637c9 commit 0dc868e

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ conf/*.cmd
2323
conf/*.properties
2424
conf/*.conf
2525
conf/*.xml
26+
conf/slaves
2627
docs/_site
2728
docs/api
2829
target/

.rat-excludes

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ log4j.properties
1919
log4j.properties.template
2020
metrics.properties.template
2121
slaves
22+
slaves.template
2223
spark-env.sh
2324
spark-env.cmd
2425
spark-env.sh.template

conf/slaves conf/slaves.template

File renamed without changes.

docs/spark-standalone.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ Finally, the following configuration options can be passed to the master and wor
6262

6363
# Cluster Launch Scripts
6464

65-
To launch a Spark standalone cluster with the launch scripts, you need to create a file called `conf/slaves` in your Spark directory, which should contain the hostnames of all the machines where you would like to start Spark workers, one per line. The master machine must be able to access each of the slave machines via password-less `ssh` (using a private key). For testing, you can just put `localhost` in this file.
65+
To launch a Spark standalone cluster with the launch scripts, you should create a file called conf/slaves in your Spark directory,
66+
which must contain the hostnames of all the machines where you intend to start Spark workers, one per line.
67+
If conf/slaves does not exist, the launch scripts defaults to a single machine (localhost), which is useful for testing.
68+
Note, the master machine accesses each of the worker machines via ssh. By default, ssh is run in parallel and requires password-less (using a private key) access to be setup.
69+
If you do not have a password-less setup, you can set the environment variable SPARK_SSH_FOREGROUND and serially provide a password for each worker.
70+
6671

6772
Once you've set up this file, you can launch or stop your cluster with the following shell scripts, based on Hadoop's deploy scripts, and available in `SPARK_HOME/bin`:
6873

sbin/slaves.sh

+22-9
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ sbin="`cd "$sbin"; pwd`"
4444
# If the slaves file is specified in the command line,
4545
# then it takes precedence over the definition in
4646
# spark-env.sh. Save it here.
47-
HOSTLIST="$SPARK_SLAVES"
47+
if [ -f "$SPARK_SLAVES" ]; then
48+
HOSTLIST=`cat "$SPARK_SLAVES"`
49+
fi
4850

4951
# Check if --config is passed as an argument. It is an optional parameter.
5052
# Exit if the argument is not a directory.
@@ -67,23 +69,34 @@ fi
6769

6870
if [ "$HOSTLIST" = "" ]; then
6971
if [ "$SPARK_SLAVES" = "" ]; then
70-
export HOSTLIST="${SPARK_CONF_DIR}/slaves"
72+
if [ -f "${SPARK_CONF_DIR}/slaves" ]; then
73+
HOSTLIST=`cat "${SPARK_CONF_DIR}/slaves"`
74+
else
75+
HOSTLIST=localhost
76+
fi
7177
else
72-
export HOSTLIST="${SPARK_SLAVES}"
78+
HOSTLIST=`cat "${SPARK_SLAVES}"`
7379
fi
7480
fi
7581

82+
83+
7684
# By default disable strict host key checking
7785
if [ "$SPARK_SSH_OPTS" = "" ]; then
7886
SPARK_SSH_OPTS="-o StrictHostKeyChecking=no"
7987
fi
8088

81-
for slave in `cat "$HOSTLIST"|sed "s/#.*$//;/^$/d"`; do
82-
ssh $SPARK_SSH_OPTS "$slave" $"${@// /\\ }" \
83-
2>&1 | sed "s/^/$slave: /" &
84-
if [ "$SPARK_SLAVE_SLEEP" != "" ]; then
85-
sleep $SPARK_SLAVE_SLEEP
86-
fi
89+
for slave in `echo "$HOSTLIST"|sed "s/#.*$//;/^$/d"`; do
90+
if [ -n "${SPARK_SSH_FOREGROUND}" ]; then
91+
ssh $SPARK_SSH_OPTS "$slave" $"${@// /\\ }" \
92+
2>&1 | sed "s/^/$slave: /"
93+
else
94+
ssh $SPARK_SSH_OPTS "$slave" $"${@// /\\ }" \
95+
2>&1 | sed "s/^/$slave: /" &
96+
fi
97+
if [ "$SPARK_SLAVE_SLEEP" != "" ]; then
98+
sleep $SPARK_SLAVE_SLEEP
99+
fi
87100
done
88101

89102
wait

0 commit comments

Comments
 (0)