#
Apache Ambari是對Hadoop進行監控、管理和生命周期管理的開源項目。它也是一個為Hortonworks數據平臺選擇管理組建的項目。Ambari向Hadoop MapReduce、HDFS、 HBase、Pig, Hive、HCatalog以及Zookeeper提供服務。最近準備裝ambari,在網上找了許久,沒找到比較系統的ambari安裝過程,于是,就根據官網進行了安裝,下面是我推薦的正確的較完善的安裝方式,希望對大家有所幫助。
一、準備工作
1、系統:我的系統是CentOS6.2,x86_64,本次集群采用兩個節點。管理節點:192.168.10.121;客戶端節點:192.168.10.122
2、系統最好配置能上網,這樣方便后面的操作,否則需要配置yum倉庫,比較麻煩。
3、集群中ambari-serveer(管理節點)到客戶端配置無密碼登錄。
4、集群同步時間
5、SELinux,iptables都處于關閉狀態。
6、ambari版本:1.2.0
二、安裝步驟
A、配置好集群環境
############ 配置無密碼登錄 #################
[root@ccloud121 ~]# ssh-keygen -t dsa
[root@ccloud121 ~]# cat /root/.ssh/id_dsa.pub >> /root/.ssh/authorized_keys
[root@ccloud121 ~]# scp /root/.ssh/id_dsa.pub 192.168.10.122:/root/
[root@ccloud121 ~]# ssh 192.168.10.122
[root@ccloud122 ~]# cat /root/.ssh/id_dsa.pub >> /root/.ssh/authorized_keys
############# NTP 時間同步 #################
[root@ccloud121 ~]# ntpdate time.windows.com
[root@ccloud121 ~]# ssh ccloud122 ntpdate time.windows.com
########### SELinux & iptables 關閉 ###########
[root@ccloud121 ~]# setenforce 0
[root@ccloud121 ~]# ssh ccloud122 setenforce 0
[root@ccloud121 ~]# chkconfig iptables off
[root@ccloud121 ~]# service iptables stop
[root@ccloud121 ~]# ssh ccloud122 chkconfig iptables off
[root@ccloud121 ~]# ssh ccloud122 service iptables stop
B、管理節點上安裝ambari-server
1、下載repo文件
[root@ccloud121 ~]# wget http://public-repo-1.hortonworks.com/AMBARI-1.x/repos/centos6/ambari.repo
[root@ccloud121 ~]# cp ambari.repo /etc/yum.repos.d
這樣,ambari-server的yum倉庫就做好了。
2、安裝epel倉庫
[root@ccloud121 ~]# yum install epel-release # 查看倉庫列表,應該有HDP,EPEL [root@ccloud121 ~]# yum repolist
3、通過yum安裝amabari bits,這同時也會安裝PostgreSQL
[root@ccloud121 ~]# yum install ambari-server
這個步驟要等一會,它需要上網下載,大概39M左右。
4、運行ambari-server setup,安裝ambari-server,它會自動安裝配置PostgreSQL,同時要求輸入用戶名和密碼,如果按n,它用默認的用戶名/密碼值:ambari-server/bigdata。接著就開始下載安裝JDK。安裝完成后,ambari-server就可以啟動了。
三、集群啟動
1、直接接通過ambari-server start和amabari-server stop即可啟動和關閉ambari-serveer。
2、啟動成功后,在瀏覽器輸入http://192.168.10.121:8080
界面如下圖所示:

登錄名和密碼都是admin。
這樣就可以登錄到管理控制臺。

下面將介紹大數據領域支持Java的主流開源工具:

1. HDFS
HDFS是Hadoop應用程序中主要的分布式儲存系統, HDFS集群包含了一個NameNode(主節點),這個節點負責管理所有文件系統的元數據及存儲了真實數據的DataNode(數據節點,可以有很多)。HDFS針對海量數據所設計,所以相比傳統文件系統在大批量小文件上的優化,HDFS優化的則是對小批量大型文件的訪問和存儲。

2. MapReduce
Hadoop MapReduce是一個軟件框架,用以輕松編寫處理海量(TB級)數據的并行應用程序,以可靠和容錯的方式連接大型集群中上萬個節點(商用硬件)。

3. HBase
Apache HBase是Hadoop數據庫,一個分布式、可擴展的大數據存儲。它提供了大數據集上隨機和實時的讀/寫訪問,并針對了商用服務器集群上的大型表格做出優化——上百億行,上千萬列。其核心是Google Bigtable論文的開源實現,分布式列式存儲。就像Bigtable利用GFS(Google File System)提供的分布式數據存儲一樣,它是Apache Hadoop在HDFS基礎上提供的一個類Bigatable。

4. Cassandra
Apache Cassandra是一個高性能、可線性擴展、高有效性數據庫,可以運行在商用硬件或云基礎設施上打造完美的任務關鍵性數據平臺。在橫跨數據中心的復制中,Cassandra同類最佳,為用戶提供更低的延時以及更可靠的災難備份。通過log-structured update、反規范化和物化視圖的強支持以及強大的內置緩存,Cassandra的數據模型提供了方便的二級索引(column indexe)。

5. Hive
Apache Hive是Hadoop的一個數據倉庫系統,促進了數據的綜述(將結構化的數據文件映射為一張數據庫表)、即席查詢以及存儲在Hadoop兼容系統中的大型數據集分析。Hive提供完整的SQL查詢功能——HiveQL語言,同時當使用這個語言表達一個邏輯變得低效和繁瑣時,HiveQL還允許傳統的Map/Reduce程序員使用自己定制的Mapper和Reducer。

6. Pig
Apache Pig是一個用于大型數據集分析的平臺,它包含了一個用于數據分析應用的高級語言以及評估這些應用的基礎設施。Pig應用的閃光特性在于它們的結構經得起大量的并行,也就是說讓它們支撐起非常大的數據集。Pig的基礎設施層包含了產生Map-Reduce任務的編譯器。Pig的語言層當前包含了一個原生語言——Pig Latin,開發的初衷是易于編程和保證可擴展性。

7. Chukwa
Apache Chukwa是個開源的數據收集系統,用以監視大型分布系統。建立于HDFS和Map/Reduce框架之上,繼承了Hadoop的可擴展性和穩定性。Chukwa同樣包含了一個靈活和強大的工具包,用以顯示、監視和分析結果,以保證數據的使用達到最佳效果。

8. Ambari
Apache Ambari是一個基于web的工具,用于配置、管理和監視Apache Hadoop集群,支持Hadoop HDFS,、Hadoop MapReduce、Hive、HCatalog,、HBase、ZooKeeper、Oozie、Pig和Sqoop。Ambari同樣還提供了集群狀況儀表盤,比如heatmaps和查看MapReduce、Pig、Hive應用程序的能力,以友好的用戶界面對它們的性能特性進行診斷。

9. ZooKeeper
Apache ZooKeeper是一個針對大型分布式系統的可靠協調系統,提供的功能包括:配置維護、命名服務、分布式同步、組服務等。ZooKeeper的目標就是封裝好復雜易出錯的關鍵服務,將簡單易用的接口和性能高效、功能穩定的系統提供給用戶。

10. Sqoop
Sqoop是一個用來將Hadoop和關系型數據庫中的數據相互轉移的工具,可以將一個關系型數據庫中數據導入Hadoop的HDFS中,也可以將HDFS中數據導入關系型數據庫中。

11. Oozie
Apache Oozie是一個可擴展、可靠及可擴充的工作流調度系統,用以管理Hadoop作業。Oozie Workflow作業是活動的Directed Acyclical Graphs(DAGs)。Oozie Coordinator作業是由周期性的Oozie Workflow作業觸發,周期一般決定于時間(頻率)和數據可用性。Oozie與余下的Hadoop堆棧結合使用,開箱即用的支持多種類型Hadoop作業(比如:Java map-reduce、Streaming map-reduce、Pig、 Hive、Sqoop和Distcp)以及其它系統作業(比如Java程序和Shell腳本)。

12. Mahout
Apache Mahout是個可擴展的機器學習和數據挖掘庫,當前Mahout支持主要的4個用例:
- 推薦挖掘:搜集用戶動作并以此給用戶推薦可能喜歡的事物。
- 聚集:收集文件并進行相關文件分組。
- 分類:從現有的分類文檔中學習,尋找文檔中的相似特征,并為無標簽的文檔進行正確的歸類。
- 頻繁項集挖掘:將一組項分組,并識別哪些個別項會經常一起出現。

13. HCatalog
Apache HCatalog是Hadoop建立數據的映射表和存儲管理服務,它包括:
- 提供一個共享模式和數據類型機制。
- 提供一個抽象表,這樣用戶就不需要關注數據存儲的方式和地址。
- 為類似Pig、MapReduce及Hive這些數據處理工具提供互操作性。
Centos集群服務器,公網ip
服務器地址
master: mypetsbj.xicp.net:13283
slave1 : mypetsbj.xicp.net:13282
slave2 : mypetsbj.xicp.net:13286
服務器開機時間
08:00 到 23:59
opt/hadoop
用戶名/密碼hadoop/wzp
摘要: 處理流程:
假設有一份要傳輸的文檔
使用某一指定算法將此文檔內容進行計算,得出一字符串,稱為“摘要”
使用私鑰將此摘要進行加密,得出一字符串,稱為“簽名”
將私鑰對應的公鑰、摘要和簽名一同發給對方
對方用公鑰對簽名進行解密,得出一字符串,與摘要對比,看是否符合,如符合,則證明對方身份確認...
閱讀全文
WINDOWS版:
@ECHO OFF
REM @ECHO STARTUP App
REM @ECHO 設置環境變量,循環當前目錄下的lib目錄下所有jar文件,并設置CLASSPATH
FOR %%F IN (lib\*.jar) DO call :addcp %%F
goto extlibe
:addcp
SET CLASSPATH=%CLASSPATH%;%1
goto :eof
:extlibe
REM @ECHO 當前目錄下的bin目錄為class文件存放目錄,設置bin目錄到CLASSPATH中
SET CLASSPATH=%CLASSPATH%;bin\
REM @ECHO 顯示CLASSPATH
REM SET CLASSPATH
REM @ECHO 運行應用程序
REM JAVA com.paul.socket.charge.client.ClientJFrame
start javaw com.paul.socket.charge.client.ClientJFrame
LINUX版:
#!/bin/sh
classpath=".:../classes/:../lib/*"
hdfs_input=hadoop/input
hdfs_output=hadoop/output0
mainclass=main.WordFinderMain
classesfolder=/job/classes
java -cp $classpath $mainclass $hdfs_input $hdfs_output $classesfolder
執行腳本:
PIGGYBANK_PATH=$PIG_HOME/contrib/piggybank/java/piggybank.jar
INPUT=pig/input/test-pig-full.txt
OUTPUT=pig/output/test-pig-output-$(date +%Y%m%d%H%M%S)
PIGSCRIPT=analyst_status_logs.pig
#analyst_500_404_month.pig
#analyst_500_404_day.pig
#analyst_404_percentage.pig
#analyst_500_percentage.pig
#analyst_unique_path.pig
#analyst_user_logs.pig
#analyst_status_logs.pig
pig -p PIGGYBANK_PATH=$PIGGYBANK_PATH -p INPUT=$INPUT -p OUTPUT=$OUTPUT $PIGSCRIPT
要分析的數據源,LOG 文件
46.20.45.18 - - [25/Dec/2012:23:00:25 +0100] "GET / HTTP/1.0" 302 - "-" "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)" "-" "-" 46.20.45.18 "" 11011AEC9542DB0983093A100E8733F8 0
46.20.45.18 - - [25/Dec/2012:23:00:25 +0100] "GET /sign-in.jspx HTTP/1.0" 200 3926 "-" "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)" "-" "-" 46.20.45.18 "" 11011AEC9542DB0983093A100E8733F8 0
69.59.28.19 - - [25/Dec/2012:23:01:25 +0100] "GET / HTTP/1.0" 302 - "-" "Pingdom.com_bot_version_1.4_(http://www.pingdom.com/)" "-" "-" 69.59.28.19 "" 36D80DE7FE52A2D89A8F53A012307B0A 15
PIG腳本:
--注冊JAR包,因為要用到DateExtractor
register '$PIGGYBANK_PATH';
--聲明一個短函數名
DEFINE DATE_EXTRACT_MM
org.apache.pig.piggybank.evaluation.util.apachelogparser.DateExtractor('yyyy-MM');
DEFINE DATE_EXTRACT_DD
org.apache.pig.piggybank.evaluation.util.apachelogparser.DateExtractor('yyyy-MM-dd');
-- pig/input/test-pig-full.txt
--把數據從變量所指的文件加載到PIG中,并定義數據列名,此時的數據集為數組(a,b,c)
raw_logs = load '$INPUT' USING org.apache.pig.piggybank.storage.MyRegExLoader('^(\\S+) (\\S+) (\\S+) \\[([\\w:/]+\\s[+\\-]\\d{4})\\] "(\\S+) (\\S+) (HTTP[^"]+)" (\\S+) (\\S+) "([^"]*)" "([^"]*)" "(\\S+)" "(\\S+)" (\\S+) "(.*)" (\\S+) (\\S+)')
as (remoteAddr: chararray,
n2: chararray,
n3: chararray,
time: chararray,
method: chararray,
path:chararray,
protocol:chararray,
status: int,
bytes_string: chararray,
referrer: chararray,
browser: chararray,
n10:chararray,
remoteLogname: chararray,
remoteAddr12: chararray,
path2: chararray,
sessionid: chararray,
n15: chararray
);
--過濾數據
filter_logs = FILTER raw_logs BY not (browser matches '.*pingdom.*');
--item_logs = FOREACH raw_logs GENERATE browser;
--percent 500 logs
--重定義數據項,數據集只取2項status,month
reitem_percent_500_logs = FOREACH filter_logs GENERATE status,DATE_EXTRACT_MM(time) as month;
--分組數據集,此時的數據結構為MAP(a{(aa,bb,cc),(dd,ee,ff)},b{(bb,cc,dd),(ff,gg,hh)})
group_month_percent_500_logs = GROUP reitem_percent_500_logs BY (month);
--重定義分組數據集數據項,進行分組統計,此時要聯合分組數據集和原數據集統計
final_month_500_logs = FOREACH group_month_percent_500_logs
{
--對原數據集做count,因為是在foreachj里做count的,即使是對原數據集,也會自動會加month==group的條件
--從這里可以看出對于group里的數據集,完全沒用到
--這時是以每一行為單位的,統計MAP中的KEY-a對應的數組在原數據集中的個數
total = COUNT(reitem_percent_500_logs);
--對原數據集做filter,因為是在foreachj里做count的,即使是對原數據集,也會自動會加month==group的條件
--重新過濾一下原數據集,得到status==500,month==group的數據集
t = filter reitem_percent_500_logs by status== 500; --create a bag which contains only T values
--重定義數據項,取group,統計結果
generate flatten(group) as col1, 100*(double)COUNT(t)/(double)total;
}
STORE final_month_500_logs into '$OUTPUT' using PigStorage(',');
I am using JAXB and I have a large set of data which i have to marshal into a xml.Since marshalling the whole thing into xml in a single step will be using most of the memory , i want to split it into parts and write to the xml file incremently
For example if my generated output xml should be like this:
<Employees>
<employee>......</employee>
<employee>.....</employee>
<employee>.....</employee>
<employee>.....</employee>
..
...
..
</Employees>
I would like to write the <employee> sections separately into a file instead of writing the whole thing together.I am retrieving the employee details from the database and converting to xml.There are almost 8 lakh records.So marshalling the whole thing in single step will use up my memory.How can i do it?????
Use Stax API (XMLStreamWriter) as the underlying XML processing thing;
write <Employees> tag using that, and then pass XMLStreamWriter to
JAXB Marshaller, marshall employee by employee.
This is the pattern I use; similarly works well with unmarshalling.
Not sure if this is in FAQ or not, but it probably should be.
http://wiki.apache.org/pig/ParameterSubstitution
%pig -param input=/user/paul/sample.txt -param output=/user/paul/output/
PIG中獲取
records = LOAD $input;
PIG中的LOAD函數,可以在LOAD數據的同時,進行正則表達式的篩選。
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the
* NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF
* licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
package org.apache.pig.piggybank.storage.apachelog;
import java.util.regex.Pattern;
import org.apache.pig.piggybank.storage.RegExLoader;
/**
* CombinedLogLoader is used to load logs based on Apache's combined log format, based on a format like
*
* LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
*
* The log filename ends up being access_log from a line like
*
* CustomLog logs/combined_log combined
*
* Example:
*
* raw = LOAD 'combined_log' USING org.apache.pig.piggybank.storage.apachelog.CombinedLogLoader AS
* (remoteAddr, remoteLogname, user, time, method, uri, proto, status, bytes, referer, userAgent);
*
*/
public class CombinedLogLoader extends RegExLoader {
// 1.2.3.4 - - [30/Sep/2008:15:07:53 -0400] "GET / HTTP/1.1" 200 3190 "-"
// "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_4; en-us) AppleWebKit/525.18 (KHTML, like Gecko) Version/3.1.2 Safari/525.20.1"
private final static Pattern combinedLogPattern = Pattern
.compile("^(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+.(\\S+\\s+\\S+).\\s+\"(\\S+)\\s+(.+?)\\s+(HTTP[^\"]+)\"\\s+(\\S+)\\s+(\\S+)\\s+\"([^\"]*)\"\\s+\"(.*)\"$");
public Pattern getPattern() {
return combinedLogPattern;
}
}