Hadoop集群支持三種運行模式:單機模式、偽分布式模式,全分布式模式,下面介紹下在Ubuntu下的部署
(1)單機模式
sudo gedit /etc/profile
加入下面代碼
#set java environment JAVA_HOME=/home/*******/jdk1.7.0_09 export CLASSPATH=$JAVA_HOME/lib:$CLASSPATH export PATH=$JAVA_HOME/bin:$PATH
java_home的路徑是自己本機上的路徑。保存退出后需要注銷當前用戶,重新登錄。
bin/hadoop jar hadoop-ex*.jar wordcount conf output
(2)偽分布式模式
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/****/hadoop/logs</value>
</property>
</configuration>
hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
mapred-site.xml
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>localhost:9001</value>
</property>
</configuration>
接下來需要安裝SSH
在ubnuntu下直接在控制台中輸入
sudo apt-get install openssh-server
如果提示找不到源,在軟件中心輸入
sudo apt-get update
安裝完SSH,需要設置登錄的密鑰,控制台輸入
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
bin/hadoop namenode -format bin/start-all.sh
bin/hadoop fs -mkdir input bin/hadoop fs -put data input
bin/hadoop jar hadoop-examples-*.jar wordcount input output
bin/hadoop fs -cat output/* >> result.txt
bin/stop-all.sh
(3)全分布式模式
192.168.6.30 master 192.168.6.31 node1
(1)主機生成SSH,並分發密鑰
ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub 用戶名@192.168.6.31
如果分發不成功可以使用下面的命令
scp ~/.ssh/id_rsa.pub MachineName@202.194.124.49:~/mas_key
然后在遠程機器上
mkdir ~/.ssh chmod 700 ~/.ssh mv ~/mas_key ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys
使用ssh-copy-id不僅可以將公鑰添加到authorized_keys中去,而且也設置了正確的權限(文件夾.ssh為700,authorized_keys為600)
參考文章:http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/
ssh免密碼登錄原理可參考:http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html
這樣在master主機上ssh 192.168.6.31主機時應該就不用輸入密碼了
如果出現Agent admitted failure to sign using the key這個問題
解決方式 使用 ssh-add 指令將私鑰 加進來
ssh-add ~/.ssh/id_rsa
(2)配置hosts文件
sudo gedit /etc/hosts 127.0.0.1 localhost #127.0.0.1 機器名 192.168.6.38 master 192.168.6.31 node1
*第二行的注釋一定要注釋掉。然后將hosts文件通過scp 分發到從機上,登錄從機移動hosts文件。
scp /etc/hosts 目標機器名@目標機器IP:~/hosts sudo mv hosts /etc/
master
slaves
master node1
