Saturday, November 19, 2016

Build a multiple Distro tftp boot server for ESXi and CentOS7

I use CentOS 7.1 for tftp boot server ( I also tried cobbler ,but the cobbler can not support esxi latest version)

Summary the steps
  1. Install and config tftp server
  2. Install and config dnsmq for dhcp server
  3. Install and config syslinux
  4. Install and config http server for Linux installation  
  5. Config pxe boot menu for CentOS7
  6. Config pxe boot menu for Esxi and prepare installation file
  7. prepare ks file 

Step 1:Install and config tftp server

commands

yum install tftp-server 


systemctl start tftp.socket
systemctl enable tftp.socket

config file :
# default: off
# description: The tftp server serves files using the trivial file transfer \
#       protocol.  The tftp protocol is often used to boot diskless \
#       workstations, download configuration files to network-aware printers, \
#       and to start the installation process for some operating systems.
service tftp
{
        socket_type             = dgram
        protocol                = udp
        wait                    = yes
        user                    = root
        server                  = /usr/sbin/in.tftpd
        server_args             = -s /var/lib/tftpboot
        disable                 = no
        per_source              = 11
        cps                     = 100 2
        flags                   = IPv4
}


Step 2:Install and config dnsmq for dhcp server

commands:

yum install dnsmasq

systemctl start dnsmasq
systemctl enable dnsmasq

Config file

interface=eth1,lo
#bind-interfaces
domain=centos7.local
# DHCP range-leases
dhcp-range= eth1,192.168.100.100,192.168.100.254,255.255.255.0,360h
# PXE
dhcp-boot=pxelinux.0,pxeserver,192.168.100.1
# Gateway
dhcp-option=3,192.168.100.1
# DNS
dhcp-option=6,192.168.100.1, 8.8.8.8
server=8.8.4.4
# Broadcast Address
# NTP Server
dhcp-option=42,0.0.0.0
pxe-prompt="Press F8 for menu.", 60
pxe-service=x86PC, "pxe network server 192.168.1.1 by Shen", pxelinux
enable-tftp
tftp-root=/var/lib/tftpboot
~


Step 3: Install and config syslinux

commands:
yum install syslinux
cp -r /usr/share/syslinux/* /var/lib/tftpboot

Step 4:Install and config http server for Linux installation

Install httpd commands
yum install httpd

systemctl enable httpd
systemctl start httpd


mount CenOS7 ISO and share install file by http
mkdir /mnt/CentOS7
mount /dev/cdrom /mnt/CentOS7
mkdir /var/www/html/CentOS7
cp -r /mnt/CentOs7 /var/www/html/CentOS7/
chmod -R 755 /var/www/html/CentOS7/

Check http server

Step 5:Config pxe boot menu for CentOS 7

commands
mkdir /var/lib/tftpboot/pxelinux.cfg
touch /var/lib/tftpboot/pxelinux.cfg/default

content of default:

DEFAULT menu.c32
MENU TITLE ESXi Linux  Boot Menu
PROMPT 0
TIMEOUT 600
LABEL CentOS7
  KERNEL vmlinuz
  APPEND initrd=CentOS7/initrd.img  ks=http://192.168.100.1/ks/CentOS7.cfg net.ifnames=0 biosdevname=0 ksdevice=eth0 ip=dhcp devfs=nomount
  MENU LABEL ^1 CentOS7


I added a kernel boot option for the nic number from eth0 
"net.ifnames=0 biosdevname=0"  


Step 6: Config pxe boot menu for Esxi and prepare installation file


prepare installation files
mkdir /mnt/ESXi6 
mount /dev/cdrom /mnt/ESXi6
mkdir /var/lib/tftpboot/ESXi6
cp -r /mnt/ESXi6 /var/lib/tftpboot/ESXi6


modify /var/lob/tftpboot/ESXi6/boot.cfg
Add prefix "prefix=ESXi6" at column 3
Delete slash eg "modules=/b.b00" to modules=b.b00
sed -e "s#/##g" -i.bak boot.cfg



update the boot menu
DEFAULT menu.c32
MENU TITLE ESXi Linux  Boot Menu
PROMPT 0
TIMEOUT 600
LABEL CentOS7
  KERNEL vmlinuz
  APPEND initrd=CentOS7/initrd.img  ks=http://192.168.100.1/ks/CentOS7.cfg net.ifnames=0 biosdevname=0 ksdevice=eth0 ip=dhcp devfs=nomount
  MENU LABEL ^1 CentOS7
LABEL ESXi 6.0
  KERNEL /ESXi6/mboot.c32
  APPEND -c /ESXi6/boot.cfg ks=http://192.168.100.1/ks/ESXi6.cfg
  MENU LABEL ^2 Esxi 6.0



Step 7 prepare ks files

mkdir /var/www/html/ks
touch /var/www/html/ks/CentOS.cfg
touch /var/www/html/ks/ESXi6.cfg

ks sample for CentOS7.cfg
#version=RHEL7
# System authorization information
auth --enableshadow --passalgo=sha512

# Use http install
install
url --url="http://192.168.100.1/CentOS7/"
# Use text mode install
text
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8
#time zone
timezone --utc Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on --ipv6=off
# Root password
rootpw --iscrypted $6$vMgre45.Qllg
# Do not configure the X Window System
skipx
# System timezone
timezone Asia/Hong_Kong --isUtc
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
autopart --type=lvm
# Partition clearing information
clearpart --all --initlabel --drives=sda

%packages
@core
kexec-tools
tcpdump
vim
net-tools
%end

%addon com_redhat_kdump --enable --reserve-mb='auto'

%end


ks sample for ESXi6.cfg
# Sample scripted installation file
# Accept the VMware End User License Agreement
vmaccepteula
# Set the root password for the DCUI and ESXi Shell
rootpw vmware123
# Install on the first local disk available on machine
install --firstdisk --overwritevmfs
# Set the network to DHCP on the first network adapater, use the specified hostname and do not create a portgroup for the VMs
network --bootproto=dhcp --device=vmnic0 --addvmportgroup=0
# reboots the host after the scripted installation is completed
reboot

%firstboot --interpreter=busybox
# Enable SSH and the ESXi Shell
vim-cmd hostsvc/enable_ssh
vim-cmd hostsvc/start_ssh
vim-cmd hostsvc/enable_esx_shell
vim-cmd hostsvc/start_esx_shell


Be careful: I closed selinux and firewalld on CentOS7 


Reference link:
http://www.vcritical.com/2011/07/vmware-esxi-5-interactive-pxe-installation-improvements/
http://www.virtuallyghetto.com/vmware-kickstart
http://www.tecmint.com/install-pxe-network-boot-server-in-centos-7/
http://www.bo-yang.net/2015/08/31/centos7-install-tftp-server
http://everythingshouldbevirtual.com/build-tftp-server-esxi-installs


Sunday, November 13, 2016

Analysis the esxtop data for performance partII

Follow up the partI

Due to my work platform is a Ubuntu server, but there is no pandas library in this server. I am trying to find a bash script to replace python.

So I met a first question, how to let awk use variable as a column number.  Specific ,  I want to awk can use variable from shell . Thanks  stackoverflow .com , someone meet same question .

The second question: How to combine  temp csv files ?
That’s easy to use paste command

I will continue work work the tools script and share on git hub
Here is my Github,
https://github.com/songshen06/esxtoptools

#!/bin/bash
# $1 is org esxtop data
if [ -z "$1" ]
  then
    echo "Please input the org esxtop date!"
fi

awk -F , {'print $1}' $1 > 1.csv
cat column | while read LINE
do gawk -F , -v var="$LINE" '{print $var}' $1 > temp"$LINE".csv
done
paste -d, 1.csv temp*.csv > new.csv
rm 1.csv
rm temp*.csv
~