• 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
  • 相关阅读:
    Problem D: 双向冒泡排序
    Problem C: 查找最大元素
    Problem D: 小平查密码
    Problem C: 文件单词首字母大写
    Problem B: 文件操作文本文件读入
    Problem A: 文件操作二进制文件读入
    Problem A: 实现链表(线性表)
    【leetcode】包含min函数的栈
    【leetcode】反转链表
    【leetcode】合并两个排序的链表
  • 原文地址:https://www.cnblogs.com/kwzblog/p/8818467.html
Copyright © 2020-2023  润新知