本文以hadoop-2.2.0,zookeeper-3.4.5, hbase-0.96为例说明集群的批量安装过程
安装前,要规划好服务器,并更改服务器的名称,并配置好host文件。
批量安装首先要准备安装文件和配置文件:
hadoop-2.2.0.tar.gz
hbase-0.96.0-hadoop2-bin.tar.gz
zookeeper-3.4.5.tar.gz
jdk-7u5-linux-i586.rpm
profile(配置好的环境变量文件)
如:我的profile文件:
export JAVA_HOME=/usr/java/jdk1.7.0_05
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export HADOOP_HOME=/home/hadoop/hadoop
export HBASE_HOME=/home/hadoop/hbase
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$HADOOP_HOME/bin:$HBASE_HOME/bin:/usr/expect/bin
hadoop 配置文件夹(已配置好) hadoopconf
hbase 配置文件夹(已配置好) hbaseconf
zookeeper配置文件夹(已配置好) zookeeperconf
1、安装jdk脚本
#!bin/bash
for((i=133;i<135;i++))
do
scp /root/jdk-7u5-linux-i586.rpm root@192.168.189.$i:/root/
scp profile root@192.168.189.$i:/etc/profile
ssh 192.168.189.$i 'source /etc/profile;
rpm -ivh /root/jdk-7u5-linux-i586.rpm'
done
2、安装hadoop和hbase脚本
#!/bin/bash
for((i=133;i<135;i++))
do
scp hadoop-2.2.0.tar.gz hadoop@192.168.189.$i:/home/hadoop/
scp hbase-0.96.0-hadoop2-bin.tar.gz hadoop@192.168.189.$i:/home/hadoop/
scp -r hadoopconf hadoop@192.168.189.$i:/home/hadoop/
scp -r hbaseconf hadoop@192.168.189.$i:/home/hadoop/
ssh 192.168.189.$i 'cd /home/hadoop/;
tar zxzf hadoop-2.2.0.tar.gz -C /home/hadoop;
tar zxvf hbase-0.96.0-hadoop2-bin.tar.gz -C /home/hadoop;
ln -s /home/hadoop/hadoop-2.2.0 /home/hadoop/hadoop;
ln -s /home/hadoop/hbase-0.96.0-hadoop2 /home/hadoop/hbase;
cp /home/hadoop/hadoopconf/* /home/hadoop/hadoop/etc/hadoop/;
cp /home/hadoop/hbaseconf/* /home/hadoop/hbase/conf/;
mv /home/hadoop/hbase/lib/hadoop-* /home/hadoop/hadoop/lib/'
done
3、安装zookeeper脚本
#!/bin/bash
j=0;
for((i=133;i<136;i++))
do
j=$[$j+1]
echo $j > myid;
scp myid root@192.168.189.$i:/home/hadoop/;
scp zookeeper-3.4.5.tar.gz root@192.168.189.$i:/home/hadoop/
scp -r zookeeperconf root@192.168.189.$i:/home/hadoop/
ssh 192.168.189.$i 'cd /home/hadoop/;
tar zxzf zookeeper-3.4.5.tar.gz -C /home/hadoop;
ln -s /home/hadoop/zookeeper-3.4.5 /home/hadoop/zookeeper;
cp -f /home/hadoop/zookeeperconf/* /home/hadoop/zookeeper/conf/;
mkdir -p /home/hadoop/zookeeper/data;
cp myid /home/hadoop/zookeeper/data/; '
done
4、配置无密钥链接
#!/bin/bash
ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa;
for((i=133;i<135;i++));
do
scp ~/.ssh/id_dsa.pub hadoop@192.168.189.$i:~/
ssh 192.168.189.$i 'mkdir .ssh;
chmod 755 .ssh;
cat id_dsa.pub >>.ssh/authorized_keys;
chmod 644 .ssh/authorized_keys;'
done
除jdk外,都默认安装到/home/hadoop路径下