Overview
If you're like me, you can't afford to
- – have downtime
- – risk hard drive failure because machines are not turned off properly during a power outage.
Enter UPS (Uninterruptable Power Supply) and NUT (Network UPS Tools). In a NUTshell (ha), NUT is the software which is run by your servers which allow them to monitor the state of the UPS. If power to the UPS is lost, the UPS will automagically switch to battery mode and alert the servers. From here there are 2 basic scenarios:
- Power is restored before battery is drained – this is the most common of the two cases. These typically happen during brown outs (temporary drop in voltage) and result in a 'no harm, no foul' outcome. By this I mean your servers will be aware that power was lost, but service will be uninterrupted.
- Power is restored after the battery is drained – this is your typical 15+ minute power outages. In this situation, the battery can no longer sustain running all equipment plugged into it. Thus, the NUT software will safely shutdown all servers which are aware of the UPS' status. Once power is returned, all servers will turn back on.
These are two of the most basic scenarios for use of a UPS and NUT. Obviously, NUT is significantly more powerful than this and I'll go into more detail later. Also, depending on what UPS you have purchased will also play a large role in how flexible of a configuration you can have. This how to will get you up and running with a Belkin UPS and http://www.networkupstools.org/ NUT
What You Need
In this how to you'll need the following:
| Qty | Description |
|---|---|
| 1 | Belkin UPS F6C900-UNV |
| NA | At least 2 computers with network capability. Both computers should be able to communicate with one another |
Choose Your Weapons
In this how to, I used a Belkin UPS 900VA. How'd I pick it? UPS's are commonly measured in VA (Volt-Amperes). Wikipedia provides a pretty decent explanation of what a volt amp is: "The VA rating is the apparent power that a UPS is capable of producing, while the Watt rating is the real power (or true power) it is capable of producing." Basically you want to pick a UPS which will be able to sustain all your equipment for some predetermined amount of time. How long you want run your equipment is purely your choice. For my use, I'd like to be able to run things for at least 5 minutes. Really I purchased a UPS just to help against brown outs (a temporary drop in voltage causing the flicker effect) but don't mind running for those rare 5+ second outages. I figure anything over 5 minutes is probably a more serious power outage and will most likely last a lot longer than 5.
On to the calculations. Here are a few rules of thumb:
| Equipment | VA |
|---|---|
| Generic Mid-Level PC | 200 |
| 5 Port Gigabit Switch | 55 |
| Generic Cable/DSL Modem | 60 |
| 15" Flat Panel LCD | 40 |
Check the box of the UPS – usually they'll tell you how long the batteries will last @ 50% and 100% load. Here's the equipment I have running off the UPS:
- (1) Desktop based PC (Router) – CF based, P4 1.8, 512 MB RAM
- (1) Mid Level Desktop Based PC (Backup, Nagios) – 1 IDE Drive, 2 SATA Drives, P4 2.4, 2GB RAM
- (1) High End Desktop Based PC (NOC) – 1 SATA WD Raptor, 4 Seagate SATAII, P4 3.4, 4GB RAM
- (2) 8 Port Netgear Gigabit Switch
- (1) Netgear B/G Wireless AP
- (1) Motorolla Cable Modem
- (1) 15" Flat Panel
On my 900VA UPS, I have a reported load of 61%... not bad for all that equipment. I'd recommend not going above the 75% mark – most factory default settings assume you will not put a load greater than 75% and will thus require you to tweak these values on the UPS so it will function the way you want.
Get NUT
NUT is a suite of tools and drivers which are used to monitor your UPS and send appropriate commands to other computers based off of the state of the UPS. There are some very basic How Tos out there on NUT – nothing has impressed me yet. I'll try to do a better job in this one...
Download & Install
This step is completely distro dependent so use whatever package manager (if any) to install it. I'm installing NUT on both a CentOS 4.4 and Gentoo 2.6.x box so I'll discuss those. NUT is in Gentoo's Portage – CentOS on the other hand is a little more of a hurdle.
Gentoo 2.6.x
# emerge -av sys-power/nut
Done.
CentOS 4.4
# yum -y install nut ... right? Not so fast. Unfortunately the NUT RPMS are not in the standard CentOS repositories so you'll need to install them by hand. Since CentOS 4.4 is Fedora Core's twin, it's (most of the time) safe to use Fedora's RPMS if there are none made for CentOS. You can start here and download the NUT RPM. Take a look at those requirements below and make sure you have all of them installed. Most likely you won't, so you'll have to get them separately. In my case, I needed to get 1 dependency RPM (nut-client) and create a soft link for libcrypto. Here's what I did:
- Download NUT Client and NUT
- Install the RPM:
# rpm -ivh nut-client-2.0.3-0.fc4.2.i386.rpm
- Create a soft link for libcryto.so.5 and install NUT without dependencies:
# ln -s /lib/libcrypto.so.0.9.7a /lib/libcryto.so.5 # rpm -ivh --nodeps nut-2.0.3-0.fc4.2.rpm
To see what was added by the RPMS, run:
# rpm -qs nut
Configure Your NUT
Configuring NUT can get a little tricky. Before I get into all the config files, let's take a look at the big picture. Here's what NUT can do for us:
- Monitor the UPS – Check to see if the UPS is online (AC power is on) or offline (power is on battery), battery charge, etc.
- Send Commands to the UPS – Run a self test, test front panel, define self test interval, etc.
- Send Commands to NUT Clients – Battery getting low? Turn off. Back online? Turn back on.
In my case, I have made the CentOS server the NUT Master and my Gentoo box is a NUT Client. Let's start with the NUT Master...
NUT Master
My NUT Master is responsible for a few things:
- Admin – sets and reads variable settings on the UPS
- Monitor Master – this will be the last machine to power off when the battery level is critical
Depending on what UPS you use, you may or may not have the option of connecting to the UPS via Serial or UPS. The most common way is through serial but I imagine USB will be the new standard a few years down the road.
| Tip This is NOT a standard RS232 cable! The pin outs are slightly different! |
Connect the NUT Master directly to the UPS via the serial (or USB) cable. For my setup I used the serial cable provided with my UPS. Now we edit our first config file.
Using your favorite editor, edit the file /etc/ups/ups.conf. This is the file used to list all the UPSes you will be monitoring. In this case we are only monitoring 1, so let's add our first entry:
[ups01]
driver = belkinunv
port = /dev/ttyS0
desc = "Belkin UPS 900VA"
[ups01] - The name of the UPS.
driver - Which driver to use. To figure out which driver (if any!) you may use, find your UPS in the NUT compatibility chart Each driver has a manual so run man <driver> for more details.
port - How is the UPS connected? /dev/ttyS0 is the first COM port.
| Tip If you are communicating over USB it's probably a good idea to set this to auto |
desc - Description of this UPS.
You can see an example config file here: ups.conf
Now onto the file /etc/ups/upsd.conf. The upsd (UPS daemon) uses this file to control access to the server and set some other miscellaneous configuration values. Basically this file defines what servers are allowed to communicate with it via the network so they can get state information about the UPS. The nice thing about NUT is it only requires (although you can have more if you want and it's supported) one physical connection to the UPS and then all other servers / workstations connected via Ethernet can get info through this one shared connection. Basically the NUT master relays the information to the boxes so everyone is up to date.
An example upsd.conf file is as follows:
ACL all 0.0.0.0/0 ACL localhost 127.0.0.1/32 ACL numark 10.5.5.1/32 ACL gw 10.5.5.9/32 ACCEPT localhost numark gw REJECT all
This file is pretty self explanitory. ACL or access control list defines a name and then it's network block. The section below defines whether or not the ACL aliases defined above should be accepted or rejected. In my case, I have the following configured:
- all, localhost, numark, and gw are all aliases of computers on my network I wish to be used for monitoring the UPS
- The first 4 ACLs define these aliases along with their IP address
- The last 2 lines are straight forward – accept from localhost, numark, and gw, then reject from all
You can see an example config file here: upsd.conf
Next we have the file /etc/ups/upsd.users. This file is responsible for usernames, passwords, and authorization. It is extremely important that the permissions on this file are set properly as it's a security risk otherwise. On my file, I had mode 640 and owned by root:nut. Here's my example config:
[admin] password = yourmom allowfrom = localhost actions = SET instcmds = ALL [monmaster] password = upsmasterpass allowfrom = localhost upsmon master [monuser] password = upsmonitorpass allowfrom = numark, gw upsmon slave
Finally we have /etc/ups/upsmon.conf. This file determines how and what actions will be taken when monitoring the ups.
MONITOR ups01@localhost 1 monmaster monmasterpass master
MINSUPPLIES 1
SHUTDOWNCMD "/sbin/shutdown -h +0"
NOTIFYCMD /usr/local/bin/ups_nsca_check
POLLFREQ 5
POLLFREQALERT 5
HOSTSYNC 15
DEADTIME 15
POWERDOWNFLAG /etc/killpower
NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC
NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 5
A few things to point out in this config:
- The first line uses the username / password from upsd.users
- NOTIFYCMD – This command is run once there is a change in UPS state (this is defined in the NOTIFYFLAG line)
- NOTIFYFLAG – When and where notifications should be sent to

Add Comment