Category Archives: Linux

The Linux Category actually encompasses *BSD, RH, Fedora, Ubuntu, and the like.

Install Nagios on Ubuntu 9.x, Client on Windows

This is how I got nagios to install on my Ubuntu 9.10 x86 server (LAMP):
***EDIT*** I’ve upgraded the 9.10 x86 server to 10.04LTS x86 and Nagios is still running like a champ. FYI.

This assumes you’ve already got LAMP up and running on the box and have at least a little common sense when it comes to linux commands. I still use putty to connect via SSH to my box. I also cheated and made it so I don’t do sudo (sudo passwd root, then su into root). If you don’t want to do that, just add ‘sudo’ in front of all the commands.

Update your box:
apt-get update
apt-get upgrade
apt-get dist-upgrade

Install the GCC compiler development libraries:
apt-get install build-essential

Install GD development libraries:
apt-get install libgd2-xpm-dev

Create a new user “nagios”:
useradd -m -s /bin/bash nagios

Make a password for the new user:
passwd nagios

Create a new group “nagcmd”
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www-data

Download the nagios files – I use /home/username as my download point:
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.0.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.14.tar.gz

Extract and compile the files:
tar xzf nagios-3.2.0.tar.gz
cd nagios-3.2.0
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

Create a nagiosadmin account for the web interface:
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Restart Apache
apache2ctl restart

That should be it for the installation phase of the main application. You can verify that everything works by viewing the site: http://localhost/nagios (or http://ipofserver/nagios) and logging in using nagiosadmin/thepasswordyoupicked. But now we should probably put the plugins in place before actually going through any other setup.

Unpack the plugins:
tar xzf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14

Configure and install the plugins:
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

Verify that the sample nagios configuration files are fine:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If there are no errors you can start nagios:
/etc/init.d/nagios start

http://localhost/nagios
Click on the Tactical Overview navbar link to see all that’s monitored right now. This may take a few moments to load as to not “kill” the machine with requests.

http://www.monitoringexchange.org/

INSTALL CLIENT ON WINDOWS MACHINE(S):
I’ve installed on WindowsXP 32, Windows Server 2003 32/64, and Windows 7 64bit without any issues.

Setting up for Windows Machine monitoring is a little more in depth:

Download the NSClient++:
http://nsclient.org/nscp/downloads
Extract to the C:\ directory
Open a CMD prompt and navigate to C:\NSClient++-0.3.7-Win32

Install the Service and System Tray:
The system tray gave me some issues on a Windows 7 x64 box. FYI.
nsclient++ /install
nsclient++ SysTray -install

Configure the NSClientpp Service:
Open up services (services.msc) and find NSCLientpp (Nagios)
Right-Click and select properties
Click on the Log On tab and make sure the Local System account can interact with the desktop

Edit the INI file:
Navigate to C:\NSClient++*\
Edit NSC.INI

Uncomment the following:

FileLogger.dll
CheckSystem.dll
CheckDisk.dll
NSClientListener.dll
NRPEListener.dll
SysTray.dll
CheckEventLog.dll
CheckHelpers.dll

Uncomment the hosts allowed file – either add the IP address of the Nagios server or just leave it blank and it will accept from all IPs.

Save the file, Start the service – I’ve had it work without interact with desktop, but it was recommended by Nagios to enable that feature.

Back on the Nagios server, edit the /usr/local/nagios/etc/objects/windows.cfg file to the liking of your windows machine.
You may have to add the host name/ip to your /etc/hosts file to rid yourself of errors

Verify your setup can run:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Then restart nagios:
/etc/init.d/nagios restart

Now you should be done. Login to your http://serverip/nagios site with your nagiosadmin/passwordyouchoseearlier account information.

As a side note, I also edited /usr/local/nagios/etc/nagios.cfg for the admin_email= to send email to my account. I already have postfix installed from another project, so it *should* send me alert emails. AND I found that you have to edit /usr/local/nagios/etc/objects/contacts.cfg as well. After editing make sure you restart the nagios service.

***EDIT***

I was receiving the emails just fine, but they were coming from the “wrong domain”. Ubuntu/debian puts the domain name by default in the /etc/mailname file. Edit that file and then reload postfix.
nano /etc/mailname
postfix reload

If the file does not exist (you’re creating a new file with nano), type in your domain name (ie thelibrarie.com), and then save the file. Then edit the postfix configuration and uncomment myorgin.
nano /etc/mailname
nano /etc/postfix/main.c

myorigin = /etc/mailname

And then try it again. You can test it out by sending yourself some mail:
mail -s test username@domain.tld
body
Control + D
Control + D

I also realized that I put how to install the client on Windows machines, so I should probably mention that in the subject, eh?

***EDIT***
OK, I had to add another user to be able to view the status of the systems.
Add the User:
SSH to your nagios system
htpasswd /usr/local/nagios/etc/htpasswd.users USERNAMEHERE
apache2ctl restart

Add the permissions:
nano /usr/local/nagios/etc/cgi.cfg
Search under GLOBAL HOST/SERVICE VIEW ACCESS
Change:
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
to:
authorized_for_all_services=*
authorized_for_all_hosts=*

Or you can comma-delimit the users. Either way, I win.

Restart nagios.
/etc/init.d/nagios restart

***EDIT 2***
Need more plugins? http://nagios.manubulon.com/

***EDIT 3***
There will be a new post regarding editing Nagios to add images to the map/new users/parents of configurations etc.

PHPSysInfo and LM-Sensors

I wanted to get phpsysinfo working with the hardware sensors suite known as lm-sensors, but I really didn’t feel like working through all the problems myself. But, despite my attempts to be lazy, I actually had to work a little bit at this.

First of all, this is running on an Ubuntu Server 9.10 x86 – 2.6.31-14-generic-pae to be exact – using an old Dell Precision 360 box to be even more exact. I installed phpsysinfo version 2.5.4 and edited the config.php file to enable lm-sensors hardware monitoring.

Unfortunately I get this error when I navigate to http://myserverip/phpsysinfo:

No sensors found!
Make sure you loaded all the kernel drivers you need.
Try sensors-detect to find out which these are.
Return value: 0

Wonderful. So I have to install lm-sensors. Now another site told me to do the following:
sudo apt-get install lm-sensors i2c-tools read-edid sensord hddtemp sensors-applet
After the lengthy download (153MB I believe), hddtemp needed some input. The defaults are fine – I selected to start the hddtemp service every reboot and run it on the default port 7634 as this is an internal only server. If it’s an externally facing server you may want to exercise some caution when opening ports.

You can verify that this is working by navigating to http://yourserverip:7634
In my case I see:

|/dev/sg0|ST380011A|38|C||/dev/sda|ST380011A|38|C|

Which I can see the Seagate HD that’s 80GB IDE with two mount points running at 38C (100.4F).

Now to setup for other sensors. Go back to your terminal session and type:
sudo sensors-detect
Hit YES for everything. When the script finishes you should probably reboot:
reboot

Reload your http://yourserverip/phpsysinfo page – you should now see a bunch of other stuff added at the bottom:
lm-sensors

What Version Of Linux Am I Running?

I wanted to upgrade my Ubuntu installation to the latest version, but wanted to make sure that it wasn’t already updated (shared servers are fun).

uname -a shows a decent amount of information, but I wanted to know what version of ubuntu I was currently on. With Ubuntu 9.10 released today, I ran some quick updates:
apt-get update
apt-get upgrade
apt-get dist-upgrade

uname -a
Showed this:

Linux ubuntuserver 2.6.28-16-server #55-Ubuntu SMP Tue Oct 20 20:50:00 UTC 2009 i686 GNU/Linux

lsb_release -a
Showed this:

Distributor ID: Ubuntu
Description: Ubuntu 9.04
Release: 9.04
Codename: jaunty

So I’m still on 9.04.

Then I realized I have to update some more…

apt-get install update-manager-core
do-release-upgrade
I then got this error:

This session appears to be running under ssh. It is not recommended
to perform a upgrade over ssh currently because in case of failure it
is harder to recover.

So I decided to run it local. At a whopping 50KB/sec this will take a while:

11 packages are going to be removed. 110 new packages are going to be installed. 444 packages are going to be upgraded.

You have to download a total of 332M. This download will take about 1 hour 10 minutes with your connection.

Fetching and installing the upgrade can take several hours. Once the download has finished, the process cannot be cancelled.

I think I’ll eat lunch while it’s doing its thing.

Setting Up Virtual Hosts In Apache

Setting Up Virtual Hosts In Apache, and also Editing The Host File On Windows.

For this test, I have an Ubuntu 9.04 Server (LAMP) running Apache2. I also have the testing machine of a Windows 7 Enterprise workstation using Firefox browser, notepad/notepad2 for editing, and putty for ssh connections.

Setting up a virtual host in Apache used to be a long and arduous task – now they’ve made it almost foolproof. Before I start on the how-to, let’s look into why-we-should:
There are a limited number of IPv4 IP addresses
Websites generally do not use up all of the resources of a high-powered server
It costs quite a bit more money to run a single website on a single server (if you’re hosting yourself there’s the power, internet, maintenance, and other problems to add up)

Obviously there is more than one way to go about this, but this is how I did it on my setup:

Log into your Linux server using putty or another SSH application
1_login
I’m using the root user – if you log as another user you may have to run “sudo command_here” commands. So if one of your commands does not work, try with the prefix sudo.
cd /etc/apache2/sites-available
nano default
2_apache_sites_avail

Page down to the end of this file. Everything that is in there should have been installed by default – and we only want to add to the sites and not edit.
Add the following:

NameVirtualHost name_of_your_host

<VirtualHost IP_of_your_webserver>
    DocumentRoot /path/to/your/files
    ServerName domain.tld
    ServerAlias *.domain.tld
</VirtualHost>

3_apache_sa_edited

Control X and select save your file. After you save, you’ll have to reset/reload apache so it can re-read the configuration files:
apache2ctl restart

Now to test on your Windows machine we need to edit your hosts file and add the hostname and IP address of your test server.

Start > run (or Windows Key + R)
c:\windows\system32\drivers\etc
4_host_file_location
Edit the hosts file using your favorite text editor (notepad or notepad2 for me)
At the bottom of the file you will need to make the changes:
IP_address DNS_Name

Notice that you can have as many DNS names for each IP address as you want.
5_host_file_edited

Now, open up your favorite browser (chrome or firefox) and navigate to the name you setup. In my case, I go to http://test.com. Since it loaded my test site which was different from my generic http://10.4.0.68 site, I know it’s working.

Desktop Background

I had just finished installing Windows 7 Enterprise 64bit and Ubuntu Desktop 9.04 64bit on my laptop as a dual boot setup.

I am not really going to write about setting it up to dual boot, as it was entirely too easy. I installed Windows 7 first, but I partitioned the 320GB drive into a 40GB empty and a 280GB empty partitioning scheme. Installed 7 on the 280GB spot and then booted off the Ubuntu CD. Installed that on the 40GB. Grub was already setup for me.

But I had the issue of not being able to find a good high-quality desktop background image for my Ubuntu side of things. I didn’t really want to use one of the generic “Linux is life” ones. So I searched for a few minutes and ended up finding a neat site:

http://interfacelift.com/wallpaper_beta/. Hopefully their site stays up for quite some time. Otherwise I may have to take one of mine and create a “wallpaper.thelibrarie.com” or something.

htaccess deny range of IPs

I was recently fired from my old job. It wasn’t a good firing – no reason behind it, and they’re being jackasses to me afterwards. So, 4 weeks later I notice that someone is still accessing my site, my personal help site, from one of their IP addresses. That can’t be. I can’t allow a company to fire me without a reason and then just let them use all of my work. Screw that.

So I did what anyone would do to prohibit these cretins from stealing my work:
edit the htaccess file to disallow their entire subnet.

SSH into your site
nano .htaccess – this will create the file if you don’t already have it
add the following:

order allow,deny
deny from 69.213.173.0/24
#deny from 69.213.173.144
allow from all
ErrorDocument 403 http://it.thelibrarie.com/errors/forbid.html

69.213.173.144 is their gateway (I should know, I only put in 4 years there). Last I checked it was a Sonicwall 4100 Pro, but they were trying to switch it out with a pair of Cisco ASA 5510’s. On a final note: Fuckers.

VMWare Server High Processor Usage

We have VMWare server 2.0 installed on a few servers for testing purposes. In fact, our entire development infrastructure is on 3 different VMWare server 2 servers.

One of the guest OSes was running Windows 2003 Enterprise R2 SP2 with a SQL server (2005 of Microsoft) and a web server (IIS6). The system process ended up using anywhere from 20 to 75% of the CPU usage. So what was causing this?

I started with the usual suspects – services that shouldn’t have been running. Nothing helped on that end.

Then I grabbed a copy of Sysinternals’ ProcessExplorer. It showed that I had anywhere from 20 to 75% use from Interrupts/Hardware Interrupts. What exactly is a hardware interrupt? It is when a piece of hardware needs to wait for the CPU in order to finish it’s task. If you’re using a CD-ROM drive in PIO mode instead of DMA you will see quite a few more hardware interrupts. But I wasn’t using a CD-ROM. It was just an idle server.

Quick search around the block and I removed the USB controller on the VMWare config side. That lowered the interrupts by about 8%. Not a heck of a lot, but it was something.

Then I took the advice of another technician – change out the generic AMD flavor of network card for the more robust Intel driver.

Download the intel driver (http://support.intel.com/support/network/sb/cs-006120.htm)
Shutdown your VMWare guest OS
Edit the .vmx file
Add Ethernet0.virtualDev = “e1000” somewhere in the ethernet ‘section’
Turn your machine back on
Your machine will now find new hardware. If it doesn’t auto install that’s no big deal since you downloaded the drivers already and you can then install them.

Now my interrupts are below 30 with an average around 12. That’s quite a bit more usable.