zoukankan      html  css  js  c++  java
  • shell脚本

    1.免密码登陆脚本 sshFreeLogin.sh

    集群服务器间相互访问:

    首先有一个ip列表:

    ip.list:

    192.168.2.240
    192.168.2.241
    192.168.2.242

    sshFreeLogin.sh:

    #!/bin/bash
      
    #author:  chongyuanHuang
    #blog:               http://blog.sina.com.cn/huangchongyuan    
    #QQ group:      191321336
    #E-mail:   874450476@qq.com
      
    function Echo() {
             parameter=$1 
             name=$2
             if [ $1 -ne 1 ]; then
                     echo "Usage:  $2  ip.list"
                     echo "        please input ip.list for freelogin and password next"
                     exit 1
             fi      
    }
      
    function LocalSsh() {
             remote=$1
             echo "------------------------------------------------------------"
             echo "Begin to set Local-Remote free login!"
             ssh-keygen -t rsa -P ''
             scp /root/.ssh/id_rsa.pub  $1:/root/id_rsa.pub
             ssh $1 'cat /root/id_rsa.pub >> /root/.ssh/authorized_keys'
             ssh  $1 'chmod 600  /root/.ssh/authorized_keys'
             echo "Local-Remote free login set Ok!"
             echo "------------------------------------------------------------"
    }
      
    if [ $# -eq 1 ]; then
             num=`awk 'END{print NR}' $1`
             echo 'Set free login ip.list:'
      
             for ((i=1;i<=$num;i++)); do
                       ip=`cat $1 | sed -n ''$i'p'`
                       echo $ip
                       LocalSsh $ip
             done
    else
             Echo $# $0
    fi

    2.optZk.sh

    zk集群操作脚本,配合免登陆设置,在一台机器上进行zk集群的启动,停止及查看状态等操作。

    optZk.sh脚本:

    #!/bin/bash
      
    #author:  chongyuanHuang
    #blog:               http://blog.sina.com.cn/huangchongyuan    
    #QQ group:      191321336
    #E-mail:   874450476@qq.com
      
    function Echo() {
             parameter=$1 
             name=$2
             if [ $parameter -ne 2 ]; then
                     echo "Usage:  $name ip.list  start/stop/status"
                     echo "        please input ip.list opt"
                     exit 1
             fi      
    }
      
    function optZk() {
             ip=$1
             opt=$2     
             echo "------------------------------------------------------------"
             echo "Begin to '$opt' '$ip' ZK:"
             ssh $1 '/usr/local/zookeeper/bin/zkServer.sh '$opt''
             echo "------------------------------------------------------------"
    }
      
    if [ $# -eq 2 ]; then
             num=`awk 'END{print NR}' $1`
      
             for ((i=1;i<=$num;i++)); do
                       ip=`cat $1 | sed -n ''$i'p'`
                       echo $ip
                       optZk $ip $2
             done
    else
             Echo $# $0
    fi

    3、nimbus监控,一旦nimbus挂掉就重启,并把日志写到log里。

    monitorNimbus.sh:

    #!/bin/bash
    
    function Init() {
             date=`date +%Y%m%d%H%M%S`
             echo ''$date': Begin monitor nimbus.' > monitorNimbus.log
    }
      
    function MonitorNimbus() {
             for ((;;)); do
                       num=`ps aux | grep nimbus | grep -v grep | wc -l`
                       if [ $num -eq 0 ]; then
                                date1=`date +%Y%m%d%H%M%S`
                                echo ''$date1': nimbus is down, and restarting!' >> monitorNimbus.log
                                storm nimbus&
                       fi
                       sleep 60
             done
              
    }
      
    Init
    MonitorNimbus
    exit 1
  • 相关阅读:
    程序员必须知道的10大基础实用算法及其讲解
    6 Java Exceptions that Haunts a Newbie Java Developer(Java菜鸟6种常见的异常)
    在线学习Java免费资源推荐(来自:importnew)
    Oracle触发器
    Oracle性能分析工具介绍及使用
    开口大数据闭口高并发,你们都是怎么回答
    Http中Get/Post请求区别
    快速排序算法
    MAG EF查询增加指定索引功能
    WEB传参
  • 原文地址:https://www.cnblogs.com/kwzblog/p/8818467.html
Copyright © 2011-2022 走看看