1. 程式人生 > >ambari 2.7 編譯與安裝

ambari 2.7 編譯與安裝

1.環境準備

安裝好JDK,maven,ant,postgresql,以及nodejs,npm和bower。參見博主的相關部落格。注意部分元件的下載需要科學上網。

安裝rpm,rpm-build,git

sudo yum install rpm
sudo yum install -y rpm-build.x86_64
sudo yum install git

安裝gcc,python環境,包管理工具以及依賴項

sudo yum install gcc
sudo yum install gcc-c++
sudo yum -y install python-devel

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo -H python get-pip.py
sudo -H pip install psutil

安裝docker虛擬化工具,與配套的weave等網路工具,其中weave建議放置於/usr/bin下,避免使用sudo許可權執行時提示找不到命令。

sudo yum install docker
sudo curl -L git.io/weave -o /usr/bin/weave
sudo chmod a+x /usr/local/bin/weave

補充知識:repo檔案是Fedora中yum源(軟體倉庫)的配置檔案,通常一個repo檔案定義了一個或者多個軟體倉庫的細節內容,例如我們將從哪裡下載需要安裝或者升級的軟體包,repo檔案中的設定內容將被yum讀取和應用。

2.下載所需檔案

wget http://mirrors.hust.edu.cn/apache/ambari/ambari-2.7.0/apache-ambari-2.7.0-src.tar.gz
tar xfvz apache-ambari-2.7.0-src.tar.gz

使用mvn設定版本,

cd apache-ambari-2.7.0-src
mvn versions:set -DnewVersion=2.7.0.0.0

mvn不僅會設定版本,而且會自動下載相關的依賴,進行編譯,提示 BUILD SUCCESS 即為成功。

然後設定ambari-metrics的版本。

pushd ambari-metrics
mvn versions:set -DnewVersion=2.7.0.0.0
popd

3.進行編譯

在centos中使用下面的命令進行編譯

mvn -B clean install rpm:rpm -DnewVersion=2.7.0.0.0 -DbuildNumber=631319b00937a8d04667d93714241d2a0cb17275 -DskipTests -Dpython.ver="python >= 2.6"

在ubuntu中使用下面的命令進行編譯

mvn -B clean install jdeb:jdeb -DnewVersion=2.7.0.0.0 -DbuildNumber=631319b00937a8d04667d93714241d2a0cb17275 -DskipTests -Dpython.ver="python >= 2.6"

mvn clean install是一個整合的命令,包括如下步驟

使用清理外掛:maven-clean-plugin:執行清理刪除已有target目錄;
使用資源外掛:maven-resources-plugin:執行資原始檔的處理;
使用編譯外掛:maven-compiler-plugin:編譯所有原始檔生成class檔案至target\classes目錄下;
使用資源外掛:maven-resources-plugin:執行測試資原始檔的處理;
使用編譯外掛:maven-compiler-plugin:編譯測試目錄下的所有原始碼;
使用外掛:maven-surefire-plugin:執行測試用例;
使用外掛:maven-jar-plugin:2.4對編譯後生成的檔案進行打包,包名稱預設為:artifactId-version。

-B引數:該引數表示讓Maven使用批處理模式構建專案,能夠避免一些需要人工參與互動而造成的掛起狀態。

如果每次編譯報錯之後重新編譯提示,則在命令中加上 -Drat.skip=true

mvn -B clean install rpm:rpm -DnewVersion=2.7.0.0.0 -DbuildNumber=631319b00937a8d04667d93714241d2a0cb17275 -DskipTests -Dpython.ver="python >= 2.6" -Drat.skip=true

提示BUILD SUCCESS  並且所有子項也為SUCCESS,文末附有常見編譯錯誤及解決方案

4.進行安裝

進入編譯生成的檔案目錄,具體的隨環境有些差異,類似的:

ambari-server/target/rpm/ambari-server/RPMS/noarch/

ambari-server/target/rpm/ambari-server/RPMS/x86_64

sudo yum install ambari-server*.rpm

配置需要的postgresql資料庫,命令如下,如此設定使用者名稱和密碼是為了和ambari的預設設定一致。

sudo su - postgres
psql
CREATE USER ambari WITH PASSWORD 'bigdata';
CREATE DATABASE ambari OWNER ambari;
GRANT ALL PRIVILEGES ON DATABASE ambari to ambari;

安裝成功後,進入設定

ambari-server setup

會詢問較多的問題,英文表述也很明確,關鍵的問題摘錄如下:

 Checking JDK...Do you want to change Oracle JDK [y/n] (n)? y

設定JDK,選擇Custom JDK並輸入$JAVA_HOME的值。

Configuring database...==============================================================================
Choose one of the following options:

設定資料庫,選擇[4] - PostgreSQL,並填寫之前設定的使用者名稱密碼,預設值一致的無需更改。

配置完成後,登入postgres資料庫,建立ambari所需的表,執行

\i /var/lib/ambari-server/resources/Ambari-DDL-Postgres-CREATE.sql;

4.啟動ambari

sudo ambari-server start

日誌地址與成功資訊如下:

Server PID at: /var/run/ambari-server/ambari-server.pid
Server out at: /var/log/ambari-server/ambari-server.out
Server log at: /var/log/ambari-server/ambari-server.log
Waiting for server start..............................
Server started listening on 8080

DB configs consistency check found warnings. See /var/log/ambari-server/ambari-server-check-database.log for more details.
Ambari Server 'start' completed successfully.

成功啟動後在瀏覽器輸入Ambari地址:http://localhost:8080/

常見錯誤:

1.Failed to execute goal org.codehaus.mojo:rpm-maven-plugin:2.0.1:rpm (default-cli) on project ambari: RPM build execution returned: '127' executing '/bin/sh -c cd /home/hadoop/apache-ambari-2.5.0-src/target/rpm/ambari/SPECS && rpmbuild -bb --buildroot /home/hadoop/apache-ambari-2.5.0-src/target/rpm/ambari/buildroot --define '_topdir /home/hadoop/apache-ambari-2.5.0-src/target/rpm/ambari' --target noarch-redhat-linux ambari.spec' -> [Help 1]

原因是rpm和rpm未安裝,參加步驟1進行安裝。

2.Failed to execute goal au.com.alderaan:eclipselink-staticweave-maven-plugin:1.0.4:weave (default) on project ambari-server: eclipselink-staticweave-maven NullPointerException

原因是java版本過高,建議使用java8

3.The parameters 'group' for goal org.codehaus.mojo:rpm-maven-plugin:2.1.4:rpm are missing or invalid

原因是pom檔案缺少相關的依賴,在外掛中加入下面的專案

	  <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>rpm-maven-plugin</artifactId>
        <version>2.2.0</version>
        <executions>
          <execution>
            <id>generate-rpm</id>
            <goals>
              <goal>rpm</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <license>GPL (c) 2005, SWWDC</license>
          <distribution>Trash 2005</distribution>
          <group>Application/Collectors</group>
		</configuration>
      </plugin>

4.Could not resolve dependencies for project org.apache.ambari:ambari-server:jar:2.2.1.1:

原因是版本號設定不對,進入子專案手動設定,並且重新編譯該完整子目錄,例如Ambari Logsearch Log Feeder編譯出錯,需要設定Ambari Logsearch Log並從此處開始編譯,可以使用 -rf 恢復 -U強制重新解析 pom

pushd ambari-logsearch
mvn versions:set -DnewVersion=2.7.0.0.0
popd

5./src/main/java/org/apache/ambari/logfeeder/metrics/LogFeederAMSClient.java:[102,3] method does not override or implement a method from a supertype

原因是自動下載的jar包版本不對,重新設定該項的版本。

6.[ERROR] Failed to execute goal on project ambari-metrics-kafka-sink: Could not resolve dependencies for project org.apache.ambari:ambari-metrics-kafka-sink:jar:2.0.0-0: The following artifacts could not be resolved: javax.jms:jms:jar:1.1, com.sun.jdmk:jmxtools:jar:1.2.1, com.sun.jmx:jmxri:jar:1.2.1: Could not transfer artifact javax.jms:jms:jar:1.1 from/to java.net (https://maven-repository.dev.java.net/nonav/repository): No connector available to access repository java.net (https://maven-repository.dev.java.net/nonav/repository) of type legacy using the available factories WagonRepositoryConnectorFactory

原因是缺少元件

The work around is to manually install the three missing artifacts:

mvn install:install-file -Dfile=jms-1.1.pom -DgroupId=javax.jms -DartifactId=jms -Dversion=1.1 -Dpackaging=jar
mvn install:install-file -Dfile=jmxtools-1.2.1.pom -DgroupId=com.sun.jdmk -DartifactId=jmxtools -Dversion=1.2.1 -Dpackaging=jar
mvn install:install-file -Dfile=jmxri-1.2.1.pom -DgroupId=com.sun.jmx -DartifactId=jmxri -Dversion=1.2.1 -Dpackaging=jar
參見:https://cwiki.apache.org/confluence/display/AMBARI/Installation+Guide+for+Ambari+2.7.0