How to install Apache then make it as a kickstart server in RHEL7

Let’s create the VM first:

[root@rhel7 ~]# virt-install \
> --hvm \
> --name www \
> --disk path=/kvm/www.img,size=50 \
> --vcpus 1 \
> --ram 1024 \
> --os-type linux \
> --os-variant rhel7 \
> --network bridge=virbr0 \
> --cdrom=/tmp/rhel-server-7.0-x86_64.iso 

Starting install...
[root@www ~]# df -h
Filesystem                      Size  Used Avail Use% Mounted on
/dev/mapper/vg00-root            17G  820M   16G   5% /
devtmpfs                        491M     0  491M   0% /dev
tmpfs                           498M     0  498M   0% /dev/shm
tmpfs                           498M  6.6M  491M   2% /run
tmpfs                           498M     0  498M   0% /sys/fs/cgroup
/dev/mapper/vg00-home          1014M   33M  982M   4% /home
/dev/mapper/vg00-var             10G  7.4G  2.7G  74% /var
/dev/mapper/vg00-var_log         10G   35M   10G   1% /var/log
/dev/mapper/vg00-var_log_audit  5.0G   44M  5.0G   1% /var/log/audit
/dev/mapper/vg00-tmp            5.0G   33M  5.0G   1% /tmp
/dev/vda1                       509M   86M  424M  17% /boot
[root@www ~]# 
[root@www ~]# pvs
  PV         VG   Fmt  Attr PSize  PFree
  /dev/vda2  vg00 lvm2 a--  49.49g 4.00m
[root@www ~]# 
[root@www ~]# ifconfig 
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet  netmask  broadcast
        inet6 fe80::5054:ff:febd:cca0  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:bd:cc:a0  txqueuelen 1000  (Ethernet)
        RX packets 7552  bytes 505891 (494.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10990  bytes 313493991 (298.9 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet  netmask
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 12  bytes 1166 (1.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12  bytes 1166 (1.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@www ~]# hostnamectl status
   Static hostname:
         Icon name: computer
           Chassis: n/a
        Machine ID: 62841b6d91304d8dbf6a78df1c9f9b24
           Boot ID: 593fb6f3df544ac8ba47b0379fb42da7
    Virtualization: kvm
  Operating System: Red Hat Enterprise Linux Server 7.0 (Maipo)
       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.0:GA:server
            Kernel: Linux 3.10.0-123.el7.x86_64
      Architecture: x86_64
[root@www ~]#

Now the VM is up and running, we’re off to the making of our kickstart server.

0. Copy the rhel-server-7.0-x86_64.iso to the server.

0. Create the mount point:

    [root@www ~]# mkdir /mnt/iso

1. Mount the ISO:

    [root@www ~]# mount -o loop ./rhel-server-7.0-x86_64.iso /mnt/iso/

2. Copy the media.repo from the ISO and enable it:

    [root@www ~]# cp /mnt/iso/media.repo /etc/yum.repos.d/dvd.repo
    [root@www ~]# vi /etc/yum.repos.d/dvd.repo
    [root@www ~]# cat /etc/yum.repos.d/dvd.repo
    name=RHEL-7.0 Server.x86_64

3. Install Apache Web Server and createrepo:

    [root@www ~]# yum -y install httpd createrepo

4. Rename the welcome page conf file:

    [root@www ~]# mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.orig

5. Edit httpd.conf, afterwards, save then quit vi:

    [root@www ~]# vi /etc/httpd/conf/httpd.conf
        # line 86: change to admin's email address
        ServerAdmin root@localhost
        # line 95: change to your server's name/ip
        # line 151: change
        AllowOverride All
        # line 164: add file name that it can access only with  
directory's name
        DirectoryIndex index.html index.cgi index.php
        # add the following at the end
        ServerTokens Prod
        KeepAlive On

6. Start httpd:

    [root@www ~]# systemctl start httpd

7. Enable httpd startup script:

    [root@www ~]# systemctl enable httpd

8. Add the source subnet to trusted zone in firewall:

    [root@www ~]# firewall-cmd --permanent --zone=trusted --add-source=

9. Add httpd to public zone and reload firewalld:

    [root@www ~]# firewall-cmd --permanent --zone=public --add-service=http
    [root@www ~]# firewall-cmd --reload

10. Create the rhel7 iso content place holder to be served via http:

    [root@www ~]# mkdir /var/www/html/rhel7

11. Copy iso content to the folder:

    [root@www ~]# cp -rpv /mnt/iso/* /var/www/html/rhel7/
    [root@www ~]# cp -p /mnt/iso/.discinfo /mnt/iso/.treeinfo /var/www/html/rhel7/

12. Go to /var/www/html/:

    [root@www ~]# cd /var/www/html/

13. Create the repo:

    [root@www html]# createrepo .

14. Create the folder/files for kickstart:

    [root@www html]# mkdir ksfiles
    [root@www html]# cd ksfiles
    [root@www ksfiles]# vi www.repo
    [root@www ksfiles]# cat www.repo
    name=RHEL-7.0 Server.x86_64
    [root@www ksfiles]# 
    [root@www ksfiles]# vi ntp.conf
    [root@www ksfiles]# cat ntp.conf
    driftfile /var/lib/ntp/drift
    restrict default nomodify notrap nopeer noquery
    restrict ::1
    includefile /etc/ntp/crypto/pw
    keys /etc/ntp/keys
    disable monitor
    logfile /var/log/ntp.log
    [root@www ksfiles]# 
    [root@www ksfiles]# vi step-tickers
    [root@www ksfiles]# cat step-tickers
    [root@www ksfiles]# 
    [root@www ksfiles]# vi network
    [root@www ksfiles]# cat network
    [root@www ksfiles]# 
    [root@www ksfiles]# vi resolv.conf
    [root@www ksfiles]# cat resolv.conf
    [root@www ksfiles]# 
    [root@www ksfiles]# vi rhel7-minimal-ks.cfg
    [root@www ksfiles]# cat rhel7-minimal-ks.cfg
    # System authorization information
    auth --enableshadow --passalgo=sha512

    # Use network installation
    url --url=""
    # Run the Setup Agent on first boot
    firstboot --disabled
    # Use text mode install
    # Keyboard layouts
    keyboard --vckeymap=us --xlayouts='us'
    # System language
    lang en_US.UTF-8

    # Network information
    #network --bootproto=dhcp --device=eth0 --ipv6=auto --activate
    #network --hostname=desktop7
    # Root password
    rootpw --iscrypted $6$uXta3WTlMzXDeV5T$hY08p7EBQTJKFVfQybNQF49rQ/SK/2T3qUwWP7spMUHdHgCykFLYdUoe7vp/.kSWaW./HjDEvPBnvzxWgPfe20
    # Skip EULA
    eula --agreed
    # System services
    services --enabled="sshd"
    # System timezone
    timezone Asia/Singapore --ntpservers=
    # Reboot the machine when the installation is finished
    # Include files
    %include /tmp/network1.cfg
    %include /tmp/partitioning.cfg

    # default from core
    # default from base

    # PreInstall stuff
    %pre --log=/root/anaconda-preinstall.log

    # get hostname and ipaddr from virt-install SERVERNAME and IPADDR arguments
    for x in `cat /proc/cmdline`; do
            case $x in SERVERNAME*)
                eval $x
            echo "network --device=eth0 --bootproto=dhcp --hostname ${SERVERNAME} --activate" > /tmp/network.cfg
    for y in `cat /proc/cmdline`; do
            case $y in IPADDR*)
            eval $y
            SERVERNAME1=`awk '{ print $5 }' /tmp/network.cfg`
            echo "network --device=eth0 --bootproto=static --hostname ${SERVERNAME1} --ip=${IPADDR} --netmask= --gateway= --nameserver= --nameserver= --activate" > /tmp/network1.cfg

    # Check physical and virtio disks
    for disk in /sys/block/sd* /sys/block/vd*
            dsk=$(basename $disk)

            if [[ `cat $disk/ro` -eq 1 ]];
                    echo "Skipping disk $dsk: READONLY"

            if [[ `cat $disk/removable` -eq 1 ]];
                    echo "Skipping disk $dsk: REMOVABLE"

            if [[ `cat $disk/size` -lt 20971520 ]];
                    echo "Skipping disk $dsk: Smaller then 10G"
                    echo "Using disk $dsk"

    > $incfile

    if [[ -n $chosen ]];
        ehco "bootloader --location=mbr" >> $incfile
            echo "zerombr" >> $incfile
            echo "ignoredisk --only-use=$chosen" >> $incfile
            echo "clearpart --all --initlabel" >> $incfile
            echo "part /boot --fstype=xfs --asprimary --size=512" >> $incfile
            echo "part pv.01 --size=1 --grow" >> $incfile
            echo "volgroup vg00 --pesize=4096 pv.01" >> $incfile
            echo "logvol /var --fstype=xfs --name=var --vgname=vg00 --size=10240" >> $incfile
            echo "logvol /var/log --fstype=xfs --name=var_log --vgname=vg00 --size=10240" >> $incfile
            echo "logvol /var/log/audit --fstype=xfs --name=var_log_audit --vgname=vg00 --size=5120" >> $incfile
            echo "logvol /tmp --fstype=xfs --name=tmp --vgname=vg00 --size=5120" >> $incfile
            echo "logvol /home --fstype=xfs --name=home --vgname=vg00 --size=1024" >> $incfile
            echo "logvol swap --name=swap --vgname=vg00 --size=2048" >> $incfile
            echo "logvol / --fstype=xfs --name=root --vgname=vg00 --size=1 --grow" >> $incfile
            echo "" > $incfile


    # PostInstall stuff
    %post --log=/root/anaconda-postinstall.log
    /usr/bin/wget -O /etc/yum.repos.d/www.repo
    /usr/bin/wget -O /etc/ntp.conf
    /usr/bin/wget -O /etc/ntp/step-tickers
    /usr/bin/wget -O /etc/sysconfig/network
    /usr/bin/wget -O /etc/resolv.conf
    /usr/bin/firewall-cmd --permanent --zone=public --add-port=123/udp
    /usr/bin/firewall-cmd --permanent --zone=public --add-port=53/udp
    /usr/bin/systemctl disable chronyd.service
    /usr/bin/systemctl enable ntpd.service
    /usr/bin/systemctl start ntpd.service
    [root@www ksfiles]#

15. Rename the repo then edit it:

    [root@www ksfiles]# mv /etc/yum.repos.d/dvd.repo /etc/yum.repos.d/www.repo
    [root@www ksfiles]# vi /etc/yum.repos.d/www.repo
    [root@www ksfiles]# cat /etc/yum.repos.d/www.repo
    name=RHEL-7.0 Server.x86_64
    [root@www ksfiles]#


Done! Next, let’s use this kickstart server to provision VMs.

Leave a Reply

Your email address will not be published. Required fields are marked *