Tampilkan postingan dengan label KICKSTART. Tampilkan semua postingan
Tampilkan postingan dengan label KICKSTART. Tampilkan semua postingan

Jumat, 17 Desember 2021

Kickstart-Server CentOS 7.9_x86_64 For Apache Hadoop®

A. Prepare Kickstart Server environment

 1. Install all the required packages through yum

     yum install syslinux xinetd tftp-server dhcp httpd deltarpm python-deltarpm createrepo yum-utils

2. Create folder/directory and copy pxelinux.0

     mkdir /var/lib/tftpboot/pxelinux.cfg
     mkdir /var/lib/tftpboot/centos7
 
     cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

3. Open the xinetd settings to enable tftp server
    vi /etc/xinetd.d/tftp
   # at line 14 change the parameter from yes to no.
        Disable=no

4. Restart the service to apply the settings made
    systemctl restart xinetd 

5. Set the service to start with each subsequent system reboots
    systemctl enable xinetd

6. Open the file and configure edit the DHCP Server
    vi /etc/dhcp/dhcpd.conf

#### vi /etc/dhcp/dhcpd.conf ###
Allow booting;
Allow bootp;
authoritative;
### Subnet definition hostname kickstart  server ###
ddns-update-style interim;
subnet 192.168.111.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.111.30 192.168.111.130;
option broadcast-address 192.168.111.255;
option routers 192.168.111.2;
filename "pxelinux.0";
next-server 192.168.111.80;
#use-host-decl-names on;
}
#### Client Node ###
host master01.kopi.com {
hardware ethernet 00:0C:29:33:9A:F2;
fixed-address 192.168.111.81;
option subnet-mask 255.255.255.0;
option routers 192.168.111.2;
option host-name "master01.kopi.com";
filename "pxelinux.0";
}
host master02.kopi.com {
hardware ethernet 00:0C:29:B0:74:AB;
fixed-address 192.168.111.82;
option subnet-mask 255.255.255.0;
option routers 192.168.111.2;
option host-name "master02.kopi.com";
filename "pxelinux.0";
}
host worker01.kopi.com {
hardware ethernet 00:0C:29:58:E8:B8;
fixed-address 192.168.111.83;
option subnet-mask 255.255.255.0;
option routers 192.168.111.2;
option host-name "worker01.kopi.com";
filename "pxelinux.0";
}
host worker02.kopi.com {
hardware ethernet 00:0C:29:CF:37:CE;
fixed-address 192.168.111.84;
option subnet-mask 255.255.255.0;
option routers 192.168.111.2;
option host-name "worker02.kopi.com";
filename "pxelinux.0";
}
host worker03.kopi.com {
hardware ethernet 00:0C:29:AE:A3:EF;
fixed-address 192.168.111.85;
option subnet-mask 255.255.255.0;
option routers 192.168.111.2;
option host-name "worker03.kopi.com";
filename "pxelinux.0";
}


7. Restart the service and make it permanent
    systemctl restart dhcpd
    systemctl enable dhcpd

8.
Create folder/directory
 

    mkdir -p /var/www/html/centos7.9
    mkdir -p /var/www/html/centos7.9/ks

9. Insert your CentOS 7. DVD + Mount it to /mnt
    mount /dev/sr0 /mnt

10. Check the contents to see if it is properly mounted
    ls -al /mnt/

11. copy all DVD the contents to the /var/www/html/centos7.9 directory & updates

    shopt -s dotglob
    cp -apvrf /mnt/* /var/www/html/centos7.9/     
 
     
sudo reposync -g -l -d -m --repoid=updates --newest-only --download-metadata --download_path=/var/www/html/

    createrepo /var/www/html/updates

    eject

12. Copy the vmlinuz and initrd.img files to the tftpboot directory
    cp /var/www/html/centos7.9/images/pxeboot/vmlinuz /var/lib/tftpboot/centos7 

    cp /var/www/html/centos7.9/images/pxeboot/initrd.img /var/lib/tftpboot/centos7

13. Copy the menu file
    cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/

14. Prepare the boot menu.
    vi /var/lib/tftpboot/pxelinux.cfg/default

default menu.c32
prompt 0
timeout 100

menu title === PXE-CentOS7.9-Boot Menu===
label 1
menu label ^ 1) CentOS 7.9.2009
kernel centos7/vmlinuz
append initrd=
centos7/initrd.img ks=http://192.168.111.80/ks/ks.cfg

15. Prepare the httpd server

    vi /etc/httpd/conf/httpd.conf
        Listen 192.168.111.80:80

    vi /etc/hosts
       192.168.111.80     kickserver    kickserver.customer.com

    vi /etc/httpd/conf.d/welcome.conf
        <LocationMatch "^/+$">
        Options +Indexes

     systemctl restart httpd
    systemctl enable httpd

    iptables -F; iptables -L
    systemctl stop iptables; systemctl disable iptables 
    systemctl stop firewalld;systemctl disable firewalld


    vi /etc/selinux/config
     SELINUX=disable
 

reboot

after that you can login and run cli (pls, verify with a local repository "updates")

yum update

reboot

(pls, verify your booting with a new kernel version 3.10.0-1160.80.1.el7)

Selasa, 08 Januari 2013

Kickstart-Server RHEL6.2_x86_64 Step-by-steps


A. Create Local Repository (yum local)
1. mount REDHAT EL6 DVD IN TO /mnt
mount /dev/cdrw /mnt

2. copy rpms from Packages directory into /opt/source/repo
cd /media/"RHEL_6.2 x86_64 Disc 1"/Packages
mkdir -p /opt/source/repo
cp -rpv * /opt/source/repo
3. Install repocreate utility rpm installation
rpm -ivh deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm createrepo-0.9.8-4.el6.noarch.rpm
4. cd /opt/source/repo
createrepo `pwd`
2293/3596 - xz-libs-4.999.9-0.3.beta.20091007git.el6.x86_64.rpm

5. vi /etc/yum.conf
"# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d"
[base-local]
name=RHEL6 $releasever - $basearch
failovermethod=priority
baseurl=file:///opt/source/repo
enabled=1
gpgcheck=0


6. check your current local repository
yum repolist



B. Prepare Kickstart-Server
1. Install all the required packages through yum
yum install syslinux xinetd tftp-server dhcp httpd

2. mkdir /var/lib/tftpboot/pxelinux.cfg
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
 

3. Open the xinetd settings to enable tftp server
vi /etc/xinetd.d/tftp
# at line 14 change the parameter from yes to no.
Disable=no


4. Restart the service to apply the settings made
service xinetd restart

5. set the service to start with each subsequent system reboots
chkconfig xinetd on

6. Open the file and configure the DHCP Server
vi /etc/dhcp/dhcpd.conf


# Here the next.sever parameter is the address of the kickstart server.
# Subnet definition Global Option
# WARNING = accomodate MAC ADDRESS (hardware ethernet) and IPADDR (fixed address)
Allow booting;
Allow bootp;
authoritative;

# Subnet definition
ddns-update-style interim;
subnet 10.128.57.0 netmask 255.255.255.0 {
range dynamic-bootp 10.128.57.107 10.128.57.110;
option broadcast-address 10.128.57.255;
option routers 10.128.57.1;
filename "pxelinux.0";
next-server 10.128.57.100;
}

host grid-compute-7 {
hardware ethernet 00:50:56:99:E0:61;
fixed-address 10.128.57.39;
option subnet-mask 255.255.255.0;
option routers 10.128.57.1;
option host-name "grid-compute-7";
filename "pxelinux.0";
}
host grid-compute-8 {
hardware ethernet 00:50:56:99:E0:62;
fixed-address 10.128.57.49;
option subnet-mask 255.255.255.0;
option routers 10.128.57.1;
option host-name "grid-compute-8";
filename "pxelinux.0";
}

7. Restart the service and make it permanent
service dhcpd restart
chkconfig dhcpd on


8. Make some required directories
mkdir -p /var/www/html/rhel
mkdir -p /var/lib/tftpboot/rhel6

9. Insert your RHEL 6.2 DVD + Mount it to /mnt
df -h
/media/RHEL_6.2 x86_64 Disc 1

10. Check the contents to see if it is properly mounted
cd /media/"RHEL_6.2 x86_64 Disc 1"

11. copy all the contents to the /var/www/html/rhel directory
cp –arv /media/RHEL_6.2 x86_64 Disc 1/* /var/www/html/rhel

12. After the file copy operation eject the DVD
eject cdrom

12. Copy the vmlinuz and initrd.img files to the tftpboot directory
cp /var/www/html/rhel/images/pxeboot/vmlinuz /var/lib/tftpboot/rhel6
cp /var/www/html/rhel/images/pxeboot/initrd.img /var/lib/tftpboot/rhel6

13. Copy the menu file
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/

14. Prepare the boot menu.
vi /var/lib/tftpboot/pxelinux.cfg/default

timeout 100
default menu.c32
menu title === Hell-Me-Kickstart ===
label 1
menu label ^ 1) RedHat Enterprise Linux
kernel rhel6/vmlinuz
append initrd=rhel6/initrd.img ks=http://10.128.57.100/ks/ks.cfg

15. Prepare the httpd server
vi /etc/httpd/conf/httpd.conf

Listen 10.128.57.100:80

service httpd restart
(ignore the fully qualified domain name error if it occurs.)
chkconfig httpd on


vi /etc/hosts
10.128.57.100 kick-server

16. Prepare nfs server
vi /etc/exports
/var/www/html/ks *(rw,no_root_squash)
/var/www/html/rhel *(rw,no_root_squash)

service nfs restart
chkconfig nfs on

exportfs

/var/www/html/ks
/var/www/html/rhel

chkconfig iptables off

disable selinux
vi /etc/selinux/config
SELINUX=disable

shutdown -r now




C. Prepare Kickstart Config (ks.cfg)

1. Make the directory and copy the kickstart file to it
2. And make the kickstart file globally read only (chmod 644)
mkdir -p /var/www/html/ks
mkdir -p /var/www/html/ks/logs
3. vi /var/www/html/ks
#platform=x86, AMD64, or Intel EM64T
#version=RHEL6.2_x86_64
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use NFS or http installation media
#nfs --server=10.128.57.100 --dir=/var/www/html/rhel
url --url http://10.128.57.100/rhel
# Root password indosat01
rootpw --iscrypted $1$nWgsJGK8$DAjPcF813tgBCqskYMzdQ0
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
#text
graphical
# Run the Setup Agent on first boot
firstboot --enable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone --isUtc Asia/Jakarta
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all
# Disk partitioning information
part /boot/efi --asprimary --fstype="vfat" --size=200
part /boot --asprimary --fstype="ext4" --size=500
part pv.01 --size=1 --grow
#
volgroup vg_gridcompute --pesize=4096 pv.01
#
logvol / --fstype="ext4" --name=lv_root --vgname=vg_gridcompute --size=10240
logvol swap --fstype="swap" --name=lv_swap --vgname=vg_gridcompute --size=800
logvol /home --fstype="ext4" --name=lv_home --vgname=vg_gridcompute --size=512
logvol /tmp --fstype="ext4" --name=lv_tmp --vgname=vg_gridcompute --size=900
logvol /var --fstype="ext4" --name=lv_var --vgname=vg_gridcompute --size=5120
bootloader --location=mbr --driveorder=sda --append="nomodeset rhgb quiet"

%packages
@backup-server
@additional-devel
@base
@basic-desktop
@compat-libraries
@debugging
@desktop-platform
@development
@directory-client
@fonts
@general-desktop
@graphical-admin-tools
@internet-browser
@large-systems
@legacy-unix
@legacy-x
@network-file-system-client
@network-tools
@nfs-file-server
@performance
@perl-runtime
@print-client
@remote-desktop-clients
@server-platform
@server-platform-devel
@system-management-snmp
@tex
@x11
glibc-utils
iptraf
mtools
pax
python-dmidecode
qt-mysql
qt-odbc
qt-postgresql
qt3-MySQL
qt3-ODBC
qt3-PostgreSQL
rdesktop
spice-client
spice-xpi
system-config-kickstart
system-config-lvm
tigervnc
tsclient
vinagre
xorg-x11-xdm
xterm
libxcb.i686
nss-softokn-freebl.i686
libcap.i686
cracklib.i686
libXau.i686
libXpm.i686
compat-libstdc++-33.i686
db4.i686
libattr.i686
libX11.i686
libselinux.i686
pam.i686
glibc.i686
libgcc.i686
audit-libs.i686
glibc-devel.i686
libstdc++.i686
libXp.i686
libXp.x86_64
libXext.i686
libxcb.i686
ksh.x86_64
%end
#======================================================

%post
# And so begins the post-install section.
# this is currently in a chroot to / on the
# new file system.
# Various variables I like to set first to use later
(
# I run everything in this, so I can log it
/bin/echo "Welcome to $HOSTNAME Server " > /etc/motd
# One way of adding to files
cat >> /etc/sysctl.conf << EOF
#Semaphore Limits SEMMSL SEMMNS SEMOPM SEMMNI
kernel.sem = 250 256000 32 1024
EOF
# Another way of inputing to files
echo 'root soft nofile 10240' >> /etc/security/limits.conf
echo 'root hard nofile 10240' >> /etc/security/limits.conf
echo 'root soft nproc -1' >> /etc/security/limits.conf
echo 'root hard nproc -1' >> /etc/security/limits.conf
# Add a user if you like
useradd -m -u 98 -d /home/ibm ibm
echo ibm | passwd ibm --stdin
# setup bonding runing script network_config.sh + hostfile.csv
# (placed both file on /var/www/html/ks)

mount -t nfs -o nolock 10.128.57.100:/var/www/html/ks /mnt
chmod 777 /mnt/network_config.sh
/mnt/network_config.sh
# Here doing some system settings
# Setup hosts file
cat > /etc/hosts << EOF
#127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
#::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

10.128.57.39 grid-compute-7
10.128.57.49 grid-compute-8
EOF
# setup NTP Client
echo 'server 10.10.100.5' >> /etc/ntp.conf
echo 'server 10.2.2.67' >> /etc/ntp.conf
# Turn some services on and off and mkdir
/sbin/chkconfig ip6tables off
/sbin/chkconfig iptables off
/sbin/chkconfig ntpd on
/sbin/chkconfig postfix off

/bin/mkdir -p /opt/oracle
/bin/mkdir -p /etl_prod
/bin/mkdir -p /etl_prod/backup
/bin/mkdir -p /etl_prod/etl_dataset
/bin/mkdir -p /etl_prod/source
/bin/mkdir -p /etl_prod/app
/bin/mkdir -p /etl_prod/etl_scratch

) > /tmp/kickstart-install.log 2>&1
# The aforementioned log.
%end

D. script "network_config.sh"
1. vi /var/www/html/ks/network_config.sh

# cat network_config.sh
#!/bin/bash
DEBUG=off
IFCONFIG=/sbin/ifconfig
NIC_FILE_DIR=/etc/sysconfig/network-scripts/
GW_FILE=/etc/sysconfig/network
HOST_FILE=/etc/hosts
DNS_FILE=/etc/resolv.conf
DOMAIN_LIST="no.domain.com"
####
## function readHostFile
## reads $HOST_MAP_FILE for specific network information about this host
## return 1 on error, 0 on success
## options can be in any order (nic, gw, or bond), broadcast and network address are calculated based on ip and mask
## calls functions to generate Gateway ($GW_FILE), Hosts ($HOST_FILE), and ifcfg ($NIC_FILE_DIR/ifcfg-{nic})
##
## host_map_file format
## {host},nic={eth#} ip mask [?primary],gw={gw_ip},bond={bond#} {nic1} {nic2} {ip} {mask},domain={dns_server},{dns_server}
## e.g. server1,nic=eth0 192.168.1.1 255.255.255.0,gw=192.168.0.1,nic=bond0 eth1 eth2 192.168.0.10 255.255.255.0 1,dns=192.168.0.254 192.168.1.254
####
readHostFile() {
if [ -e $HOST_MAP_FILE ]
then
# override default DOMAIN_LIST if it exists
DOMAIN_TMP=$(cat $HOST_MAP_FILE | grep -wi "DOMAINSEARCH" | cut -f2 -d =)
if [ ! -z "$DOMAIN_TMP" ]
then
log info "Domain search list found -- $DOMAIN_TMP"
DOMAIN_LIST="$DOMAIN_TMP"
else
log info "Domain search not found, using defaults -- $DOMAIN_LIST"
fi

# parse the file for this host exactly (-w) and case insensitive
HOST_INFO=$(cat $HOST_MAP_FILE | grep -wi `hostname`)
# check to see there was an entry for this host
if [ -z "$HOST_INFO" ]
then
log warning "Host information for `hostname` was not found in HOST_MAP_FILE"
return 1
fi
log notify "Host information found for `hostname` in $HOST_MAP_FILE"
log notify "Host info is $HOST_INFO"
# parse HOST_INFO
IFS=$','
for entry in $HOST_INFO
do
log debug "Working on entry $entry"
KEY=`echo $entry | cut -f1 -d =`
VALUE=`echo $entry | cut -f2 -d =`
case "$KEY" in
nic)
log debug "nic is specified -- $VALUE"
NIC=`echo $VALUE | cut -f1 -d " "`
if [ ${#NIC} -eq 12 ]
then
# we are working with a MAC address
NIC=$(getNIC $NIC)
fi
IPADDR=`echo $VALUE | cut -f2 -d " "`
MASK=`echo $VALUE | cut -f3 -d " "`
PRIMARY=`echo $VALUE | cut -f4 -d " "`
BROADCAST=$(getBroadcastAddress $IPADDR $MASK)
NETWORK=$(getNetworkAddress $IPADDR $MASK)
# MAC address for this card
MAC=$(getMAC $NIC)

if [ -z $NIC ]
then
log error "Missing NIC information aborting file creation"
else
log info "Values for NIC $NIC - MAC $MAC - IP $IPADDR - NetMask $MASK - Broadcast $BROADCAST - Network $NETWORK"
genIPFile $NIC $MAC $IPADDR $MASK $BROADCAST $NETWORK
fi

if [ "$PRIMARY" == 1 ]
then
genHostFile $IPADDR
fi
;;
bond)
#nic=bond0 eth1 eth2 192.168.0.10 255.255.255.0 1
log debug "bond is specified -- $VALUE"
BOND=`echo $VALUE | cut -f1 -d " "`
NIC1=`echo $VALUE | cut -f2 -d " "`
if [ ${#NIC1} -gt 12 ]
then
# we are working with a MAC address
NIC1=$(getNIC $NIC1)
fi
NIC2=`echo $VALUE | cut -f3 -d " "`
if [ ${#NIC2} -gt 12 ]
then
# we are working with a MAC address
NIC2=$(getNIC $NIC2)
fi
IPADDR=`echo $VALUE | cut -f4 -d " "`
MASK=`echo $VALUE | cut -f5 -d " "`
BROADCAST=$(getBroadcastAddress $IPADDR $MASK)
NETWORK=$(getNetworkAddress $IPADDR $MASK)

log info "Values for BOND $BOND - NIC1 $NIC1 - NIC2 $NIC2 - IP $IPADDR - NetMask $MASK - Broadcast $BROADCAST - Network $NETWORK"
genBondFile $BOND $NIC1 $NIC2 $IPADDR $MASK $BROADCAST $NETWORK

if [ "$PRIMARY" == 1 ]
then
genHostFile $IPADDR
fi
;;
gw)
log debug "Gateway value - $VALUE"
genGWFile $VALUE
;;
dns)
log debug "DNS is specified -- $VALUE"
genDNSFile "$VALUE"
esac
done
else
log warning "Hostfile $HOST_MAP_FILE does not exist"
return 1
# configure eth0 as static based on the current DHCP address
fi
}

####
## function getNIC {mac_addr}
## returns eth# based on MAC address
####
getNIC() {
local RAW_MAC=$1
# a properly formatted MAC address is 00:10:20:30:40:50 (17 characters)
if [ ${#RAW_MAC} -ne 17 ]
then
# assume the user didn't put in : marks
COUNT=0
# in case this is IPv6 loop for the entire raw mac length
while [ $COUNT -lt ${#RAW_MAC} ]
do
if [ $COUNT -eq 0 ]
then
SEARCH_MAC=${RAW_MAC:$COUNT:2}
else
SEARCH_MAC="$SEARCH_MAC:${RAW_MAC:$COUNT:2}"
fi
COUNT=$(($COUNT + 2))
done
else
SEARCH_MAC=$RAW_MAC
fi

# return eth# for a specific MAC
local NIC=`$IFCONFIG -a | grep -i $SEARCH_MAC | awk '{print $1}'`
if [ -z $NIC ]
then
log error "Network interface was not found for nic $SEARCH_MAC, this interface will not be configured correctly"
log error "ifconfig output is \n`$IFCONFIG -a`"
else
log info "NIC $SEARCH_MAC found as $NIC"
fi
echo $NIC
}

####
## function genBondFile {bond#} {nic1} {nic2} {ip} {mask} {broadcast} {network}
## nic=bond0 eth0 eth1 192.168.0.10 255.255.255.0
## nic=eth0 192.168.0.10 255.255.255.0 192.168.0.254 192.168.0.0
####
genBondFile() {
local BOND=$1
local NIC1=$2
local NIC2=$3
local IP=$4
local MASK=$5
local BROADCAST=$6
local NETWORK=$7
local BOND_FILE=${NIC_FILE_DIR}ifcfg-$BOND
local NIC1_FILE=${NIC_FILE_DIR}ifcfg-$NIC1
local NIC2_FILE=${NIC_FILE_DIR}ifcfg-$NIC2

log info "Creating Bond file $BOND_FILE"
echo "DEVICE=$BOND" > $BOND_FILE
echo "BOOTPROTO=none" >> $BOND_FILE
echo "ONBOOT=yes" >> $BOND_FILE
echo "NETWORK=$NETWORK" >> $BOND_FILE
echo "NETMASK=$MASK" >> $BOND_FILE
echo "IPADDR=$IP" >> $BOND_FILE
echo "BROADCAST=$BROADCAST" >> $BOND_FILE
echo "USERCTL=no" >> $BOND_FILE
echo "BONDING_OPTS=\"mode=1 miimon=300 primary=$NIC1\"" >> $BOND_FILE

log info "Creating network file $NIC1_FILE"
echo "DEVICE=$NIC1" > $NIC1_FILE
echo "BOOTPROTO=none" >> $NIC1_FILE
echo "HWADDR=$(getMAC $NIC1)" >> $NIC1_FILE
echo "ONBOOT=yes" >> $NIC1_FILE
echo "MASTER=$BOND" >> $NIC1_FILE
echo "SLAVE=yes" >> $NIC1_FILE
echo "USERCTL=no" >> $NIC1_FILE

log info "Creating network file $NIC2_FILE"
echo "DEVICE=$NIC2" > $NIC2_FILE
echo "BOOTPROTO=none" >> $NIC2_FILE
echo "HWADDR=$(getMAC $NIC2)" >> $NIC2_FILE
echo "ONBOOT=yes" >> $NIC2_FILE
echo "MASTER=$BOND" >> $NIC2_FILE
echo "SLAVE=yes" >> $NIC2_FILE
echo "USERCTL=no" >> $NIC2_FILE

log info "Modifying modprobe.conf file /etc/modprobe.d/bonding.conf"
echo "alias $BOND bonding" >> /etc/modprobe.d/bonding.conf
}

####
## function getMAC {nic}
## gets the MAC address for a given interface using ifconfig
####
getMAC() {
HWINFO=`$IFCONFIG $1 | grep HWaddr` # eth0 Link encap:Ethernet HWaddr 00:50:56:9C:1B:00
if [ $? -ne 0 ]
then
log error "Cannot find MAC address for interface $1"
# return nothing to the calling process
echo " "
else
# return the MAC address
echo $HWINFO | awk '{print $5}'
fi
}

####
## function genDomainFile {nameserver} {nameserver} {etc}
## creates a basic DNS file for nameserver entries
####
genDNSFile() {
log info "Creating DNS file $DNS_FILE"
OldIFS=$IFS
IFS=" "
> $DNS_FILE
# create search entries
echo "search $DOMAIN_LIST" >> $DNS_FILE
# create server entries
for dnsEntry in $1
do
echo "nameserver $dnsEntry" >> $DNS_FILE
done
IFS=$OldIFS
}
####
## function genHostFile {local_ip}
## creates a basic hosts file with loopback and this host
####
genHostFile() {
local IP=$1
log info "Creating host file $HOST_FILE"
echo "127.0.0.1 localhost.localdomain localhost" > $HOST_FILE
echo "$IP `hostname`" >> $HOST_FILE

}

####
## function genGWFile {gateway_ip}
## create the default route file including default RedHat values
####
genGWFile() {
local GW=$1
log info "Creating gateway file $GW_FILE"
echo "NETWORKING=yes" > $GW_FILE
echo "NETWORKING_IPV6=no" >> $GW_FILE
echo "HOSTNAME=`hostname`" >> $GW_FILE
echo "GATEWAY=$GW" >> $GW_FILE
}

####
## function genIPFile {nic} {mac} {ip} {mask} {broadcast} {network}
## create the IP Address file (ifcfg-eth{x})
## e.g. nic=eth0 00:50:56:9C:1B:00 192.168.0.10 255.255.255.0 192.168.0.254 192.168.0.0
####
genIPFile() {
local NIC=$1
local MAC=$2
local IP=$3
local MASK=$4
local BROADCAST=$5
local NETWORK=$6
local IP_FILE=${NIC_FILE_DIR}ifcfg-${NIC}

log info "Creating network file $IP_FILE"
echo "DEVICE=$NIC" > $IP_FILE
echo "BOOTPROTO=static" >> $IP_FILE
echo "BROADCAST=$BROADCAST" >> $IP_FILE
echo "HWADDR=$MAC" >> $IP_FILE
echo "IPADDR=$IP" >> $IP_FILE
echo "NETMASK=$MASK" >> $IP_FILE
echo "NETWORK=$NETWORK" >> $IP_FILE
log debug "----------- ifcfg-$NIC file -----------"
log debug "\n`cat $IP_FILE`"
log debug "----------------------"
}

####
## function getNetworkAddress
## calculates the network address given an ip and subnet mask
## converts the ip and mask into an array and does a bitwise and for each element
####
getNetworkAddress() {
OldIFS=$IFS
IFS=.
typeset -a IP_Array=($1)
typeset -a MASK_Array=($2)
IFS=$OldIFS
echo $((${IP_Array[0]} & ${MASK_Array[0]})).$((${IP_Array[1]} & ${MASK_Array[1]})).$((${IP_Array[2]} & ${MASK_Array[2]})).$((${IP_Array[3]} & ${MASK_Array[3]}))
}

####
## function getBroadcastAddress
## calculates the broadcast address given an ip and subnet mask
## converts the ip and mask into an array and does a bitwise or (|) against an XOR (^)
####
getBroadcastAddress() {
OldIFS=$IFS
IFS=.
typeset -a IP_Array=($1)
typeset -a MASK_Array=($2)
IFS=$OldIFS
echo $((${IP_Array[0]} | (255 ^ ${MASK_Array[0]}))).$((${IP_Array[1]} | (255 ^ ${MASK_Array[1]}))).$((${IP_Array[2]} | (255 ^ ${MASK_Array[2]}))).$((${IP_Array[3]} | (255 ^ ${MASK_Array[3]})))
}

####
## function readDHCPAddress
## reads information currently running and writes it out as a static IP entry
####
readDHCPAddress() {
log info "Host information was not found for this server, copying information from running configuration (DHCP)"
# the grep will grab two lines of output and merge them together
# eth0 Link encap:Ethernet HWaddr 00:50:56:9C:1B:00
# inet addr:192.168.0.10 Bcast:192.168.0.254 Mask:255.255.255.0
HWINFO=`$IFCONFIG | grep -A 1 -i hwaddr`
NIC=`echo $HWINFO | cut -f1 -d " "`
MAC=`echo $HWINFO | cut -f5 -d " "`
for i in $HWINFO
do
case "$i" in
addr:*)
IP=`echo $i | cut -f2 -d :`
;;
Bcast:*)
BROADCAST=`echo $i | cut -f2 -d :`
;;
Mask:*)
MASK=`echo $i | cut -f2 -d :`
;;
esac
done
NETWORK=$(getNetworkAddress $IP $MASK)
log debug "DHCP information is NIC $NIC - MAC $MAC - IP $IP - MASK $MASK - BROADCAST $BROADCAST - NETWORK $NETWORK"
genIPFile $NIC $MAC $IP $MASK $BROADCAST $NETWORK
genHostFile $IP
GATEWAY=`netstat -rn | grep -w UG | awk '{print $2}'`
genGWFile $GATEWAY
}

####
## function log
## logs activities to the screen, a file, or both
####
log() {
LOG_TYPE="$1"
LOG_MSG="$2"
TIME=`date +'%H:%M:%S %Z'`
# specify the log file only once
if [ ! -d /mnt/logs ]
then
mkdir ${/mnt}/logs
fi
if [ -z $LOG_FILE ]
then
LOG_FILE="/mnt/logs/network_config-`hostname`-`date +%Y%m%d-%H%M%S`"
fi
if [ $LOG_TYPE == "error" ]
then
echo -e "$TIME - **ERROR** - $LOG_MSG" >> $LOG_FILE
elif [ $LOG_TYPE == "debug" ]
then
if [ $DEBUG == "on" ]
then
echo -e "DEBUG - $LOG_MSG" >> "$LOG_FILE"
fi
elif [ $LOG_TYPE == "warning" ]
then
echo -e "$TIME - **WARNING** - $LOG_MSG" >> $LOG_FILE
else
echo -e "$TIME - $LOG_MSG" >> "$LOG_FILE"
fi
}

# read source directory from command line. This is where we will read the hostfile.csv and output logs to
SOURCE_DIR=$1
HOST_MAP_FILE=/mnt/hostfile.csv

readHostFile
if [ $? -ne 0 ]
then
readDHCPAddress
fi





D. script "hostfile.csv"
1.vi /var/www/html/ks/hostfile.csv
#Format -- server_name,[bond|nic] eth# [eth#] IP MASK Primary,gw={gateway},dns={dns1 dns2 etc}
# as long as the server name comes first, the order of the rest doesn't really matter
# Primary is used to determine which interface should be placed in the host file
# an example with multiple bonded interfaces.
# an example with one bond using MAC addresses
server2,bond=bond0 0050569c25e5 0050569c6cbd 192.168.0.11 255.255.255.0 1,gw=192.168.0.1,dns=192.168.0.254 192.168.1.254


grid-compute-7,bond=bond0 eth0 eth1 10.128.57.39 255.255.255.0 1,gw=10.128.57.1
grid-compute-8,bond=bond0 eth0 eth1 10.128.57.49 255.255.255.0 1,gw=10.128.57.1