hadoop 集羣一共有4種部署模式,詳見《hadoop 生態圈介紹》。 僞分佈式模式將hadoop安裝在一臺機器上,一般用來用做實驗、開發和調試用。html
全部四種模式的部署指南見:java
Hadoop 僞分佈式搭建指南node
Hadoop 徹底分佈式搭建指南linux
Hadoop HA+Federation(聯邦)模式搭建指南apache
Ubuntu 14.04 x64 Server LTS
Hadoop 2.7.2
vagrant 模擬一臺主機,內存爲4Gvim
IP | 主機名 | 角色描述 |
---|---|---|
192.168.100.201 | h01.vm.com | 主節點, NameNode, Secondary-NameNode, (yarn)ResourceManager, job-history-server |
另,以上節點都同時是 slave從節點,即 datanode。運行Namenode和ResourceManager的節點即爲主節點。centos
sudo apt-get update
sudo apt-get install ssh sudo apt-get install rsync
sudo vim /etc/hostname # centos系統可能沒有該文件,建立便可 h01.vm.com # 該節點主機名
將該文件內容修改成對應的主機名,例如 h01.vm.combash
sudo vim /etc/hosts 192.168.100.201 h01.vm.com h01
# 先在其中一臺機子操做,後面會使用 scp 命令或者其餘方法同步到其餘主機 mkdir -p /home/vagrant/VMBigData/hadoop /home/vagrant/VMBigData/java tar zxf jdk-7u79-linux-x64.tar.gz -C /home/vagrant/VMBigData/java tar zxf hadoop-2.7.2.tar.gz -C /home/vagrant/VMBigData/hadoop
ln -s /home/vagrant/VMBigData/java/jdk1.7.0_79/ /home/vagrant/VMBigData/java/default ln -s /home/vagrant/VMBigData/hadoop/hadoop-2.7.2/ /home/vagrant/VMBigData/hadoop/default
sudo vim /etc/profile export HADOOP_HOME=/home/vagrant/VMBigData/hadoop/default export JAVA_HOME=/home/vagrant/VMBigData/java/default export PATH=$JAVA_HOME/bin:$HADOOP_HOME/bin:$PATH source /etc/profile
hadoop主節點須要能遠程登錄集羣內的全部節點(包括本身),以執行命令。因此須要配置免密碼的ssh登錄。可選的ssh祕鑰對生成方式有rsa和dsa兩種,這裏選擇rsa。服務器
ssh-keygen -t rsa -C "youremail@xx.com" # 注意在接下來的命令行交互中,直接按回車跳過輸入密碼
ssh-copy-id vagrant@h01.vm.com # vagrant是遠程主機用戶名
!!! 注意使用rsa模式生成密鑰對時,不要輕易覆蓋原來已有的,肯定無影響時方可覆蓋 !!!
在 slaves 文件中配置的主機即爲從節點,將自動運行datanode服務
vim /home/vagrant/VMBigData/hadoop/default/etc/hadoop/slaves h01.vm.com
mkdir -p /home/vagrant/VMBigData/hadoop/data/hdfs/tmp mkdir -p /home/vagrant/VMBigData/hadoop/data/pid mkdir -p /home/vagrant/VMBigData/hadoop/data/namenode mkdir -p /home/vagrant/VMBigData/hadoop/data/namesecondary mkdir -p /home/vagrant/VMBigData/hadoop/data/datanode1 mkdir -p /home/vagrant/VMBigData/hadoop/data/datanode2 mkdir -p /home/vagrant/VMBigData/hadoop/data/local-dirs mkdir -p /home/vagrant/VMBigData/hadoop/data/log-dirs
vim /home/vagrant/VMBigData/hadoop/default/etc/hadoop/hadoop-env.sh # export JAVA_HOME=${JAVA_HOME} # 注意註釋掉原來的這行 export JAVA_HOME=/home/vagrant/VMBigData/java/default export HADOOP_PREFIX=/home/vagrant/VMBigData/hadoop/default # export HADOOP_PID_DIR=${HADOOP_PID_DIR} # 注意註釋掉原來的這行 export HADOOP_PID_DIR=/home/vagrant/VMBigData/hadoop/data/hdfs/pid export YARN_PID_DIR=/home/vagrant/VMBigData/hadoop/data/hdfs/pid # export HADOOP_SECURE_DN_PID_DIR=${HADOOP_PID_DIR} # 注意註釋掉原來的這行 export HADOOP_SECURE_DN_PID_DIR=${HADOOP_PID_DIR}
vim /home/vagrant/VMBigData/hadoop/default/etc/hadoop/mapred-env.sh export HADOOP_MAPRED_PID_DIR=/home/vagrant/VMBigData/hadoop/data/hdfs/pid
<?xml version="1.0" encoding="utf-8"?> <configuration> <!-- 指定hdfs的nameservice爲h01 --> <property> <name>fs.defaultFS</name> <value>hdfs://h01.vm.com:9000</value> </property> <!-- 指定hadoop數據存儲目錄 --> <property> <name>hadoop.tmp.dir</name> <value>/home/vagrant/VMBigData/hadoop/data/hdfs/tmp</value> </property> </configuration>
<?xml version="1.0" encoding="utf-8"?> <configuration> <property> <name>dfs.replication</name> <!-- 單機版的通常設爲1,如果集羣,通常設爲3 --> <value>1</value> </property> <property> <name>dfs.namenode.name.dir</name> <!-- 建立的namenode文件夾位置,若有多個用逗號隔開。配置多個的話,每個目錄下數據都是相同的,達到數據冗餘備份的目的 --> <value>file:///home/vagrant/VMBigData/hadoop/data/namenode</value> </property> <property> <name>dfs.datanode.data.dir</name> <!-- 建立的datanode文件夾位置,多個用逗號隔開,實際不存在的目錄會被忽略 --> <value>file:///home/vagrant/VMBigData/hadoop/data/datanode1,file:///home/vagrant/VMBigData/hadoop/data/datanode2</value> </property> <!-- 配置Secondary NameNode在本節點上 --> <property> <name>dfs.http.address</name> <value>h01.vm.com:50070</value> <description>Secondary get fsimage and edits via dfs.http.address</description> </property> <property> <name>dfs.secondary.http.address</name> <value>h01.vm.com:50090</value> </property> <property> <name>dfs.namenode.checkpoint.dir</name> <value>file:///home/vagrant/VMBigData/hadoop/data/hdfs/namesecondary</value> </property> </configuration>
<?xml version="1.0" encoding="utf-8"?> <configuration> <property> <name>yarn.resourcemanager.hostname</name> <value>h01.vm.com</value> </property> <property> <name>yarn.log-aggregation-enable</name> <!-- 打開日誌聚合功能,這樣才能從web界面查看日誌 --> <value>true</value> </property> <property> <name>yarn.log-aggregation.retain-seconds</name> <!-- 聚合日誌最長保留時間 --> <value>86400</value> </property> <property> <name>yarn.nodemanager.resource.memory-mb</name> <!-- NodeManager總的可用內存,這個要根據實際狀況合理配置 --> <value>1024</value> </property> <property> <name>yarn.scheduler.minimum-allocation-mb</name> <!-- MapReduce做業時,每一個task最少可申請內存 --> <value>256</value> </property> <property> <name>yarn.scheduler.maximum-allocation-mb</name> <!-- MapReduce做業時,每一個task最多可申請內存 --> <value>512</value> </property> <property> <name>yarn.nodemanager.vmem-pmem-ratio</name> <!-- 可申請使用的虛擬內存,相對於實際使用內存大小的倍數。實際生產環境中可設置的大一些,如4.2 --> <value>2.1</value> </property> <property> <name>yarn.nodemanager.vmem-check-enabled</name> <value>false</value> </property> <property> <name>yarn.nodemanager.local-dirs</name> <!-- 中間結果存放位置。注意,這個參數一般會配置多個目錄,已分攤磁盤IO負載。 --> <value>/home/vagrant/VMBigData/hadoop/data/localdir1,/home/vagrant/VMBigData/hadoop/data/localdir2</value> </property> <property> <name>yarn.nodemanager.log-dirs</name> <!-- 日誌存放位置。注意,這個參數一般會配置多個目錄,已分攤磁盤IO負載。 --> <value>/home/vagrant/VMBigData/hadoop/data/logdir1,/home/vagrant/VMBigData/hadoop/data/logdir2</value> </property> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <property> <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name> <value>org.apache.hadoop.mapred.ShuffleHandler</value> </property> </configuration>
<?xml version="1.0" encoding="utf-8"?> <configuration> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property> <property> <name>yarn.app.mapreduce.am.resource.mb</name> <!-- 默認值爲 1536,可根據須要調整,調小一些也是可接受的 --> <value>512</value> </property> <property> <name>mapreduce.map.memory.mb</name> <!-- 每一個map task申請的內存,每一次都會實際申請這麼多 --> <value>384</value> </property> <property> <name>mapreduce.map.java.opts</name> <!-- 每一個map task中的child jvm啓動時參數,須要比 mapreduce.map.memory.mb 設置的小一些 --> <!-- 注意:map任務裏不必定跑java,可能跑非java(如streaming) --> <value>-Xmx256m</value> </property> <property> <name>mapreduce.reduce.memory.mb</name> <value>384</value> </property> <property> <name>mapreduce.reduce.java.opts</name> <value>-Xmx256m</value> </property> <property> <name>mapreduce.tasktracker.map.tasks.maximum</name> <value>2</value> </property> <property> <name>mapreduce.tasktracker.reduce.tasks.maximum</name> <value>2</value> </property> <property> <name>mapred.child.java.opts</name> <!-- 默認值爲 -Xmx200m,生產環境能夠設大一些 --> <value>-Xmx384m</value> </property> <property> <name>mapreduce.task.io.sort.mb</name> <!-- 任務內部排序緩衝區大小 --> <value>128</value> </property> <property> <name>mapreduce.task.io.sort.factor</name> <!-- map計算徹底後的merge階段,一次merge時最多可有多少個輸入流 --> <value>100</value> </property> <property> <name>mapreduce.reduce.shuffle.parallelcopies</name> <!-- reuduce shuffle階段並行傳輸數據的數量 --> <value>50</value> </property> <property> <name>mapreduce.jobhistory.address</name> <value>h01.vm.com:10020</value> </property> <property> <name>mapreduce.jobhistory.webapp.address</name> <value>h01.vm.com:19888</value> </property> </configuration>
hdfs namenode -format
!!! 注意僅在首次啓動時執行,由於此命令會刪除hadoop集羣全部的數據 !!!
啓動和中止NameNode守護進程
cd /home/vagrant/VMBigData/hadoop/default sbin/hadoop-daemon.sh --script hdfs start namenode sbin/hadoop-daemon.sh --script hdfs stop namenode
啓動和中止全部從節點的DataNode守護進程
cd /home/vagrant/VMBigData/hadoop/default sbin/hadoop-daemon.sh --script hdfs start datanode sbin/hadoop-daemon.sh --script hdfs stop datanode
啓動和中止ResourceManager守護進程
cd /home/vagrant/VMBigData/hadoop/default sbin/yarn-daemon.sh start resourcemanager sbin/yarn-daemon.sh stop resourcemanager
啓動和中止全部從節點的NodeManager守護進程
cd /home/vagrant/VMBigData/hadoop/default sbin/yarn-daemon.sh start nodemanager sbin/yarn-daemon.sh stop nodemanager
啓動和中止MapReduce JobHistory Server
cd /home/vagrant/VMBigData/hadoop/default sbin/mr-jobhistory-daemon.sh start historyserver sbin/mr-jobhistory-daemon.sh stop historyserver
cd /home/vagrant/VMBigData/hadoop/default sbin/start-dfs.sh sbin/stop-dfs.sh
cd /home/vagrant/VMBigData/hadoop/default sbin/start-yarn.sh sbin/stop-yarn.sh
cd /home/vagrant/VMBigData/hadoop/default sbin/mr-jobhistory-daemon.sh start historyserver sbin/mr-jobhistory-daemon.sh stop historyserver
NameNode http://192.168.100.201:50070
Secondary NameNode http://192.168.100.201:50090
ResourceManager http://192.168.100.201:8088
MapReduce JobHistory Server http://192.168.100.201:19888
Datanode http://192.168.100.201:50075
集羣狀態 hdfs dfsadmin -report
hadoop進程 jps