Gateway是與EMR叢集處於同一個內網中的ECS伺服器,使用者可以使用Gateway實現負載平衡和安全隔離,也可以通過Gateway向E-MapReduce叢集提交作業。
您可以通過以下兩種方式建立Gateway:
- (推薦)通過EMR控制台建立。
- 手動搭建。
通過E-MapReduce控制台建立Gateway
在建立Gateway前,請確保您已經建立了E-MapReduce叢集。建立Gateway,請按照如下步驟進行操作:
- 登入阿里雲E-MapReduce控制台,進入叢集列表頁面。
- 單擊頁面右上方的建立Gateway按鈕。
- 在建立Gateway頁面中進行配置。
- 付費類型:訂用帳戶是一次性支付一段時間的費用,價格相對來說會比較便宜,特別是包三年的時候折扣會比較大。隨用隨付是根據實際使用的小時數來支付費用,每個小時計一次費用。
- 我的叢集:為該叢集建立Gateway,即建立的Gateway可以向哪個叢集提交作業。Gateway將會自動設定與該叢集一致的Hadoop環境。
- 配置:該地區內可選擇的ECS執行個體規格。
- 系統硬碟配置:Gateway節點使用的系統硬碟類型。系統硬碟有2種類型:SSD雲端硬碟和高效雲端硬碟,根據不同機型和不同的Region,系統硬碟顯示類型會有不同。系統硬碟預設隨著叢集的釋放而釋放。
- 系統硬碟大小:最小為40GB,最大為500GB。預設值為300GB。
- 資料盤配置:Gateway節點使用的資料盤類型。資料盤有2種類型:SSD雲端硬碟和高效雲端硬碟,根據不同機型和不同的Region,資料盤顯示類型會有不同。資料盤預設隨著叢集的釋放而釋放。
- 資料盤大小:最小為200GB,最大為4000GB。預設值為300GB。
- 數量:資料盤的數量,最小設定為1台,最大設定為10台。
- 叢集名稱:建立的Gateway的名稱,長度限制為1~64個字元,只允許包含中文、字母、數字、串連號(-)、底線(_)。
- 密碼/金鑰組:
- Cipher 模式:在文字框中輸入登入Gateway的密碼。
- 金鑰組模式:在下拉式功能表中選擇登入Gateway的金鑰組名稱。如果還未建立過金鑰組,單擊右側的建立金鑰組連結,進入ECS控制台建立。請妥善保管好金鑰組所對應的私密金鑰檔案(.pem檔案)。在Gateway建立成功後,該金鑰組的公開金鑰部分會自動綁定到Gateway所在的Elastic Compute Service上。在您通過SSH登入Gateway時,請輸入該私密金鑰檔案中的私密金鑰。
- 單擊建立完成Gateway的建立。
新建立的Gateway會顯示在叢集列表中,建立完成後,狀態列會變為空閑狀態。
手動搭建Gateway
- 網路環境
首先要保證Gateway節點在EMR對應叢集的安全性群組中,Gateway節點可以順利的訪問EMR叢集。設定節點的安全性群組請參考建立安全性群組。
- 軟體環境
- 系統內容:推薦使用CentOS 7.2及以上版本。
- Java環境:安裝JDK 1.7及以上版本,推薦使用OpenJDK version 1.8.0版本。
- 搭建步驟
- EMR 2.7及以上版本,3.2及以上版本
這些版本推薦直接使用EMR控制台來建立Gateway。
如果您選擇手動搭建,請先建立一個指令碼,指令碼內容如下所示,然後在Gataway節點上執行。執行命令為: sh deploy.sh <masteri_ip> master_password_file。- deploy.sh:指令碼名稱,內容見下面代碼。
- masteri_ip:叢集的master節點的IP,請確保可以訪問。
- master_password_file:儲存master節點的密碼檔案,將master節點的密碼直接寫在檔案內即可。
#!/usr/bin/bash if [ $# != 2 ] then echo "Usage: $0 master_ip master_password_file" exit 1; fi masterip=$1 masterpwdfile=$2 if ! type sshpass >/dev/null 2>&1; then yum install -y sshpass fi if ! type java >/dev/null 2>&1; then yum install -y java-1.8.0-openjdk fi mkdir -p /opt/apps mkdir -p /etc/ecm echo "Start to copy package from $masterip to local gateway(/opt/apps)" echo " -copying hadoop-2.7.2" sshpass -f $masterpwdfile scp -r -o 'StrictHostKeyChecking no' root@$masterip:/usr/lib/hadoop-current /opt/apps/ echo " -copying hive-2.0.1" sshpass -f $masterpwdfile scp -r root@$masterip:/usr/lib/hive-current /opt/apps/ echo " -copying spark-2.1.1" sshpass -f $masterpwdfile scp -r root@$masterip:/usr/lib/spark-current /opt/apps/ echo "Start to link /usr/lib/\${app}-current to /opt/apps/\${app}" if [ -L /usr/lib/hadoop-current ] then unlink /usr/lib/hadoop-current fi ln -s /opt/apps/hadoop-current /usr/lib/hadoop-current if [ -L /usr/lib/hive-current ] then unlink /usr/lib/hive-current fi ln -s /opt/apps/hive-current /usr/lib/hive-current if [ -L /usr/lib/spark-current ] then unlink /usr/lib/spark-current fi ln -s /opt/apps/spark-current /usr/lib/spark-current echo "Start to copy conf from $masterip to local gateway(/etc/ecm)" sshpass -f $masterpwdfile scp -r root@$masterip:/etc/ecm/hadoop-conf /etc/ecm/hadoop-conf sshpass -f $masterpwdfile scp -r root@$masterip:/etc/ecm/hive-conf /etc/ecm/hive-conf sshpass -f $masterpwdfile scp -r root@$masterip:/etc/ecm/spark-conf /etc/ecm/spark-conf echo "Start to copy environment from $masterip to local gateway(/etc/profile.d)" sshpass -f $masterpwdfile scp root@$masterip:/etc/profile.d/hdfs.sh /etc/profile.d/ sshpass -f $masterpwdfile scp root@$masterip:/etc/profile.d/yarn.sh /etc/profile.d/ sshpass -f $masterpwdfile scp root@$masterip:/etc/profile.d/hive.sh /etc/profile.d/ sshpass -f $masterpwdfile scp root@$masterip:/etc/profile.d/spark.sh /etc/profile.d/ if [ -L /usr/lib/jvm/java ] then unlink /usr/lib/jvm/java fi echo "" >>/etc/profile.d/hdfs.sh echo export JAVA_HOME=/usr/lib/jvm/jre-1.8.0 >>/etc/profile.d/hdfs.sh echo "Start to copy host info from $masterip to local gateway(/etc/hosts)" sshpass -f $masterpwdfile scp root@$masterip:/etc/hosts /etc/hosts_bak cat /etc/hosts_bak | grep emr | grep cluster >>/etc/hosts if ! id hadoop >& /dev/null then useradd hadoop fi
- EMR 2.7以下版本,3.2以下版本
建立一個指令碼,指令碼內容如下所示,然後在Gataway節點上執行。執行命令為: sh deploy.sh <masteri_ip> master_password_file。
- deploy.sh:指令碼名稱,內容見下面代碼。
- masteri_ip:叢集的master節點的IP,請確保可以訪問。
- master_password_file:儲存master節點的密碼檔案,將master節點的密碼直接寫在檔案內即可。
!/usr/bin/bash if [ $# != 2 ] then echo "Usage: $0 master_ip master_password_file" exit 1; fi masterip=$1 masterpwdfile=$2 if ! type sshpass >/dev/null 2>&1; then yum install -y sshpass fi if ! type java >/dev/null 2>&1; then yum install -y java-1.8.0-openjdk fi mkdir -p /opt/apps mkdir -p /etc/emr echo "Start to copy package from $masterip to local gateway(/opt/apps)" echo " -copying hadoop-2.7.2" sshpass -f $masterpwdfile scp -r -o 'StrictHostKeyChecking no' root@$masterip:/usr/lib/hadoop-current /opt/apps/ echo " -copying hive-2.0.1" sshpass -f $masterpwdfile scp -r root@$masterip:/usr/lib/hive-current /opt/apps/ echo " -copying spark-2.1.1" sshpass -f $masterpwdfile scp -r root@$masterip:/usr/lib/spark-current /opt/apps/ echo "Start to link /usr/lib/\${app}-current to /opt/apps/\${app}" if [ -L /usr/lib/hadoop-current ] then unlink /usr/lib/hadoop-current fi ln -s /opt/apps/hadoop-current /usr/lib/hadoop-current if [ -L /usr/lib/hive-current ] then unlink /usr/lib/hive-current fi ln -s /opt/apps/hive-current /usr/lib/hive-current if [ -L /usr/lib/spark-current ] then unlink /usr/lib/spark-current fi ln -s /opt/apps/spark-current /usr/lib/spark-current echo "Start to copy conf from $masterip to local gateway(/etc/emr)" sshpass -f $masterpwdfile scp -r root@$masterip:/etc/emr/hadoop-conf /etc/emr/hadoop-conf sshpass -f $masterpwdfile scp -r root@$masterip:/etc/emr/hive-conf /etc/emr/hive-conf sshpass -f $masterpwdfile scp -r root@$masterip:/etc/emr/spark-conf /etc/emr/spark-conf echo "Start to copy environment from $masterip to local gateway(/etc/profile.d)" sshpass -f $masterpwdfile scp root@$masterip:/etc/profile.d/hadoop.sh /etc/profile.d/ if [ -L /usr/lib/jvm/java ] then unlink /usr/lib/jvm/java fi ln -s /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.131-3.b12.el7_3.x86_64/jre /usr/lib/jvm/java echo "Start to copy host info from $masterip to local gateway(/etc/hosts)" sshpass -f $masterpwdfile scp root@$masterip:/etc/hosts /etc/hosts_bak cat /etc/hosts_bak | grep emr | grep cluster >>/etc/hosts if ! id hadoop >& /dev/null then useradd hadoop fi
- EMR 2.7及以上版本,3.2及以上版本
- 測試
- Hive
[hadoop@iZ23bc05hrvZ ~]$ hive hive> show databases; OK default Time taken: 1.124 seconds, Fetched: 1 row(s) hive> create database school; OK Time taken: 0.362 seconds hive>
- 運行Hadoop作業
[hadoop@iZ23bc05hrvZ ~]$ hadoop jar /usr/lib/hadoop-current/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.6.0.jar pi 10 10 Number of Maps = 10 Samples per Map = 10 Wrote input for Map #0 Wrote input for Map #1 Wrote input for Map #2 Wrote input for Map #3 Wrote input for Map #4 Wrote input for Map #5 Wrote input for Map #6 Wrote input for Map #7 Wrote input for Map #8 Wrote input for Map #9 File Input Format Counters Bytes Read=1180 File Output Format Counters Bytes Written=97 Job Finished in 29.798 seconds Estimated value of Pi is 3.20000000000000000000
- Hive