Automatically implement Hadoop decommission shell script version

Source: Internet
Author: User
Tags ansible playbook

Introduced

Before I had a blog post that describes how to automate Hadoop decommission with Ansible playbook, this article describes using shell scripting.

The scripts are placed on the springboard machine, and the remote server calls the local script to complete all operations without copying files to the remote server.


Body

Main script: decom.sh

#!/bin/bashiplist=/home/hadoop/shell_scripts/iplist#1. process iplist ,append them  into exclude files # call append.shfor exclude_host in  ' cat $ IPList '  ; do    ssh [email protected]  "Bash -s"  <  append.sh  "$exclude _host"  hdfs-exclude    ssh [email protected]   "Bash -s"  < append.sh  "$exclude _host"  mapred-exclude     ssh [email protected]  "Bash -s"  < append.sh  "$exclude _host"   hdfs-exclude    ssh [email protected]  "Bash -s"  <  append.sh  "$exclude _host"  mapred-excludedone#2. ssh [email protected]  "bash  -s " < refreshnodes.shssh [email protected] " Bash -s " <  Refreshnodes.sh#3. stop nodemanaGer and datanode service ,maybe regionserver service toofor client  in  ' cat iplist ';  do    ssh [email protected] "${client}"   "Bash -s"   < stopservice.shdone

Sub-script: append.sh

#!/bin/bashconf_dir=/opt/hadoop-2.6.0/etc/hadoop/backup_dir=/opt/hadoop-2.6.0/etc/hadoop/bak/exclude_host=$ 1exclude_file=$2function usage ()  {    echo -e  "usage: $0  exclude file\nplease input the parameter ---- mapred-exclude or  Hdfs-exclude "}if [ $# -ne 2 ] ;then    usage     exit 1elif [  "$exclude _file"  !=  "Mapred-exclude"  -a  "$exclude _ File " != " Hdfs-exclude " ];then    usage    exit  1fi#if [ -d /apache/hadoop/conf ] ;then#    cd /apache/ hadoop/conf#else#    echo  "dir /apache/hadoop/conf doesnot exist  ,  please check! " #    exit 3#fi[ ! -d ${backup_dir} ] && mkdir  ${backup_dir}# backup exclude file cp  "${conf_dir}${exclude_file}"  ${backup_dir} "${ Exclude_file} "-' date +%f.%h.%m.%s ' # append hosts to exclude file     grep ${exclude_host}  "${conf_dir}${exclude_file}"  >/dev/null 2>&1     retval=$?    if [  $retval  -ne 0 ];then         echo ${exclude_host} >>  "${conf_dir}${ Exclude_file} "    else        echo " Duplicated host: ${exclude_host} "    fi

Sub-script: refreshnodes.sh

#!/bin/bashhadoop_bin_dir=/opt/hadoop-2.6.0/bin/${hadoop_bin_dir}yarn rmadmin-refreshnodes 2>/dev/nullif [$?- NE 0];    then echo "Command yarn rmadmin-refreshnodes Failed on $ (hostname)!!!" Exit 2fi# Wait a while to let MapReduce can switch jobs to other nodes sleep 2${hadoop_bin_dir}hadoop Dfsadmin-refreshnod Es 2>/dev/nullif [$?-ne 0];        then echo "Command Hadoop dfsadmin-refreshnodes Failed on $ (hostname)!!!" Exit 3fi

Sub-script: stopservice.sh

#!/bin/bashhadoop_bin_dir=/opt/hadoop-2.6.0/sbin/#svc-D/service/nodemanager#svc-d/service/datanode${hadoop_bin _dir}yarn-daemon.sh Stop nodemanager${hadoop_bin_dir}hadoop-daemon.sh Stop Datanode

Files: IPList

10.9.214.16010.9.214.149

Operation:

Bash decom.sh


This article is from "Linux and Network" blog, declined reprint!

Automatically implement Hadoop decommission shell script version

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.