How to use SAR to troubleshoot linux box and generate reports.

SAR stands for System Activity Report, as its name suggest sar command is used to collect, report & save CPU, Memory, I/O usage in Unix like operating system. SAR command produce the reports on the fly and can also save the reports in the log files as well.
Now a days sar includes in general Linux installation. You can check if sar is installed by executing following command.



rpm -qa | grep sysstat


Incase if sar is not installed you can use following command or RPM package to install it.

yum install sysstat


Sysstat data collection is doing by sadc (system activity data collector). It saves the reports in log file “/var/log/sa/saDD”  where DD represents Current day and already existing files will be archived.


[root@localhost ~]# systemctl start sysstat
[root@localhost ~]# systemctl enable sysstat



It collects the data every 10 minutes and generate its report daily. Below crontab file is responsible for collecting and generating reports.


Generating CPU Report on the Fly 5 times every 2 seconds.


[root@localhost ~]# sar 2 5 

Linux 3.10.0-123.el7.x86_64 (localhost.localdomain)     Monday 26 October 2015     _x86_64_    (2 CPU) 01:43:55  EDT     CPU     %user     %nice   %system   %iowait    %steal     %idle 01:43:57  EDT     all      0.00      0.00      0.25      0.00      0.00     99.75 01:43:59  EDT     all      0.00      0.00      0.00      0.00      0.00    100.00 01:44:01  EDT     all      0.00      0.00      0.25      0.00      0.00     99.75 01:44:03  EDT     all      0.00      0.00      0.25      0.25      0.00     99.50 01:44:05  EDT     all      0.00      0.00      0.00      0.00      0.00    100.00 Average:        all      0.00      0.00      0.15      0.05      0.00     99.80 [root@localhost ~]#


Generating Memory Usage report using -r











Reading SAR log file using -f












[root@localhost ~]# sar -r -f /var/log/sa/sa26


Create Graphs using KSAR tool


You need download KSAR tool to create graphs using /var/log/sa/sar* files


https://sourceforge.net/projects/ksar/


You need to convert time format in sar file before loading to sar you can do it by using following commands


cd /var/log/sa

LC_TIME="POSIX" sar -A -f sa08 > /tmp/sar.data.txt


now download sar.data.txt file and load it in to KSAR


Tuesday, October 23, 2018

How Reset Root Password in RHEL 7 from 9 Simple st...

cyber-techno-lk: How Reset Root Password in RHEL 7 from 9 Simple st...:
 How Reset Root Password in RHEL 7 from 9 Simple steps =================================================

How to install Apache from source

Download and copy Apache source to local Linux machine

cd /opt/software/httpd-2.4.33


./configure --prefix=/usr/local/apache LD_LIBRARY_PATH=/usr/local/ssl/lib/ LIBS=-L/usr/local/ssl/lib --with-included-apr --enable-ssl --enable-so --enable-http --enable-info --enable-cgi --enable-vhost-alias --enable-rewrite --with-mpm=prefork --enable-mods-shared --enable-deflate --enable-headers --enable-security --enable-reqtimeout --enable-so

make

make install

cp /usr/local/apache/bin/apachectl /etc/init.d/web.system chmod 777 /etc/init.d/web.system

change http.conf according to your settings.

Go to browser and open http://x.x.x.x/index.html

How to install PHP 7

Download and extract php source to /opt/software folder

cd /opt/software/php-7.2.7

yum install libjpeg-devel libpng-devel


./configure --prefix=/usr/local/apache/php --with-config-file-path=/usr/local/apache/php --with-apxs2=/usr/local/apache/bin/apxs --disable-cgi --with-zlib --with-gettext --with-sqlite3 --enable-mbstring --enable-calendar --with-curl=/usr/lib64 --with-gd --with-jpeg-dir=/usr/lib64/libjpeg.so --with-png-dir=/usr/lib64/libpng.so --enable-soap --with-libdir=/lib64 --enable-zip --with-mysqli --with-pdo-mysql --with-openssl-dir

make

make install

Add following lines in httpd.conf to enable php

LoadModule php7_module        modules/libphp7.so
AddType application/x-httpd-php .php
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

Restart httpd

/etc/init.d/web.system restart

Monday, October 22, 2018

Installing nagios NRPE on AWS EC2

yum install nagios-plugins-all nagios-plugins-nrpe nrpe

chkconfig nrpe on
update the config by checking allowed_hosts and
vi /etc/nagios/nrpe.cfg
sudo /etc/init.d/nrpe start

How to install Nagios on AWS

Prerequisites
=========

* Apache
* PHP
* GCC compiler
* GD development libraries

Steps
====

sudo yum install httpd php
sudo yum install gcc glibc glibc-common
sudo yum install gd gd-devel

Create Users
=========

sudo adduser -m nagios
sudo passwd nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd apache

Download Nagios Core
=================

mkdir ~/downloads
cd ~/downloads
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz
wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz


Compile and Install Nagios
====================

tar zxvf nagios-4.0.8.tar.gz
cd nagios-4.0.8
./configure --with-command-group=nagcmd

make all

sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode


Customize Configuration
==================

Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These sample files should work fine for getting started with Nagios. You'll need to make just one change before you proceed...

Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you'd like to use for receiving alerts.

sudo vim /usr/local/nagios/etc/objects/contacts.cfg

Configure the Web Interface
====================

Install the Nagios web config file in the Apache conf.d directory.

sudo make install-webconf

Create a nagiosadmin account for logging into the Nagios web interface. Remember the password you assign to this account - you'll need it later.

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Type the new password twice. Restart Apache to make the new settings take effect.

sudo service httpd restart

Compile and Install the Nagios Plugins
============================

cd ~/downloads
tar zxvf nagios-plugins-2.0.3.tar.gz
cd nagios-plugins-2.0.3

Compile and install the plugins.

./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
sudo make install

Start Nagios
=========

sudo chkconfig --add nagios
sudo chkconfig nagios on

Verify the sample Nagios configuration files.

sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

If there are no errors, start Nagios.

sudo service nagios start


Enable 80 port in AWS
=================

* From the EC2 console select Security Groups from the left navigation pane.
* Select the Security Group applicable for the instance that Nagios was installed on and open the Inbound tab
* If there is no rule to allow HTTP traffic on port 80 then click edit in the Inbound tab to add a new rule
* Click on New Rule button
* Scroll down to select HTTP from the list under Type
* If you want to be able to access nagios from anywhere then select Save, otherwise enter the IP address or range of IP address you want to be able to access it from then select Save.

Access Nagios
===========

http://ec2-xx-xxx-xxx-xx.ap-southeast-2.compute.amazonaws.com/nagios/