linux 常用脚本

自定义环境变量

/etc/profile.d/my_env.sh

# JAVA_HOME
export JAVA_HOME=/opt/module/jdk1.8.0_171
export JRE_HOME=$JAVA_HOME/jre
export ClASSPATH=.:$JAVA_HOME:$JRE_HOME/lib:$CLASSPATH
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin 

# KAFKA_HOME
export PATH=$PATH:/opt/module/kafka/bin

#ZOOKEEPER_HOME
export PATH=$PATH:/opt/module/zookeeper/bin

一、文件分发脚本

/usr/local/bin/xsync

#!/bin/bash
pdir=$(cd -P $(dirname $1); pwd)
for i in 22 23;
do
    scp -r $1 [email protected].$i:$pdir/;
done

示例:

xsync Copt/software/jdk-8u171-linux-x64.tar.gz

二、远程执行命令脚本

/usr/local/bin/xcall

#!/bin/bash

for i in kafka-21 kafka-22 kafka-23
do
    echo "------------- $i  \"$1\"   ------------------"
    ssh $i "$1"
done

示例:

xcall "jps -l"

三、zookeeper启停脚本

/usr/local/bin/zk

#!/bin/bash
case $1 in
"start") {
    for i in kafka-21 kafka-22 kafka-23
    do
        echo "---------------------- start $i ------------"
        ssh $i "/opt/module/zookeeper/bin/zkServer.sh start /opt/module/zookeeper/conf/zoo.cfg"
    done
};;
"stop") {
    for i in kafka-21 kafka-22 kafka-23
    do
        echo "------------------ stop $i -----------------"
        ssh $i "/opt/module/zookeeper/bin/zkServer.sh stop"
    done
};;
"status") {
    for i in kafka-21 kafka-22 kafka-23
    do
        echo "----------------- status $i ------------------"
        ssh $i "/opt/module/zookeeper/bin/zkServer.sh status"
    done
};;
esac

四、kafka启停脚本

/usr/local/bin/kf

#!/bin/bash
case $1 in
"start") {
    for i in kafka-21 kafka-22 kafka-23
    do
        echo "---------------------- start $i ------------"
        ssh $i "/opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties"
    done
};;
"stop") {
    for i in kafka-21 kafka-22 kafka-23
    do
        echo "------------------ stop $i -----------------"
        ssh $i "/opt/module/kafka/bin/kafka-server-stop.sh"
    done
};;
esac

你可能感兴趣的:(zookeeper,kafka,Linux下的操作,linux,kafka,zookeeper)