设置环境
1、解压
[centos@localhost data]$ tar -zxvf hadoop-3.1.3.tar.gz -C /data/module/
[centos@localhost data]$ mv hadoop-3.1.3 /data/moudle/hadoop
2、添加Hadoop环境
[centos@localhost data]$ sudo vim /etc/profile.d/my_env.sh
3、在profile文件末尾添加JDK路径:这边可能需要root权限才能更改
#HADOOP_HOME
export HADOOP_HOME=/data/module/hadoop
export PATH=$PATH:$HADOOP_HOME/bin
export PATH=$PATH:$HADOOP_HOME/sbin
配置集群
1)核心配置文件
配置core-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!-- 指定NameNode的地址 -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop10:8020</value>
</property>
<!-- 指定hadoop数据的存储目录 -->
<property>
<name>hadoop.tmp.dir</name>
<value>/data/module/hadoop/data</value>
</property>
<!-- 配置HDFS网页登录使用的静态用户为centos -->
<property>
<name>hadoop.http.staticuser.user</name>
<value>centos</value>
</property>
<!-- 配置该centos(superUser)允许通过代理访问的主机节点 -->
<property>
<name>hadoop.proxyuser.centos.hosts</name>
<value>*</value>
</property>
<!-- 配置该centos(superUser)允许通过代理用户所属组 -->
<property>
<name>hadoop.proxyuser.centos.groups</name>
<value>*</value>
</property>
<!-- 配置该centos(superUser)允许通过代理的用户-->
<property>
<name>hadoop.proxyuser.centos.users</name>
<value>*</value>
</property>
</configuration>
2)HDFS配置文件
配置hdfs-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!-- nn web端访问地址-->
<property>
<name>dfs.namenode.http-address</name>
<value>hadoop10:9870</value>
</property>
<!-- 2nn web端访问地址-->
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>hadoop11:9868</value>
</property>
<!-- 测试环境指定HDFS副本的数量1 -->
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
</configuration>
3)YARN配置文件
配置yarn-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!-- 指定MR走shuffle -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<!-- 指定ResourceManager的地址-->
<property>
<name>yarn.resourcemanager.hostname</name>
<value>hadoop12</value>
</property>
<!-- 环境变量的继承 -->
<property>
<name>yarn.nodemanager.env-whitelist</name>
<value>JAVA_HOME,HADOOP_COMMON_HOME,HADOOP_HDFS_HOME,HADOOP_CONF_DIR,CLASSPATH_PREPEND_DISTCACHE,HADOOP_YARN_HOME,HADOOP_MAPRED_HOME</value>
</property>
<!--yarn单个容器允许分配的最大最小内存 -->
<property>
<name>yarn.scheduler.minimum-allocation-mb</name>
<value>512</value>
</property>
<property>
<name>yarn.scheduler.maximum-allocation-mb</name>
<value>4096</value>
</property>
<!-- yarn容器允许管理的物理内存大小 -->
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>4096</value>
</property>
<!-- 关闭yarn对物理内存和虚拟内存的限制检查 -->
<property>
<name>yarn.nodemanager.pmem-check-enabled</name>
<value>true</value>
</property>
<property>
<name>yarn.nodemanager.vmem-check-enabled</name>
<value>false</value>
</property>
</configuration>
4)MapReduce配置文件
配置mapred-site.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<!-- 指定MapReduce程序运行在Yarn上 -->
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
5)配置workers
[centos@localhost hadoop]$ vim workers
[centos@localhost hadoop]$ cat workers
hadoop10
hadoop11
配置历史服务器
查看历史运行情况,需要配置历史服务器.具体步骤如下
配置mapred-site.xml 在该文件中追加如下配置
<!-- 历史服务器端地址 -->
<property>
<name>mapreduce.jobhistory.address</name>
<value>hadoop10:10020</value>
</property>
<!-- 历史服务器web端地址 -->
<property>
<name>mapreduce.jobhistory.webapp.address</name>
<value>hadoop10:19888</value>
</property>
配置日志聚集功能
日志聚集概念:应用运行完成以后,将程序运行日志信息上传到HDFS系统上。
日志聚集功能好处:可以方便的查看到程序运行详情,方便开发调试。
注意:开启日志聚集功能,需要重新启动NodeManager 、ResourceManager和HistoryManager。
1、配置yarn-site.xml
<!-- 开启日志聚集功能 -->
<property>
<name>yarn.log-aggregation-enable</name>
<value>true</value>
</property>
<!-- 设置日志聚集服务器地址 -->
<property>
<name>yarn.log.server.url</name>
<value>http://hadoop10:19888/jobhistory/logs</value>
</property>
<!-- 设置日志保留时间为7天 -->
<property>
<name>yarn.log-aggregation.retain-seconds</name>
<value>604800</value>
</property>
一)分发Hadoop
$ xsync /opt/module/hadoop/
1、启动集群
如果是第一次启动,需要在hadoop10节点格式化NameNode(格式化之前一定要停止上次启动的所有namenode和datanode进程,然后再删除data和log数据)
[centos@hadoop10 hadoop]$ bin/hdfs namenode -format
2、启动HDFS
[centos@hadoop10 hadoop]$ sbin/start-dfs.sh
Starting namenodes on [hadoop10]
hadoop10: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
Starting datanodes
hadoop10: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
hadoop11: WARNING: /data/module/hadoop/logs does not exist. Creating.
Starting secondary namenodes [hadoop11]
主机没有权限,master需要对自己免密登录
[centos@hadoop10 hadoop]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/centos/.ssh/id_rsa):
/home/centos/.ssh/id_rsa already exists.
Overwrite (y/n)?
[centos@hadoop10 hadoop]$ ssh-copy-id centos@hadoop10
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/centos/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
centos@hadoop10's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'centos@hadoop10'"
and check to make sure that only the key(s) you wanted were added.
[centos@hadoop10 hadoop]$ cd ~/.ssh/
[centos@hadoop10 .ssh]$ ll
总用量 16
-rwxrwxrwx. 1 centos centos 820 8月 17 07:00 authorized_keys
-rw-------. 1 centos centos 1679 8月 16 06:44 id_rsa
-rw-r--r--. 1 centos centos 410 8月 16 06:44 id_rsa.pub
-rw-r--r--. 1 centos centos 368 8月 16 07:28 known_hosts
[centos@hadoop10 .ssh]$ cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDLI9fogg2g+VXcu/HulYnDnUuCJphcg3Rrh347v7C80YeQIsXxeQgiORia/j9jsWLzIm6hkMGpYdaeqmXbsiNrKtKLSIM8Xv5U79/0HsMvqf7LRpdxDCRn3wtqnIIXKcF7+EDAnvdTj4bNsD9SV49gl+YRD1E7O0bb6KJEUA+xqWilRt6trh97RHtYpYadiSP6ztT+4Ah7QBX7fJa/JD71g/VymRcSIGlaAtTDHcU1+VgdZSs62+hP0yzo8lEKrHOo/KJeY2GdmsMolQhLEO7KGNAjnO7q6gLr8FF4jKjculaaRsJOMy8QsNIDZawLK0Yo00msEpBRm6pDjcdl6WH3 centos@localhost.localdomain
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCoow0BXfwFzNOIVaaEE4pyHtGkS9PgB9+THm4tHy2mKg5fBj3ewou0VAPWkp7RwZQUX61mX9QJ1ZbzfESYe6KZQ6GMx3cBwP2qlaxQjQQmBu0aGkETdQ9pexAteGK9IjlgQ7qa1vN3U9jUOjJzXMXIVYW/hhxHL1tY9Mj8rj2L4gJfxxZnt9xbPdz7uiFgpQ1PYqH9KrA4kiKd0s730xZtnaiPI782aOmuVA75INBiZcpuw6QFgBmTDqjpSohAhCInoXNY3Mk1aqFR7OUK4k2E3IH2AVlr5xdpVAd3VwNrJMINJQ8NrrPBA/sF8xnUdy4gRt2UE88npsRhepN//cJV centos@localhost.localdomain
[centos@hadoop10 .ssh]$
[centos@hadoop10 hadoop]$ cd ~/.ssh/
[centos@hadoop10 .ssh]$ chmod 600 authorized_keys
第二种可能防火墙
3、在配置了ResourceManager 节点11 启动YARN
[centos@hadoop10 hadoop]$ start-yarn.sh
4、web端查看HDFS 页面 http://hadoop10:9870
防火墙端口未开
[root@localhost hadoop]# firewall-cmd --zone=public --add-port=9870/tcp --permanent
success
[root@localhost hadoop]# firewall-cmd --reload
success
[root@localhost hadoop]# firewall-cmd --list-ports
8848/tcp 9870/tcp
可以使用Ambari、Ganglia、Nagios等工具进行监控。
- 监控HDFS和YARN的运行情况
[centos@hadoop10 hadoop]$ sbin/stop-yarn.sh
[centos@hadoop10 hadoop]$ sbin/start-yarn.sh
需要重新启动NodeManager、ResourceManager 和 HistoryManager
- 开启日志聚集功能
[centos@hadoop10 hadoop]$ sbin/mr-jobhistory-daemon.sh start historyserver
- 启动历史服务器
Hadoop群起脚本
vim hdp.sh
#!/bin/bash
if [ $# -lt 1 ]
then
echo "No Args Input..."
exit ;
fi
case $1 in
"start")
echo " =================== 启动 hadoop集群 ==================="
echo " --------------- 启动 hdfs ---------------"
ssh hadoop10 "/data/module/hadoop/sbin/start-dfs.sh"
echo " --------------- 启动 yarn ---------------"
ssh hadoop11 "/data/module/hadoop/sbin/start-yarn.sh"
echo " --------------- 启动 historyserver ---------------"
ssh hadoop10 "/data/module/hadoop/bin/mapred --daemon start historyserver"
;;
"stop")
echo " =================== 关闭 hadoop集群 ==================="
echo " --------------- 关闭 historyserver ---------------"
ssh hadoop10 "/data/module/hadoop/bin/mapred --daemon stop historyserver"
echo " --------------- 关闭 yarn ---------------"
ssh hadoop11 "/data/module/hadoop/sbin/stop-yarn.sh"
echo " --------------- 关闭 hdfs ---------------"
ssh hadoop10 "/data/module/hadoop/sbin/stop-dfs.sh"
;;
*)
echo "Input Args Error..."
;;
esac
http://192.168.31.11:9868/ 2nn 报错以下为处理方式
[centos@hadoop11 static]$ pwd
/data/module/hadoop/share/hadoop/hdfs/webapps/static
[centos@hadoop11 static]$ vim dfs-dust.js
'date_tostring' : function (v) {
return Number(v).toLocaleString();
},
[hadoop优化]