1.VBOX安装CentOS7

1.1.安装VBOX软件
    (略)

1.2.下载CentOS7镜像文件
    从阿里镜像网站(https://mirrors.aliyun.com/centos/7.4.1708/isos/x86_64/)下载镜像文件

1.3.初始化VBOX虚拟盘
    (略)

1.4.CentOS7网络配置
    ip addr  检查网卡信息,显示有两个网卡 eno0s3 和 enp0s8,如下图:

    

dokcer windows镜像 dos7.1镜像_运维


    cd /etc/sysconfig/network-scripts/ 修改对应ifcfg-enp0s3 和 ifcfg-enp0s8文件,如下图:

dokcer windows镜像 dos7.1镜像_运维_02


    enp0s3对应VBOX网卡1  NET方式取动态获取IP,如下图:

dokcer windows镜像 dos7.1镜像_dokcer windows镜像_03


    enp0s8对应VBOX网卡2 仅主机(Host-only)网络,配置静态IP,与宿主机windows中VBOX网卡对应,如下图:

dokcer windows镜像 dos7.1镜像_大数据_04

dokcer windows镜像 dos7.1镜像_xml_05

    service network restart 重启网络后,在xshell中配置静态IP即可访问,如下图:

dokcer windows镜像 dos7.1镜像_dokcer windows镜像_06


1.5.CentOS7 yum源配置

    访问阿里镜像网站(https://opsx.alibaba.com/mirror),点击centos右侧帮助按钮

备份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

下载新的CentOS-Base.repo 到/etc/yum.repos.d/

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

运行yum makecache生成缓存

    

    安装一些基础工具 

yum install -y lrzsz

1.6.CentOS7 一般配置
    关闭防火墙
centos7之前不含7 
service iptable status --查看防火墙状态
servcie iptables stop  --临时关闭防火墙
chkconfig iptables off --永久关闭防火墙

centos7之后含7
firewall-cmd --state                                 --查看防火墙状态(关闭后显示notrunning,开启后显示running)
systemctl list-unit-files|grep firewalld.service 或 systemctl status firewalld.service     
                                                    --从centos7开始使用systemctl来管理服务和程序,包括了service和chkconfig
systemctl stop firewalld.service                     --#停止firewall
systemctl disable firewalld.service                 --#禁止firewall开机启动
额外的介绍说明:
systemctl start firewalld.service                    --#启动一个服务
systemctl stop firewalld.service                    --#关闭一个服务
systemctl restart firewalld.service                    --#重启一个服务
systemctl status firewalld.service                    --#显示一个服务的状态
systemctl enable firewalld.service                    --#在开机时启用一个服务
systemctl disable firewalld.service                    --#在开机时禁用一个服务
systemctl is-enabled firewalld.service                --#查看服务是否开机启动
systemctl list-unit-files|grep enabled                 --#查看已启动的服务列表

    修改hostname
临时修改 hostname
[root@localhost Desktop]# hostname bigdata01    --这种修改方式,系统重启后就会失效

永久修改 hostname
想永久修改,应该修改配置文件
1. vi /etc/sysconfig/network
写入以下内容:
NETWORKING=yes #使用网络
HOSTNAME=bigdata01 #设置主机名
2.vi /etc/hosts
修改 127.0.0.1这行中的 localhost.localdomain为 bigdata01
修改 ::1这行中的localhost.localdomain 为bigdata01
3.vi /etc/hostname
删除文件中的所有文字,在第一行添加slave3    
4.重启并验证
#>reboot -f 
#>hostnamectl

    配置DNS绑定
将所有主机的vi /etc/hosts 都配置如下:
192.168.56.3 bigdata01
192.168.56.4 bigdata02
192.168.56.5 bigdata03

    关闭selinux
vi /etc/sysconfig/selinux

dokcer windows镜像 dos7.1镜像_dokcer windows镜像_07

修改为

dokcer windows镜像 dos7.1镜像_dokcer windows镜像_08


2.JDK等基础安装配置

2.1.安装JDK前检查
    检查是否已经安装了JDK

dokcer windows镜像 dos7.1镜像_xml_09

    注意: Hadoop机器上的JDK, 最好是Oracle的JavaJDK, 不然会有一些问题,比如可能没有 JPS 命令。如果安装了其他版本的JDK, 卸载掉。

    删除自带 java

[root@server media]# rpm -qa |grep java
 tzdata-java-2014g-1.el6.noarch
 java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el6_5.x86_64
 java-1.6.0-openjdk-1.6.0.0-11.1.13.4.el6.x86_64
 [root@server media]# rpm -e java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el6_5.x86_64
 [root@server media]# rpm -e java-1.6.0-openjdk-1.6.0.0-11.1.13.4.el6.x86_64 --nodeps
 [root@server media]# rpm -qa|grep java
 tzdata-java-2014g-1.el6.noarch

2.2.安装tar格式JDK
    上传tar.gz包只安装目录

将 jdk-7u67-linux-x64.tar.gz 解压到/opt/modules 目录下
 [root@bigdata-senior01 /]# tar -zxvf jdk-7u67-linux-x64.tar.gz -C /opt/modules    添加环境变量
 设置 JDK 的环境变量 JAVA_HOME。需要修改配置文件/etc/profile,追加
 export JAVA_HOME="/opt/modules/jdk1.7.0_67"
 export PATH=$JAVA_HOME/bin:$PATH
 修改完毕后,执行 source /etc/profile
     
 2.3.安装rpm格式JDK
     详细安装见"编程语言/JAVA语言/JAVASE/JDK/JDK笔记    添加环境变量
 vi /etc/profile
 export JAVA_HOME="/usr/java/jdk1.7.0_80"
 export PATH=$JAVA_HOME/bin:$PATH
 修改完毕后,执行 source /etc/profile2.4.配置SSH互信
     SSH(安全外壳协议) 推荐安装OpenSSH
     安装expect
 yum -y install expect
 [root@bigdata01 ~]# which expect
 /usr/bin/expect

    编写节点文件如下:

dokcer windows镜像 dos7.1镜像_大数据_10


    上传sshkey.sh,执行

./sshkey.sh root XXXXX hosts

dokcer windows镜像 dos7.1镜像_dokcer windows镜像_11


    在每台机器上测试互信

(略)

2.5.配置NTP时钟同步
     bigdata01 ntpd服务器,用于与外部公共ntpd同步标准时间
     bigdata02 ntpd客户端,用于与ntpd同步时间
     bigdata03 ntpd客户端,用于与ntpd同步时间
     
     使用rpm检查ntp包是否安装
 rpm -q ntp     使用yum进行安装,并设置系统开机自动启动并启动服务
 yum -y install ntp
 systemctl enable ntpd
 systemctl start ntpd    配置前先使用命令:ntpdate -u cn.pool.ntp.org,同步服务器
     修改vi /etc/ntp.conf文件,红色字体是修改的内容
 # For more information about this file, see the man pages
 # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
 driftfile /var/lib/ntp/drift
 # Permit time synchronization with our time source, but do not
 # permit the source to query or modify the service on this system.
 restrict default nomodify notrap nopeer noquery# Permit all access over the loopback interface.  This could
 # be tightened as well, but to do so would effect some of
 # the administrative functions.
 restrict 127.0.0.1
 restrict ::1# Hosts on local network are less restricted.
 #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
 restrict 192.168.56.0 mask 255.255.255.0 nomodify notrap
 #允许内网其他机器同步时间,如果不添加该约束默认允许所有IP访问本机同步服务# Use public servers from the pool.ntp.org project.
 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
 #server 0.centos.pool.ntp.org iburst#server 101.201.72.121  # 中国国家授时中心
 #server 133.100.11.8  #日本[福冈大学]
 #server 3.cn.pool.ntp.org
 #server 1.asia.pool.ntp.org
 #server 3.asia.pool.ntp.org
 #配置和上游标准时间同步,时间服务器的域名,如不需要连接互联网,就将他们注释掉#broadcast 192.168.1.255 autokey        # broadcast server
 #broadcastclient                        # broadcast client
 #broadcast 224.0.1.1 autokey            # multicast server
 #multicastclient 224.0.1.1              # multicast client
 #manycastserver 239.255.254.254         # manycast server
 #manycastclient 239.255.254.254 autokey # manycast client
 #配置允许上游时间服务器主动修改本机(内网ntp Server)的时间
 #restrict 101.201.72.121 nomodify notrap noquery
 #restrict 133.100.11.8 nomodify notrap noquery
 #restrict 3.cn.pool.ntp.org nomodify notrap noquery
 #restrict 1.asia.pool.ntp.org nomodify notrap noquery
 #restrict 3.asia.pool.ntp.org nomodify notrap noquery#确保localhost有足够权限,使用没有任何限制关键词的语法。
 #外部时间服务器不可用时,以本地时间作为时间服务。
 #注意:这里不能改,必须使用127.127.1.0,否则会导致无法!
 #在ntp客户端运行ntpdate serverIP,出现no server suitable for synchronization found的错误。
 #在ntp客户端用ntpdate –d serverIP查看,发现有“Server dropped: strata too high”的错误,并且显示“stratum 16”。而正常情况下stratum这个值得范围是“0~15”。
 #这是因为NTP server还没有和其自身或者它的server同步上。
 #以下的定义是让NTP Server和其自身保持同步,如果在ntp.conf中定义的server都不可用时,将使用local时间作为ntp服务提供给ntp客户端。
 server 127.127.1.0  # local clock
 fudge 127.127.1.0  stratum 8# Enable public key cryptography.
 #cryptoincludefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
 # with symmetric key cryptography. 
 keys /etc/ntp/keys# Specify the key identifiers which are trusted.
 #trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.
 #requestkey 8# Specify the key identifier to use with the ntpq utility.
 #controlkey 8# Enable writing of statistics records.
 #statistics clockstats cryptostats loopstats peerstats# Disable the monitoring facility to prevent amplification attacks using ntpdc
 # monlist command when default restrict does not include the noquery flag. See
 # CVE-2013-5211 for more details.
 # Note: Monitoring will not be disabled with the limited restriction flag.
 disable monitor

    重启ntp服务
systemctl restart ntpd

    启动后,查看同步情况
ntpq -p
ntpstat

    检查是否启动ntp服务
lsof -i:123

    ntp客户机/etc/ntp.conf按照如下配置,并启动ntp服务
#配置上游时间服务器为本地的ntpd Server服务器
server 192.168.56.3

# 配置允许上游时间服务器主动修改本机的时间
restrict 192.168.56.3 nomodify notrap noquery

server 127.127.1.0
fudge 127.127.1.0  stratum 10

3.Hadoop安装

3.1.Hadoop1.x伪分布式
    
3.1.1.上传hadoop-1.2.1-bin.tar.gz至/opt目录
tar -zxvf hadoop-1.2.1-bin.tar.gz
ln -s hadoop-1.2.1 hadoop

dokcer windows镜像 dos7.1镜像_java_12

3.1.2.配置环境变量
    如下图配置/etc/profile,并source生效

其中export HADOOP_HOME_WARN_SUPPRESS=1 配置后是为了解决Hadoop1.2.1出现Warning: $HADOOP_HOME is deprecated.的问题
3.1.3.修改Hadoop配置文件
     conf/hadoop-env.sh
 # The java implementation to use.  Required.
 # export JAVA_HOME=/usr/lib/j2sdk1.5-sun
 export JAVA_HOME=/usr/java/jdk1.7.0_80    conf/core-site.xml
 <?xml version="1.0"?>
 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
 <!-- Put site-specific property overrides in this file. -->
 <configuration>
      <property>
          <name>fs.default.name</name>
          <value>hdfs://bigdata01:9000</value>
        <description>用于dfs命令模块中指定默认的文件系统协议</description>
      </property>
      <property>
          <name>hadoop.tmp.dir</name>
          <value>/tmp/hadoop1xlocalm</value>
        <description>临时目录,其他临时目录的父目录</description>
      </property>
      </property>     
 </configuration>    conf/hdfs-site.xml
 <?xml version="1.0"?>
 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
 <!-- Put site-specific property overrides in this file. -->
 <configuration>
      <property>
          <name>dfs.name.dir</name>
          <value>/hadoop/1x/localm/hdfs/name</value>
        <description>name node的元数据,以,号隔开,hdfs会把元数据冗余复制到这些目录,一般这些目录是不同的块设备,不存在的目录会被忽略掉</description>
      <property>
          <name>dfs.data.dir</name>
          <value>/hadoop/1x/localm/hdfs/data</value>
        <description>data node的数据目录,以,号隔开,hdfs会把数据存在这些目录下,一般这些目录是不同的块设备,不存在的目录会被忽略掉</description>
      </property>
      
      <property>
          <name>dfs.replication</name>
          <value>1</value>
        <description>文件复制的副本数,如果创建时不指定这个参数,就使用这个默认值作为复制的副本数</description>
      </property>
 </configuration>    conf/mapred-site.xml
 <?xml version="1.0"?>
 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
 <!-- Put site-specific property overrides in this file. -->
 <configuration>
      <property>
          <name>mapred.job.tracker</name>
          <value>bigdata01:9001</value>
        <description>job tracker交互端口</description>
      </property>
 </configuration>    conf/masters
 bigdata01    conf/slaves
 bigdata013.1.4.启动Hadoop
     格式化工作空间


hadoop namenode –format

    

dokcer windows镜像 dos7.1镜像_xml_13


    启动hdfs

start-all.sh     启动所有的Hadoop守护。包括namenode, datanode, jobtracker, tasktrack

stop-all.sh     停止所有的Hadoop

start-mapred.sh 启动Map/Reduce守护。包括Jobtracker和Tasktrack

stop-mapred.sh     停止Map/Reduce守护

start-dfs.sh     启动Hadoop DFS守护Namenode和Datanode

stop-dfs.sh     停止DFS守护

dokcer windows镜像 dos7.1镜像_大数据_14


    

3.1.5.使用jps命令查看结果

dokcer windows镜像 dos7.1镜像_大数据_15


3.1.6.查看Web界面

NameNode  
 http://192.168.56.3:50070/dfshealth.jsp
    JobTracker
 http://192.168.56.3:50030/jobtracker.jsp 3.2.Hadoop1.x完全分布式
     安装部署完全分布式集群,现有3台机器,分别规划为
 bigdata01 : namenode,secondarynamenode,jobtracker
 bigdata02 : datanode,tasktracker
 bigdata03 : datanode,tasktracke
  
 3.2.1.hadoop1.x配置
     conf/hadoop-env.sh
 # The java implementation to use.  Required.
 # export JAVA_HOME=/usr/lib/j2sdk1.5-sun
 export JAVA_HOME=/usr/java/jdk1.7.0_80    conf/core-site.xml
 <?xml version="1.0"?>
 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
 <!-- Put site-specific property overrides in this file. -->
 <configuration>
      <property>
          <name>fs.default.name</name>
          <value>hdfs://bigdata01:9000</value>
      <description>用于dfs命令模块中指定默认的文件系统协议</description>
      </property>
      
      <property>
          <name>hadoop.tmp.dir</name>
          <value>/tmp/hadoop1xclusterm</value>
      <description>临时目录,其他临时目录的父目录</description>
      </property>     
 </configuration>    conf/hdfs-site.xml
 <?xml version="1.0"?>
 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
 <!-- Put site-specific property overrides in this file. -->
 <configuration>
      <property>
          <name>dfs.name.dir</name>
          <value>/hadoop/1x/clusterm/hdfs/name</value>
         <description>name node的元数据,以,号隔开,hdfs会把元数据冗余复制到这些目录,一般这些目录是不同的块设备,不存在的目录会被忽略掉</description>
      </property>     <property>
          <name>dfs.data.dir</name>
          <value>/hadoop/1x/clusterm/hdfs/data</value>
         <description>data node的数据目录,以,号隔开,hdfs会把数据存在这些目录下,一般这些目录是不同的块设备,不存在的目录会被忽略掉</description>
      </property>
      
      <property>
          <name>dfs.replication</name>
          <value>2</value>
         <description>文件复制的副本数,如果创建时不指定这个参数,就使用这个默认值作为复制的副本数</description>
      </property>
 </configuration>    conf/mapred-site.xml
 <?xml version="1.0"?>
 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
 <!-- Put site-specific property overrides in this file. -->
 <configuration>
      <property>
          <name>mapred.job.tracker</name>
          <value>bigdata01:9001</value>
          <description>job tracker交互端口</description>
      </property>
 </configuration>    conf/masters
 bigdata01    conf/slaves
 bigdata02
 bigdata03


    
3.2.2.复制hadoop1.2.1的安装包至其他两个机器
    上传集群拷贝脚本和集群命令脚本,并执行chmod +x *.sh
cluster_copy_all_nodes.sh
cluster_run_all_nodes.sh

    压缩hadoop-1.2.1目录,并scp至bigdata02,bigdata03
tar -zcvf hadoop-1.2.1.tar.gz hadoop-1.2.1
./cluster_copy_all_nodes.sh "bigdata02 bigdata03" /opt/hadoop-1.2.1.tar.gz /opt/hadoop-1.2.1.tar.gz

    解压缩,并创建软连接
./cluster_run_all_nodes.sh "bigdata02 bigdata03" "tar -zxvf /opt/hadoop-1.2.1.tar.gz"
./cluster_run_all_nodes.sh "bigdata02 bigdata03" "cd  /opt;ln -s hadoop-1.2.1 hadoop"

3.2.3.格式化启动
    
hadoop namenode -format
start-all.sh
3.2.4.验证
    在各台机器上执行jps

3.2.5.异常错误处理
    hadoop上传文件命令,报错could only be replicated to 0 nodes, instead of 1
    并且logs文件中也提示错误

    
首先排除是之前安装的旧版本影响,确认目录没有重复
第二修改/etc/hosts文件,将127.0.0.1 的两行都屏蔽,并执行service network restart

3.3.Hadoop2.X伪分布式

待完成

3.4.Hadoop2.X完全分布式

待完成