Setting Up NRPE for Nagios on Ubuntu Servers

Step 1: Install Required Packages

sudo apt update
sudo apt install -y xinetd monitoring-plugins nagios-nrpe-server

Step 2: Configure NRPE

Edit the NRPE configuration file to allow connections from the Nagios server:

sudo vi /etc/nagios/nrpe.cfg

# Add your Nagios server's IP address to allowed_hosts
allowed_hosts=127.0.0.1, <NAGIOS_SERVER_IP>

Step 3: Restart NRPE Service

sudo systemctl restart nrpe
sudo systemctl enable nrpe

Step 4: Verify NRPE is Listening

sudo ss -tulnp | grep 5666

Step 5: Verify NRPE Commands

Use the following command from the Nagios server to verify NRPE checks:

/usr/local/nagios/libexec/check_nrpe -H <REMOTE_SERVER_IP> -c check_disk

Step 6: Add Custom Check (Optional)

If you want to add a custom memory check, create a script:

sudo vi /usr/lib/nagios/plugins/check_mem.sh

# Paste the following content into the file
#!/bin/bash
used=$(free | awk '/Mem:/ { printf("%.2f", $3/$2 * 100) }')
echo "MEMORY OK - $used% used | mem=$used%;80;90;0;100"
exit 0

# Make the script executable
sudo chmod +x /usr/lib/nagios/plugins/check_mem.sh

Step 7: Define the Command in NRPE

Add the following line to /etc/nagios/nrpe.cfg:

command[check_mem]=/usr/lib/nagios/plugins/check_mem.sh

Step 8: Final Restart

Restart the NRPE service one final time:

sudo systemctl restart nrpe

test

  • How Do I Install Nagios on an Ubuntu Server?

    To install Nagios, follow these steps:

    1. Update your system:
      bash
      sudo apt update && sudo apt upgrade -y

      <button class=”copy-code-button”>Copy Code</button>

    2. Install required dependencies:
      bash
      sudo apt install -y build-essential libgd-dev openssl libssl-dev apache2 php

      <button class=”copy-code-button”>Copy Code</button>

    3. Download and compile Nagios Core:
      bash
      wget https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.5.9/nagios-4.5.9.tar.gz
      tar -zxvf nagios-4.5.9.tar.gz
      cd nagios-4.5.9
      ./configure
      make all
      sudo make install

      <button class=”copy-code-button”>Copy Code</button>


add nrpe for all ubuntu servers

1. Install Required NRPE Packages

bash
sudo apt update
sudo apt install -y xinetd monitoring-plugins nagios-nrpe-server

2. Verify NRPE Installation

bash
which nrpe

3. Update /etc/nagios/nrpe.cfg Configuration
Add or update the following lines:

bash
allowed_hosts=127.0.0.1,<Nagios_Server_IP>
dont_blame_nrpe=1
command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_load]=/usr/lib/nagios/plugins/check_load -w 1.0,0.75,0.5 -c 2.0,1.5,1.0
command[check_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_mem]=/usr/lib/nagios/plugins/check_mem.sh 80 90

4. Create and Set Permissions for check_mem.sh Script

bash
sudo vi /usr/lib/nagios/plugins/check_mem.sh

Paste the following code into the file:

bash
#!/bin/bash
USED_MEM=$(free | awk '/Mem:/ {print $3/$2 * 100.0}')
USED_MEM_INT=${USED_MEM%.*}
echo "MEMORY OK - $USED_MEM% used | mem=$USED_MEM%;$1;$2;0;100"
exit 0

Set the correct permissions:

bash
sudo chown nagios:nagios /usr/lib/nagios/plugins/check_mem.sh
sudo chmod 755 /usr/lib/nagios/plugins/check_mem.sh

5. Restart the NRPE Service

bash
sudo systemctl restart nrpe
sudo systemctl status nrpe

6. Test NRPE Commands Locally and from the Nagios Server

  • Local Test
    bash
    /usr/lib/nagios/plugins/check_nrpe -H localhost -c check_disk
    /usr/lib/nagios/plugins/check_nrpe -H localhost -c check_mem
  • Remote Test (Run from Nagios Server)
    bash
    /usr/local/nagios/libexec/check_nrpe -H <Remote_Server_IP> -c check_disk
    /usr/local/nagios/libexec/check_nrpe -H <Remote_Server_IP> -c check_mem

upgrade MariaDB 5.5->10.3 CentOS 7

CentOS 7 is shipped with MariaDB. MariaDB 10.x version is a drop-in replacement for MySQL 5.5-5.7.

  1. Create a backup of all databases with the following command:

    # MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysqldump -u admin –all-databases –routines –triggers > /tmp/all-databases.sql

  2. Stop the MariaDB service:

    # service mariadb stop

    Note: Remove additional packages like mariadb-bench:

    # rpm -e mariadb-bench

  3. Copy a databases directory in a separate folder like this (for backup purposes also):

    # cp -a /var/lib/mysql/ /var/lib/mysql_backup

  4. Check if you already have mysql-server installed:

    # rpm -q –whatprovides mysql-server

    If it is installed and the command above gives output, it is required to be removed using the following command:

    # rpm -e –nodeps `rpm -q –whatprovides mysql-server`

  5. Configure MariaDB repository: open the Setting MariaDB repositories page, select OS distro, release and MariaDB version to see the configuration that should be added to /etc/yum.repos.d/MariaDB.repo file. Example for MariaDB 10.1:

    # vi /etc/yum.repos.d/MariaDB.repo

    [mariadb]
    name = MariaDB
    baseurl = http://yum.mariadb.org/10.1/centos7-amd64
    gpgkey = https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
    gpgcheck = 1

  6. Perform an upgrade with:

    # yum install MariaDB-client MariaDB-server

  7. Start the MariaDB service:

    # service mariadb start

    OR

    # service mysql start

  8. Upgrade MySQL databases:

    # MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql_upgrade -uadmin

  9. Restart mysql service:

    # service mariadb restart

    OR

    # service mysql restart

upgrade mysql 5.1->5.7 (CentOS 6)

first, upgrade from 5.1 to 5.5 https://support.plesk.com/hc/en-us/articles/213367429

 

  • Install the Atomicorp repository:

    wget -q -O – http://www.atomicorp.com/installers/atomic | sh

  • Upgrade MySQL:

    yum upgrade mysql

 

 

  • Restart the MySQL service:

    service mysqld restart

  • Upgrade MySQL databases:

    mysql_upgrade -uadmin -p`cat /etc/psa/.psa.shadow`

  • In case the message below appears, refer to the KB article Error during yum upgrade: Packages excluded due to repository protections:

    yum upgrade mysql
    ….
    881 packages excluded due to repository protections
    No Packages marked for Update

 

Next, update from 5.5->5.7 https://support.plesk.com/hc/en-us/articles/213403429-How-to-upgrade-MySQL-5-5-to-5-6-5-7-or-MariaDB-5-5-to-10-0-10-1-10-2-on-Linux

  1. Stop the MySQL service:

    # service mysqld stop

  2. Create a backup of databases:

    # cp -a /var/lib/mysql /var/lib/mysql_backup

    Note: Disable Atomic repository, if it is enabled:

    # vi /etc/yum.repos.d/atomic.repo
    enabled = 0

  3. Install the MySQL-community repository:

    # yum install https://dev.mysql.com/get/mysql80-community-release-el6-1.noarch.rpm

  4. Select a MySQL version:

    # vi /etc/yum.repos.d/mysql-community.repo
    [mysql56-community]
    enabled=0
    [mysql57-community]
    enabled=1

  5. Install MySQL packages:

    # yum update mysql

    If update of mysql package ends with Nothing to do message, make sure that mysql* packages are not added to excludes in yum.conf file and remove it if it is in the list:

    # cat /etc/yum.conf | grep exclude
    exclude=php-common php-cli php mysql* httpd* mod_ssl*

  6. Type y if this message appears:

    warning: rpmts_HdrFromFdno: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
    Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    Importing GPG key 0x5072E1F5:
    Userid : MySQL Release Engineering <mysql-build@oss.oracle.com>
    Package: mysql57-community-release-el6-7.noarch (@/mysql57-community-release-el6-7.noarch)
    From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    Is this ok [y/N]:

  7. Start the MySQL service:

    # service mysqld start

    If the service does not start, check the following article: MySQL fails to start: mysql.user table is damaged.

  8. Upgrade MySQL databases:

    # MYSQL_PWD=`cat /etc/psa/.psa.shadow` mysql_upgrade -uadmin

  9. Restart mysql service:

    # service mysqld restart

 

setup gmail to POP your new account

Open Gmail.
In the top right, click Settings Settings and then Settings.
Click the Accounts tab.
In the 3rd section, click Add a mail account
Follow the steps on the screen
email address: you@yourdomain.com
(Next)
username: you@yourdomain.com (it will default to just part of your address – make sure you type the full email address)
password:
POP server: yourdomain.com
Port 110
Leave all other boxes unchecked
(Add Account)
Yes, I want to be able to send mail as you@yourdomain.com
(Next)
Name: you@yourdomain.com
Treat as an alias – leave checked
(Next Step)
SMTP Server: yourdomain.com
Port: 25
Username: you@yourdomain.com (it will default to just part of your address – make sure you type the full email address)
Password:
Unsecured connection
(Add Account)
You will get a popup screen asking that you enter a verification code that was sent to your you@yourdomain.com account – a bit of a catch22, huh? How can you get the verification code to setup gmail if gmail is not setup to get the code yet? Well, we have you covered…..just a few more steps. In a separate window:
go to http://webmail.yourdomain.com
username: you@yourdomain.com
password:
(login)
click the Mail link in the top left
you should see the email from gmail. Get the verification code.
Enter verification code into google screen and submit
If all went well – you should be done!

have .html files run as .php

A client ran into an interesting problem to get .html files parsed as .php. It was not enough to add a .htaccess directive for php-script because then the php.ini file was used out of the /etc directory instead of the domain’s custom php.ini file. He had to do the following.

I was researching the problem and finally figured out the answer. Just in case you ever get asked again, I added the following to my .htaccess file and now works with the right php.ini file.

AddHandler php-script .html

SetHandler fcgid-script
FCGIWrapper /var/www/cgi-bin/cgi_wrapper/cgi_wrapper .html
Options +ExecCGI

Originally I only had the “AddHandler php-script .html” in the .htaccess file which made it work, but did not pull in the right php.ini file.

Thanks Robert!

credit:
Robert Thaller | Net-Flow Corporation
1556 First Street, Suite 103, Napa, CA 94559
Phone 707-259-1233
Fax 707-255-7218
rthaller@net-flow.com

libarchive error after upgrade to plesk 12.5

Error:

Fatal error during packages installation: Test Transaction Errors: package libarchive-2.8.4-11082614.x86_64 (which is newer than libarchive-2.8.4-6.el5.i386) is already installed

YumTestTransactionError: Test Transaction Errors: package libarchive-2.8.4-11082614.x86_64 (which is newer than libarchive-2.8.4-6.el5.i386) is already installed

Error: Failed to run the Yum utility.
The Yum utility failed to install the required packages.
Attention! Your software might be inoperable.
Please, contact product technical support.

Fix:


rpm -e --nodeps libarchive
wget -q https://dl.fedoraproject.org/pub/epel/epel-release-latest-5.noarch.rpm
rpm -Uvh epel-release-latest-5.noarch.rpm
yum install libarchive
/usr/local/psa/admin/bin/autoinstaller