论小脚本的重要性

脚本可以节约很多麻烦的问题 可以省时省力 

将本地磁盘的日志文件,收集到hadoop集群中

#!/bin/bash

#设置jdk环境变量

export JAVA_HOME=/hadoop/java/jdk1.7.0_80

export JRE_HOME=${JAVA_HOME}/jre

export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib

export PATH=${JAVA_HOME}/bin:$PATH

#设置hadoop的环境变量

export HADOOP_HOME=/hadoop/hadoopinfo/hadoop-2.4.1

export PATH=${HADOOP_HOME}/bin:${HADOOP_HOME}/sbin:$PATH

#日志文件存放的目录

log_src_dir=/opt/

#日志文件上传到hdfs的根路径

hdfs_root_dir=/

#读取日志文件的目录,判断是否有需要上传的文件

ls $log_src_dir | while read fileName

do

        if [ "hadoop.log" = "$fileName" ];then

                hadoop fs -put $log_src_dir$fileName $hdfs_root_dir

                

        fi

done

**********************************************************************************************

 

使用一个for循环 就可以启动三台机器 不需要一台一台麻烦了

启动hadoop集群的脚本

#!/bin/bash

user=root

echo start zookeeper...

for zk in slave slave2 slave3

do

ssh $user@$zk "/hadoop/zookeeper/zookeeper-3.4.5/bin/zkServer.sh start"

done

echo zookeeper started

 

echo start hdfs...

hdfs=master

ssh $user@$hdfs "/hadoop/hadoopinfo/hadoop-2.4.1/sbin/start-dfs.sh"

echo hdfs started

 

echo start yarn...

yarn=master

rsm=master2

ssh $user@$yarn "/hadoop/hadoopinfo/hadoop-2.4.1/sbin/start-yarn.sh"

ssh $user@$rsm "/hadoop/hadoopinfo/hadoop-2.4.1/sbin/yarn-daemon.sh start resourcemanager"

echo yarn started

 

***********************************************************

关闭hadoop集群的脚本

#!/bin/bash

user=root

echo stop zookeeper...

for zk in slave slave2 slave3

do

ssh $user@$zk "/hadoop/zookeeper/zookeeper-3.4.5/bin/zkServer.sh stop"

done

echo zookeeper stoped

 

echo stop hdfs...

hdfs=master

ssh $user@$hdfs "/hadoop/hadoopinfo/hadoop-2.4.1/sbin/stop-dfs.sh"

echo hdfs stoped

 

echo stop yarn...

yarn=master

rsm=master2

ssh $user@$yarn "/hadoop/hadoopinfo/hadoop-2.4.1/sbin/stop-yarn.sh"

ssh $user@$rsm "/hadoop/hadoopinfo/hadoop-2.4.1/sbin/yarn-daemon.sh stop resourcemanager"

echo yarn stoped

^^^^^^启动和关闭是不是一样  哈哈哈哈哈

posted @ 2019-04-08 18:44  后山人  阅读(336)  评论(0编辑  收藏  举报