安装zookeeper请参考本人其他文章
CentOS安装hadoop3.1.2集群 分别在三台机器上执行如下命令安装epel源
yum -y install epel-release
分别在三台机器上执行如下命令安装vim、wget、lrzsz、wget、net-tools、redhat-lsb、ntpyum -y install vim axel lrzsz wget net-tools redhat-lsb ntp
分别在三台机器上执行如下操作关闭防火墙停止防火墙
systemctl stop firewalld.service
禁止开启启动防火墙:
systemctl disable firewalld.service
关闭selinux :
vim /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled
重启机器
reboot
分别在三台机器上安装jdk把jdk-8u201-linux-x64.tar.gz压缩包放入/tmp/目录
cd /tmp
rz
tar -zxf jdk-8u201-linux-x64.tar.gz
mv jdk1.8.0_201 /opt
vim /etc/profile
在/etc/profile文件末端添加以下内容
#JAVA_HOME
export JAVA_HOME=/opt/jdk1.8.0_201
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}
source /etc/profile
修改三台机器的hostnamevim /etc/hostname
第一台hadoop1
第二台hadoop2
第三台hadoop3
修改三台机器的hosts
vim /etc/hosts
添加以下内容到/etc/hosts文件里面
192.168.10.11 hadoop1
192.168.10.12 hadoop2
192.168.10.13 hadoop3
service network restart
配置SSH互信(1)、分别在三台机器上创建目录
mkdir ~/.ssh
chmod 700 -R ~/.ssh
(2)、分别在三台机器上执行如下命令生成密钥文件和私钥文件
ssh-keygen -t rsa
(3)、在第一节点上追加公钥文件到authorized_keys文件:
ssh hadoop1 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh hadoop2 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh hadoop3 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
(4)、把authorized_keys文件复制到第二第三节点上
scp ~/.ssh/authorized_keys hadoop2:~/.ssh/
scp ~/.ssh/authorized_keys hadoop3:~/.ssh/
在第一节点下载配置hadoop(1)、下载、解压文件
cd /tmp
axel -n 16 http://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/hadoop-3.1.2/hadoop-3.1.2.tar.gz
tar -zxf hadoop-3.1.2.tar.gz
mv hadoop-3.1.2 /opt/
(2)、配置hodoop
vim /opt/hadoop-3.1.2/etc/hadoop/hadoop-env.sh
在hadoop-env.sh文件中加入以下内容
export JAVA_HOME=/opt/jdk1.8.0_201
vim /opt/hadoop-3.1.2/etc/hadoop/core-site.xml
在core-site.xml文件中加入以下内容
vim /opt/hadoop-3.1.2/etc/hadoop/hdfs-site.xml
在hdfs-site.xml文件中加入以下内容
vim /opt/hadoop-3.1.2/etc/hadoop/mapred-site.xml
在mapred-site.xml文件中加入以下内容
vim /opt/hadoop-3.1.2/etc/hadoop/yarn-site.xml
在yarn-site.xml文件中加入以下内容
vim /opt/hadoop-3.1.2/sbin/start-dfs.sh
vim /opt/hadoop-3.1.2/sbin/stop-dfs.sh
在这两个文件空白位置加入
HDFS_DATANODE_USER=root
HDFS_DATANODE_SECURE_USER=hdfs
HDFS_NAMENODE_USER=root
HDFS_SECONDARYNAMENODE_USER=root
vim /opt/hadoop-3.1.2/sbin/start-yarn.sh
vim /opt/hadoop-3.1.2/sbin/stop-yarn.sh
在这两个文件空白位置加入
YARN_RESOURCEMANAGER_USER=root
HADOOP_SECURE_DN_USER=yarn
YARN_NODEMANAGER_USER=root
vim /opt/hadoop-3.1.2/etc/hadoop/workers
在workers文件中加入以下内容
hadoop2
hadoop3
创建文件夹
mkdir -p /opt/hadoop-3.1.2/data/tmp
mkdir -p /opt/hadoop-3.1.2/data/name
mkdir -p /opt/hadoop-3.1.2/data/datanode
复制到节点二、节点三
scp -r /opt/hadoop-3.1.2/ hadoop2:/opt
scp -r /opt/hadoop-3.1.2/ hadoop3:/opt
vim /etc/profile
在文件末端添加下面的内容
#HADOOP_HOME
export HADOOP_HOME=/opt/hadoop-3.1.2
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_YARN_HOME=$HADOOP_HOME
export HADOOP_CONF_DIR=$HADOOP_HOME/etc/hadoop
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib"
#HADOOP_CLASSPATH
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:${Hbase_HOME}/share/hadoop/common/*
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:${Hbase_HOME}/share/hadoop/common/lib/*
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:${Hbase_HOME}/share/hadoop/hdfs/*
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:${Hbase_HOME}/share/hadoop/hdfs/lib/*
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:${Hbase_HOME}/share/hadoop/mapreduce/*
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:${Hbase_HOME}/share/hadoop/mapreduce/lib/*
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:${Hbase_HOME}/share/hadoop/yarn/*
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:${Hbase_HOME}/share/hadoop/yarn/lib/*
scp /etc/profile hadoop2:/etc
scp /etc/profile hadoop3:/etc
分别在三节点上执行下面的命令
source /etc/profile
在第一节点上执行如下命令格式化Hadoop
hdfs namenode -format HadoopCluster
执行以下命令启动hadoop
/opt/hadoop-3.1.2/sbin/start-all.sh
检测是否安装成功在浏览器打开http://192.168.10.11:8088/,看到下面的页面就说明以安装成功!
或者在浏览器打开http://192.168.10.11:9870/,看到下面的页面就说明以安装成功!