Wednesday, 25 March 2015

How to install Cacti Network Monitoring Tool on CentOS 6.4

Cacti is an open source, front-end for the data logging tool called RRDtool. It is a web based network monitoring and graphing tool.

Install the following required packages for Cacti. Cacti and some of the below prerequisites are not included in the CentOS official repository. So let us install them from EPEL repository. To install EPEL repository enter the following commands.

[root@server ~]# wget
[root@server ~]# rpm -ivh epel-release-6-8.noarch.rpm

Install Apache

Apache is used to display the the network graphs created by PHP and RRDtool.
[root@server ~]# yum install httpd httpd-devel -y

Install MySQL

MySQL is used to store the Cacti Database details.
[root@server ~]# yum install mysql mysql-server -y

Install PHP

PHP script is used to create graphs using RRDtool.
[root@server ~]# yum install php-mysql php-pear php-common php-gd php-devel php 
php-mbstring php-cli php-mysql -y

Install PHP-SNMP

It is an extension for SNMP to access data.
[root@server ~]# yum install php-snmp -y

Install NET-SNMP

It is used to manage network.
[root@server ~]# yum install net-snmp-utils net-snmp-libs php-pear-Net-SMTP -y

Install RRDtool

It is a database tool to manage and retrieve data’s like Network Bandwidth and CPU Load etc.
[root@server ~]# yum install rrdtool -y
After installing all the above softwares, start them.
[root@server ~]# /etc/init.d/httpd start
[root@server ~]# /etc/init.d/mysqld start
[root@server ~]# /etc/init.d/snmpd start
Let the above services to start automatically on every reboot.
[root@server ~]# chkconfig httpd on
[root@server ~]# chkconfig mysqld on
[root@server ~]# chkconfig snmpd on

Installing Cacti Tool

[root@server ~]# yum install cacti -y

Configure MySQL

Login to MySQL server as root user and create a database for Cacti. Here i use Cacti database name as cacti, username as cacti and password as centos respectively.

[root@server ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.1.69 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database cacti;
Query OK, 1 row affected (0.01 sec)

mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'centos';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> exit

Now import Cacti Tables to Cacti Database. Find the location of the file cacti.sql and import it to cacti database. To find out this file, enter the following command.

[root@server ~]# rpm -ql cacti | grep cacti.sql

Note down the path of cacti.sql file and import it using the following command.
[root@server ~]# mysql -u cacti -p cacti < /usr/share/doc/cacti-0.8.8a/cacti.sql 
Enter password:

Now the tables are imported into cacti database.

Open the /etc/cacti/db.php and make the following changes.
[root@server ~]# vi /etc/cacti/db.php 
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";        ## Name of the Cacti Database ##
$database_hostname = "localhost";
$database_username = "cacti";       ## Username for Cacti database ##     
$database_password = "centos";              ## Database password ##
$database_port = "3306";
$database_ssl = false;



Configure Apache server

Open the file /etc/httpd/conf.d/cacti.conf and add your network range or you can add a single ip. In this case, i add my local network ip range

[root@server ~]# vi /etc/httpd/conf.d/cacti.conf
Alias /cacti    /usr/share/cacti

<Directory /usr/share/cacti/>
        <IfModule mod_authz_core.c>
                # httpd 2.4
                Require host localhost
        <IfModule !mod_authz_core.c>
                # httpd 2.2
                Order deny,allow
                Deny from all
                Allow from

Restart your apache server finally.
[root@server ~]# /etc/init.d/httpd restart
If you wanna to start the installer from a remote machine, you should allow the apache default port 80 through your iptables.
[root@server ~]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
-A INPUT -p udp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -p udp -m state --state NEW --dport 53 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 53 -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited

Restart iptables.
[root@server ~]# /etc/init.d/iptables restart

Configure Cron for Cacti

Open the file /etc/cron.d/cacti and uncomment the following line.
[root@server ~]# vi /etc/cron.d/cacti
*/5 * * * *     cacti   /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1

 The above cron job runs the poller.php script every five minutes and collects the data of the known hosts by Cacti.

Run Cacti installer

Navigate to your web browser using the URL http://ip-address/cacti. The following screen should appear, Click Next.


Select New install from the drop down box and click Next.


In the next screen make sure that all the values are valid and click Finish.

Now the installation is completed and it will ask the cacti username and password to login to admin console. The default username and password of Cacti is admin.

It will ask you to change the admin password now. Enter the new password and click Save.



Now you will get the main console window of Cacti.


Create Graphs

Click New Graphs on the left pane of console screen. Select the Host or create a new one and Select SNMP – Generic OID Template in Graph Templates section and click Create.

After creating the graphs, you can preview them using graphs tab on the menu bar. Here are some of my localhost Cacti screen-shots.

Localhost – Memory Usage Graph


Localhost – Disk space Graph


Localhost – Load Average Graph


Localhost – Logged in users Graph


Localhost – Processes Graph

 Thats it. Happy Monitoring!!!

 Source: Unixmen

Monday, 23 March 2015

How to set Prioritize Browsing and Downloading on Mikrotik

The file about to be downloaded >1MB (larger than 1 MB) then it would be categorized as Download and if <1MB (smaller than 1 MB) this is categorized as Browsing. The Confinguration is not limiting Bandwidth, but only just distinguish the priority. So if there is no client browsing the download will be fast again.

Ok I think is clear enough, and now how do we apply the browsing can be prioritize when many clients use our internet connection in mikrotik winbox.  

Log in into your Winbox with a password that you have. If you not have yet, ask with your internet service provider (ISP). Look at the picture above! Go to the new terminal menu tab and right click and paste the script below at the cursor terminal command mikrotik.

/ip firewall mangle
add chain=prerouting action=mark-connection new-connection-mark=conn-download passthrough=yes protocol=tcp dst-port=80 connection-bytes=1000000-0 comment="CONN-DOWNLOAD"

add chain=prerouting action=mark-packet new-packet-mark=download-packet passthrough=no connection-mark=conn-download

add chain=prerouting action=mark-connection new-connection-mark=conn-browsing passthrough=yes protocol=tcp dst-port=80 connection-bytes=0-1000000 comment="CONN-BROWSING"

add chain=prerouting action=mark-packet new-packet-mark=browsing-packet passthrough=no connection-mark=conn-browsing


/queue tree

add name="paket browsing" parent=global-in packet-mark=browsing-packet limit-at=0 queue=default priority=1 max-limit=0 burst-limit=0 burst-threshold=0 burst-time=0s

add name="paket download" parent=global-in packet-mark=download-packet limit-at=0 queue=default priority=8 max-limit=0 burst-limit=0 burst-threshold=0 burst-time=0s

Note: parent=global-in means wan port

Sunday, 15 March 2015

Find System And Hardware Information On Linux

INXI is a command line tool that can be used to find the complete system and hardware details such as.
  • Hardware,
  • CPU,
  • Drivers,
  • Xorg,
  • Desktop,
  • Kernel,
  • GCC version,
  • Processes,
  • RAM usage,
  • and other useful information.


Inxi is available in the default repositories of most modern GNU/Linux operating systems. So, we can simply install it by running the following commands.

On Debian based system:
#apt-get install inxi
On Fedora:

#yum install inxi

On RHEL based systems:
Install EPEL repository:

#yum install epel-release
Then, install inxi using command:

#yum install inxi


To find the quick view of the system information, run the following command from Terminal.

Sample output:
CPU~Dual core Intel Core i3-2350M CPU (-HT-MCP-) clocked at Min:800.000Mhz Max:1200.000Mhz Kernel~3.13.0-45-generic x86_64 Up~6:41 Mem~1537.7/3861.3MB HDD~500.1GB(52.5% used) Procs~183 Client~Shell inxi~1.9.17
Ofcourse, we can retrieve a particular hardware details. For example to retrieve the Audio/Sound hardware details, run the following command:
#inxi -A

Sample output:
Audio:     Card: Intel 6 Series/C200 Series Family High Definition Audio Controller driver: snd_hda_intel 
           Sound: Advanced Linux Sound Architecture ver: k3.13.0-45-generic

You can retrieve the details of Graphic card information.
#inxi -G

Sample output:
Graphics:  Card: Intel 2nd Generation Core Processor Family Integrated Graphics Controller 
           X.Org: 1.15.1 drivers: intel (unloaded: fbdev,vesa) Resolution: 1366x768@60.0hz 
           GLX Renderer: Mesa DRI Intel Sandybridge Mobile GLX Version: 3.0 Mesa 10.3.0

What about harddisk information? That’s also possible. To view the full  
harddisk information, run the following command.
#inxi -D

Sample Output:
Drives:    HDD Total Size: 500.1GB (52.5% used) 1: id: /dev/sda model: ST9601325BD size: 500.1GB
To display the Bios and Motherboard details:
#inxi -M

Sample output:
Machine:   System: Dell (portable) product: Inspiron N5050
           Mobo: Dell model: 01HXXJ version: A05 Bios: Dell version: A05 date: 08/03/2012

Not only hardware details, it can also displays the list of available repositories in our system.
#inxi -r

Sample output:

Repos:     Active apt sources in file: /etc/apt/sources.list
           deb trusty main restricted
           deb-src trusty main restricted
           deb trusty-updates main restricted
           deb-src trusty-updates main restricted
           deb trusty universe
           Active apt sources in file: /etc/apt/sources.list.d/intellinuxgraphics.list
           deb trusty main #Intel Graphics drivers
           Active apt sources in file: /etc/apt/sources.list.d/linrunner-tlp-trusty.list
           Active apt sources in file: /etc/apt/sources.list.d/wseverin-ppa-trusty.list
           deb trusty main

Tired of finding each hardware details? Well, you can list all details at once using command:
#inxi -F

Sample output:
System:    Host: sk Kernel: 3.13.0-45-generic x86_64 (64 bit) Desktop: LXDE (Openbox 3.5.2) Distro: Ubuntu 14.04 trusty
Machine:   System: Dell (portable) product: Inspiron N5050
           Mobo: Dell model: 01HXXJ version: A05 Bios: Dell version: A05 date: 08/03/2012
CPU:       Dual core Intel Core i3-2350M CPU (-HT-MCP-) cache: 3072 KB flags: (lm nx sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx) 
           Clock Speeds: 1: 800.00 MHz 2: 1000.00 MHz 3: 800.00 MHz 4: 800.00 MHz
Graphics:  Card: Intel 2nd Generation Core Processor Family Integrated Graphics Controller 
           X.Org: 1.15.1 drivers: intel (unloaded: fbdev,vesa) Resolution: 1366x768@60.0hz 
           GLX Renderer: Mesa DRI Intel Sandybridge Mobile GLX Version: 3.0 Mesa 10.3.0
Audio:     Card: Intel 6 Series/C200 Series Family High Definition Audio Controller driver: snd_hda_intel 
           Sound: Advanced Linux Sound Architecture ver: k3.13.0-45-generic
Network:   Card-1: Qualcomm Atheros AR9285 Wireless Network Adapter (PCI-Express) driver: ath9k 
           IF: wlan0 state: up mac: 
           Card-2: Realtek RTL8101E/RTL8102E PCI Express Fast Ethernet controller driver: r8169 
           IF: eth0 state: down mac: 
Drives:    HDD Total Size: 500.1GB (52.5% used) 1: id: /dev/sda model: ST9500325AS size: 500.1GB 
Partition: ID: / size: 455G used: 245G (57%) fs: ext4 ID: /boot size: 236M used: 159M (72%) fs: ext2 
           ID: swap-1 size: 4.19GB used: 0.00GB (0%) fs: swap 
RAID:      No RAID devices detected - /proc/mdstat and md_mod kernel raid module present
Sensors:   System Temperatures: cpu: 64.5C mobo: N/A 
           Fan Speeds (in rpm): cpu: N/A 
Info:      Processes: 186 Uptime: 6:52 Memory: 1547.2/3861.3MB Client: Shell (bash) inxi: 1.9.17

As you see in the above, inxi displays the complete hardware details.
For more details, refer the man pages.
#man inxi




Saturday, 14 March 2015

How to install Apache2, PHP5 And MySQL Support On CentOS 6.5

1 Preliminary Note

In this tutorial I use the hostname with the IP address These settings might differ for you, so you have to replace them where appropriate. 

2 Installing MySQL 5

To install MySQL, we do this:

#yum -y install mysql mysql-server

Then we create the system startup links for MySQL (so that MySQL starts automatically whenever the system boots) and start the MySQL server:

#chkconfig --levels 235 mysqld on
#/etc/init.d/mysqld start

 Set passwords for the MySQL root account:


[root@server1 ~]# mysql_secure_installation

In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] <-- ENTER
New password: <-- yourrootsqlpassword
Re-enter new password: <-- yourrootsqlpassword
Password updated successfully!

Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] <-- ENTER
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] <-- ENTER
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] <-- ENTER
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] <-- ENTER
... Success!
Cleaning up...

All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!

3 Installing Apache2 

 Apache2 is available as a CentOS package, therefore we can install it like this:

#yum -y install httpd

#chkconfig --levels 235 httpd on

... and start Apache:   

#/etc/init.d/httpd start

Now direct your browser to, and you should see the Apache2 placeholder page:  

Apache's default document root is /var/www/html on CentOS, and the configuration file is /etc/httpd/conf/httpd.conf. Additional configurations are stored in the /etc/httpd/conf.d/ directory. 

4 Installing PHP5

We can install PHP5 and the Apache PHP5 module as follows:

# yum -y install php

#/etc/init.d/httpd restart

5 Testing PHP5 / Getting Details About Your PHP5 Installation

The document root of the default web site is /var/www/html. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

#vi /var/www/html/info.php

Now we call that file in a browser (e.g.

 As you see, PHP5 is working, and it's working through the Apache 2.0 Handler, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don't have MySQL support in PHP5 yet.


6 Getting MySQL Support In PHP5

To get MySQL support in PHP, we can install the php-mysql package. It's a good idea to install some other PHP5 modules as well as you might need them for your applications. You can search for available PHP5 modules like this:

#yum search php

#yum -y install php-mysql

In the next step I will install some common PHP modules that are required by CMS Systems like Wordpress, Joomla and Drupal:

#yum -y install php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy curl curl-devel

APC is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It's similar to other PHP opcode cachers, such as eAccelerator and Xcache. It is strongly recommended to have one of these installed to speed up your PHP page.  

APC can be installed as follows: 

#yum -y install php-pecl-apc  

Now restart Apache2:

#/etc/init.d/httpd restart

Now reload in your browser and scroll down to the modules section again. You should now find lots of new modules there, including the APC module:  

7 phpMyAdmin

phpMyAdmin is a web interface through which you can manage your MySQL databases. 

First we enable the RPMforge repository on our CentOS system as phpMyAdmin is not available in the official CentOS 6.5 repositories:

Import the RPMforge GPG key:

#rpm --import

On x86_64 systems:

#yum -y install 

On i386 systems:

#yum -y install

phpMyAdmin can now be installed as follows:  

#yum -y install phpmyadmin

Now we configure phpMyAdmin. We change the Apache configuration so that phpMyAdmin allows connections not just from localhost (by commenting out the <Directory "/usr/share/phpmyadmin"> stanza):

#vi /etc/httpd/conf.d/phpmyadmin.conf

 Next we change the authentication in phpMyAdmin from cookie to http:


#vi /usr/share/phpmyadmin/

 Restart Apache:

#/etc/init.d/httpd restart  

Afterwards, you can access phpMyAdmin under



Some Links

Tuesday, 3 March 2015

How to configure mikrotik auto backup and backup send to gmail..

Step 1: log in your mikrotik with winbox
Step 2: Click on tools> email

* Server ip is google smtp server ip
* Port  587 (TLS required)
* Tls yes
* from : your email address
* User : your email address
* Password : your email password

Just Finish email set up, Now we are going to configure a scheduler which is send mikrotik back up file to an email...

Step 3: Click on System > Scheduler > Click on "+"  sign

On Event:

/system backup save name=backupemail
/tool e-mail send file=backupemail.backup  to="" body="Dear Sir,\n\n $[/system identity get name]  $[/system clock get date] \n\nThis is Mikrotik Schedule Backup.\nThis Backup will be generate after every three days.\n\n\nAmir Azam\nJunior System Admin.\n" subject="$[/system identity get name]  $[/system clock get time] $[/system clock get date] Backup"

just copy and pest on your scheduler on event box.

backupemail is your mikrotik backup file which is in file,

send file =backupemail.backup

Done! enjoy .....