无需修改,默认local
1.配置spark_home
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]# vim /etc/profile
SPARK_HOME=/usr/local/src/app/spark-2.1.1-bin-hadoop2.7
export PATH=$PATH:$SPARK_HOME/bin
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]# source /etc/profile
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]# echo $SPARK_HOME
/usr/local/src/app/spark-2.1.1-bin-hadoop2.7
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]#
2.启动
启动两个线程 [2]
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]# spark-shell --master local[2]
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]# spark-shell --master local[2]
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
17/07/22 19:13:12 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
17/07/22 19:13:12 WARN SparkConf:
SPARK_WORKER_INSTANCES was detected (set to '2').
This is deprecated in Spark 1.0+.
Please instead use:
- ./spark-submit with --num-executors to specify the number of executors
- Or set SPARK_EXECUTOR_INSTANCES
- spark.executor.instances to configure the number of instances in the spark config.
17/07/22 19:13:13 WARN Utils: Your hostname, ecs-24b3 resolves to a loopback address: 127.0.0.1; using 192.168.1.116 instead (on interface eth0)
17/07/22 19:13:13 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another address
17/07/22 19:13:21 WARN ObjectStore: Version information not found in metastore. hive.metastore.schema.verification is not enabled so recording the schema version 1.2.0
17/07/22 19:13:21 WARN ObjectStore: Failed to get database default, returning NoSuchObjectException
17/07/22 19:13:22 WARN ObjectStore: Failed to get database global_temp, returning NoSuchObjectException
Spark context Web UI available at http://192.168.1.116:4040
Spark context available as 'sc' (master = local[2], app id = local-1500721993893).
Spark session available as 'spark'.
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 2.1.1
/_/
Using Scala version 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131)
Type in expressions to have them evaluated.
Type :help for more information.
scala> 1+1
res0: Int = 2
scala> :q
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]#
3.web UI 访问
http://114.115.132.90:8080/
standalone模式
1.修改配置文件
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]# cd conf/
[root@ecs-24b3 conf]# cp spark-env.sh.template spark-env.sh
[root@ecs-24b3 conf]# vim spark-env.sh
#主机
SPARK_MASTER_HOST=hadoop001
#cpu核数
SPARK_WORKER_CORES=2
#内存
SPARK_WORKER_MEMORY=2g
#worker数
SPARK_WORKER_INSTANCES=1
export JAVA_HOME=/usr/local/src/java/jdk
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]# sbin/start-all.sh
#停止
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]# sbin/stop-all.sh
starting org.apache.spark.deploy.master.Master, logging to /usr/local/src/app/spark-2.1.1-bin-hadoop2.7/logs/spark-root-org.apache.spark.deploy.master.Master-1-ecs-24b3.out
root@localhost's password:
localhost: starting org.apache.spark.deploy.worker.Worker, logging to /usr/local/src/app/spark-2.1.1-bin-hadoop2.7/logs/spark-root-org.apache.spark.deploy.worker.Worker-1-ecs-24b3.out
localhost: starting org.apache.spark.deploy.worker.Worker, logging to /usr/local/src/app/spark-2.1.1-bin-hadoop2.7/logs/spark-root-org.apache.spark.deploy.worker.Worker-2-ecs-24b3.out
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]# jps
7155 Nailgun
17865 Jps
17641 Master
17740 Worker
17804 Worker
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]#
#查看master log
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]# cat /usr/local/src/app/spark-2.1.1-bin-hadoop2.7/logs/spark-root-org.apache.spark.deploy.master.Master-1-ecs-24b3.out
Spark Command: /usr/local/src/java/jdk/bin/java -cp /usr/local/src/app/spark-2.1.1-bin-hadoop2.7/conf/:/usr/local/src/app/spark-2.1.1-bin-hadoop2.7/jars/* -Xmx1g org.apache.spark.deploy.master.Master --host localhost --port 7077 --webui-port 8080
========================================
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
17/07/22 19:22:32 INFO Master: Started daemon with process name: 17641@ecs-24b3
17/07/22 19:22:32 INFO SignalUtils: Registered signal handler for TERM
17/07/22 19:22:32 INFO SignalUtils: Registered signal handler for HUP
17/07/22 19:22:32 INFO SignalUtils: Registered signal handler for INT
17/07/22 19:22:32 WARN Utils: Your hostname, ecs-24b3 resolves to a loopback address: 127.0.0.1; using 192.168.1.116 instead (on interface eth0)
17/07/22 19:22:32 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another address
17/07/22 19:22:32 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
17/07/22 19:22:32 INFO SecurityManager: Changing view acls to: root
17/07/22 19:22:32 INFO SecurityManager: Changing modify acls to: root
17/07/22 19:22:32 INFO SecurityManager: Changing view acls groups to:
17/07/22 19:22:32 INFO SecurityManager: Changing modify acls groups to:
17/07/22 19:22:32 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users with view permissions: Set(root); groups with view permissions: Set(); users with modify permissions: Set(root); groups with modify permissions: Set()
17/07/22 19:22:32 INFO Utils: Successfully started service 'sparkMaster' on port 7077.
17/07/22 19:22:32 INFO Master: Starting Spark master at spark://localhost:7077
17/07/22 19:22:32 INFO Master: Running Spark version 2.1.1
17/07/22 19:22:33 INFO Utils: Successfully started service 'MasterUI' on port 8080.
17/07/22 19:22:33 INFO MasterWebUI: Bound MasterWebUI to 0.0.0.0, and started at http://192.168.1.116:8080
17/07/22 19:22:33 INFO Utils: Successfully started service on port 6066.
17/07/22 19:22:33 INFO StandaloneRestServer: Started REST server for submitting applications on port 6066
17/07/22 19:22:33 INFO Master: I have been elected leader! New state: ALIVE
17/07/22 19:22:41 INFO Master: Registering worker 192.168.1.116:13706 with 2 cores, 2.0 GB RAM
17/07/22 19:22:44 INFO Master: Registering worker 192.168.1.116:8010 with 2 cores, 2.0 GB RAM
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]# vim /home/hello.txt
huawei mate 9
huawei mate 10
huawei p 9
huawei p 10 plus
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]# spark-shell --master spark://localhost:7077
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties
Setting default log level to "WARN".
To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).
17/07/22 19:34:32 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
17/07/22 19:34:32 WARN SparkConf:
SPARK_WORKER_INSTANCES was detected (set to '2').
This is deprecated in Spark 1.0+.
Please instead use:
- ./spark-submit with --num-executors to specify the number of executors
- Or set SPARK_EXECUTOR_INSTANCES
- spark.executor.instances to configure the number of instances in the spark config.
17/07/22 19:34:32 WARN Utils: Your hostname, ecs-24b3 resolves to a loopback address: 127.0.0.1; using 192.168.1.116 instead (on interface eth0)
17/07/22 19:34:32 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another address
17/07/22 19:34:43 WARN ObjectStore: Failed to get database global_temp, returning NoSuchObjectException
Spark context Web UI available at http://192.168.1.116:4040
Spark context available as 'sc' (master = spark://localhost:7077, app id = app-20170722193433-0000).
Spark session available as 'spark'.
Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 2.1.1
/_/
Using Scala version 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_131)
Type in expressions to have them evaluated.
Type :help for more information.
scala> val file = spark.sparkContext.textFile("file:///home/hello.txt")
file: org.apache.spark.rdd.RDD[String] = file:///home/hello.txt MapPartitionsRDD[14] at textFile at :23
scala> val wordCounts = file.flatMap(line => line.split(" ")).map((word => (word, 1))).reduceByKey(_ + _)
wordCounts: org.apache.spark.rdd.RDD[(String, Int)] = ShuffledRDD[17] at reduceByKey at :25
scala> wordCounts.collect
res1: Array[(String, Int)] = Array((p,2), (plus,1), (wei,1), (mate,2), (9,2), (huawei,3), (10,2))
scala> :q
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]#
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]# spark-shell --help
Usage: ./bin/spark-shell [options]
Options:
--master MASTER_URL spark://host:port, mesos://host:port, yarn, or local.
--deploy-mode DEPLOY_MODE Whether to launch the driver program locally ("client") or
on one of the worker machines inside the cluster ("cluster")
(Default: client).
--class CLASS_NAME Your application's main class (for Java / Scala apps).
--name NAME A name of your application.
--jars JARS Comma-separated list of local jars to include on the driver
and executor classpaths.
--packages Comma-separated list of maven coordinates of jars to include
on the driver and executor classpaths. Will search the local
maven repo, then maven central and any additional remote
repositories given by --repositories. The format for the
coordinates should be groupId:artifactId:version.
--exclude-packages Comma-separated list of groupId:artifactId, to exclude while
resolving the dependencies provided in --packages to avoid
dependency conflicts.
--repositories Comma-separated list of additional remote repositories to
search for the maven coordinates given with --packages.
--py-files PY_FILES Comma-separated list of .zip, .egg, or .py files to place
on the PYTHONPATH for Python apps.
--files FILES Comma-separated list of files to be placed in the working
directory of each executor.
--conf PROP=VALUE Arbitrary Spark configuration property.
--properties-file FILE Path to a file from which to load extra properties. If not
specified, this will look for conf/spark-defaults.conf.
--driver-memory MEM Memory for driver (e.g. 1000M, 2G) (Default: 1024M).
--driver-java-options Extra Java options to pass to the driver.
--driver-library-path Extra library path entries to pass to the driver.
--driver-class-path Extra class path entries to pass to the driver. Note that
jars added with --jars are automatically included in the
classpath.
--executor-memory MEM Memory per executor (e.g. 1000M, 2G) (Default: 1G).
--proxy-user NAME User to impersonate when submitting the application.
This argument does not work with --principal / --keytab.
--help, -h Show this help message and exit.
--verbose, -v Print additional debug output.
--version, Print the version of current Spark.
Spark standalone with cluster deploy mode only:
--driver-cores NUM Cores for driver (Default: 1).
Spark standalone or Mesos with cluster deploy mode only:
--supervise If given, restarts the driver on failure.
--kill SUBMISSION_ID If given, kills the driver specified.
--status SUBMISSION_ID If given, requests the status of the driver specified.
Spark standalone and Mesos only:
--total-executor-cores NUM Total cores for all executors.
Spark standalone and YARN only:
--executor-cores NUM Number of cores per executor. (Default: 1 in YARN mode,
or all available cores on the worker in standalone mode)
YARN-only:
--driver-cores NUM Number of cores used by the driver, only in cluster mode
(Default: 1).
--queue QUEUE_NAME The YARN queue to submit to (Default: "default").
--num-executors NUM Number of executors to launch (Default: 2).
If dynamic allocation is enabled, the initial number of
executors will be at least NUM.
--archives ARCHIVES Comma separated list of archives to be extracted into the
working directory of each executor.
--principal PRINCIPAL Principal to be used to login to KDC, while running on
secure HDFS.
--keytab KEYTAB The full path to the file that contains the keytab for the
principal specified above. This keytab will be copied to
the node running the Application Master via the Secure
Distributed Cache, for renewing the login tickets and the
delegation tokens periodically.
[root@ecs-24b3 spark-2.1.1-bin-hadoop2.7]#