Tuesday, October 22, 2013

Creating a Kickstart Server for Red Hat / CentOS Machines

This post will focus on setting up a Red Hat / CentOS Kickstart server so hosts can perform an automated install using pxe.

Step 1:
Install necessary packages on CentOS.

yum -y install wget syslinux syslinux-tftpboot xinetd \
tftp-server tftp dhcp httpd openssh-clients

Step 2:
Create the anaconda directory structure.

mkdir -p /export/anaconda/iso/CentOS
mkdir -p /export/anaconda/media
mkdir -p /export/anaconda/media/CentOS-6.4-x86_64
mkdir -p /export/anaconda/media/CentOS-6.4-i386
mkdir -p /export/anaconda/tftpboot
mkdir -p /export/anaconda/tftpboot/pxelinux.cfg
mkdir -p /export/anaconda/tftpboot/CentOS-6.4-x86_64
mkdir -p /export/anaconda/tftpboot/CentOS-6.4-i386
mkdir -p /export/anaconda/postinstall/
mkdir -p /export/anaconda/cfg/
ln -s /export/anaconda /anaconda

Step 3:
Modify tftp server configuration.

cd /etc/xinetd.d
diff tftp tftp.bak
13,14c13,14
<       server_args             = -s /export/anaconda/tftpboot
<       disable                 = no
---
>       server_args             = -s /var/lib/tftpboot
>       disable                 = yes

Step 4:
Modify dhcp server configuration.

cd /etc/dhcp 
cat dhcpd.conf
subnet 192.168.1.0 netmask 255.255.255.0 {

        option routers 192.168.1.1;
        option domain-name-servers 8.8.8.8;
        option subnet-mask 255.255.255.0;
        range 192.168.1.240 192.168.1.250;

        next-server 192.168.1.10;
        filename "pxelinux.0";
}

Step 5:
Copy CentOS iso and extract the files.

scp CentOS-6.4-i386-minimal.iso root@192.168.1.10:/export/anaconda/iso/CentOS
cd /export/anaconda/tftpboot/CentOS-6.4-i386
mount -o loop /export/anaconda/iso/CentOS/CentOS-6.4-i386-minimal.iso /mnt
cp -Rp /mnt/* ./
umount /mnt 

Step 6:
Configure the boot menu.


cat /export/anaconda/tftpboot/pxelinux.cfg/default
timeout 3600
default menu.c32

menu title Boot Menu

label 1
    menu label ^ 1) CentOS-6.3-x86_64 (64-bit)
    kernel CentOS-6.4-x86_64/vmlinuz
    append initrd=CentOS-6.4-x86_64/initrd.img ramdisk_size=15491 ip=dhcp ksdevice=bootif \
    ks=http://192.168.1.10/anaconda/cfg/CentOS-6.4-x86_64-ks.cfg
    IPAPPEND 2

label 2
    menu label ^ 2) CentOS-6.4-i386 (32-bit)
    kernel CentOS-6.4-i386/vmlinuz
    append initrd=CentOS-6.4-i386/initrd.img ramdisk_size=15491 ip=dhcp ksdevice=bootif \
    ks=http://192.168.1.10/anaconda/cfg/CentOS-6.4-i386-ks.cfg
    IPAPPEND 2

label 3
    menu label ^ 3) Rescue CentOS-6.4-x86_64 (64-bit)
    kernel CentOS-6.4-x86_64/vmlinuz
    append initrd=CentOS-6.4-x86_64/initrd.img ramdisk_size=15491 ip=dhcp \
    repo=http://192.168.1.10/anaconda/CentOS-6.4-x86_64 lang=en_US.UTF-8 keymap=us rescue

label 4
    menu label ^ 4) Rescue CentOS-6.4-i386 (32-bit)
    menu default
    kernel CentOS-6.4-i386/vmlinuz
    append initrd=CentOS-6.4-i386/initrd.img ramdisk_size=15491 ip=dhcp \
    repo=http://192.168.1.10/anaconda/CentOS-6.4-i386 lang=en_US.UTF-8 keymap=us rescue

Step 7:
Configure apache.

cat /etc/httpd/conf.d/anaconda.conf 
Alias /anaconda/cfg /export/anaconda/cfg

    Options Indexes FollowSymLinks
    Allow from All


Alias /anaconda/postinstall /export/anaconda/postinstall

    Options Indexes FollowSymLinks
    Allow from All


Alias /anaconda /export/anaconda/media

    Options Indexes FollowSymLinks
    Allow from All


Step 8:
Modify the kickstart files.

cat CentOS-6.4-i386-ks.cfg

install

# Specifies the language
lang en_US.UTF-8

# Specifies the keyboard layout
keyboard us

# Skip Red Hat subscriber key input
key --skip

# Forces the text installer to be used (saves time)
text

# Forces the cmdline installer to be used (debugging)
#cmdline

# Skips the display of any GUI during install (saves time)
skipx

# Used with an HTTP install to specify where the install files are located
url --url http://192.168.1.10/anaconda/CentOS-6.4-i386

# Assign a static IP address upon first boot & set the hostname
network --device eth0 --onboot yes --bootproto static --ip=192.168.1.13 \
--netmask=255.255.255.0 --gateway=192.168.1.1 --nameserver=8.8.8.8

# Give the second interface a DHCP address (if you are not using a second interface comment this line out)
network --device eth1 --onboot yes --bootproto static --ip=172.16.0.13 \
--netmask=255.255.0.0

# Set the root password
rootpw password

# Need a repo as only the minimal iso was used
repo --name=es --baseurl=http://linux.mirrors.es.net/centos/6/os/i386/

# Enable the firewall and open port 22 for SSH remote administration
firewall --enabled --port=22:tcp

# Setup security and SELinux levels
authconfig --enableshadow --passalgo=sha512

selinux --disabled

# Set the timezone
timezone --utc Etc/UTC

# Create the bootloader in the MBR with drive sda being the drive to install it on
bootloader --location=mbr --driveorder=sda,sdb --append=audit=1

# Wipe all partitions and build them with the info below
clearpart --all --initlabel

#Disk partitioning information
zerombr

# Create primary partitions
part /boot --fstype ext4 --size=512 --asprimary --ondisk=sda
part swap --size=256 --asprimary --ondisk=sda
part pv.01 --size=4096 --grow --asprimary --ondisk=sda

# Create LVM logical volumes
volgroup system --pesize=4096 pv.01
logvol  /  --vgname=system  --size=3000  --grow  --name=root_vol

# reboot when installation completes
reboot

# Install the Core software packages, aka "minimal", plus a couple extras
%packages
%end

%pre
# redirect debugging output to tty3
#exec < /dev/tty3 > /dev/tty3
#chvt 3

%post --log=/var/tmp/install.log
# redirect debugging output to tty3
#exec < /dev/tty3 > /dev/tty3
#chvt 3

echo "Creating CentOS-6.4-i386 post installation directory ..."
mkdir -p /opt/postinstall


echo "Downloading CentOS-6.4-i386 post installation files ..."
cd /opt/postinstall
wget http://192.168.1.10/kickstart/postinstall/CentOS-6.4-i386-postinstall.tgz
tar zxf CentOS-6.4-i386-postinstall.tgz
rm CentOS-6.4-i386-postinstall.tgz > /dev/null 2>&1

echo "Executing CentOS-6.4-i386 post installation script ..."
./CentOS-6.4-i386-postinstall >> CentOS-6.4-i386-postinstall.out 2>&1
echo "Done."
 
Step 9:
Finish configuring pxe.
cp /usr/share/syslinux/pxelinux.0 /export/anaconda/tftpboot/
cp /usr/share/syslinux/menu.c32 /export/anaconda/tftpboot/
 
Step 10:
Enable services.
chkconfig dhcpd on
chkconfig httpd on
chkconfig xinetd on
service dhcpd restart
service httpd restart
service xinetd restart
 

Step 11:
Start the server.  The only option that will need to be specified is on the initial pxe boot menu.

Once selected, the system should perform an unattended install, requiring no user interaction.

After it completes, the system will reboot and present a login screen for the newly installed system.

And the new system is up with the packages and ip addresses specified in the kickstart file.

#ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:75:23:1D  
          inet addr:192.168.1.13  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe75:231d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:70 errors:0 dropped:0 overruns:0 frame:0
          TX packets:62 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8224 (8.0 KiB)  TX bytes:13776 (13.4 KiB)

eth1      Link encap:Ethernet  HWaddr 00:0C:29:75:23:27  
          inet addr:172.16.0.13  Bcast:172.16.255.255  Mask:255.255.0.0
          inet6 addr: fe80::20c:29ff:fe75:2327/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:120 (120.0 b)  TX bytes:720 (720.0 b)

The system can easily be modified to specify different kickstart files for different types of servers.  For example, there could be an option for "Directory Server", "LAMP Server", or "Database Server", all pointing to different kickstart files, and each file specifying the required packages, as well as any necessary post installation configurations.  For example:


No comments:

Post a Comment