Saturday 28 April 2012

Configuring Cacti on RHEL 6

This is the Cacti installation from EPEL so enable the EPEL repo.
Also enable the rhel-6-server-optional channel in redhat.repo as it's required for php-snmp.

Install the packages cacti, mysql-server, httpd, net-snmp-utils

Turn on and chkconfig mysqld and httpd
(Amend ServerName in httpd.conf if hostname is not resolvable)

 Set cacti passwords and create the cacti database

mysqladmin -u root password rootsecretpassword
mysql -u root -p -e 'create database cacti'
mysql -u root -p
mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'cactisecretpassword';
mysql> FLUSH privileges;

Replace the default /etc/snmp/snmpd.conf with this as it's too secure.
com2sec local     localhost           public
group MyRWGroup v1         local
group MyRWGroup v2c        local
group MyRWGroup usm        local
view all    included  .1                     80
access MyRWGroup ""  any  noauth  exact   all    all    none
syslocation My House
syscontact Me

Turn on and chkconfig snmpd

Walk the snmp mib and verify it returns active interfaces; otherwise it's not configured right.
snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

Configure the cacti database
mysql -u cacti -p  cacti < /usr/share/doc/cacti-0.8.7i/cacti.sql

 Edit /etc/cacti/db.php
$database_username = "cacti";
$database_password = "cactisecretpassword";

Edit /etc/httpd/conf.d/cacti.conf

Alias /cacti    /usr/share/cacti

<Directory /usr/share/cacti/>
        Order Deny,Allow
        Deny from all
        Allow from all
</Directory>


Restart httpd

Uncomment poller cron job in /etc/cron.d/cacti

Your Cacti server awaits:

http://yourserver/cacti  & login as admin / admin

How To Build a PXE Server

So you've created some kickstart files (here) now wouldn't it be nice to have the client net boot and the installation served up over the network to create a fully automated build.

This is how to be a build a PXE server on RHEL 6. I'm assuming the server has been setup for anonymous FTP to serve out the install media from /pub/inst and the kickstart files from /pub/ks. You could also use HTTP.

Install packages tftp-server & dhcp.

Enable TFTP server in /etc/xinetd.d/tftp
disable=no
And turn it on
service xinetd start

chkconfig xinetd on

Configure a DHCP subnet in /etc/dhcp/dhcpd.conf
( PXE specific stuff in red; next-server is the PXE server)

# Global Options
Allow booting;
Allow bootp;
authoritative;
# Subnet definition
subnet 192.168.122.0 netmask 255.255.255.0 {
option routers 192.168.122.2;
option subnet-mask 255.255.255.0;
option domain-name “example.com”;
option domain-name-servers 192.168.122.2;
default-lease-time 21600;
max-lease-time 43200;
range dynamic-bootp 192.168.122.100 192.168.122.200;
filename “pxelinux.0”;
next-server 192.168.122.2;

}
And turn it on
service dhcpd start

chkconfig dhcpd on 

Create TFTP directories and copy files
mkdir /var/lib/tftpboot/rhel6
mkdir /var/lib/tftpboot/pxelinux.cfg
cp /var/ftp/pub/inst/images/pxeboot/vmlinuz /var/lib/tftpboot/rhel6
cp /var/ftp/pub/inst/images/pxeboot/initrd.img /var/lib/tftpboot/rhel6
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /usr/share/syslinux/menu.c32 /var/lib/tftpboot/

We'll create a default client config file which is served to everyone. You can make client specific ones and place them in the same directory.
Create /var/lib/tftpbook/pxelinux.cfg/default

timeout 100
default menu.c32
menu title Boot Menu
label 1
   menu label ^ 1) Boot next available boot device
   localboot
label 2
   menu label ^ 2) RHEL 6 (with kickstart)
   kernel rhel6/vmlinuz
   append initrd=rhel6/initrd.img ks=ftp://192.168.122.2/pub/ks/server1.cfg
label 3
   menu label ^ 3) RHEL 6 (interactive)
   kernel rhel6/vmlinuz
   append initrd=rhel6/initrd.img ip=dhcp repo=ftp://192.168.122.2/pub/inst

By placing localboot as the first option we avoid an accidental build if the first boot device is set to network as we default to booting the next available device.
Option 2 is an example of a fully automated install with a kickstart file
Option 3 will deliver an interactive installation
If it's all working you'll see something like this from a PXE booting client.

Thursday 19 April 2012

Building RHEL with Kickstart Files

How to build RHEL 6 on an HP Server from DVD installation with a kickstart file on a USB key:

Assume machine has already been hardware mirrored.
USB sticks are enumerated as sda so kickstart file has to use sdb for internal disk.
Those dodgy Dektek sticks enumerate as 2 drives (sda & sdb) so use sdc for internal disk which is why example below uses sdc.

Boot machine of DVD, highlight first install / upgrade option and press tab to edit. Add this to end of line:
ks=hd:sda1:/kickstart-file.cfg
Sample kickstart here, based on an autogen'ed basic server  install. Bit's I modified are in red.

# Kickstart file automatically generated by anaconda.
#version=DEVEL
install
cdrom
lang en_GB.UTF-8
keyboard uk
network --onboot no --device eth0 --noipv4 --noipv6
network --onboot no --device eth1 --noipv4 --noipv6
network --onboot no --device eth2 --noipv4 --noipv6
network --onboot no --device eth3 --noipv4 --noipv6
network --onboot yes --device eth4 --bootproto static --ip 10.182.46.6 --netmask 255.255.255.0 --gateway 10.182.46.252 --noipv6 --hostname know-msvarnish-01.knon.dtv
network --onboot no --device eth5 --noipv4 --noipv6
rootpw  --iscrypted $6$woBbCXzYdNZUmerV$mz9mELXXNXBLL.k5MpL1S7nn7c3Dlf9i7sWUTRX7W2D0qjQY6sFBrSJA.wi2EfbL.YYz.gGf8AcwwOPEUuYgw1
firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --enforcing
timezone --utc Europe/London
bootloader --location=mbr --driveorder=sdc --append=" rhgb crashkernel=auto quiet"
# The following is the partition information you requested
# Note that any partitions you deleted are not expressed
# here so unless you clear all partitions first, this is
# not guaranteed to work
ignoredisk --drives=sda,sdb
clearpart --all --initlabel --drives=sdc
part /boot --fstype=ext4 --size=500 --ondisk=sdc
part pv.008002 --grow --size=1 --ondisk=sdc
volgroup vg_knowmsvarn --pesize=4096 pv.008002
logvol /var --fstype=ext4 --name=lv_var --vgname=vg_knowmsvarn --size=51200
logvol swap --name=lv_swap --vgname=vg_knowmsvarn --size=34288
logvol / --fstype=ext4 --name=lv_root --vgname=vg_knowmsvarn --size=100 --grow
 
#repo --name="Red Hat Enterprise Linux"  --baseurl=cdrom:sr0 --cost=100 
%packages
@base
@client-mgmt-tools
@console-internet
@core
@debugging
@directory-client
@hardware-monitoring
@java-platform
@large-systems
@network-file-system-client
@performance
@perl-runtime
@server-platform
@server-policy
pax
python-dmidecode
oddjob
sgpio
certmonger
pam_krb5
krb5-workstation
perl-DBD-SQLite
%end
Need to set the language to UK.
The --initlabel to clearpart should stop it asking for confirmation of initialising a new disk
The ignoredisk param tells installer to ignore usb sticks during partitioning
Make sure the --ondisk, --drives, --driveorder all match up with the enumeration of the internal disk
The --grow option tells that logvol to fill the rest of the disk.
Comment out the repo line as it defaults to DVD and didn't seem to work with it in.