Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Tuesday, September 3, 2013

ls - no colors on Ubuntu

I have some older Ubuntu servers that don't display colors when executing the ls command over Putty. So I took a .bashrc file from a different Ubuntu server and copied over the relevant section that contains the ls --color command. After that I applied the ~/.bashrc file so I don't have to restart the session. This will set the foloring for grep and vi as well.


~$ vim ~/.bashrc

if [ "$TERM" != "dumb" ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
    alias vi='vim'

else
    alias ls="ls -F"
    alias ll='ls -alF'
    alias la='ls -A'
    alias l='ls -CF'
fi


~$ source ~/.bashrc

References


Monday, August 19, 2013

MySQL Backup Script in Bash / Cron Job

The following is a handy cron job that backs up a MySQL database, compress it with gzip and will delete the ones older than 30 days. Make sure the user running the job has write permissions (in my case the user levente@testsrv) on the backup output directory. The mysql backup job will be executed daily at 2:15am and the cleanup job at 2:20am.


levente@testsrv:~$ crontab -e


# ....
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command

 15 2 * * * mysqldump -u mysqluser -pmysqlpassword db_name | gzip > /var/backups/mysql/db_name_`date '+\%Y\%m\%d-\%H\%M\%S'`.sql.gz
 20 2 * * * find /var/backups/mysql/db_name* -mtime +30 -exec rm {} \;


If you want to run the MySQL backup script directly at the shell, you have to remove the backslash characters before the % because these are escaped in cron.


levente@testsrv:~$ mysqldump -u mysqluser -pmysqlpassword db_name | gzip > /var/backups/mysql/db_name_`date '+%Y%m%d-%H%M%S'`.sql.gz

Friday, August 9, 2013

Installing/Enabling RPMForge on CentOS 6.5 (latest binaries)

The steps needed to install RPMForge on CentOS are already described on this excellent page, I'll just update the script to use the latest binaries.

rnd=$RANDOM
wget -O /tmp/rpmforge-`echo $rnd`.rpm http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt
rpm -i /tmp/rpmforge-`echo $rnd`.rpm
rm -f /tmp/rpmforge-`echo $rnd`.rpm
#


To test you can try installing something from the RPMForge repositories, like htop:
yum install htop

Configuring Web Proxy on CentOS

If your internet connection is behind a web proxy, you need to configure the following on your CentOS server:

System-wide proxy settings - add the following lines to your /etc/environment file:
# vi /etc/environment

http_proxy="http://proxysrv:8080/"
https_proxy="https://proxysrv:8080/"
ftp_proxy="ftp://proxysrv:8080/"
no_proxy=".mylan.local,.domain1.com,host1,host2"

To apply these settings without restarting the machine run the following commands on the bash shell:
export http_proxy="http://proxysrv:8080/"
export https_proxy="https://proxysrv:8080/"
export ftp_proxy="ftp://proxysrv:8080/"
export no_proxy=".mylan.local,.domain1.com,host1,host2"

You also need to configure yum:
# vi /etc/yum.conf

proxy=http://proxysrv:8080/

CentOS 6.4 on HyperV - No Neworking on eth0

Just installed CentOS 6.4 from the CentOS-6.4-x86_64-bin-DVD1.iso image as a HyperV virtual machine.

After installation I observed that the eth0 adapter is not configured.
This blog post helped me to start networking, thanks Rutger Thomschutz!

Based on the blog post mentioned I did the following:

vi /etc/sysconfig/network-scripts/ifcfg-eth0

# changed ONBOOT to Yes
ONBOOT = yes

Created the hard links, brang up the adapter and rebooted the server:
# edit 9/10/2013 - in most cases you don't have to create the links below. 
# ln /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/networking/devices/ifcfg-eth0
# ln /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/networking/profiles/default/ifcfg-eth0
ifconfig eth0 up
reboot now
#

Saturday, February 16, 2013

Configuring SELinux for Centeron 2.4 on CentOS 6.3

  • CentOS 6.3 x64
  • Centreon 2.4

Problem


During Centreon installation when the tool starts up, the website is blank and nothing's happening.



I can observe the following error in /var/log/httpd/error_log:
[Sat Feb 16 18:07:58 2013] [error] [client 192.168.189.63] PHP Fatal error:  Smarty error: unable to write to $compile_dir '/usr/local/centreon/GPL_LIB/SmartyCache/compile'. Be sure $compile_dir is writable by the web server user. in /usr/local/centreon/GPL_LIB/Smarty/libs/Smarty.class.php on line 1095, referer: http://192.168.189.36/centreon/install/setup.php

Other errors can also be seen in the log but those are irrelevant:
[Sat Feb 16 18:29:29 2013] [error] [client 192.168.189.63] PHP Fatal error:  require_once(): Failed opening required 'www/class/centreonXMLBGRequest.class.php' (include_path='.:/usr/share/pear:/usr/share/php') in /usr/local/centreon/www/include/monitoring/status/TopCounter/xml/ndo/statusCounter.php on line 43, referer: http://192.168.189.36/centreon/main.php?p=61701&num=1&limit=30&poller=&template=&search=&type=&o=&search_type_service=1&search_type_host=1&search_service=
[Sat Feb 16 18:29:31 2013] [error] [client 192.168.189.63] PHP Warning:  include_once(/etc/centreon/centreon.conf.php): failed to open stream: No such file or directory in /usr/local/centreon/www/include/monitoring/status/TopCounter/xml/ndo/statusCounter.php on line 41, referer: http://192.168.189.36/centreon/main.php?p=604
[Sat Feb 16 18:29:31 2013] [error] [client 192.168.189.63] PHP Warning:  include_once(): Failed opening '/etc/centreon/centreon.conf.php' for inclusion (include_path='.:/usr/share/pear:/usr/share/php') in /usr/local/centreon/www/include/monitoring/status/TopCounter/xml/ndo/statusCounter.php on line 41, referer: http://192.168.189.36/centreon/main.php?p=604
[Sat Feb 16 18:29:31 2013] [error] [client 192.168.189.63] PHP Notice:  Undefined variable: centreon_path in /usr/local/centreon/www/include/monitoring/status/TopCounter/xml/ndo/statusCounter.php on line 43, referer: http://192.168.189.36/centreon/main.php?p=604
[Sat Feb 16 18:29:31 2013] [error] [client 192.168.189.63] PHP Warning:  require_once(www/class/centreonXMLBGRequest.class.php): failed to open stream: No such file or directory in /usr/local/centreon/www/include/monitoring/status/TopCounter/xml/ndo/statusCounter.php on line 43, referer: http://192.168.189.36/centreon/main.php?p=604
[Sat Feb 16 18:29:31 2013] [error] [client 192.168.189.63] PHP Fatal error:  require_once(): Failed opening required 'www/class/centreonXMLBGRequest.class.php' (include_path='.:/usr/share/pear:/usr/share/php') in /usr/local/centreon/www/include/monitoring/status/TopCounter/xml/ndo/statusCounter.php on line 43, referer: http://192.168.189.36/centreon/main.php?p=604
[Sat Feb 16 18:33:46 2013] [error] [client 192.168.189.63] PHP Fatal error:  require_once(): Failed opening required 'www/class/centreonXMLBGRequest.class.php' (include_path='.:/usr/share/pear:/usr/share/php') in /usr/local/centreon/www/include/monitoring/status/TopCounter/xml/ndo/statusCounter.php on line 43, referer: http://192.168.189.36/centreon/main.php?p=604

Solution


SELinux blocks httpd to write in any folder other than /var/www/ and some exceptions have to be made.

Configuring SELinux for Centeron 2.4 on CentOS 6.3

yum -y install policycoreutils-python
semanage fcontext -a -t httpd_sys_rw_content_t "/usr/local/centreon(/.*)?"
restorecon -R /usr/local/centreon/
semanage fcontext -a -t httpd_sys_rw_content_t "/etc/centreon(/.*)?"
restorecon -R /etc/centreon
semanage fcontext -a -t httpd_sys_rw_content_t "/usr/local/nagios/var/spool(/.*)?"
semanage fcontext -a -t httpd_sys_content_t "/usr/local/nagios/share(/.*)?"
restorecon -R /usr/local/nagios
semanage fcontext -a -t httpd_sys_content_t "/usr/share/php(/.*)?"
restorecon -R /usr/share/php
semanage fcontext -a -t httpd_sys_content_t "/usr/share/pear(/.*)?"
restorecon -R /usr/share/pear
#

You may want to check out my blog post on Installing Centreon 2.4 on CentOS 6.3 x64.

Installing Centreon 2.4 on CentOS 6.3 x64 - Step by Step - Part 2

This is the continuation of Installing Centreon 2.4 on CentOS 6.3 x64 - Step by Step

Preparing MySQL

## Add innodb_file_per_table=1 under the [mysqld] section in my.cnf
vim /etc/my.cnf

## then
service mysqld start
chkconfig mysqld on
# 

Installing Centreon

#
service httpd start
groupadd centreon
useradd -g centreon centreon
cd /usr/local/src/
wget http://download.centreon.com/index.php?id=4264

tar -zxf centreon-2.4.0.tar.gz
cd centreon-2.4.0
export PATH="$PATH:/usr/local/nagios/bin/"

# create an answer file with the following contents:
vim ./answer
#
And create the answer file with the following content:
## CentWeb: Web front Centreon for Nagios
PROCESS_CENTREON_WWW=1
## CentStorage: Log and charts archiving.
PROCESS_CENTSTORAGE=1
## CentCore: Distributed Monitoring engine.
PROCESS_CENTCORE=1
## CentPlugins: Centreon Plugins for nagios
PROCESS_CENTREON_PLUGINS=1
## CentTraps: Centreon Snmp traps process for nagios
PROCESS_CENTREON_SNMP_TRAPS=1

#####################################################################
## Begin: Default variables
#####################################################################
## Your default variables
## $BASE_DIR is the centreon source directory
LOG_DIR="$BASE_DIR/log"
LOG_FILE="$LOG_DIR/install_centreon.log"

## Don't change values above unless you perfectly understand
## what you are doing.
## Centreon temporary directory to work
TMP_DIR="/tmp/centreon-setup"
## default snmp config directory
SNMP_ETC="/etc/snmp/"
## a list of pear modules require by Centreon
PEAR_MODULES_LIST="pear.lst"
#####################################################################
## End: Default variables
##################################################################


#####################################################################
## Begin: Centreon preferences
#####################################################################
## Above variables are necessary to run a silent install
## Where you want to install Centreon (Centreon root directory)
INSTALL_DIR_CENTREON="/usr/local/centreon"
## Centreon log files directory
CENTREON_LOG="/usr/local/centreon/log"
## Centreon config files
CENTREON_ETC="/etc/centreon"
## Where is your Centreon binaries directory ?
CENTREON_BINDIR="/usr/local/centreon/bin"
## Where is your Centreon data informations directory ?
CENTREON_DATADIR="/usr/local/centreon/data"
## Centreon generation config directory
##  filesGeneration and filesUpload
## Where is your Centreon generation_files directory ?
CENTREON_GENDIR="/usr/local/centreon"
## libraries temporary files directory
## Where is your Centreon variable library directory ?
CENTREON_VARLIB="/var/lib/centreon"
## Where is your CentPlugins Traps binary?
CENTPLUGINSTRAPS_BINDIR="/usr/local/centreon/bin"
## Where is the RRD perl module installed [RRDs.pm]
## ATTENTION: ON x64 SYSTEMS THE PATH IS LIB64 INSTEAD OF LIB
##               vv
RRD_PERL="/usr/lib64/perl5"
## What is the Centreon group ?
CENTREON_GROUP="centreon"
## What is the Centreon user ?
CENTREON_USER="centreon"
## What is the Monitoring engine user ?
MONITORINGENGINE_USER="nagios"
## What is the Monitoring engine group ?
MONITORINGENGINE_GROUP="nagios"
## What is the Monitoring engine log directory ?
MONITORINGENGINE_LOG="/usr/local/nagios/var"
## Where is your monitoring plugins (libexec) directory ?
PLUGIN_DIR="/usr/local/nagios/libexec"
## Path to sudoers file (optional)
## Where is sudo configuration file
SUDO_FILE="/etc/sudoers"
## What is the Monitoring engine init.d script ?
MONITORINGENGINE_INIT_SCRIPT="/etc/init.d/nagios"
## What is the Monitoring engine binary ?
MONITORINGENGINE_BINARY="/usr/local/nagios/bin/nagios"
## What is the Monitoring engine configuration directory ?
MONITORINGENGINE_ETC="/usr/local/nagios/etc"
## Where is the configuration directory for broker module ?
BROKER_ETC="/usr/local/nagios/etc"
## Where is the init script for broker module daemon ?
BROKER_INIT_SCRIPT="/etc/init.d/ndo2db"
## Do you want me to configure your sudo ? (WARNING)
FORCE_SUDO_CONF=1

#####################################################################
## Begin: Apache preferences
#####################################################################
## Apache configuration directory (optional)
#DIR_APACHE="/etc/apache"
## Apache local specific configuration directory (optional)
## Do you want to update Centreon Apache sub configuration file ?
# DIR_APACHE_CONF="/etc/apache/conf.d"
## Apache configuration file. Only file name. (optional)
#APACHE_CONF="apache.conf"
## Apache user (optional)
WEB_USER="apache"
## Apache group (optional)
WEB_GROUP="apache"
## Force apache reload (optional): set APACHE_RELOAD to 1
## Do you want to reload your Apache ?
APACHE_RELOAD=1
#####################################################################
## End: Apache preferences
#####################################################################


## Do you want me to install/upgrade your PEAR modules
PEAR_AUTOINST=1
## Centreon run dir (all .pid, .run, .lock)
## Where is your Centreon Run Dir directory?
CENTREON_RUNDIR="/var/run/centreon"

## path to centstorage binary
## Where is your CentStorage binary directory
CENTSTORAGE_BINDIR="/usr/local/centreon/bin"
## CentStorage RRDs directory (where .rrd files go)
## Where is your CentStorage RRD directory
CENTSTORAGE_RRD="/var/lib/centreon"
## Do you want me to install CentStorage init script ?
CENTSTORAGE_INSTALL_INIT=1
## Do you want me to install CentStorage run level ?
CENTSTORAGE_INSTALL_RUNLVL=1


## path to centcore binary
CENTCORE_BINDIR="usr/local/centreon/bin"
## force install init script (install in init.d)
## Set to "1" to enable
## Do you want me to install CentCore init script ?
CENTCORE_INSTALL_INIT=1
## force install run level for init script (add all link on rcX.d)
## Set to "1" to enable
## Do you want me to install CentCore run level
CENTCORE_INSTALL_RUNLVL=1

## Some plugins require temporary datas to process output.
## These temp datas are store in the CENTPLUGINS_TMP path.
## Where is your CentPlugins lib directory
CENTPLUGINS_TMP="/var/lib/centreon/centplugins"

## path for snmptt installation
SNMPTT_BINDIR="/usr/local/centreon/bin/"
## What is the Broker user ? (optional)
BROKER_USER=$MONITORINGENGINE_USER

## Nagios user (optional)
NAGIOS_USER="nagios"
## Nagios group (optional)
NAGIOS_GROUP="nagios"
## Centreon Connector PATH
## Mail (optional)
BIN_MAIL="/bin/mail"
## 
Save the file and you're ready to install.
# install using the answer file
./install.sh -f ./answer

# After installation configure SELinux
yum -y install policycoreutils-python
semanage fcontext -a -t httpd_sys_rw_content_t "/usr/local/centreon(/.*)?"
restorecon -R /usr/local/centreon/
semanage fcontext -a -t httpd_sys_rw_content_t "/etc/centreon(/.*)?"
restorecon -R /etc/centreon
semanage fcontext -a -t httpd_sys_rw_content_t "/usr/local/nagios/var/spool(/.*)?"
semanage fcontext -a -t httpd_sys_content_t "/usr/local/nagios/share(/.*)?"
restorecon -R /usr/local/nagios/
semanage fcontext -a -t httpd_sys_content_t "/usr/share/php(/.*)?"
restorecon -R /usr/share/php
semanage fcontext -a -t httpd_sys_content_t "/usr/share/pear(/.*)?"
restorecon -R /usr/share/pear

# Restart some services
service httpd restart
service ndo2db restart
service nagios restart
#

When the installation is finished, open http://server/centreon/ in the browser.

Next, Next




At the third page:

  • Nagios directory: /usr/local/nagios/
  • Nagiostats binary: /usr/local/nagios/bin/nagiostats
  • Nagios image directory: /usr/local/nagios/share/images

At the forth page:
  • Broker Module: ndoutils
  • Ndomod binary (ndomod.o): /usr/local/nagios/bin/ndomod.o

At the fifth page enter the details of the admin user.


At the 6th page you have to specify the db details. By default the mysql root password is blank.


After finishing the setup there'll be something wrong with the db so you'll have to go back to the shell to grant permissions for the centreon db user.


#
mysql -e "grant all on centreon.* to 'centreon'@localhost identified by 'CentreonDBPassword';"
mysql -e "grant all on centreon_storage.* to 'centreon'@localhost identified by 'CentreonDBPassword'"
mysql -e "grant all on centreon_status.* to 'centreon'@localhost identified by 'CentreonDBPassword';"
#

Friday, February 15, 2013

Perl module Test-Simple-0.70 fails to build while compiling Nagios Plugins 1.4.16


  • CentOS 6.3 x64
  • Nagios-Plugins-1.4.16


Problem


While compiling nagios-plugins-1.4.16:
cd /usr/local/src
tar -xzf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl --enable-perl-modules
make
make install
The following error shows up at the end of make install:
make[3]: Entering directory `/usr/local/src/nagios-plugins-1.4.16/perlmods/Test-Simple-0.70'
make[3]: *** No rule to make target `install'.  Stop.
make[3]: Leaving directory `/usr/local/src/nagios-plugins-1.4.16/perlmods/Test-Simple-0.70'
Can't run make install at ../tools/build_perl_modules line 85.
make[2]: *** [install-exec-local] Error 2
make[2]: Leaving directory `/usr/local/src/nagios-plugins-1.4.16/perlmods'
make[1]: *** [install-am] Error 2
make[1]: Leaving directory `/usr/local/src/nagios-plugins-1.4.16/perlmods'
make: *** [install-recursive] Error 1

Solution


Build the Test-Simple-0.70 package manually then make install the nagios-plugins again:

#inside the extracted nagios-plugins that is being built
cd nagios-plugins-1.4.16/perlmods/Test-Simple-0.70
perl Makefile.PL
make
make install

# go back to nagios-plugins to make install
cd ../..
make install

You may want to check out my blog post on Installing Centreon 2.4 on CentOS 6.3 x64.

make: *** No rule to make target `/usr/lib64/perl5/CORE/config.h', needed by `Makefile'. Stop.

Problem


While compiling ExtUtils-MakeMaker-6.64 on CentOS 6.3: x64

cd /usr/local/src
wget http://search.cpan.org/CPAN/authors/id/M/MS/MSCHWERN/ExtUtils-MakeMaker-6.64.tar.gz
tar -xzf ExtUtils-MakeMaker-6.64.tar.gz
cd ExtUtils-MakeMaker-6.64
perl Makefile.PL
make

I get the following error:
make: *** No rule to make target `/usr/lib64/perl5/CORE/config.h', needed by `Makefile'.  Stop.

Solution


The package perl-devel needs to be installed then make again:
yum -y install perl-devel

cd /usr/local/src
cd ExtUtils-MakeMaker-6.64
make
make install

Error compiling Nagios-Plugins-1.4.16 on CentOS 6.3

System

  • Centos 6.3
  • Nagios-Plugins-1.4.16

Problem


After running the follwing commands to compile nagions-plugins
cd /usr/local/src
wget http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz/download
tar -xzf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl --enable-perl-modules
make

Make crashes at the end with the following error:
Can't locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 11.
BEGIN failed--compilation aborted at Makefile.PL line 11.
Can't run perl Makefile.PL at ../tools/build_perl_modules line 68.
make[2]: *** [all-local] Error 2
make[2]: Leaving directory `/usr/local/src/nagios-plugins-1.4.16/perlmods'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/src/nagios-plugins-1.4.16'
make: *** [all] Error 2

Solution


The package ExtUtils-MakeMaker has to be installed first. Additionally, perl-devel is also needed to compile it. Then, reconfigure nagios-plugins.


# install perl-devel
yum -y install perl-devel

# install ExtUtils-MakeMaker
cd /usr/local/src
wget http://search.cpan.org/CPAN/authors/id/M/MS/MSCHWERN/ExtUtils-MakeMaker-6.64.tar.gz
tar -xzf ExtUtils-MakeMaker-6.64.tar.gz
cd ExtUtils-MakeMaker-6.64
perl Makefile.PL
make
make install

# now reconfigure nagios-plugins
cd /usr/local/src
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl --enable-perl-modules
make
make install



You may want to check out my blog post on Installing Centreon 2.4 on CentOS 6.3 x64.

Installing Centreon 2.4 on CentOS 6.3 x64 - Step by Step

Scope


In this no-brainer guide I am going to detail how to install Centreon on a brand new CentOS 6.3 x64 machine.
Components:
  • CentOS 6.3 x64 (this)
  • Nagios Core 3.4.4 (this)
  • Nagios Plugins 1.4.16 (this)
  • Centreon 2.4 (this)

Prerequisites


  • CentOS is installed in text-mode using the CentOS-6.3-x86_64-LiveCD.iso image on a VirtualBox VM in my case
  • Firewall ports 22 and 80 have been opened by the configuration tool
  • Default services have been installed + sshd
  • I consciously don't start the with yum update/upgrade so the expected result should be as much the same as possible

# install RPMForge
# for details visit this website: http://wiki.centos.org/AdditionalResources/Repositories/RPMForge
rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt

uname -i
# for me 'x86_64' is the result so I'll choose the x86_64 version
wget -N http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
rpm -i rpmforge-release-0.5.2-2.el6.rf.*.rpm


# Installing Apache2 + PHP
yum -y install httpd php php-mysql php-gd
usermod -U apache
chkconfig httpd on
# Set your timezone in php.ini to get rid of an ugly warinng in the future.
# find date.timezone at the [date] section, uncomment and set it. for me it's Europe/Bucharest
# date.timezone = Europe/Bucharest
# find yours here: http://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/timezone.html
vim /etc/php.ini
#
# Add port 80 to Firewall
sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT 
sudo service iptables save


# Installing GD modules
yum -y install gd fontconfig-devel libjpeg-devel libpng-devel gd-devel perl-GD

# Installing MySQL
yum -y install openssl-devel perl-DBD-MySQL mysql-server mysql-devel

# Installing PHP Dependencies
yum -y install php-ldap php-xml php-mbstring

# Installing DBI modules
yum -y install perl-DBI perl-DBD-MySQL

# Installing PERL modules
yum -y install perl-Config-IniFiles

# Installing RRDTools
yum -y install rrdtool perl-rrdtool

# Installing SNMP
yum -y install perl-Crypt-DES perl-Digest-SHA1 perl-Digest-HMAC net-snmp-utils
yum -y install perl-Socket6 perl-IO-Socket-INET6 net-snmp net-snmp-libs php-snmp dmidecode lm_sensors perl-Net-SNMP net-snmp-perl

# Misc
yum -y install fping cpp gcc gcc-c++ libstdc++ glib2-devel
# Make is not included on cent-os by default
yum -y install make

# PEAR
yum -y install php-pear
pear channel-update pear.php.net 
# for those who have a web proxy
# pear config-set http_proxy http://my_proxy.com:port 
pear upgrade-all


# add the line rocommunity public 127.0.0.1/32 to snmpd.conf
sed -i '$ a\rocommunity public 127.0.0.1/32' /etc/snmp/snmpd.conf
service snmpd start
chkconfig snmpd on
# enabling NTP couldn't hurt
chkconfig ntpd on 
ntpdate pool.ntp.org 
service ntpd start
# 


Installing Nagios


# Creating the nagios user
/usr/sbin/useradd -m nagios
/usr/sbin/usermod -L nagios

# Creating a group to be able to use external commands
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -G nagios,nagcmd nagios
/usr/sbin/usermod -G nagios,nagcmd apache

# Download & Compile
cd /usr/local/src/
wget -N http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.4.tar.gz
tar -xzf nagios-3.4.4.tar.gz
cd nagios

./configure --prefix=/usr/local/nagios --with-command-group=nagcmd --enable-nanosleep --enable-event-broker
make all
make install
make install-init
make install-commandmode
make install-config
chkconfig nagios on
service nagios start
#



Compiling Nagios Plugins


#
cd /usr/local/src
wget -N http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz/download

yum -y install fping openssl-devel openldap-devel postgresql-devel radiusclient-ng-devel samba-client libsmbclient

yum -y install perl-devel
cd /usr/local/src
wget -N http://search.cpan.org/CPAN/authors/id/M/MS/MSCHWERN/ExtUtils-MakeMaker-6.64.tar.gz
tar -xzf ExtUtils-MakeMaker-6.64.tar.gz
cd ExtUtils-MakeMaker-6.64
perl Makefile.PL
make
make install

cd /usr/local/src
tar -xzf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl --enable-perl-modules
make

# Test-Simple-0.70 fails to compile otherwise so have to do it manually first
cd ./perlmods/Test-Simple-0.70
perl Makefile.PL
make
make install

# go back to nagios-plugins to make install
cd ../..
make install
# 

Installing NDOutils

#
cd /usr/local/src
wget -N http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.5.2/ndoutils-1.5.2.tar.gz/download
tar -zxvf ndoutils-1.5.2.tar.gz
cd ndoutils-1.5.2

# get the patch and apply it; wget to same folder as ndoutils
wget -N http://svn.centreon.com/trunk/ndoutils-patch/ndoutils1.5.2_light.patch
yum -y install patch
patch -p1 -N < ndoutils1.5.2_light.patch

# continue installation
./configure --prefix=/usr/local/nagios/ --enable-mysql --with-ndo2db-user=nagios --with-ndo2db-group=nagios
make


# After creating the binaries and libraries they have to be copied
cp -f ./src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o
cp -f ./src/ndo2db-3x /usr/local/nagios/bin/ndo2db
cp -f ./config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
cp -f ./config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
sudo chmod 774 /usr/local/nagios/bin/ndo*
sudo chown nagios:nagios /usr/local/nagios/bin/ndo*

# make ndo2db daemon autorun
cp -f ./daemon-init /etc/init.d/ndo2db
chmod +x /etc/init.d/ndo2db
chkconfig ndo2db on
#

Click here for Part 2

Friday, November 16, 2012

MySQL 5.5 service won't start: Job failed to start

Trying to connect to my local MySQL 5.5 on an Ubuntu Server 12.10 x64 gave me the following error:

   levente@linuxvm:/$ mysql
   ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Turned out that the MySQL Service is not running.

   levente@linuxvm:/$ ps -ef | grep mysql
   levente 5347 2842 0 08:47 pts/1 00:00:00 grep --color=auto mysql

Trying to start it failed:

   levente@linuxvm:/var/log$ sudo service mysql start
   start: Job failed to start

Syslog shows like this:

   levente@linuxvm:/$ cat /var/log/syslog
   Nov 16 08:28:49 linuxvm kernel: [ 1307.007001] type=1400 audit(1353072529.161:42): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=4600 comm="apparmor_parser"
   Nov 16 08:28:50 linuxvm kernel: [ 1308.658583] init: mysql main process (4604) terminated with status 1
   Nov 16 08:28:50 linuxvm kernel: [ 1308.658625] init: mysql main process ended, respawning
   Nov 16 08:28:51 linuxvm kernel: [ 1309.291148] init: mysql post-start process (4605) terminated with status 1
   Nov 16 08:28:51 linuxvm kernel: [ 1309.306516] type=1400 audit(1353072531.461:43): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=4651 comm="apparmor_parser"
   Nov 16 08:28:52 linuxvm kernel: [ 1310.791380] init: mysql main process (4655) terminated with status 1
   Nov 16 08:28:52 linuxvm kernel: [ 1310.791400] init: mysql main process ended, respawning
   Nov 16 08:28:53 linuxvm kernel: [ 1311.380212] init: mysql post-start process (4656) terminated with status 1
   Nov 16 08:28:53 linuxvm kernel: [ 1311.395653] type=1400 audit(1353072533.549:44): apparmor="STATUS" operation="profile_replace" name="/usr/sbin/mysqld" pid=4702 comm="apparmor_parser"
   Nov 16 08:28:55 linuxvm kernel: [ 1312.886555] init: mysql main process (4706) terminated with status 1
   Nov 16 08:28:55 linuxvm kernel: [ 1312.886635] init: mysql respawning too fast, stopped


The problem is that I had some incorrect values in /etc/mysql/my.cnf. In my case it was an incorrect bind address that I just uncommented.

  #
  # Instead of skip-networking the default is now to listen only on
  # localhost which is more compatible and is not less secure.
  # bind-address = 172.17.1.1
  #
  levente@linuxvm:/$ sudo start mysql
  mysql start/running, process 5432

Yay!

Monday, October 1, 2012

Graph icons not showing up in Centreon

Ubuntu Server 12.04 x64
Nagois 3.4.1
Centreon 2.3.9
Nagios-Plugins 1.4.16
NDOUtils-1.5.2

I followed this excellent guide to install Nagios + Centreon from the ground.

After completing all steps and adding some Windows hosts to Centreon, the graph icons did not show up although I configured graphing at the service properties (except for ping).



Checking the logs revealed that in fact my db username was incorrect (it was Centreon instead of ndouser).

tail -n 5 /usr/local/centreon/log/centstorage.log

2012-10-01 16:37:49 - Error when connecting to database : Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
2012-10-01 16:37:51 - Error when connecting to database : Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
2012-10-01 16:37:53 - Error when connecting to database : Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
2012-10-01 16:37:55 - Error when connecting to database : Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
2012-10-01 16:37:57 - Error when connecting to database : Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)


so I opened up ndo2db.cfg to correct the credentials then restarted Centreon.

sudo vim /usr/local/nagios/etc/ndo2db.cfg

Thursday, September 6, 2012

Compiling nagios-plugins-1.4.16 throws an error

I was installing Nagios on a new Ubuntu Server following this guide, but using the latest versions (Nagios 3.4.1 and Nagios Plugins 1.4.15).

Running make on the Nagios Plugins threw me the following error:
....
 check_http.c:312:9: error: ‘ssl_version’ undeclared (first use in this function)
....
make[2]: *** [check_http.o] Error 1
make[2]: Leaving directory `/home/nicadmin/nagios-plugins-1.4.16/plugins'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/nicadmin/nagios-plugins-1.4.16'
make: *** [all] Error 2


A workaround is installing the libssl-dev package and reconfiguring.
root@host1:~/nagios-plugins-1.4.16# apt-get install libssl-dev
root@host1:~/nagios-plugins-1.4.16# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
root@host1:~/nagios-plugins-1.4.16# make
root@host1:~/nagios-plugins-1.4.16# make install


Source: http://sourceforge.net/mailarchive/forum.php?thread_name=0957CCC9-6B31-4081-ADF1-D04F00212EC4%40gmail.com&forum_name=nagiosplug-devel