Customize a Golden Image or RHEL ISO with kickstart file? Rhel4/5/6//7

Issue

 

  • How can we create a customized RHEL6 ISO with kickstart file included in the ISO?
  • How to include a kickstart file in ISO image and create customized ISO?

Resolution

1. Download the RHEL installation dvd iso or minimal boot media boot.iso

2. Mount the ISO

    # mount /path/to/rhel-dvd.iso /mnt/ -o loop


3. Copy the entire contents of the disk to another location.

    # mkdir /rhel
    # shopt -s dotglob
    # cp -ai /mnt/* /rhel

4. Create a kickstart file.
This is an example: 

5. Copy the kickstart file to the /rhel directory

      # cp /path/to/ks.cfg /rhel

6. Change the file '/rhel/isolinux/isolinux.cfg',  change the following lines :
     label linux
      menu label ^Install or upgrade an existing system
      menu default
      kernel vmlinuz
      append initrd=initrd.img
to
     label linux
      menu label ^Install or upgrade an existing system
      menu default
      kernel vmlinuz
      append initrd=initrd.img  ks=cdrom:/ks.cfg
NOTE: For Red Hat Enterprise Linux 7, use the following append line:
append initrd=initrd.img inst.stage2=hd:LABEL=***Volume_ID*** quiet ks=cdrom:/ks.cfg
Replace Volume_ID by the same value as one specified in -V option of the following mkisofs command.

7. Rebuild the DVD iso image

    # cd /rhel
    # mkisofs -o /tmp/new.iso -b isolinux/isolinux.bin -c isolinux/boot.cat --no-emul-boot --boot-load-size 4 --boot-info-table -J -R -V disks .
NOTE: In Red Hat Enterprise Linux 7, please make sure that you specify the volume id with -V option, and it's same as Volume_ID in step 6.

8. Boot the machine from this ISO

Mission Statement

Linux was made to be free and open.

Linux was made to be free and open. The idea is, an individual working with a piece of software should be allowed to view, edit, and share its source code without legal consequence. The free software Movement was largely the brainchild of Richard Stallman. Having been a member of the academic hacker community for over a decade, he had grown frustrated by the spread of proprietary software and came to see it as a violation of people’s rights to innovate and improve existing software.

In 1983, Stallman launched the GNU Project – an effort to create a complete operating system which would provide its users with the freedom to view, change, and share its source code. According to Stallman, the proprietary software puts an unfair burden on users and developers who would otherwise be able to change the code to suit their own needs or alter it to serve a new function.

Fast forward to 1991, Linus Torvalds while studying computer science at University of Helsinki, began a project that later became the Linux kernel. Linux (also known as GNU/Linux) is a computer operating systems, like Microsoft or Apple Mac OS. Unlike those two, Linux is built with a collaborative development model. The operating system and most of its software are created by volunteers and employees of companies, governments, and organizations from all over the world. To continue this legacy, Linux Administrators and Engineers all over the world must invest in the personal and professional development of Newcomers. We must leverage our networks in order to do so effectively and efficiently. We are always open to new ideas, energy and engineering contributions.

Our goal at ShebangLinux is simple: We aim to create a platform that provides everyone with the connection they need to be successful in their career.

 

Find broken symlinks and delete them

Find broken symlinks and delete them

Look for the broken link, and  list them:

#find -L /path -type l

Delete broken link

#find -L /path -type l -delete

To delete with confirmation do:

#find -L /path -type l -exec rm -i {} +

L flag follows symlinks, so the -type l test only returns true if the link can’t be followed, or is a symlink to another broken symlink.

How to Install Nagios

Nagios is an awesome Open Source monitoring tool, its provides you more comprehensive monitoring environment to always keep an eye on your all machines / networks whether you are in a your data center or just your small labs.

With Nagios, you can monitor your remote hosts and their services remotely on a single window. It shows warnings and indicates if something goes wrong in your servers which eventually helps us to detect some problems before they occur. It helps us to reduce downtime and business losses.

Recently, Nagios released its latest versions Nagios Core 4.3.4 and its latest stable release of Nagios plugins 2.2.1 on April 19, 2017.

This article is intended to guide you with easy instructions on how to install latest Nagios Core 4.3.4 from source (tarball) on RHEL 7.x/6.x/5.xCentOS 7.x/6.x/5.x  distributions.

Within 30 minutes you will be monitoring your local machine, no any advanced installation procedure only basic installation that will work 100% on most of the today’s Linux servers.

Please Note: The installation instructions were shown in here are written based on CentOS 7.2 Linux distribution.

Installing Nagios 4.3.4 and Nagios Plugin 2.2.1

If you follow these instructions correctly, you will end up with following information.

  1. Nagios and its plugins will be installed under /usr/local/nagios directory.
  2. Nagios will be configured to monitor few services of your local machine (Disk UsageCPU LoadCurrent UsersTotal Processes, etc.)
  3. Nagios web interface will be available at http://localhost/nagios

Step 1: Install Required Dependencies:

We need to install ApachePHP and some libraries like gccglibcglibc-common and GD libraries and its development libraries before installing Nagios 4.3.4 with source. And to do so, we can use yum default package installer.

yum install -y httpd httpd-tools php gcc glibc glibc-common gd gd-devel make net-snmp

Step 2: Create Nagios User and Group

Create a new nagios user and nagcmd group account and set a password.

# useradd nagios
# groupadd nagcmd

Next, add both the nagios user and the apache user to the nagcmd group.
# usermod -G nagcmd nagios
# usermod -G nagcmd apache

Step 3: Download Nagios Core 4.3.4 and Nagios Plugin 2.2.1

# mkdir /root/nagios
# cd /root/nagios

Now download latest Nagios Core 4.3.4 and Nagios plugins 2.2.1 packages with wget.
# wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.4.tar.gz
# wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

Step 4: Extract Nagios Core and its Plugins

We need to extract downloaded package with tar command as follows.

# tar -xvf nagios-4.3.4.tar.gz
# tar -xvf nagios-plugins-2.2.1.tar.gz

When you extract these tarballs with tar command, two new folders will appear in that directory.
Dir:nagios-4.3.4 / nagios-plugins-2.2.1
Files : nagios-4.3.4.tar.gz / nagios-plugins-2.2.1.tar.gz

Configure Nagios Core

Now, first we will configure Nagios Core and to do so we need to go to Nagios directory and run configure file and if everything goes fine, it will show the output in the end as sample output. Please see below.

# cd nagios-4.3.4/
# ./configure --with-command-group=nagcmd

Sample output:
Creating sample config files in sample-config/ ...
*** Configuration summary for nagios 4.3.4 2017-08-24 ***:
General Options:
-------------------------
Nagios executable:  nagios
Nagios user/group:  nagios,nagios
Command user/group:  nagios,nagcmd
Event Broker:  yes
Install ${prefix}:  /usr/local/nagios
Install ${includedir}:  /usr/local/nagios/include/nagios
Lock file:  /run/nagios.lock
Check result directory:  ${prefix}/var/spool/checkresults
Init directory:  /etc/rc.d/init.d
Apache conf.d directory:  /etc/httpd/conf.d
Mail program:  /usr/bin/mail
Host OS:  linux-gnu
IOBroker Method:  epoll
Web Interface Options:
------------------------
HTML URL:  http://localhost/nagios/
CGI URL:  http://localhost/nagios/cgi-bin/
Traceroute (used by WAP):  /usr/bin/traceroute
Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

After configuring, we need to compile and install all the binaries with make all and make install command, it will
 install all the needed libraries in your machine and we can proceed further.
# make all
# make install
Sample output:
*** Exfoliation theme installed ***
NOTE: Use 'make install-classicui' to revert to classic Nagios theme
make[1]: Leaving directory `/root/nagios/nagios-4.3.4'
make install-basic
make[1]: Entering directory `/root/nagios/nagios-4.3.4'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/archives
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/spool/checkresults
chmod g+s /usr/local/nagios/var/spool/checkresults
*** Main program, CGIs and HTML files installed ***
You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
make install-init
- This installs the init script in /etc/rc.d/init.d
make install-commandmode
- This installs and configures permissions on the
directory for holding the external command file
make install-config
- This installs sample config files in /usr/local/nagios/etc
make[1]: Leaving directory `/root/nagios/nagios-4.3.4'

Following command will install the init scripts for Nagios.
# make install-init
/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios

*** Init script installed ***
To make nagios work from command line we need to install command-mode
# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagcmd -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw

*** External command directory configured ***
Next, install sample nagios files, please run following command.
# make install-config
Sample output:
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg
*** Config files installed ***
Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

Step 5: Customizing Nagios Configuration

Open the “contacts.cfg” file with your choice of editor and set the email address associated
 with the nagiosadmin contact definition to receiving email alerts.
# vi /usr/local/nagios/etc/objects/contacts.cfg
 
Sample Output:
###############################################################################
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################
# Just one contact defined by default - the Nagios admin (that's you)
# This contact definition inherits a lot of default values from the 'generic-contact'
# template which is defined elsewhere.
define contact{
contact_name                    nagiosadmin             ; Short name of user
use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
alias                           Nagios Admin            ; Full name of user
email                           admin@yourdomain.com     ; *** CHANGE THIS TO YOUR EMAIL ADDRESS ****
}

Step 6: Install and Configure Web Interface for Nagios

We are done with all configuration in the backend, 
now we will configure Web Interface For Nagios with following command.
The below command will Configure Web interface for Nagios and a web admin user will be created “nagiosadmin”.
# make install-webconf

In this step, we will be creating a password for “nagiosadmin”. 
After executing this command, please provide a password twice and keep it remember because this password will be used
when you login in the Nagios Web interface.
# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin


Restart Apache to make the new settings take effect.
# service httpd start 
Starting httpd:                                            [  OK  ]

Step 7: Compile and Install Nagios Plugin

We have downloaded nagios plugins in /root/nagios, Go there and configure and install it as directed below.

# cd /root/nagios
# cd nagios-plugins-2.2.1/
# ./configure --with-nagios-user=nagios --with-nagios-group=nagios



Sample Output:

.......
configure: creating ./config.status
config.status: creating gl/Makefile
config.status: creating nagios-plugins.spec
config.status: creating tools/build_perl_modules
config.status: creating Makefile
config.status: creating tap/Makefile
config.status: creating lib/Makefile
config.status: creating plugins/Makefile
config.status: creating lib/tests/Makefile
config.status: creating plugins-root/Makefile
config.status: creating plugins-scripts/Makefile
config.status: creating plugins-scripts/utils.pm
config.status: creating plugins-scripts/utils.sh
config.status: creating perlmods/Makefile
config.status: creating test.pl
config.status: creating pkg/solaris/pkginfo
config.status: creating po/Makefile.in
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands
config.status: executing po-directories commands
config.status: creating po/POTFILES
config.status: creating po/Makefile


# make

Sample Output:
........
make[2]: Leaving directory `/root/nagios/nagios-plugins-2.2.1/plugins-root'
Making all in po
make[2]: Entering directory `/root/nagios/nagios-plugins-2.2.1/po'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/nagios/nagios-plugins-2.2.1/po'
make[2]: Entering directory `/root/nagios/nagios-plugins-2.2.1'
make[2]: Leaving directory `/root/nagios/nagios-plugins-2.2.1'
make[1]: Leaving directory `/root/nagios/nagios-plugins-2.2.1'


# make install

Sample Output:

installing fr.gmo as /usr/local/nagios/share/locale/fr/LC_MESSAGES/nagios-plugins.mo
installing de.gmo as /usr/local/nagios/share/locale/de/LC_MESSAGES/nagios-plugins.mo
if test "nagios-plugins" = "gettext-tools"; then \
 /bin/mkdir -p /usr/local/nagios/share/gettext/po; \
 for file in Makefile.in.in remove-potcdate.sin Makevars.template; do \
 /usr/bin/install -c -o nagios -g nagios -m 644 ./$file \
 /usr/local/nagios/share/gettext/po/$file; \
 done; \
 for file in Makevars; do \
 rm -f /usr/local/nagios/share/gettext/po/$file; \
 done; \
 else \
 : ; \
 fi
make[1]: Leaving directory `/root/nagios/nagios-plugins-2.2.1/po'
make[1]: Entering directory `/root/nagios/nagios-plugins-2.2.1'
make[2]: Entering directory `/root/nagios/nagios-plugins-2.2.1'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/root/nagios/nagios-plugins-2.2.1'
make[1]: Leaving directory `/root/nagios/nagios-plugins-2.2.1'

Step 8: Verify Nagios Configuration Files

Now we are all done with Nagios configuration and its time to verify it and to do so please insert following command.
If everything goes smooth it will show up similar to below output.

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Sample Output:
Nagios Core 4.3.4
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2017-08-24
License: GPL
Website: https://www.nagios.org
Reading configuration data...
Read main config file okay...
Read object config files okay...
Running pre-flight check on configuration data...
Checking objects...
Checked 8 services.
Checked 1 hosts.
Checked 1 host groups.
Checked 0 service groups.
Checked 1 contacts.
Checked 1 contact groups.
Checked 24 commands.
Checked 5 time periods.
Checked 0 host escalations.
Checked 0 service escalations.
Checking for circular paths...
Checked 1 hosts
Checked 0 service dependencies
Checked 0 host dependencies
Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors:   0
Things look okay - No serious problems were detected during the pre-flight check

Step 9: Add Nagios Services to System Startup

To make Nagios work across reboots, we need to add nagios and httpd with chkconfig and systemctl command.

# chkconfig --add nagios
# chkconfig  nagios on
# chkconfig --add httpd
# chkconfig  httpd on
Restart Nagios to make the new settings take effect.
# service nagios start  
Starting nagios: done.

Step 10: Login to the Nagios Web Interface

username: nagiosadmin

Password: yourpassword

 

Nagios Web Dashboard

 

The best AWK one-liners

The best AWK one-liners

I love perl and I use it for most scripts but nothing beats awk on the commandline.
Print selected fields

Split up the lines of the file file.txt with “:” (colon) separated fields and print the second field ($2) of each line:
awk -F”:” ‘{print $2}’ file.txt
Same as above but print only output if the second field ($2) exists and is not empty:
awk -F”:” ‘{if ($2)print $2}’ file.txt
Print selected fields from each line separated by a dash:
awk -F: ‘{ print $1 “-” $4 “-” $6 }’ file.txt
Print the last field in each line:
awk -F: ‘{ print $NF }’ file.txt
Print every line and delete the second field:
awk ‘{ $2 = “”; print }’

Good to know:
The commandline option -F sets the field separator. The default is space.
$0 the entire line without the newline at the end
$1 to $9, $10 to …, the fields
NF number of fields
NR currant line number (counting across all files for multiple files)
FR line number (just for that file)
Print matching lines

Print field number two ($2) only on lines matching “some regexp”:
awk -F”:” ‘/some regexp/{print $2}’ file.txt
Print field number two ($2) only on lines matching “some regexp” otherwise print field number three ($3):
awk -F”:” ‘/some regexp/{print $2;next}{print $3}’ file.txt
The “next” command causes awk to continue with the next line and execute “{print $3}” only for non matching lines. This is like
/regexp/{…if..regexp..matches…;next}{…else…}

Print the next two (i=2) lines after the line matching regexp:
awk ‘/regexp/{i=2;next;}{if(i){i–; print;}}’ file.txt
Print the line and the next two (i=2) lines after the line matching regexp:
awk ‘/regexp/{i=2+1;}{if(i){i–; print;}}’ file.txt
Print the lines from a file starting at the line matching “start” until the line matching “stop”:
awk ‘/start/,/stop/’ file.txt
Regexp syntax:
c matches the non-metacharacter c.
\c matches the literal character c.
. matches any character including newline.
^ matches the beginning of a string (example: ^1 , only lines starting with a one)
$ matches the end of a string (example: end$ , only lines ending in “end”)
[abc…] character list, matches any of the characters abc….
[0-9a-zA-Z] range of characters 0-9 and a-z,A-Z
[^abc…] negated character list, matches any character except abc….
r1|r2 alternation: matches either r1 or r2.
r1r2 concatenation: matches r1, and then r2.
r+ matches one or more r’s.
r* matches zero or more r’s.
r? matches zero or one r’s.
(r) grouping: matches r.
Replacement for some common unix commands (useful in a non unix environment)

Count lines (wc -l):
awk ‘END{print NR}’
Search for matching lines (egrep regexp):
awk ‘/regexp/’
Print non matching lines (egrep -v regexp):
awk ‘!/regexp/’
Print matching lines and ignore case (egrep -i regexp):
awk ‘BEGIN {IGNORECASE=1};/regexp/’
Number lines (cat -n):
awk ‘{print FNR “\t” $0}’
Remove duplicate consecutive lines (uniq):
awk ‘a !~ $0{print}; {a=$0}’
Print first 5 lines of file (head -5):
awk ‘NR < 6’
Number non empty lines

This prints all lines and adds a line number to non empty lines:
awk ‘/^..*$/{ print NR “:” $0 ;next}{print}’ file.txt
Substitute foo for bar on lines matching regexp

awk ‘/regexp/{gsub(/foo/, “bar”)};{print}’ file.txt
Delete trailing white space (spaces, tabs)

awk ‘{sub(/[ \t]*$/, “”);print}’ file.txt
Delete leading white space

awk ‘{sub(/^[ \t]+/, “”); print}’ file.txt
Add some characters at the beginning of matching lines

Add ++++ at lines matching regexp.
awk ‘/regexp/{sub(/^/, “++++”); print;next;}{print}’ file.txt
Color gcc warnings in red

gcc -Wall main.c |& awk ‘/: warning:/{print “\x1B[01;31m” $0 “\x1B[m”;next;}{print}’
The “\x1B” means the ascii character with hex number 1B (ESC).
Print only lines of less than 80 characters

awk ‘length < 80’ file.txt

Print every line that is longer than 80 characters:
awk ‘length($0) > 80’ data
The sole rule has a relational expression as its pattern and has no action—so it uses the default action, printing the record.

Print the length of the longest input line:
awk ‘{ if (length($0) > max) max = length($0) }
END { print max }’ data
The code associated with END executes after all input has been read; it’s the other side of the coin to BEGIN.

Print the length of the longest line in data:
expand data | awk ‘{ if (x < length($0)) x = length($0) }
END { print “maximum line length is ” x }’
This example differs slightly from the previous one: the input is processed by the expand utility to change TABs into spaces, so the widths compared are actually the right-margin columns, as opposed to the number of input characters on each line.

Print every line that has at least one field:
awk ‘NF > 0’ data
This is an easy way to delete blank lines from a file (or rather, to create a new file similar to the old file but from which the blank lines have been removed).

Print seven random numbers from 0 to 100, inclusive:
awk ‘BEGIN { for (i = 1; i <= 7; i++)
print int(101 * rand()) }’
Print the total number of bytes used by files:
ls -l files | awk ‘{ x += $5 }
END { print “total bytes: ” x }’
Print the total number of kilobytes used by files:
ls -l files | awk ‘{ x += $5 }
END { print “total K-bytes:”, x / 1024 }’
Print a sorted list of the login names of all users:
awk -F: ‘{ print $1 }’ /etc/passwd | sort
Count the lines in a file:
awk ‘END { print NR }’ data
Print the even-numbered lines in the data file:
awk ‘NR % 2 == 0’ data
If you used the expression ‘NR % 2 == 1’ instead, the program would print the odd-numbered lines.

How to roll back to a patched server to an earlier patch level

How to roll back to a patched server to an earlier patch level

1.) Edit the /etc/grub.conf file to make the kernel boot to an eariler kernel. Inside of /etc/grub.conf, file the line “default=0” and change to “default=1”

#vi /etc/grub.conf

Change: default=0
To: default=1
<save and quit>
2.) Reboot the server so you can boot into the second, pervious, kernel

#reboot
3.) After reboot, find out when the patching took place.

#yum history list

4.) After finding out when the patching took place. undo the patching by the ID number.

#yum history undo <ID # of patch update>

5.) Check for patch duplicates

#yum check duplicates