Linux Tips, Tricks and random useful information that I've come across. Can find me @ irc.freenode.net nick kylepike
1/17/11
8/25/10
Preformance data via submit check result NSCA
define command{
command_name submit_check_result
command_line /opt/nagios/plugins/eventhandlers/distributed-monitoring/submit_check_result_via_nsca $HOSTNAME$ '$SERVICEDESC$' $SERVICESTATE$ '$SERVICEOUTPUT$|$SERVICEPERFDATA$'
}
This is of course assuming you already have preformance data.
7/30/10
Enable Nagios Serivce Acknowledgement Comments in Emails
edit your notification command cfg file and find this line: notify-service-by-email
Right after $SERVICEOUTPUT$\n\n append
"Notes: $SERVICEACKCOMMENT$"
Thats it, reload nagios and your done.
http://nagios.sourceforge.net/docs/2_0/macros.html
11/23/09
Upgrading CentOS to 5.4 breaks vmware
5.4 upgrades glibc to 2.5-42.i686, this causes problems with vmware-hostd and it crashes shortly after being started (I can get it to crash just by logging in and clicking on a vm)
fix ...
Get a copy of 5.3 glibc, you can get it from a install dvd, google, another box. Just make sure if you have a 32bit machine you get the 32 bit, and 64 for 64bit.
mkdir /usr/lib/vmware/lib/libc.so.6
cp libc-2.5.so /usr/lib/vmware/lib/libc.so.6/
chown root:root /usr/lib/vmware/lib/libc.so.6/libc-2.5.so
mv /usr/lib/vmware/lib/libc.so.6/libc-2.5.so /usr/lib/vmware/lib/libc.so.6/libc.so.6
vi /usr/sbin/vmware-hostd
added an "export LD_LIBRARY_PATH=/usr/lib/vmware/lib/libc.so.6:$LD_LIBRARY_PATH" before the last line.
restart /etc/init.d/vmware
10/28/09
Forwarding Samba over SSH - Plus! an easy to use script
ssh -L 22330:SAMBA_SERVER:139 USER_NAME@SSH_SERVER
smbmount //SAMBA_SERVER/SHARE_NAME /PATH/TO/SHARE_MOUNT --verbose -o ip=127.0.0.1,port=22330,credentials=/PATH/TO/CREDS/FILE
Now my problem was I need to make an easy to use way for dev's to access samba without installing a VPN. They also needed to make two hops from an access server to another ssh server then finally the samba server.
Here is the two hop method on one line:
ssh -t -t -L 22330:localhost:22330 USER_NAME@SSH_SERVER "ssh -t -t -L 22330:SAMBA_SERVER:139 INTERNAL_SSH_SERVER_IP"
-t Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.
Now for the script, Its written in two parts, one script for creating the tunnel, the other for mounting the smb share.
createsshtunnel.sh
----------------------------------------------------------
#!/bin/bash
#This script will forward a randomly generated port for tunneling samba connections
username=user_name
PORT=$[ ( $RANDOM % ( $[ 22999 - 22000 ] + 1 ) ) + 22000 ]
echo " "
echo Port Number is: $PORT
echo " "
echo " "
echo "Creating Samba Tunnel"
ssh -t -t -L $PORT:localhost:$PORT $username@ssh_server "ssh -t -t -L $PORT:SAMBA_SERVER:139 INTERNAL_SSH_SERVER"
-------------------------------------------------------------------------
mountsamba.sh
------------------------------------------------------------------------
#!/bin/bash
#This will mount samba shares in combination with the sambassh.sh script
#Enter in the port number returned from sambassh.sh
#Location of a credentials file (chmod 600 file)
#Format:
#username=
#password=
credentials=/PATH/TO/creds
echo " "
echo "Enter Port Number:"
read portnumber
echo "$portnumber is "
echo "Which Share?"
read sharename
if [ -d "~/$sharename" ]
then
echo "Mount Point Exists, trying to unmount if its mounted"
sudo umount "~/$sharename"
echo " "
else
echo "Directory "~/$sharename" does not exist, creating for you."
echo " "
mkdir "~/$sharename"
fi
smbmount //SMB_SERVER/$sharename ~/$sharename --verbose -o ip=127.0.0.1,port=$portnumber,credentials=$credentials
----------------------------------------------------------------------
10/12/09
HOWTO Install LVS on Centos 5.3
#10/12/09
#Install Packages
sudo yum install -y Cluster_Administration-en-US.noarch piranha.i386 / piranha.x86_64
#Set to start on boot
sudo chkconfig pulse on
sudo chkconfig piranha-gui on (primary node only)
#Start Piranah WebUI and set passwd
sudo /usr/sbin/piranha-passwd
sudo /sbin/service piranha-gui start #(listens on port 3636)
#Set Access restrictions to web interface (localhost only)
sudo vi /etc/sysconfig/ha/web/secure/.htaccess
----
Order deny,allow
Deny from all
Allow from 127.0.0.1
----
#Turn on Packet Forwarding
sudo vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
/sbin/sysctl -w net.ipv4.ip_forward=1 #(manually set)
#Apply Firewall Changes
iptables -A RH-Firewall-1-INPUT -p udp -m udp --dport 539 -j ACCEPT #port for pulse
iptables -A RH-Firewall-1-INPUT -p tcp -m tcp --dport 3636 -j ACCEPT #port for piranah webUI
iptables -A RH-Firewall-1-INPUT -m pkttype --pkt-type multicast -j ACCEPT #allow multicast packets for arp failover
#Layout
#Interfaces
Master Backup
----------------------------------
Public: 172.16.1.133 Public: 172.16.1.134
Private: 10.0.1.2 Private: 10.0.1.3
Public floating VIP 172.16.1.136, 172.16.1.137, 172.16.1.138 etc...
Private VIP 10.0.1.254 (gateway for real servers)
#/etc/sysconfig/ha/lvs.cf
serial_no = 91
primary = 172.16.1.133
primary_private = 10.0.1.2
service = lvs
backup_active = 1
backup = 172.16.1.134
backup_private = 10.0.1.3
heartbeat = 1
heartbeat_port = 539
keepalive = 6
deadtime = 18
network = nat
nat_router = 10.0.1.254 eth1:1
nat_nmask = 255.255.255.255
debug_level = 1
monitor_links = 1
syncdaemon = 0
virtual webservers {
active = 1
address = 172.16.1.136 eth0:1
vip_nmask = 255.255.255.0
port = 80
send = "GET / HTTP/1.0\r\n\r\n"
expect = "HTTP"
use_regex = 0
load_monitor = none
scheduler = wlc
protocol = tcp
timeout = 6
reentry = 15
quiesce_server = 0
server A {
address = 10.0.1.5
active = 1
weight = 1
}
}
9/28/09
MySQL Master/Master Config
#Master 1/Slave 2 ip: 192.168.1.2 (ServerA)
#Master 2/Slave 1 ip : 192.168.1.3 (ServerB)
#Step 1
#On Master 1 (ServerA), make changes in my.cnf:
-----------------
[mysqld]
datadir=/d2/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
bind-address = 192.168.1.2 #enable tcp access
server-id=1 #server id
log-bin=/d2/mysql/db1-bin-log #Where to store the bin logs for replication TO ServerB
log-bin-index=/d2/mysql/db1-bin-log.index
binlog-do-db=redmine1 #DB to replicate
binlog-ignore-db=mysql #DB's not to replicate
binlog-ignore-db=test
master-host = 192.168.1.3 #Set Master info for ServerA
master-user = replication
master-password = *****************
master-port = 3306
relay-log=/d2/mysql/db1-relay-log #where to store the relay logs for replication FROM ServerB
relay-log-index=/d2/mysql/db1-relay-log.index
#[mysqld_safe]
#log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid
------------------
#Step 2 (granting access to replcation users on both boxes)
#On master 1 (ServerA), create a replication slave account on master1 for master2:
mysql -u root -p
mysql> grant replication slave on *.* to 'replication'@'192.168.1.3' identified by '**************';
#Create a replication slave account on master2(ServerB) for master1:
mysql -u root -p
mysql> grant replication slave on *.* to 'replication'@192.168.1.2 identified by '****************';
#Step 3
#Now edit my.cnf on Slave1 or Master2 (ServerB):
--------------------
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
bind-address = 192.168.1.3
server-id=2
log-bin=/var/lib/mysql/db2-bin-log
log-bin-index=/var/lib/mysql/db2-bin-log.index
binlog-do-db=redmine1
binlog-ignore-db=mysql
binlog-ignore-db=test
master-host = 192.168.1.2
master-user = replication
master-password = *****************
master-port = 3306
relay-log=/var/lib/mysql/db2-relay-log
relay-log-index=/var/lib/mysql/db2-relay-log.index
#[mysqld_safe]
#log-error=/var/log/mysqld.log
#pid-file=/var/run/mysqld/mysqld.pid
--------------------
#Step 4
#Restart mysqld on both servers.
sudo /etc/init.d/mysqld restart
#Step 5
#Start slave 1 and slave 2 (both servers)
mysql -u root -p
mysql> start slave;
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event #Make sure this isn't blank
Master_Host: 192.168.1.2
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: db1-bin-log.000014
Read_Master_Log_Pos: 404
Relay_Log_File: db2-relay-log.000029
Relay_Log_Pos: 543
Relay_Master_Log_File: db1-bin-log.000014
Slave_IO_Running: Yes #Make sure this is yes
Slave_SQL_Running: Yes #Make sure this is yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 404
Relay_Log_Space: 543
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
1 row in set (0.00 sec)
ERROR:
No query specified
#Step 6
#Check on master status (both boxes):
mysql> show master status;
+--------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+--------------------+----------+--------------+------------------+
| db2-bin-log.000001 | 1214 | redmine1 | mysql,test |
+--------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
9/26/09
Nagios administrator
Monitor Web/Mail/FTP/SSH/DNS/SMB Servers etc...
Monitor Devices (Printers, Switches/Routers, Firewalls)
SNMP
PNP integration for graphing performance data, be able to view uptime availability over time.
Phone/Pager/Email/Backberry alerts!
Different Time periods for alerts, work day, weekends, 24x7 etc.
Contact groups
Escalations
Interface with climate/motion/light sensors.
Windows Integration (NSClient++)
Security Considerations
Also ask me about using an Amazon EC2 instance for an affordable alternative to expensive external solutions. For as little as $100/year you could have an external monitoring solution on your own dedicated server, fully customizable and secure.
Please email with contact info and I'll give you a call, or send me an email and I can provide my contact information.
- Resume/References available upon request. Currently work as a full time administrator managing 100's of servers and several Nagios instances including fail-over redundant configurations.
9/11/09
Packages and Install for The "Perfect Webserver"
Apache
-------------
sudo yum install -y httpd.x86_64
sudo yum install -y mod_ssl.x86_64
MySQL
-------------
sudo yum install -y mysql-devel.x86_64 mysql.x86_64 mysql-server.x86_64
PHP
------------
sudo yum install -y php-mysql.x86_64
sudo yum install -y php.x86_64
Deps
----------
sudo yum install -y httpd-devel apr-devel
Ruby
------------
sudo yum install -y ruby
sudo yum install -y ruby-devel ruby-docs ruby-ri ruby-irb ruby-rdoc
Ruby Gems
-------------
wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz
tar xzvf rubygems-1.3.5.tgz
sudo ruby setup.rb
sudo gem update
sudo gem update --system
sudo gem install -v=2.1.2 rails
sudo gem list
Passenger
-------------
gem install passenger
add to httpd.conf:
LoadModule passenger_module /usr/lib64/ruby/gems/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib64/ruby/gems/1.8/gems/passenger-2.2.5
PassengerRuby /usr/bin/ruby
Include conf/sites-enabled/*.conf
Create: in sites-enabled/
ServerName www.yourhost.com
DocumentRoot /somewhere/public # <-- be sure to point to 'public'!
9/2/09
Getting bonded networking connections working in xen
------------------
#!/bin/sh
dir=$(dirname "$0")
"$dir/network-bridge" "$@" vifnum=0 netdev=bond0
"$dir/network-bridge" "$@" vifnum=1 netdev=bond1
-------------------
edit /etc/xen/xend-config.sxp
comment out:
#(network-script network-bridge)
and add:
(network-script mybond)
restart xen
8/3/09
Xen Centos Host Freebsd Guest
http://www.gitco.de/repo/
$ cd /etc/yum.repos.d
$ wget http://www.gitco.de/repo/CentOS5-GITCO_x86_64.repo
$ sudo yum groupremove Virtualization
$ sudo yum groupinstall Virtualization
$ sudo reboot
[root@xen1 xen]# cat freebsd.hvm
name = "FreeBSD7"
builder = "hvm"
memory = "1024"
disk = ['file:/d2/images/bsdsmtpgateway/disk1.img,hda,w','file:/d2/iso/7.2-RELEASE-i386-dvd1.iso,hdc:cdrom,r']
vif = [ "mac=00:16:3e:70:66:ee,bridge=xenbr0" ]
device_model = "/usr/lib64/xen/bin/qemu-dm"
kernel = "/usr/lib/xen/boot/hvmloader"
vnc=1
boot="d"
vcpus=1
acpi="0"
pae="0"
serial = "pty" # enable serial console
on_reboot = 'restart'
on_crash = 'restart'
$ xm create freebsd.hvm
$ sudo lsof -i -n -P | grep qemu #find out what port vnc is listening on.
qemu-dm 6045 root 14u IPv4 18110 TCP 127.0.0.1:5900 (LISTEN)
From remote box;
$ ssh -L 5900:localhost:5900 hostname
$ vncviewer localhost
7/13/09
Converting a Mantis database in mysql from latin1 to utf8, so it can be imported into postgres by redmine:migrate_from_mantis
---------------------------------
character-set-server=utf8
default-collation=utf8_unicode_ci
[client]
default-character-set=utf8
---------------------------------
sudo service mysqld restart
mysqldump -u root -p --opt --default-character-set=latin1 --skip-extended-insert > mantis-latin1.sql
iconv -t LATIN1 -f UTF8 -c mantis-latin1.sql > latest.mantis-utf8.sql
sed 's/DEFAULT CHARSET=latin1/DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci/g' latest.mantis-utf8.sql > latest.mantis-utf8.sql2
vi latest.mantis-utf8.sql2
:set encoding=utf-8
:set guifont=-misc-fixed-medium-r-normal--18-120-100-100-c-90-iso10646-1
save w!
mysql -u root -p utf8mantisdb --default-character-set=utf8 < latest.mantis-utf8.sql2
sudo rake redmine:migrate_from_mantis RAILS_ENV="production"
7/9/09
Using apache allow/deny with a load balancer forwarding the clients IP as X-Forwarded-For
It is fowarded by changing the log format to:
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
Where You substitute %{X-Forwarded-For}i for %U
In order for apache to use this value to allow/deny people you need to set it like the following:
SetEnvIfNoCase ^X-Forwarded-For ^1\.2\.3\.4 officeip
Order deny,allow
Deny from all
Allow from env=officeip
6/5/09
Nagios - Favorite Linux Monitoring Application! by linux journal.
Favorite Linux Monitoring Application
Nagios (51%)
Honorable Mention
Hyperic HQ (15%)
up.time (11%)
Nagios was not only recently dubbed one of the most important open-source apps of all time, but it also is the winner of the new Readers' Choice category, Favorite Linux Monitoring Application. A slim majority 51% of you use Nagios to keep close tabs on your networks of all shapes, sizes and levels of complexity. Most of you not using Nagios opt for the Honorable Mention candidates, Hyperic HQ (with 15%) and up.time (11%). Ganglia and GroundWork also garnered respectable votes in the single digits.
6/4/09
Easy remote syslog-ng setup
Force its install via:
sudo rpm --force -Uvh syslog-ng-1.6.12-1.el5.centos.i386.rpm
or remove the old syslog first via:
rpm -e --nodeps rsyslogstop syslog and start syslog-ng:
sudo /etc/init.d/syslog stop && sudo /etc/init.d/syslog-ng start
Test that its working via:
logger "test message" && sudo tail /var/log/messages
remove syslog from starting and setup syslog-ng to start up on boot:
sudo chkconfig syslog off && sudo chkconfig syslog-ng on && sudo chkconfig --list | grep syslog
Enable remote syslogging on the host syslog server
HOST:
sudo vi /etc/syslog-ng/syslog-ng.conf
add:
source s_network {
tcp(max-connections(5000));
udp();
};
destination d_network {
file ("/var/log/syslog-ng/$HOST/$FACILITY.log");
};
log { source(s_network);
destination(d_network);
};
Sending messages from your syslog-ng client
CLIENT:
sudo vi /etc/syslog-ng/syslog-ng.conf
destination loghost {
tcp("192.168.1.5");
};
log {
source(s_sys);
destination(loghost);
};
Add an iptables allow rule for port 514, and optionally add the -s and mention the host (much more secure)
sudo vi /etc/sysconfig/iptables
add:
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 514 -s 192.168.1.5 -j ACCEPT
restart iptables:
sudo /etc/init.d/iptables restart
Test that its working by running on the client:
logger "test to remote"
and running on the host:
tail -f /var/log/messages
If you see the msg its working .. if not, you fail... try again.
5/18/09
Amazon New features! Loan balancing and monitoring.... finally!
Dear AWS Community Member,
You signed up to be notified when we released monitoring, auto scaling and load balancing for Amazon EC2. We are excited to announce the public beta of these new features: Amazon CloudWatch, a web service for monitoring AWS cloud resources, Auto Scaling for automatically growing and shrinking Amazon EC2 capacity based on demand, and Elastic Load Balancing for distributing incoming traffic across Amazon EC2 compute instances. Together, these capabilities provide you with visibility into the health and usage of your AWS compute resources, enhance application performance, and lower costs.
Monitoring
Amazon CloudWatch is a web service that provides monitoring for AWS cloud resources, starting with Amazon EC2. It provides customers with visibility into resource utilization, operational performance, and overall demand patterns -- including metrics such as CPU utilization, disk reads and writes, and network traffic. To use Amazon CloudWatch, simply select the Amazon EC2 instances that you'd like to monitor; within minutes, Amazon CloudWatch will begin aggregating and storing monitoring data that can be accessed using web service APIs or Command Line Tools.
Auto Scaling
Auto Scaling allows you to automatically scale your Amazon EC2 capacity up or down according to conditions you define. With Auto Scaling, you can ensure that the number of Amazon EC2 instances you're using scales up seamlessly during demand spikes to maintain performance, and scales down automatically during demand lulls to minimize costs. Auto Scaling is particularly well suited for applications that experience hourly, daily, or weekly variability in usage. Auto Scaling is enabled by Amazon CloudWatch and available at no additional charge beyond Amazon CloudWatch fees.
Elastic Load Balancing
Elastic Load Balancing automatically distributes incoming application traffic across multiple Amazon EC2 instances. It enables you to achieve even greater fault tolerance in your applications, seamlessly providing the amount of load balancing capacity needed in response to incoming application traffic. Elastic Load Balancing detects unhealthy instances within a pool and automatically reroutes traffic to healthy instances until the unhealthy instances have been restored. Customers can enable Elastic Load Balancing within a single Availability Zone or across multiple zones for even more consistent application performance.
Like all Amazon Web Services and features, Amazon CloudWatch and Elastic Load Balancing are available on a pay-as-you-go basis with no up-front fee, minimum spend or long term commitment. Auto Scaling is free to Amazon CloudWatch customers. Each instance launched by Auto Scaling is automatically enabled for monitoring and the Amazon CloudWatch monitoring charge will be applied.
For more information on these new features and details on how to start using them, please see the resources listed below:
These have been among the most requested Amazon EC2 features by our customers. We hope they prove useful to you, and we look forward to your feedback.
Sincerely,
The Amazon Web Services Team
5/6/09
Amazon has a new feature, reserved instances.
You can have a small instance (Small Instance (Default) 1.7 GB of memory, 1 EC2 Compute Unit (1 virtual core with 1 EC2 Compute Unit), 160 GB of instance storage, 32-bit platform)
For around - 65$/month - 780$/year, you could have a dedicated server ... pretty sweet deal.
Now if you add in the reserved instance's feature...
A small instance will cost
$325(reserved instance fee) + $262/year = $587/year ... even better deal.
Sign up for 3 years, and you now are paying...
$587 1st year, and then $262 ... end of 3 years total = $1111 compared to $2340 for the regular price for 3 years.
4/9/09
Rebundeling a running ec2 instance....
-d, --destination PATH
-c, --cert PATH
-k, --privatekey PATH
--kernel ID Id of the default kernel to launch the AMI with.
-r, --arch ARCHITECTURE Specify target architecture. One of ["i386", "x86_64"]
-s, --size MB The size, in MB (1024 * 1024 bytes), of the image file to create. The maximum size is 10240 MB.
(change the kernel type and arch to suite your needs... might as well use the largest size 10240)
This will bundle your running instance, and place the files in /mnt/ami
ec2-upload-bundle -b bucketname -m /mnt/ami/what_you_named_it.manifest.xml --access-key XYZ --secret-key XYZ
This will upload your bundled image to your bucket.
ec2-register /bucket/what_you_named_it.manifest.xml
The last step is to register your image, you will get back the AMI ID, and can either start your instance on the cmd line, or simply login to the web console and start it.
Nagios - Instead of a ping check to see if a host is alive, use http instead
You can add this to commands.cfg and hosts.cfg for those hosts to check via http instead.
commands.cfg
define command {
command_name check-host-alive-by-http
command_line $USER1$/check_http -H $HOSTADDRESS
}
hosts.cfg
define host{
host_name hostname.com
address ip.address
alias hostnamealias
use networking_machines_template
check_command check-host-alive-by-http
}
4/8/09
Installing Nagios
---------------------
*need to have basic centos install, with apache installed.
Install rpmforge repo
wget http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
wget http://apt.sw.be/redhat/el5/en/x86_64/RPMS.dag/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
rpm -K rpmforge-release-0.3.6-1.el5.rf.*.rpm #verify package
rpm -i rpmforge-release-0.3.6-1.el5.rf.*.rpm #install package
Install yum-priorities #this is't required, but I like to limit the rpmforge repository from effecting any base packages
yum install yum-priorities
#Make sure that yum-priorities is enabled by editing the /etc/yum/pluginconf.d/priorities.conf
#Edit the .repo files in /etc/yum.repos.d/ and set up priorities by adding the line: (lower number = higher priority, 0 = disabled)
priority=N
Install nagios packages
sudo yum install nagios nagios-devel nagios-plugins nagios-plugins-setuid rrdtool
Configure Nagios
sudo htpasswd -c /etc/nagios/htpasswd.users kylec #Create htpasswd file for auth
sudo htpasswd /etc/nagios/htpasswd.users username #for adding users
sudo vi /etc/nagios/nagios.cfg
comment out...
#cfg_file=/etc/nagios/objects/templates.cfg
#cfg_file=/etc/nagios/objects/localhost.cfg
add...
cfg_file=/etc/nagios/objects/hosts.cfg
cfg_file=/etc/nagios/objects/hostgroups.cfg
cfg_file=/etc/nagios/objects/services.cfg
cfg_file=/etc/nagios/objects/contactgroups.cfg
set...
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
sudo vi /etc/nagios/cgi.cfg
set...
authorized_for_system_information=*
authorized_for_configuration_information=*
authorized_for_system_commands=*
authorized_for_all_services=*
authorized_for_all_hosts=*
authorized_for_all_service_commands=*
authorized_for_all_host_commands=*
----------------------------------------------------------------------------------------------
Installing Nagios pnp
wget http://switch.dl.sourceforge.net/sourceforge/pnp4nagios/pnp-0.4.13.tar.gz
./configure
make all
make fullinstall
edit hosts.cfg
add:
define host{
use generic-host,host-pnp #add host-pnp to networking_machines_template
define host {
name host-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$' onmouseover="get_g('$HOSTNAME$','_HOST_')" onmouseout="clear_g()"
}
edit services.cfg
Add to the main template... (in my case basic-service)
define service{
use generic-service,srv-pnp (srv-pnp is whats added)
name basic-service
.... truncated
define service {
name srv-pnp
register 0
action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$' onmouseover="get_g('$HOSTNAME$','$SERVICEDESC$')" onmouseout="clear_g()"
}
edit commands.cfg
add:
define command {
command_name process-service-perfdata
command_line /usr/bin/perl /usr/local/nagios/libexec/process_perfdata.pl
}
define command {
command_name process-host-perfdata
command_line /usr/bin/perl /usr/local/nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}
comment out the existing SAMPLE PERFORMANCE DATA COMMANDS
setup configs
cd /usr/local/nagios/etc/pnp/
sudo mv npcd.cfg-sample npcd.cfg
sudo mv process_perfdata.cfg-sample process_perfdata.cfg
sudo mv rra.cfg-sample rra.cfg
If you are seeing ... "File does not exist: /usr/share/nagios/pnp," in your httpd logs.
cp -R /usr/local/nagios/share/pnp/ /usr/share/nagios/pnp
edit as you would like them.
start npcd
/etc/init.d/npcd start
-------------------------------------------------------------------------------------------------------
EXAMPLE .cfgs #this is custom, these are just some examples to get you started.
contacts.cfg
define contact{
contact_name kyle
alias kyle
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email kyle@email.com
}
contactgroups.cfg
define contactgroup{
contactgroup_name admins
alias admins
members internal_infosec, kylepager
}
hosts.cfg
define host{
host_name website.com
address website.com
alias website.com
use networking_machines_template
}
hostgroups.cfg
define hostgroup{
hostgroup_name webservers
alias webservers
members server1, server2, server3, website.com
}
services.cfg
define service{
use basic-service
hostgroup_name webservers
service_description HTTP
check_command check_http!
contact_groups admins
}