Thursday, March 17, 2016

Install and Configure Nagios On CentOS, RHEL, Scientific Linux 6.5/6.4


Install and Configure Nagios On CentOS, RHEL, Scientific Linux 6.5/6.4

Nagios is an open source software that can be used for network and infrastructure monitoring. Nagios will monitor servers, switches, applications and services. It alerts the System Administrator when something went wrong and also alerts back when the issues has been rectified.
With Nagios you can:
– Monitor your entire IT infrastructure.
– Identify problems before they occur.
– Know immediately when problems arise.
– Share availability data with stakeholders.hypothetical question
– Detect security breaches.
– Plan and budget for IT upgrades.
– Reduce downtime and business losses.
Scenario
In this tutorial i am going to use two systems as mentioned below.

Nagios server:

Operating system : CentOS 6.5 minimal installation
IP Address       : 192.168.1.101/24

Nagios client:

Operating System : Ubuntu 13.04
IP Address       : 192.168.1.100/24
Prerequisites
Before installing Nagios, make sure that you’ve a properly installed and configured LAMP stack in your server. To install and configure LAMP server, refer any one of the following links.
Also install the following prerequisites too. All commands should be run as root user.
# yum install gd gd-devel gcc glibc glibc-common
Install Nagios
I tested this how-to on CentOS 6.5 minimal server, although it should work on all RHEL 6.x and its clones like CentOS 6.x and Scientific Linux 6.x.
Nagios will not be found in CentOS official repositories, so let us add the EPEL repository to install nagios. To add and enable EPEL repository, refer the following link.
Next install nagios with all plug-ins and nagios agents(nrpe-agent) using command:
# yum install nagios*
Note: It worked for me either if i keep SELINUX and iptables enable or disable. All you need to do is allow the apache port through iptables as shown below.
# vi /etc/sysconfig/iptables
Add the following line:
[...]
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
[...]
Save and close the file. Restart iptables.
# service iptables restart
Configure Nagios
Add the admin mail address in the nagios contact file to receive alerts from nagios server. To do that edit file /etc/nagios/objects/contacts.cfg,
# vi /etc/nagios/objects/contacts.cfg
Find the following line and enter the email id:
[...]
email                           sk@unixmen.com ;
[...
Save and close the file. Then Edit file /etc/httpd/conf.d/nagios.conf,
# vi /etc/httpd/conf.d/nagios.conf
And edit the following lines if you want to access nagios administrative console from a particular IP series. Here i want to allow nagios administrative access from 192.168.1.0/24 series only.
[...]
## Comment Lines 15 & 16 ##
#   Order allow,deny
#   Allow from all
## Uncomment and Change lines 17,18 & 19 as shown below ##
Order deny,allow
Deny from all
Allow from 127.0.0.1 192.168.1.0/24
[...]
Set nagiosadmin password
# htpasswd /etc/nagios/passwd nagiosadmin
New password:
Re-type new password:
Updating password for user nagiosadmin
Start nagios and httpd services and let them to start automatically on every boot.
# service nagios start
# service httpd start
# chkconfig nagios on
# chkconfig httpd on
Access Nagios admin console
Open nagios administrator console with URL http://nagios-server-ip/nagios and enter the username as nagiosadmin and its password which we created in the earlier steps.
New Tab - Mozilla Firefox_001This is how Nagios administrative console looks:
Nagios Core - Mozilla Firefox_002Click on the “Hosts” section in the left pane of the console. You will see the no of hosts to be monitored by Nagios server. Initially, the nagios server (localhost) itself will only be monitored.
Nagios Core - Mozilla Firefox_003Click on the monitoring host to display more details:
Nagios Core - Mozilla Firefox_004

Add Monitoring targets to Nagios server
Now let us add some clients to monitor by Nagios server. To do that we have to install nrpeand nagios-plugins in our monitoring targets.
On CentOS/RHEL/Scientifc Linux clients:
Like i said before, you have to add EPEL repository in your CentOS/RHEL/Scientific Linux 6.x clients to install nrpe package.
Install “nrpe” and “nagios-plugins” packages in client systems to be monitored.
# yum install nrpe nagios-plugins-all openssl
On Debian/Ubuntu clients:
$ sudo apt-get install nagios-nrpe-server nagios-plugins
Configure Monitoring targets
Edit /etc/nagios/nrpe.cfg file,
# vi /etc/nagios/nrpe.cfg
Add your Nagios server ip address
[...]
## Line 81 - Add the Nagios server IP ##
allowed_hosts=127.0.0.1 192.168.1.101
[...]
Start nrpe service:
# service nrpe start
# chkconfig nrpe on
For Debian/Ubuntu Clients, start nrpe service as shown below.
$ sudo /etc/init.d/nagios-nrpe-server restart
Now go back to your Nagios server to add the clients to be monitored through nagios server. Edit “/etc/nagios/nagios.cfg” file,
# vi /etc/nagios/nagios.cfg
and uncomment the following lines.
## Line 52 - Uncomment ##
cfg_dir=/etc/nagios/servers
Create a directory called “servers” under “/etc/nagios/”.
# mkdir /etc/nagios/servers
Create config file to the client to be monitored:
# vi /etc/nagios/servers/clients.cfg
define host{
use                             linux-server
host_name                       client
alias                           client
address                         192.168.1.100
max_check_attempts              5
check_period                    24x7
notification_interval           30
notification_period             24x7
}
Finally restart nagios service.
# service nagios restart
Now open the nagios admin console in the browser and navigate to “Hosts” section in the left pane. You will see the newly added client will be visible there. Click on the host to see if there is anything wrong or alerts.
Nagios Core - Mozilla Firefox_005Click on the monitoring target, you’ll get the detailed output:
Nagios Core - Mozilla Firefox_006Like this way, you can define more clients by creating a separate config files“/etc/nagios/servers directory for each client.
Define services
We did define the monitoring host before. Now let us add some services of the monitoring host. For example to monitor the ssh service, add the following lines shown in red colour in the /etc/nagios/servers/clients.cfg file.
# vi /etc/nagios/servers/clients.cfg
define host{
use                             linux-server
host_name                       client
alias                           client
address                         192.168.1.100
max_check_attempts              5
check_period                    24x7
notification_interval           30
notification_period             24x7
}
define service {
        use                             generic-service
        host_name                       client
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
        }
Save and close the file. Restart Nagios.
# service nagios restart
Now log in to Nagios web console and check for the added services. Navigate to Services section, you’ll see the ssh service there.
Nagios Core - Mozilla Firefox_008To know more about object definitions such as Host definitions, service definitions, contact definitions and more please do visit here. This page will describe you the description and format of all object definitions.
That’s all about now. Good Luck! Stay healthy!
You might want to check Nagios 4 installation on CentOS 7.

Wednesday, March 2, 2016

What is a raw device?

What is a raw device?

Generally when you access(read or write) a device without going through the usual layers, it is considered a "raw" access. For a harddrive, the usual layer would be a filesystem.

When you click "save" to save a file, the writing is handled/organized by the filesystem.

If you do this (as root), 'less /dev/sda', then you will view the raw output of what your harddrive disk looks like.

Raw access to devices is a feature in Linux that can be very powerful, but must be used with care.


Raw by definition means you are not mounting it. It may or may not also mean that the kernel won't buffer/cache/etc data to and from the hardware.

If you mounted /dev/sda or /dev/hda or whatever, then you would see the filesystem on it, like '/' or '/home' or whatever.
If you don't mount it, then you (or a program) can see the bytes that make up the filesystem directly, like the previous poster said.

There is a further (stricter) meaning of 'raw device', too. When you access /dev/sda etc, you're bypassing the kernel's filesystem layers, but you're not bypassing its buffered I/O layers.

Some software (such as I believe Oracle, optionally) thinks it knows better than the kernel how to buffer/optimise disk I/O and lay out data, so it bypasses both layers, and uses other 'raw' devices. These 'raw' devices used to be called /dev/raw[1-8] (see man MAKEDEV), but they're obsolete in kernel 2.6.22.1 according to its kconfig help.

Tuesday, March 1, 2016

How to Resize Root LVM Logical Volume

How to Resize Root LVM Logical Volume

Boot with rescue CD. Skip mounting of the system partitions.

# lvm vgchange -a y
# e2fsck -f /dev/VolGroup00/LogVol00
# resize2fs -f /dev/VolGroup00/LogVol00 10G
# lvm lvreduce -L10G /dev/VolGroup00/LogVol00

Above maybe wrong !!!!!


Example: Removed one LV, and enlarged another LV

# umount /oracle_grid
# df -h
# lvremove /dev/mapper/vg_knaerp01n-lv_oracle_grid
# lvdisplay /dev/mapper/vg_knaerp01n-lv_fra
# man lvextend
# lvextend -L+20G /dev/vg_knaerp01n/lv_fra
# df -h
# umount /fra
# e2fsck -f /dev/vg_knaerp01n/lv_fra
# resize2fs /dev/vg_knaerp01n/lv_fra

# mount /dev/mapper/vg_knaerp01n-lv_fra /fra


Sunday, February 28, 2016

Convert a XenServer HVM domain to PV (paravirtual) and back again


Convert a XenServer HVM domain to PV (paravirtual) and back again


After wading through complicated and poorly organized how-to’s for converting a XenServer HVM domain to PV (paravirtual), I wrote a quick and dirty tool to make the conversion in both directions. I was able to get Debian Lenny 5.0.8 paravirtual domain running without any issues. All memory, CPU, disk, and network stats shows up perfectly in XenCenter, too!
Usage:
[root@vps1a ~]# ./vmtool.pl
Usage: vmtool.pl --cmd (hvmtopv|pvtohvm) ([--vm name-label] or [--uuid uuid]) [--root partition_num]
Here’s an example of it running:
[root@vps1a ~]# ./vmtool.pl --cmd=hvmtopv --vm=c1068vm1
uuid = 7cf68fa6-3d07-0869-fa2d-40c89a724042
cmd = hvmtopv
Changing HVM-boot-policy
Changing PV-args
Setting disk boot flag
***Please update /etc/fstab, /etc/inittab. then reboot VM
Done.
If your root partition is anywhere except the 1st partition on the virtual disk, specify the partition number with the –root argument.
To reverse the process, change the –cmd argument from ‘hvmtopv’ to ‘pvtohvm’.
PV domains can be made into templates within XenCenter, so you don’t have to run the script all the time.
Here are steps to take on your domain after changingtour HVM domain to PV. Make sure to complete these steps (except 4) in HVM mode before rebooting. After the reboot, you can install the Xen tools and reboot again.
1. Install a Xen-aware kernel and make it the default boot option in grub.conf or menu.lst.
2. Update /etc/fstab entries – Example: replace /dev/hda1 with /dev/xvda1, /dev/hdd with /dev/xvdd, ect.
3. Update /etc/inittab – Example: replace tty1 with hvc0 so that the Console works properly
4. Make sure the /boot or / partition (depending on your partition layout) has the boot flag set. THIS IS IMPORTANT!
5. Install the Xen tools from the xs-tools CD so that memory, disk, and network usage appears properly in XenCenter
Get the script here:
It’s a shame that XenServer still caters to the Windows crowd by making HVM domains the default, with no way to easily switch to PV. Hopefully this script makes life easier for someone.

Thursday, January 14, 2016

About Starting and Stopping Components with Oracle Restart

About Starting and Stopping Components with Oracle Restart

Oracle Restart automatically restarts various Oracle components when required, and automatically stops Oracle components in an orderly fashion when you manually shut down your system. There may be times, however, when you want to manually start or stop individual Oracle components. Oracle Restart includes the Server Control (SRVCTL) utility that you use to manually start and stop Oracle Restart–managed components. When Oracle Restart is in use, Oracle strongly recommends that you use SRVCTL to manually start and stop components.
Oracle utilities such as SQL*Plus, the Listener Control utility (LSNRCTL), and ASMCMD are integrated with Oracle Restart. If you shut down the database with SQL*Plus, Oracle Restart does not interpret this as a database failure and does not attempt to restart the database. Similarly, if you shut down the Oracle ASM instance with SQL*Plus or ASMCMD, Oracle Restart does not attempt to restart it.
An important difference between starting a component with SRVCTL and starting it with SQL*Plus (or another utility) is the following:
* When you start a component with SRVCTL, any components on which this component depends are automatically started first, and in the proper order.
* When you start a component with SQL*Plus (or another utility), other components in the dependency chain are not automatically started; you must ensure that any components on which this component depends are started.

About Starting and Stopping Oracle Restart

The CRSCTL utility starts and stops Oracle Restart. You can also use the CRSCTL utility to enable or disable Oracle high availability services. Oracle Restart uses Oracle high availability services to start and stop automatically the components managed by Oracle Restart. For example, Oracle high availability services daemons automatically start databases, listeners, and Oracle ASM instances. When Oracle high availability services are disabled, none of the components managed by Oracle Restart are started when a node is rebooted.
Typically, you use the CRSCTL utility when you must stop all of the running Oracle software in an Oracle installation. For example, you might need to stop Oracle Restart when you are installing a patch or performing operating system maintenance. When the maintenance is complete, you use the CRSCTL utility to start Oracle Restart.

Oracle Restart Configuration

Oracle Restart maintains a list of all the Oracle components that it manages, and maintains configuration information for each component. All of this information is collectively known as theOracle Restart configuration. When Oracle Restart starts a component, it starts the component according to the configuration information for that component. For example, the Oracle Restart configuration includes the location of the server parameter file (SPFILE) for databases, and the TCP port to listen on for listeners.
If you install Oracle Restart and then create your database with Database Configuration Assistant (DBCA), DBCA automatically adds the database to the Oracle Restart configuration. When DBCA then starts the database, the required dependencies between the database and other components (for example disk groups in which the database stores data) are established, and Oracle Restart begins to manage the database.
You can manually add and remove components from the Oracle Restart configuration with SRVCTL commands. For example, if you install Oracle Restart onto a host on which a database is already running, you can use SRVCTL to add that database to the Oracle Restart configuration. When you manually add a component to the Oracle Restart configuration and then start it with SRVCTL, Oracle Restart begins to manage the component, restarting it when required.

Thursday, December 31, 2015

HP-UX networking related tools and commands

HP-UX networking related tools and commands

As my journey continues to exploring HP-UX I found couple of nice utilities and tools to configure and administrate HP-UX networking subsystem.
FILES
  • /etc/hosts - Hosts configuration file (resolve hosts and IPs)
  • /etc/rc.config.d/netconf – IP address, routeing address and hostname stored in this file
SCRIPTS
  • /etc/init.d/net start – Use to start, stop network service
HPUX Commands
(a) Display lan interface info:
# lanscan
(b) All in one lan configuration utility (lan0 is first Ethernet interface) to configure and view the system IP address:
# ifconfig lan0 - Display IP info such as IP address netmask etc.
# ifconfig lan0 up - Up network interface (allow traffic)
# ifconfig lan0 down - Down network interactive (deny traffc)
# ifconfig lan0 192.168.1.1 netmask 255.255.255.0 up - Setup/change IP adddress
(c) Displaying host name
# hostname
(d) Arp administration (cache)
# arp -a
(e) Display routing table/info:
# netstat -nr
(f) Define new route:
# route add default 192.168.1.254 1
(g) HP's LAN diagnostic tool
# lanadmin
(h) Test a remote host connectivity
ping host.mycorp.com
(i) Setup various lan properties, dns client, NIS client configuration etc using GUI tool:
# sam
# set_parms
(j) Check dns connectivity:
$ nslookup www.google.co.uk

Monday, December 14, 2015

How to Shrink SQL Server 2012 Transaction log file

How to Shrink SQL Server 2012 Transaction log file


use eSPTest;
go
alter database eSPTest set recovery simple;
go
dbcc shrinkfile(eSPTest_log,200)
go
alter database eSPTest set recovery full;
go

  DAILY CHECKLIST Oracle Database instance is running or not select name,open_mode from V$database; Note: Check the Oracle databases are ru...