shell脚本分析笔记(2)

dockerfile

#!/bin/bash

ORIGIN_PATH="/home/admin/jstorm"
JSTORM_PATH="/export/servers/jstorm"
HOST_IP=`/sbin/ip -4 addr|grep inet |grep -v '127.0.0.1'|grep -E "192.|172.|10."|awk '{print $2}'|cut -d / -f1|head -1`

function init_env()
{
   
    useradd adsop
    source /home/admin/tags
    echo "$__ADSOP_PAWD__"|passwd --stdin adsop
    echo "$__ROOT_PASSWORD__"|passwd --stdin root
    echo "$__ADMIN_PASSWORD__"|passwd --stdin admin

    sed -i '/net.ipv4.ip_local_port_range/d' /etc/sysctl.conf
    echo "net.ipv4.ip_local_port_range = 32768 65535" >> /etc/sysctl.conf
    sysctl -p
}

function execshell()
{
   
    echo "[execshell]$@ begin."                                            #输出“”里的字符串
    eval $@                                                                 #执行@传入的参数,$@:传递给脚本或函数的所有参数。
    [[ $? != 0 ]] && {
                          
        echo "[execshell]$@ failed."                                          #如果$@传入的参数不是0,输出“exeshell xxx failed”
        exit 1                                                                   #返回1 
    }
    echo "[execshell]$@ success."                                              #成功输出“exeshell xxx success”
    return 0																    #返回0
}

function abnormal_exit()
{
   
    echo "[FATAL]$@"
    exit 1
}

function jstorm_release()
{
   
    execshell "install_java"
    # execshell "install_jcollect"
    #install jstorm
    cd /export/servers/
    wget -T30 -t2 ftp://mfs.jd.com:/mnt/mfs/release/software/jstorm/jstorm-2.2.1.zip -O jstorm-2.2.1.zip &>/dev/null
    [[ $? -ne 0 ]] && abnormal_exit "wget jstorm-2.2.1.zip fail"
    /bin/rm -rf jstorm-2.2.1 jstorm ~/.jstorm
    unzip jstorm-2.2.1.zip &>/dev/null
    [[ $? -ne 0 ]] && abnormal_exit "unzip jstorm-2.2.1.zip fail"
    /bin/rm -rf jstorm-2.2.1.zip
    ln -s jstorm-2.2.1 jstorm
    mv ./jstorm/conf/storm.yaml ./jstorm/conf/storm.yaml.bak  #备份源生配置文件
    cp -f $ORIGIN_PATH/storm.yaml ./jstorm/conf/
    cp -f $ORIGIN_PATH/jstorm.logback.xml ./jstorm/conf/
    #set cluster.name
    sed -i "s/cluster.name:.*/cluster.name: \"$__CLUSTER_NAME__\"/g" /export/servers/jstorm/conf/storm.yaml
    #set work mem
    sed -i "s/^worker.memory.size:.*/worker.memory.size: $__WORKER_MEM__/g" /export/servers/jstorm/conf/storm.yaml
    # clear supervisor_slots
    sed -ri '/^supervisor.slots.ports:/,${/^ +- [0-9]+$/d}' /export/servers/jstorm/conf/storm.yaml
    # set supervisor_slots
    for((i=$[__SUPERVISOR_SLOTS__-1];i>=0;i--))
    do
        port=$[6800+i]
        sed -ri "/^supervisor.slots.ports:/a\    - $port" /export/servers/jstorm/conf/storm.yaml
    done
    # clear zookeeper server
    local zoo_num=`grep -Eoc '^\s+- "[0-9.]+"$' /export/servers/jstorm/conf/storm.yaml`
    sed -ri "/^storm.zookeeper.servers/,+$zoo_num{/^\s+- \"[0-9.]+\"$/d}" /export/servers/jstorm/conf
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值