本篇引用文章地址:
https://blog.csdn.net/u014454538/article/details/81103986
主机名 | IP地址 | 操作系统 | 运行服务 | 角色 |
---|---|---|---|---|
adserver | 192.168.200.10 | ubuntu 16.04 | NameNode、SecondaryNameNode、ResourceManager、JobHistoryServer | Master |
monserver | 192.168.200.20 | ubuntu 16.04 | DataNode、NodeManager | Slave |
osdserver-1 | 192.168.200.30 | ubuntu 16.04 | DataNode、NodeManager | Slave |
设置Ubuntu 16.04静态ip地址,此处仅作方法演示
1.首先查看IP地址
修改网卡配置文件,使其成为静态IP地址,修改好之后需要重启实例生效
$ sudo vi /etc/network/interfaces
修改主机名,此处用
$ sudo hostnamectl set-hostname YOUR_HOSTNAME
sudo useradd -d /home/hadoop -m hadoop
sudo passwd hadoop
echo "hadoop ALL = (root) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/hadoop
sudo chmod 0440 /etc/sudoers.d/hadoop
配置ssh免密登录 ,需先安装openssh-server(sudo apt get install openssh-server)
ubuntu@adserver:~$ ssh-keygen
ubuntu@adserver:~$ ssh-copy-id adserver
ubuntu@adserver:~$ ssh-copy-id monserver
ubuntu@adserver:~$ ssh-copy-id osdserver-1
ubuntu@adserver:~$ ssh-copy-id -i .ssh/id_rsa.pub hadoop@adserver
ubuntu@adserver:~$ ssh-copy-id -i .ssh/id_rsa.pub hadoop@monserver
ubuntu@adserver:~$ ssh-copy-id -i .ssh/id_rsa.pub hadoop@osdserver-1
下载JDK jdk-8u77-linux-x64.tar.gz
https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.html
ubuntu@adserver:~$ ls -lh
total 173M
-rw-rw-r-- 1 ubuntu ubuntu 173M Mar 28 09:11 jdk-8u77-linux-x64.tar.gz
ubuntu@adserver:~$ tar -zxf jdk-8u77-linux-x64.tar.gz
ubuntu@adserver:~$ ls -lh
total 173M
drwxr-xr-x 8 ubuntu ubuntu 4.0K Mar 21 2016 jdk1.8.0_77
-rw-rw-r-- 1 ubuntu ubuntu 173M Mar 28 09:11 jdk-8u77-linux-x64.tar.gz
ubuntu@adserver:~$ sudo mkdir /usr/lib/jdk
ubuntu@adserver:~$ sudo mv jdk1.8.0_77/ /usr/lib/jdk/
ubuntu@adserver:~$ sudo ls /usr/lib/jdk/
jdk1.8.0_77
ubuntu@adserver:~$ sudo vi /etc/profile
添加jdk环境
#JDK
export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_77
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH
安装Hadoop-2.7.2
下载地址:
https://archive.apache.org/dist/hadoop/core/hadoop-2.7.2/hadoop-2.7.2.tar.gz
ubuntu@adserver:~$ tar -zxf hadoop-2.7.2.tar.gz
ubuntu@adserver:~$ ls -lh
$ sudo vi /etc/profile
#HADOOP
export HADOOP_HOME=/usr/local/hadoop-2.7.2
export PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
$ vi ~/.bashrc
#HADOOP
export HADOOP_HOME=/usr/local/hadoop-2.7.2
export PATH=$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$PATH
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
$ source /etc/profile
$ source ~/.bashrc
$ hadoop version
修改/hadoop-2.7.2/etc/hadoop目录下的hadoop-env.sh、yarn-env.sh、slaves、core-site.xml、hdfs-site.xml、mapred-site.xml、yarn-site.xml
ubuntu@adserver:~$ sudo mkdir -p /usr/local/hadoop-2.7.2/tmp/dfs/data
ubuntu@adserver:~$ sudo mkdir -p /usr/local/hadoop-2.7.2/tmp/dfs/name
ubuntu@adserver:~$ cd /usr/local/hadoop-2.7.2/etc/hadoop/
export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_77
export JAVA_HOME=/usr/lib/jdk/jdk1.8.0_77
ubuntu@adserver:/usr/local/hadoop-2.7.2/etc/hadoop$ vi slaves
monserver
osdserver-1
ubuntu@adserver:/usr/local/hadoop-2.7.2/etc/hadoop$ vi core-site.xml
在
中添加如下内容
fs.defaultFS</name>
hdfs://adserver:8020</value>
</property>
hadoop.tmp.dir</name>
file:/usr/local/hadoop-2.7.2/tmp</value>
Abase for other temporary directories.</description>
</property>
ubuntu@adserver:/usr/local/hadoop-2.7.2/etc/hadoop$ vi hdfs-site.xml
在
中添加如下内容
dfs.namenode.secondary.http-address</name>
adserver:50090</value>
</property>
dfs.namenode.name.dir</name>
file:/usr/local/hadoop-2.7.2/tmp/dfs/name</value>
</property>
dfs.datanode.data.dir</name>
file:/usr/local/hadoop-2.7.2/tmp/dfs/data</value>
</property>
dfs.replication</name>
3</value>
</property>
dfs.webhdfs.enabled</name>
true</value>
</property>
ubuntu@adserver:/usr/local/hadoop-2.7.2/etc/hadoop$ cp mapred-site.xml.template mapred-site.xml
ubuntu@adserver:/usr/local/hadoop-2.7.2/etc/hadoop$ vi mapred-site.xml
在
中添加如下内容
mapreduce.framework.name</name>
yarn</value>
</property>
mapreduce.jobhistory.address</name>
adserver:10020</value>
</property>
mapreduce.jobhistory.webapp.address</name>
adserver:19888</value>
</property>
ubuntu@adserver:/usr/local/hadoop-2.7.2/etc/hadoop$ vi yarn-site.xml
在
中添加如下内容
yarn.nodemanager.aux-services</name>
mapreduce_shuffle</value>
</property>
yarn.resourcemanager.scheduler.address</name>
adserver:8030</value>
</property>
yarn.resourcemanager.address</name>
adserver:8032</value>
</property>
yarn.resourcemanager.resource-tracker.address</name>
adserver:8031</value>
</property>
yarn.resourcemanager.admin.address</name>
adserver:8033</value>
</property>
yarn.resourcemanager.webapp.address</name>
adserver:8088</value>
</property>
ubuntu@adserver:~$ scp /etc/hosts ubuntu@monserver:~/
ubuntu@adserver:~$ scp -r /etc/profile ubuntu@monserver:~/
ubuntu@adserver:~$ scp -r .bashrc ubuntu@monserver:~/
ubuntu@adserver:~$ scp -r /usr/local/hadoop-2.7.2/ ubuntu@monserver:~/
ubuntu@adserver:~$ scp -r /usr/lib/jdk/ ubuntu@monserver:~/
ubuntu@monserver:~$ sudo mv hosts /etc/hosts
ubuntu@monserver:~$ sudo mv hadoop-2.7.2/ /usr/local/
ubuntu@monserver:~$ sudo mv jdk/ /usr/lib/
ubuntu@monserver:~$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jdk/jdk1.8.0_77/bin/java 300
ubuntu@monserver:~$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jdk/jdk1.8.0_77/bin/javac 300
ubuntu@monserver:~$ source /etc/profile
ubuntu@monserver:~$ source .bashrc
ubuntu@monserver:~$ java -version
ubuntu@monserver:~$ hadoop version
ubuntu@adserver:~$ sudo chmod -R 0777 /usr/local/hadoop-2.7.2
ubuntu@monserver:~$ sudo chmod -R 0777 /usr/local/hadoop-2.7.2
ubuntu@osdserver-1:~$ sudo chmod -R 0777 /usr/local/hadoop-2.7.2
ubuntu@adserver:~$ hadoop namenode -format
注意:首次运行需要执行初始化,之后不需要。
成功运行,应该返回Exitting with status 0,提示Shuting down Namenode at adserver/xxx.xxx.xxx.xx(adserver的IP地址),具体结果如下图所示:
ubuntu@adserver:~$start-dfs.sh
$ start-yarn.sh
$ mr-jobhistory-daemon.sh start historyserver
查看三台节点运行状态
ubuntu@adserver:~$ jps
ubuntu@adserver:~$ ssh monserver "/usr/lib/jdk/jdk1.8.0_77/bin/jps"
ubuntu@adserver:~$ ssh osdserver-1 "/usr/lib/jdk/jdk1.8.0_77/bin/jps"