脚本两则--用于快速部署HADOOP,SPARK这些(特别是VM虚拟机模板部署出来的)。。...

感觉可能只是适合我自己的部署习惯吧,且只针对CENTOS6及以下版本,以后有时间,可能还是要改进。。

1,从VM的模块产生的虚拟机,如何快速搞定网络配置?

#!/bin/bash

#usage:./init_cdh_sys.sh hostname hostip
#generate the host from esxi template.must change NIC mac address and change hostname 
net_rule_file="/etc/udev/rules.d/70-persistent-net.rules"
net_conf_file="/etc/sysconfig/network-scripts/ifcfg-eth0"
net_hostname_file="/etc/sysconfig/network"
netmask_conf="255.255.255.0"
gateway_conf="192.168.xx.1"
dns1_conf="a.b.c.d"
old_mac="00:50:56:BD:92:DA"#此处要替换为模板的MAC地址

#============================================
#resetup 70-persistent-net.rules file
if  (cat $net_rule_file|grep -i $old_mac) ;then
  new_mac_str=$(sed -n -e '/eth1/ p' $net_rule_file)
  #new_mac_1=${new_mac_str:64:17}
  new_mac=$(echo $new_mac_str| awk -F ',' {'print $4'}|awk -F '==' {'print $2'}|sed 's/\"//g')
  sed -i "/$old_mac/Id" $net_rule_file
  sed -i "s/eth1/eth0/g" $net_rule_file
else
  new_mac_str=$(sed -n -e '/eth0/ p' $net_rule_file)
  #new_mac_1=${new_mac_str:64:17}
  new_mac=$(echo $new_mac_str| awk -F ',' {'print $4'}|awk -F '==' {'print $2'}|sed 's/\"//g')
  echo "done 70-persistent-net.rules file!"
fi

#====================================
#change hostname
if [ ! -n "$1" ] ;then
    echo "you have not input a hostname!"
    echo "usage:./init_sys_nic.sh cm222.wdzjcdh.com 192.168.14.222"
else
  sed -i "s/localhost.localdomain/$1/g" $net_hostname_file
fi
#===================================
#resetup NIC config file
if  (cat $net_conf_file|grep $netmask_conf) ;then
  echo "done /etc/sysconfig/network-scripts/ifcfg-eth0"
elif [ ! -n "$2" ] ;then
    echo "you have not input a ip address!"
else
  sed -i "/$old_mac/Id" $net_conf_file
  sed -i "s/dhcp/static/g" $net_conf_file
  echo "HWADDR=$new_mac" >> $net_conf_file
  echo "IPADDR=$2" >> $net_conf_file
  echo "NETMASK=$netmask_conf" >> $net_conf_file
  echo "GATEWAY=$gateway_conf" >> $net_conf_file
  echo "DNS1=$dns1_conf" >> $net_conf_file
  service network restart
  reboot
fi

2,SSH-KEYGEN -T RSA这个命令暂时没有想到好的操作方面(ANSIBLE来部署?)最近动了这个心了,SALTSTACK作应用部署,快,但运维自己的操作,ANSIBLE也是一个选择哟,毕竟纯SSH。。

3,在弄好首台HADOOP之后,如何愉快的COPY到其它结点?这个脚本不太方便,可能相关目录要自定义。。。如果能所有的东东统一到一个目录的话。。。:),还有scp -r $var_folder root@$1:/usr/local/,这个写得奇丑,当时只求快。。

#!/bin/bash

echo "Usage: ./init_hadoop_spark -f demo-data"
cp_file=("/etc/hosts" "/etc/profile.d/env.sh")
cp_folder=("/root/.ssh/" "/usr/local/scala-2.11.4" "/usr/local/hadoop-2.6.0" "/usr/local/spark-1.2.2-bin-hadoop2.4" "/usr/local/jdk1.7.0_71")

function cp_file_folder()
{
  for var_file in ${cp_file[@]};
  do
    scp $var_file root@$1:$var_file
  done 

  for var_folder in ${cp_folder[@]};
  do
    scp -r $var_folder root@$1:/usr/local/
  done
}

while getopts :f:h file_name
do
    case $file_name in
    f) cat $OPTARG | while read line
        do
                arr_var=(${line})
            cp_file_folder ${arr_var[0]}
                #run_docker ${arr_var[0]}  ${arr_var[1]} ${arr_var[2]}
        done
        sleep 2
        ;;
    h) echo "Usage: ./init_hadoop_spark -f demo-data"  
            exit 1
            ;;
        \?) echo "Usage: ./init_hadoop_spark -f demo-data"  
            exit 1  
            ;;  
    :) echo "Usage: ./init_hadoop_spark -f demo-data"  
            exit 1
            ;;
    esac
done

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值