hadoop完全分布式(fully)安装 主机资源的整体规划 1 2 3 4 5 6 host01 host02 host03 备注 (测试机器配置 32vCPU 128gMem 2tDisk) namenode secondarynamenode redourcemanager 实际环境中nn、snn、rm重要节点必须单独部署 datanode datanode datanode 主要消耗硬盘 nodemanager nodemanager nodemanager 主要消耗CPU historyserver MR任务历史记录服务
基本hadoop完全分布式环境搭建的主要步骤 1) 准备工作
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 略 $ sudo vim /etc/security/limits.conf * soft nofile 65536 * hard nofile 131072 * soft nproc 4096 * hard nproc 4096 * soft memlock unlimited * hard memlock unlimited 略 略 $ sudo yum install ntp ntpdate $ sudo timedatectl set -timezone Asia/Shanghai $ sudo ntpdate cn.pool.ntp.org 或 sudo date -s "2018-06-30 11:11:11" $ sudo hwclock -w $ sudo vim /etc/ntp.conf restrict 192.168.56.0 mask 255.255.255.0 nomodify notrap server 127.127.1.0 fudge 127.127.1.0 stratum 10 $ sudo vim /etc/ntp.conf restrict 192.168.56.0 mask 255.255.255.0 server host01 $ sudo ntpdate host01 SYNC_HWCLOCK=yes $ sudo systemctl restart ntpd $ sudo systemctl enable ntpd $ sudo systemctl list-unit-files | grep enable $ sudo timedatectl set -ntp yes $ sudo timedatectl
请注意: 使用ntpd服务,要好于ntpdate加cron的组合。因为,ntpdate同步时间,会造成时间的跳跃,对一些依赖时间的程序和服务会造成影响。比如sleep,timer等。而且ntpd服务可以在修正时间的同时,修正cpu tick。理想的做法为,在开机的时候,使用ntpdate强制同步时间,在其他时候使用ntpd服务来同步时间。 要注意的是,ntpd有一个自我保护设置: 如果本机与上源时间相差太大,ntpd不运行。所以新设置的时间服务器一定要先ntpdate从上源取得时间初值,然后启动ntpd服务。ntpd服务运行后,先是每64秒与上源服务器同步一次,根据每次同步时测得的误差值经复杂计算逐步调整自己的时间,随着误差减小,逐步增加同步的间隔。 每次跳动,都会重复这个调整的过程。
2) 配置基本的 xxx-env.sh 文件
主要包含 hadoop-env.sh、mapred-env.sh、yarn-env.sh 三个文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 export hJAVA_HOME=/opt/jdk1.8.0_181export HADOOP_LOG_DIR=/var/log /hadoop/$USER export HADOOP_MAPRED_LOG_DIR="/var/log/hadoop/mr/logs" if [ "$YARN_LOG_DIR " = "" ]; then YARN_LOG_DIR="/var/log/hadoop/yarn/logs" fi if [ "$YARN_LOGFILE " = "" ]; then YARN_LOGFILE='yarn.log' fi sudo mkdir -p /var/lib/hadoop/data/tmp sudo mkdir -p /var/log /hadoop sudo mkdir -p /var/log /hadoop/mr/logs sudo mkdir -p /var/log /hadoop/yarn/logs sudo chown -R hadoop:hadoop /var/lib/hadoop sudo chown -R hadoop:hadoop /var/log /hadoop
3) 配置 xxx-site.xml 文件和 slaves 文件
主要包含 core-site.xml、hdfs-site.xml、mapred-site.xml、yarn-site.xml、slaves 这 4+1个文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 <configuration > <property > <name > fs.defaultFS</name > <value > hdfs://host01:8020</value > </property > <property > <name > hadoop.tmp.dir</name > <value > /var/lib/hadoop/data/tmp</value > </property > <property > <name > hadoop.http.staticuser.user</name > <value > hadoop</value > </property > <property > <name > fs.trash.interval</name > <value > 10080</value > </property > <property > <name > fs.trash.checkpoint.interval</name > <value > 0</value > </property > </configuration > <configuration > <property > <name > dfs.replication</name > <value > 3</value > </property > <property > <name > dfs.permissions.enabled</name > <value > false</value > </property > <property > <name > dfs.namenode.secondary.http-address</name > <value > host02:50090</value > </property > </configuration > host01 host02 host03 <configuration > <property > <name > mapreduce.framework.name</name > <value > yarn</value > </property > <property > <name > mapreduce.jobhistory.address</name > <value > host03:10020</value > </property > <property > <name > mapreduce.jobhistory.webapp.address</name > <value > host03:19888</value > </property > </configuration > <configuration > <property > <name > yarn.nodemanager.aux-services</name > <value > mapreduce_shuffle</value > </property > <property > <name > yarn.resourcemanager.hostname</name > <value > host03</value > </property > <property > <name > yarn.resourcemanager.webapp.address</name > <value > host03:8088</value > </property > <property > <name > yarn.log-aggregation-enable</name > <value > true</value > </property > <property > <name > yarn.log-aggregation.retain-seconds</name > <value > 604800</value > </property > </configuration >
4) 往各个节点分发hadoop安装及配置文件
1 $ zcopy /home/hadoop/hadoop-2.7.6/ /home/hadoop/
5) 在namenode节点(此处为host01)格式化文件系统
1 2 3 4 5 $ zcall rm -rf /var/lib/hadoop/data/tmp/* $ hdfs namenode -format
6) 在对应的节点(不强制要求)启动服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 [hadoop@host01 ~]$ start-dfs.sh Starting namenodes on [host01] host01: starting namenode, logging to xxx/userxxx/hadoop-hadoop-namenode-host01.out host03: starting datanode, logging to xxx/userxxx/hadoop-hadoop-datanode-host03.out host01: starting datanode, logging to xxx/userxxx/hadoop-hadoop-datanode-host01.out host02: starting datanode, logging to xxx/userxxx/hadoop-hadoop-datanode-host02.out Starting secondary namenodes [host02] host02: starting secondarynamenode, logging to xxx/hadoop/hadoop-hadoop-secondarynamenode-host02.out [hadoop@host03 ~]$ start-yarn.sh starting yarn daemons starting resourcemanager, logging to xxx/yarn/logs/yarn-hadoop-resourcemanager-host03.out host02: starting nodemanager, logging to xxx/yarn/logs/yarn-hadoop-nodemanager-host02.out host01: starting nodemanager, logging to xxx/yarn/logs/yarn-hadoop-nodemanager-host01.out host03: starting nodemanager, logging to xxx/yarn/logs/yarn-hadoop-nodemanager-host03.out [hadoop@host03 ~]$ mr-jobhistory-daemon.sh start historyserver starting historyserver, logging to xxx/mr/logs/mapred-hadoop-historyserver-host03.out
7) 查看各个节点的服务启动情况
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 [hadoop@host01 ~]$ zcall jps -------------host01--------------- 21430 Jps 20746 DataNode 21276 NodeManager 20591 NameNode -------------host02--------------- 8242 DataNode 8354 SecondaryNameNode 9078 Jps 8892 NodeManager -------------host03--------------- 6993 DataNode 7762 ResourceManager 8515 Jps 8440 JobHistoryServer 7881 NodeManager