Linux中SparkSQL分布式SQL引擎部署RDB|安裝MySQL+Hive(教程),sparksqlrdb
● 部署MySQL
# 尋找並刪除本地MySQLrpm -qa | grep mysqlrpm -e mysql-libs-5.1.66-2.el6_3.i686 --nodeps# 安裝指定版本MySQLrpm -ivh MySQL-server-5.1.73-1.glibc23.i386.rpm rpm -ivh MySQL-client-5.1.73-1.glibc23.i386.rpm # 修改mysql的密碼(直接輸入以下命令執行)/usr/bin/mysql_secure_installation(注意:設定root密碼 並選擇刪除匿名使用者,允許使用者遠端連線)# 登陸mysqlmysql -u root -p
完成基本的MySQL安裝。
接著給Spark SQL添加帳號並開通帳號許可權。預設使用的DB名是hiveMetadata,假設帳號和密碼都是spark,授權SQL可以這樣寫:
mysql> grant all on hiveMetastore.* to spark@'localhost' identified by 'spark';mysql> flush privileges;
●
準備設定檔conf/hive-site.xml
接下來,我們準備啟動JDBC/ODBC Server,在啟動之前,需要準備以下設定檔。
如果是與現有的Hive一起工作,直接實用Hive的設定檔conf/hive-site.xml即可,或者建立一個,在conf目錄下準備一個名為hive-site.xml的設定檔,其內容如下:
javax.jdo.option.ConnectionURL jdbc:mysql://localhost:3306/hiveMetastore?createDatabaseIfNotExist=true JDBC connect string for a JDBC metastore javax.jdo.option.ConnectionDriverName com.mysql.jdbc.Driver Driver class name for a JDBC metastore javax.jdo.option.ConnectionUserName spark username to use against metastore database javax.jdo.option.ConnectionPassword spark password to use against metastore database hive.hwi.war.file lib/hive-hwi-0.12.0.war This sets the path to the HWI war file, relative to ${HIVE_HOME}. hive.hwi.listen.host 0.0.0.0 This is the host address the Hive Web Interface will listen on hive.hwi.listen.port 9999 This is the port the Hive Web Interface will listen on ●
啟動JDBC/ODBC Server
現在可以啟動JDBC/ODBC Server了,其命令是:
./sbin/start-thriftserver.sh
●
使用beeline互動式工具
JDBC/ODBC Server啟動之後,我們可以用beeline來測試啟動是否正常:
./bin/beeline
下面的命令可以串連到JDBC/ODBC Server:
beeline> !connect jdbc:hive2://localhost:10000
也可以在啟動beeline時,直接指定JDBC Server:
./bin/beeline -u 'jdbc:hive2://localhost:10000'
可以修改系統編碼,防止SQL查詢結果中文顯示亂碼。
LANG=zh_CN.UTF-8; ./bin/beeline -u 'jdbc:hive2://localhost:10000'
●
運行Spark SQL命令列介面
./bin/spark-sql