• 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
  • 相关阅读:
    关于OCI接口理解
    linux 关闭selinux
    Web 浏览器之事件循环 Event Loop
    Web 浏览器之页面展示原理
    Web 前端工程化(Node、Babel、webpack、Vue、Nginx)
    Web 包管理工具(npm、yarn、cnpm、pnpm)
    kmeans算法
    Django_re_path_使用正则匹配url
    VMware_关机未关闭vm导致显示红叉的处理方法
    Django_发送邮件
  • 原文地址:https://www.cnblogs.com/kwzblog/p/8818467.html
Copyright © 2020-2023  润新知