Small script a---CDH in a batch deployment, if it is a virtual machine generated from an ESXi vcenter template, how to quickly fix the network card configuration?

Source: Internet
Author: User

Of course, in the process of making a template, in addition to defining a good selinux,iptables,

Hosts file maintenance, with zookeeper or rsync implementation?

Have to plan well in the early days.

The script is as follows, usually changed to their own can be used.

Now it's time to look at how to run a one-off script without the need for manual involvement.

#!/bin/bash# This script implements a new template from ESXi, quickly configures the machine network and MAC address, involving two file changes # Defining constants Net_rule_file="/etc/udev/rules.d/70-persistent-net.rules"Net_conf_file="/etc/sysconfig/network-scripts/ifcfg-eth0"netmask_conf="255.255.xxx.0"gateway_conf="192.168.xxx.xx"dns1_conf="114.xxx.xxx.114"Old_mac="00:50:56:xx:f6:xx"#判断是否已正确执行过脚本, and then remove the old Mac from the file and change it to the new MAC address,--eth0if(Cat$net _rule_file|grep-I $old _mac); ThenNew_mac_str=$(sed-n-e'/eth1/p'$net _rule_file) #new_mac_1=${NEW_MAC_STR: -: -} New_mac=$(Echo$new _mac_str|awk-F','{'Print $4'}|awk-F'=='{'Print $'}|sed 's/\ "//g')  sed-I."/$old _mac/id"$net _rule_filesed-I."s/eth1/eth0/g"$net _rule_fileElseNew_mac_str=$(sed-n-e'/eth0/p'$net _rule_file) #new_mac_1=${NEW_MAC_STR: -: -} New_mac=$(Echo$new _mac_str|awk-F','{'Print $4'}|awk-F'=='{'Print $'}|sed 's/\ "//g')  Echo "Done 70-persistent-net.rules file!"fi#===================================#将新的网络配置入写网卡文件, restart the networkif(Cat$net _conf_file|grep$netmask _conf); Then  Echo "Done/etc/sysconfig/network-scripts/ifcfg-eth0"elif[!-N" $"] ; Then    Echo "You had not input a IP address!"Else  sed-I."/$old _mac/id"$net _conf_filesed-I."s/dhcp/static/g"$net _conf_fileEcho "hwaddr= $new _mac">>$net _conf_fileEcho "ipaddr=$1">>$net _conf_fileEcho "netmask= $netmask _conf">>$net _conf_fileEcho "gateway= $gateway _conf">>$net _conf_fileEcho "dns1= $dns 1_conf">>$net _conf_file Service Network Restartfi

Small script a---CDH in a batch deployment, if it is a virtual machine generated from an ESXi vcenter template, how to quickly fix the network card configuration?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.