hadoop@Master:~$ cd$SPARK_HOME hadoop@Master:/usr/local/bigdata/spark-2.4.3$ ./bin/spark-shell 19/06/14 01:55:17 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). Spark context Web UI available at http://Master:4040 Spark context available as 'sc' (master = local[*], app id = local-1560477340912). Spark session available as 'spark'. Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /___/ .__/\_,_/_/ /_/\_\ version 2.4.3 /_/ Using Scala version 2.11.12 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_211) Type in expressions to have them evaluated. Type :help for more information.
1.2 连接到集群
连接到集群使用如下命令
bash
1
spark-shell --master spark://master:7077
具体如下:
bash
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
$ spark-shell --master spark://master:7077 19/06/14 05:39:22 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). Spark context Web UI available at http://Master:4040 Spark context available as 'sc' (master = spark://master:7077, app id = app-20190614053947-0006). Spark session available as 'spark'. Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /___/ .__/\_,_/_/ /_/\_\ version 2.4.3 /_/ Using Scala version 2.11.12 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_211) Type in expressions to have them evaluated. Type :help for more information.
scala>val textFile = spark.read.textFile("file:///usr/local/bigdata/spark-2.4.3/README.md") textFile: org.apache.spark.sql.Dataset[String] = [value: string] scala> textFile.count() // Number of items in this Dataset res0: Long = 105
scala> textFile.first() // First item in this Dataset res1: String = # Apache Spark