1.      卸载CentOS自带的JDK和多余的软件

yum remove java* libreoffice* -y

2.      关闭防火墙,SELINUX

systemctl stop firewalld.service

systemctl disable firewalld.service

编辑文件/etc/selinux/config

SELINUX=enforcing 改为 SELINUX= disabled

3.      设置SSH免密码登陆

输入命令,ssh-keygen -t rsa ,生成key,一直回车,/root就会生成.ssh文件夹

接下来执行以下命令


cd ~/.ssh/ 

cat id_rsa.pub >> authorized_keys

chmod 644 ~/.ssh/authorized_keys

chmod 744 ~/.ssh/

systemctl enable sshd.service

scp -rp authorized_keys 客户端IP:/root/.ssh/

(scp没有.ssh目录,使用客户端ssh连接一下服务端即生成该文件夹)


三台hadoop集群:

192.168.159.151  master

192.168.159.152  slave1

192.168.159.153  slave2


修改主机名hostname(客户端服务端均修改)

[root@master ~]# cat /etc/sysconfig/network(永久修改)

# Created by anaconda

NETWORKING=yes

HOSTNAME=master



hostnamectl set-hostname [主机名]

例 :hostnamectl set-hostname master

修改/etc/hosts

格式为:

[root@slave1 /]# cat /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.159.151  master

192.168.159.152  slave1

192.168.159.153  slave2


解压包:

cd /usr/local/src/;rz -yb 上传hadoop-1.2.1-bin.tar.gz和jdk-6u45-linux-x64.bin

tar zxvf  hadoop-1.2.1-bin.tar.gz;./jdk-6u45-linux-x64.bin


拷贝到各节点:

scp -rp jdk1.6.0_45  slave1:/usr/local/src/

cd  /usr/local/src/jdk1.6.0_45/bin;./java


vi ~/.bashrc 

加入JAVA的环境变量:

export JAVA_HOME=/usr/local/src/jdk1.6.0_45

export CLASSPATH=.:CLASSPATH:JAVA_HOME/lib

export PATH=$PATH:$JAVA_HOME/bin

source ~/.bashrc 


hadoop安装:

cd /usr/local/src/hadoop-1.2.1

mkdir tmp(存放临时文件,core-site.xml 配置文件指定其pwd路径)

cd /usr/local/src/hadoop-1.2.1/conf


修改masters,slaves文件:

[root@master conf]# cat masters 

master

[root@master conf]# cat slaves 

slave1

slave2


[root@master conf]# cat 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.replication</name>

                <value>3</value>

        </property>

</configuration>

                                                                                                                                                                           

[root@master conf]# cat 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>hadoop.tmp.dir</name>

                <value>/usr/local/src/hadoop-1.2.1/tmp</value>

        </property>

        <property>

                <name>fs.default.name</name>

                <value>hdfs://192.168.159.151:9000</value>

        </property>

</configuration>


[root@master conf]# cat 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.replication</name>

                <value>3</value>

        </property>

</configuration>


[root@master conf]# cat 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>http://192.168.159.151:9001</value>

        </property>

</configuration>


在hadoop-env.sh加入一行JAVA_HOME的环境变量: 

export JAVA_HOME=/usr/local/src/jdk1.6.0_45


master执行:

然后将服务端的hadoop-1.2.1目录scp到各客户端:

scp -rp /usr/local/src/hadoop-1.2.1 slave1:/usr/local/src/


cd /usr/local/src/hadoop-1.2.1/bin

格式化namenode:

 ./hadoop namenode -format

启动各节点: 

./start-all.sh


设置开机自动启动hadoop各节点,和生成hadoop启动命令的环境变量:


cat /root/.bashrc 

export JAVA_HOME=/usr/local/src/jdk1.6.0_45

export HADOOP_HOME=/usr/local/src/hadoop-1.2.1

#export PATH=.:$HADOOP_HOME/bin:$JAVA_HOME/bin:$PATH


$PATH换成现在定义的环境变量即可, :  用来分隔环境变量


export PATH=$PATH:$JAVA_HOME/bin:/usr/local/src/hadoop-1.2.1/bin


cat .bash_profile

.bash_profile里面追加一行:

export HADOOP_HOME_WARN_SUPPRESS=1

启动Hadoop时报了一个警告信息,我的系统是CentOS,安装的Hadoop版本是hadoop1.2.1,具体警告信息如下:

 bin/start-all.sh Warning: $HADOOP_HOME is deprecated.

网上的说法是因为Hadoop本身对HADOOP_HOME做了判断,具体在bin/hadoop和bin/hadoop-config.sh里。在hadoop-config.sh里有如下的配置:

if [ "$HADOOP_HOME_WARN_SUPPRESS" = "" ] && [ "$HADOOP_HOME" != "" ]; then
  echo "Warning: \$HADOOP_HOME is deprecated." 1>&2
  echo 1>&2fi


2. 在当前用户目录下的 .bash_profile 里增加一个环境变量: 
export HADOOP_HOME_WARN_SUPPRESS=1 注:修改完 .bash_profile 后需要执行 source 操作使其生效 


master查看启动的节点

[root@master hadoop-1.2.1]# jps

5676 Jps

3237 JobTracker

3158 SecondaryNameNode

2994 NameNode

slave查看启动的节点:

[root@slave1 ~]# jps

2673 DataNode

3346 Jps

2757 TaskTracker


查看hdfs

./hadoop fs -ls /

上传文件

./hadoop fs -put  /etc/passwd  /

查看上传的文件

./hadoop fs -cat  /passwd