linux常用脚本


#!/bin/bash
#1 获取输入参数个数,如果没有参数,直接退出
pcount=$#
if ((pcount==0)); then
echo no args;
exit;
fi
#2 获取文件名称
p1=$1
fname=`basename $p1`
echo fname=$fname
#3 获取上级目录到绝对路径
pdir=`cd -P $(dirname $p1); pwd`
echo pdir=$pdir
#4 获取当前用户名称
user=`whoami`
#5 循环
for((host=104; host<107; host++)); do
        echo ------------------- hadoop$host --------------
        rsync -rvl $pdir/$fname $user@hadoop$host:$pdir
done

#!/bin/bash
for i in hadoop104 hadoop105 hadoop106
do
        echo "===-------------$i--------------==="
        ssh $i /opt/module/jdk1.8.0_144/bin/jps
done

#!/bin/bash
echo " __  __    ______    _____     ______    ______    ______  ";
echo "/\ \_\ \  /\  __ \  /\  __-.  /\  __ \  /\  __ \  /\  == \ ";
echo "\ \  __ \ \ \  __ \ \ \ \/\ \ \ \ \/\ \ \ \ \/\ \ \ \  _-/ ";
echo " \ \_\ \_\ \ \_\ \_\ \ \____-  \ \_____\ \ \_____\ \ \_\   ";
echo "  \/_/\/_/  \/_/\/_/  \/____/   \/_____/  \/_____/  \/_/   ";
echo "                                                           ";

case $1 in
"start"){
        echo "=-=-=-=-=-=-=-=-=-=-=-=-启动HDFS=-=-=-=-=-=-=-=-=-=-=-=-=-"
        /opt/module/hadoop-2.7.2/sbin/start-dfs.sh
        echo "=-=-=-=-=-=-=-=-=-=-=-=-启动YARN=-=-=-=-=-=-=-=-=-=-=-=-=-"

        ssh hadoop105 "/opt/module/hadoop-2.7.2/sbin/start-yarn.sh"
        echo "=-=-=-=-=-=-=-=-=-=-=-启动历史服务器=-=-=-=-=-=-=-=-=-=-"
        ssh hadoop106 "/opt/module/hadoop-2.7.2/sbin/mr-jobhistory-daemon.sh start historyserver"
};;
"stop"){
        echo "=-=-=-=-=-=-=-=-=-=-=-=-=-关闭历史服务器=-=-=-=-=-=-=-=-=-=-"
        ssh hadoop106 "/opt/module/hadoop-2.7.2/sbin/mr-jobhistory-daemon.sh stop historyserver"
        echo "=-=-=-=-=-=-=-=-=-=-=-=-=-关闭YARN=-=-=-=-=-=-=-=-=-=-=-=-=-"
        ssh hadoop105 "/opt/module/hadoop-2.7.2/sbin/stop-yarn.sh"
        echo "=-=-=-=-=-=-=-=-=-=-=-=-=-关闭HDFS=-=-=-=-=-=-=-=-=-=-=-=-=-"
        /opt/module/hadoop-2.7.2/sbin/stop-dfs.sh
};;
esac

#! /bin/bash
echo "                _                             ";
echo " _______   ___ | | _____  ___ _ __   ___ _ __ ";
echo "|_  / _ \ / _ \| |/ / _ \/ _ \ '_ \ / _ \ '__|";
echo " / / (_) | (_) |   <  __/  __/ |_) |  __/ |   ";
echo "/___\___/ \___/|_|\_\___|\___| .__/ \___|_|   ";
echo "                             |_|              ";

case $1 in
"start"){
        for i in hadoop104 hadoop105 hadoop106
        do
                ssh $i "/opt/module/zookeeper-3.4.10/bin/zkServer.sh start"
        done
};;
"stop"){
        for i in hadoop104 hadoop105 hadoop106
        do
                ssh $i "/opt/module/zookeeper-3.4.10/bin/zkServer.sh stop"
        done
};;
"status"){
        for i in hadoop104 hadoop105 hadoop106
        do
                ssh $i "/opt/module/zookeeper-3.4.10/bin/zkServer.sh status"
        done
};;
esac

#! /bin/bash




echo " _    _       ___ _          ";
echo "| |  / )     / __) |         ";
echo "| | / / ____| |__| |  _ ____ ";
echo "| |&lt; &lt; / _  |  __) | / ) _  |";
echo "| | \ ( ( | | |  | |&lt; ( ( | |";
echo "|_|  \_)_||_|_|  |_| \_)_||_|";
echo "                             ";

case $1 in
"start"){
        for i in hadoop104 hadoop105 hadoop106
        do
                echo " --------启动 $i Kafka-------"
                ssh $i "/opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties "
        done
};;
"stop"){
        for i in hadoop104 hadoop105 hadoop106
        do
                echo " --------停止 $i Kafka-------"
                ssh $i "/opt/module/kafka/bin/kafka-server-stop.sh stop"
        done
};;
esac

#!/bin/bash
es_home=/opt/module/elasticsearch-6.3.1
case $1  in
 "start") {
  for i in hadoop104 hadoop105 hadoop106
  do
    echo "==============$i=============="
    ssh $i  "source /etc/profile;su elsearch;${es_home}/bin/elasticsearch >/dev/null 2>&amp;1 &amp;"
  done

};;
"stop") {
  for i in hadoop104 hadoop105 hadoop106
  do
    echo "==============$i=============="
    ssh $i "ps -ef|grep $es_home |grep -v grep|awk '{print \$2}'|xargs kill" >/dev/null 2>&amp;1
  done

};;
esac

#! /bin/bash

case $1 in
"start"){
        for i in hadoop104 hadoop105
        do
                echo " --------启动 $i 采集flume-------"
                ssh $i "nohup /opt/module/flume/bin/flume-ng agent --conf-file /opt/module/flume/conf/file-flume-kafka.conf --name a1 -Dflume.root.logger=INFO,LOGFILE >/opt/module/fl.txt 2>&amp;1 &amp;"
        done
};;
"stop"){
        for i in hadoop104 hadoop105
        do
                echo " --------停止 $i 采集flume-------"
                ssh $i "ps -ef | grep file-flume-kafka | grep -v grep |awk '{print \$2}' | xargs kill"
        done

};;
esac

#! /bin/bash

case $1 in
"start"){
        for i in hadoop106
        do
                echo " --------启动 $i 消费flume-------"
                ssh $i "nohup /opt/module/flume/bin/flume-ng agent --conf-file /opt/module/flume/conf/kafka-flume-hdfs.conf --name a1 -Dflume.root.logger=INFO,LOGFILE >/opt/module/flume/log.txt   2>&amp;1 &amp;"
        done
};;
"stop"){
        for i in hadoop106
        do
                echo " --------停止 $i 消费flume-------"
                ssh $i "ps -ef | grep kafka-flume-hdfs | grep -v grep |awk '{print \$2}' | xargs kill"
        done

};;
esac
linux常用脚本

发表评论

电子邮件地址不会被公开。 必填项已用*标注

滚动到顶部