Ubuntu 14.04下Hadoop 2.6.0单机配置和伪分布式配置
在Ubuntu下创建Hadoop用户组和用户
Hadoop的管理员最好就是以后要登录桌面环境运行eclipse的用户,否则后面会有拒绝读写的问题出现。当然不是也有办法办法解决。
1. 创建hadoop用户组;
sudo addgroup hadoop
2. 创建hadoop用户;
sudo adduser -ingroup hadoop hadoop
3. 给hadoop用户添加权限,打开/etc/sudoers文件;
sudo gedit /etc/sudoers
在root ALL=(ALL:ALL) ALL下添加hadoop ALL=(ALL:ALL) ALL.
在Ubuntu下安装JDK
具体见: //JAVA_HOME=/usr/lib/jvm/jdk1.8.0_25
安装ssh服务
sudo apt-get install ssh openssh-server
建立ssh无密码登录本机
切换到hadoop用户,执行以下命令:
su - hadoopssh生成密钥有rsa和dsa两种生成方式,默认情况下采用rsa方式。
1. 创建ssh-key,,这里我们采用rsa方式;
ssh-keygen -t rsa -P "" (注:回车后会在~/.ssh/下生成两个文件:id_rsa和id_rsa.pub这两个文件是成对出现的)
2. 进入~/.ssh/目录下,将id_rsa.pub追加到authorized_keys授权文件中,开始是没有authorized_keys文件的;
cd ~/.ssh
cat id_rsa.pub >> authorized_keys (完成后就可以无密码登录本机了。)
3. 登录localhost;
ssh localhost
4. 执行退出命令;
exit
安装hadoop
1. 把hadoop解压到/usr/local下:
sudo tar -zxvf hadoop-2.6.0.tar.gz
sudo mv hadoop-2.6.0 /usr/local/hadoop
sudo chmod -R 775 /usr/local/hadoop
sudo chown -R hadoop:hadoop /usr/local/hadoop //否则ssh会拒绝访问
2.配置
修改bashrc的配置:
sudo gedit ~/.bashrc
在文件末尾添加:
#HADOOP VARIABLES START
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_25
export HADOOP_INSTALL=/usr/local/hadoop
export PATH=$PATH:$HADOOP_INSTALL/bin
export PATH=$PATH:$HADOOP_INSTALL/sbin
export HADOOP_MAPRED_HOME=$HADOOP_INSTALL
export HADOOP_COMMON_HOME=$HADOOP_INSTALL
export HADOOP_HDFS_HOME=$HADOOP_INSTALL
export YARN_HOME=$HADOOP_INSTALL
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_INSTALL/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_INSTALL/lib"
#HADOOP VARIABLES END
如果不知道JAVA_HOME可以通过命令获得:
update-alternatives --config java目录取到java根目录即可。
执行下面命令使改动生效:
source ~/.bashrc
修改hadoop-env.sh的配置:
sudo gedit /usr/local/hadoop/etc/hadoop/hadoop-env.sh
找到JAVA_HOME改为上面的值。
测试
通过执行hadoop自带实例WordCount验证是否安装成功
/usr/local/hadoop路径下创建input文件夹
mkdir input
cp README.txt input
在hadoop目录下执行WordCount:
bin/hadoop jar share/hadoop/mapreduce/sources/hadoop-mapreduce-examples-2.6.0-sources.jar
org.apache.hadoop.examples.WordCount input output
Hadoop伪分布式配置
sudo gedit /usr/local/hadoop/etc/hadoop/core-site.xml
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/local/hadoop/tmp</value>
<description>Abase for other temporary directories.</description>
</property>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
sudo gedit /usr/local/hadoop/etc/hadoop/mapred-site.xml //此项不必要
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>localhost:9001</value>
</property>
</configuration> sudo gedit /usr/local/hadoop/etc/hadoop/yarn-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
</configuration>
sudo gedit /usr/local/hadoop/etc/hadoop/hdfs-site.xml