DBILITY

테스트 시스템 관리(?) 스크립트 본문

bigdata

테스트 시스템 관리(?) 스크립트

DBILITY 2018. 5. 20. 20:12
반응형

테스트용 서버 5대를 한꺼번에 명령을 입력할 수는 없다...힘들다...

Shell Programming을 잘 하진 못하니 이것만도 어딘가.

스크립트를 실행할 호스트의 root ssh인증키로 관리할 서버에 비밀번호없이 접근가능하게 되어 있어야 한다.

이미 시작되어 있는 경우등을 체크해야 하겠지만 능력없다.

동일서버에 있는 서비스는 한꺼번에 적용 가능하다. 기록만이 살길이다

 

  • system 전체
    #!/bin/bash
    enable() {
            systemctl daemon-reload
            systemctl enable zookeeper
            systemctl enable hadoop
            systemctl enable tajo
            systemctl enable sqoop
            ssh big-slave2 "systemctl enable mariadb"
            ssh big-slave1 "systemctl enable zookeeper"
            ssh big-slave2 "systemctl enable zookeeper"
    
            systemctl enable kafka-manager
            ssh big-slave2 "systemctl enable kafka"
            ssh big-slave3 "systemctl enable kafka"
            ssh big-slave4 "systemctl enable kafka"
    
            echo "ecosystem enabled."
    }
    
    disable() {
            systemctl daemon-reload
            systemctl disable zookeeper
            systemctl disable hadoop
            systemctl disable tajo
            systemctl disable sqoop
            ssh big-slave2 "systemctl disable mariadb"
            ssh big-slave1 "systemctl disable zookeeper"
            ssh big-slave2 "systemctl disable zookeeper"
            
            systemctl disable kafka-manager
            ssh big-slave2 "systemctl disable kafka"
            ssh big-slave3 "systemctl disable kafka"
            ssh big-slave4 "systemctl disable kafka"
    
            echo "ecosystem disabled."
    }
    
    restart() {
    
            stop
            sleep 5
            start
    }
    
    start() {
            systemctl start zookeeper
            ssh big-slave1 "systemctl start zookeeper"
            ssh big-slave2 "systemctl start zookeeper"
            ssh big-slave2 "systemctl start mariadb"
    
            sleep 5
    
            systemctl start hadoop
            systemctl start tajo
            systemctl start sqoop
    
            ssh big-slave2 "systemctl start kafka"
            ssh big-slave3 "systemctl start kafka"
            ssh big-slave4 "systemctl start kafka"
            systemctl start kafka-manager
    
            echo "ecosystem started."
    }
    
    stop() {
            systemctl stop sqoop
            systemctl stop tajo
            systemctl stop hadoop
            systemctl stop zookeeper
            ssh big-slave1 "systemctl stop zookeeper"
            ssh big-slave2 "systemctl stop zookeeper"
            ssh big-slave2 "systemctl stop mariadb"
    
            systemctl stop kafka-manager
            ssh big-slave2 "systemctl stop kafka"
            ssh big-slave3 "systemctl stop kafka"
            ssh big-slave4 "systemctl stop kafka"
    
            echo "ecosystem stopped."
    }
    
    reboot() {
            echo "ecosystem reboot start...."
            stop
            sleep 3
            ssh big-slave1 "systemctl reboot"
            ssh big-slave2 "systemctl reboot"
            ssh big-slave3 "systemctl reboot"
            ssh big-slave4 "systemctl reboot"
            systemctl reboot
    }
    
    shutdown() {
            echo "ecosystem shutdown start...."
            stop
            sleep 3
            ssh big-slave1 "systemctl poweroff"
            ssh big-slave2 "systemctl poweroff"
            ssh big-slave3 "systemctl poweroff"
            ssh big-slave4 "systemctl poweroff"
            systemctl poweroff
    }
    
    case $1 in
            enable|disable|start|stop|restart|reboot|shutdown) "$1" ;;
    esac
    
    exit 0
  • kafka용
    #!/bin/bash
    
    enable() {
    
            systemctl daemon-reload
            systemctl enable zookeeper
            systemctl enable kafka-manager
    
            ssh big-slave1 "systemctl enable zookeeper"
            ssh big-slave2 "systemctl enable zookeeper"
            ssh big-slave2 "systemctl enable kafka"
            ssh big-slave3 "systemctl enable kafka"
            ssh big-slave4 "systemctl enable kafka"
    
            echo "kafka ecosystem enabled."
    }
    
    disable() {
            systemctl disable kafka-manager
            ssh big-slave2 "systemctl disable kafka"
            ssh big-slave3 "systemctl disable kafka"
            ssh big-slave4 "systemctl disable kafka"
            ssh big-slave1 "systemctl disable zookeeper"
            ssh big-slave2 "systemctl disable zookeeper"
            systemctl disable zookeeper
    
            echo "kafka ecosystem disabled."
    }
    
    restart() {
    
            stop
            sleep 5
            start
    }
    
    start() {
    
            systemctl start zookeeper
            ssh big-slave1 "systemctl start zookeeper"
            ssh big-slave2 "systemctl start zookeeper"
            sleep 3
            ssh big-slave2 "systemctl start kafka"
            ssh big-slave3 "systemctl start kafka"
            ssh big-slave4 "systemctl start kafka"
            systemctl start kafka-manager
    
            echo "kafka ecosystem started."
    }
    
    stop() {
            systemctl stop kafka-manager
            ssh big-slave2 "systemctl stop kafka"
            ssh big-slave3 "systemctl stop kafka"
            ssh big-slave4 "systemctl stop kafka"
            sleep 3
    
            systemctl stop zookeeper
            ssh big-slave1 "systemctl stop zookeeper"
            ssh big-slave2 "systemctl stop zookeeper"
    
            echo "kafka ecosystem stopped."
    }
    
    
    case $1 in
            enable|disable|start|stop|restart) "$1" ;;
    esac
    
    exit 0

 

반응형
Comments