1. Download Zepplin
Go to the official website and download the full tar package.
2. Unzip
tar zxvf zeppelin-0.7. 3. tgz
3. Modify the Configuration
New configuration file
CP zeppelin-env. sh. Template zeppelin-env. SH
Modifying a configuration file
VI zeppelin-env. SH
# Set the Java home path
Export JAVA_HOME=/USR/LIB/JVM/JAVA-1.8.0-OPENJDK-1.8.0.141-1.B16.EL7_3.X86_64/JRE
# Set Spark Master Address
Export master=spark://10.100.12.16:7077
# Set Spark Home path
Export spark_home=/opt/spark/
# set Spark MongoDB Connector, note: Here is 2.2.2 version
Export spark_submit_options= "--packages org.mongodb.spark:mongo-spark-connector_2.11:2.2.2"
4. Start Zepplin
Bin/zeppelin-daemon. SH start
5. Use the browser to enter Zepplin backstage: http://localhost:8080
6. Click Notebook to create a new query.
7. Write Scala Query code
ImportCom.mongodb.spark.config.ReadConfigImportcom.mongodb.spark.sql._val config=SqlContext.sparkContext.getConf.set ("Spark.mongodb.keep_alive_ms", "15000"). Set ("Spark.mongodb.input.uri", "mongodb://10.100.12.14:27017"). Set ("Spark.mongodb.input.database", "BI"). Set ("Spark.mongodb.input.collection", "usergroupmapping") Val Readconfig=readconfig (config) Val objusergroupmapping=SqlContext.read.format ("Com.mongodb.spark.sql"). MONGO (Readconfig) Objusergroupmapping.printschema () Val tbusergroupmapping=objusergroupmapping.todf () tbusergroupmapping.registertemptable ("Usergroupmapping")
8. Returning Query Results
Querying MongoDB data in Zepplin using spark SQL