Server Monitor is an important thing we have to take care .It is a process to monitor the server performance in CPU usage,Memory Consumption,I/O,Network ,Disk usage,Process Speed,Etc.
Monitoring helps to understand the resource available and how it is used.It can help to improve the planning capacity and provide better end user experience.
There are several software's available to monitor the server process.Here i take Cacti software for monitoring the server process.Because the Cacti is a free and open source software and is easy to use ,handle and more comfortable friendly user.
The following steps will clearly guide you to install the cacti for server monitoring purposes.
Monitor your web server:
Step 1 - Installing Apache
It is recommend to update the server before installing the package so that the existing packages and repositories are updated.
yum -y update
Once the system is updated we can proceed for next step installation of Apache web server.
yum -y install httpd
Now start Apache web server and enable it to start using the following command.
systemctl start httpd systemctl enable httpd
Step 2 - Installing PHP
Cacti support all the version of PHP greater than 5.3. But here, we will install PHP 7.1 Installing the latest version of PHP will give the maximum security and better performance of the application.
The default YUM repository of CentOS does not have PHP 7.1 included, hence you will need to add the Webtatic repository in your system.
Webtatic repository requires EPEL repository to work. Run the following command to install EPEL repository.
yum -y install epel-release yum -y update
Type the commands to install Webtatic repository.
pm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm yum -y update
Type the following command to install PHP 7.1 along with all the required dependencies.
yum -y install php71w php71w-snmp php71w-mysqli php71w-cli php71w-ldap php71w-xml php71w-session php71w-sockets php71w-pcre php71w-gd php71w-dom php71w-posix php71w-mbstring
To check if PHP is installed successfully, Enter the below command,
php -v
You should get output similar to this.
[root@liptan-pc ~]# php -v PHP 7.1.6 (cli) (built: Jun 10 2017 07:28:42) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
Now we want to configure few configurations in PHP. Open the PHP configuration file,php.ini using your favourite text editor.
Here i am using nano editor. If you do not have nano installed, you can run
yum -y install nano. nano /etc/php.ini
Find the following line and Uncomment the line and set the timezone according to your region. For example:
[Date] Defines the default timezone used by the date functions http://php.net/date.timezone date.timezone = Asia/Kolkata
Step 3 - Installing MariaDB
MariaDB is a fork of MySQL database. To install MariaDB on your server, run:
yum -y install mariadb mariadb-server
Enter and execute the following commands to start MariaDB and enable it to start at boot time.
systemctl start mariadb systemctl enable mariadb
Now run the following commands to secure your MariaDB installation.
mysql_secure_installation
The above command will run a script to secure fresh MariaDB installation. The script will ask for the existing root user password, we have just installed MariaDB, the root password is not set, just press enter to proceed further.
Now we want to set a root password for the MariaDB installation, choose y and set a strong password for the installation. The output will look like shown below.
To create a database we will need to login to MySQL command line first. Run the following command for same.
mysql -u root -p
The above command will login to MySQL shell of the root user, it will prompt for the password of the root user. Provide the password to login. Now run the following query to create a new database for your Cacti installation.
CREATE DATABASE enter the database name (xxxxxxxx);
The above query will create a new database named xxxxxxxx. We can use any other name for our database if we want. Make sure that you use semicolon at the end of each query as the query always ends with a semicolon.
Once the database is created you can create a new user and grant all the permissions to the user for the database. To create a new database user, run the following query.
CREATE USER '123456789'@'localhost' IDENTIFIED BY 'Password';
The above query will create a user with username 123456789. You can use any username you prefer instead of 123456789. Replace Password with a very strong password as your wish. Now provide the all the privileges to your database user over the database you have created. Run the following command.
GRANT ALL PRIVILEGES ON xxxxxxxx* TO '123456789'@'localhost';
Now run the following command to immediately apply the changes on the database privileges.
FLUSH PRIVILEGES;
Exit from MySQL prompt using the following command.
EXIT;
You will also need to populate the time zone table. Run the following command to populate the timezone tables.
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
Provide the MySQL root password to proceed. Once the tables are populated, you will need to provide select access to Cacti user account over the tables. Login to MySQL prompt again using:
mysql -u root -p
Now run the following query.
GRANT SELECT ON mysql.time_zone_name TO '123456789'@'localhost'; FLUSH PRIVILEGES;
The above query will SELECT give access to cacti_user on
Step 4 - Installing and Configuring Cacti
Cacti require few more dependencies, run the following command to install them.
yum -y install net-snmp rrdtool net-snmp-utils
As we have all the dependencies ready, we can now download the install package from Cacti website.
cd /var/www/html wget http://www.cacti.net/downloads/cacti-1.1.10.tar.gz
You can always find the link to the latest version of the application on Cacti download page. Extract the archive using the following command.
tar xzvf cacti*.tar.gz
Rename your Cacti folder using:
mv cacti-1*/ cacti/
Now import the Cacti database by running the following command.
cd /var/www/html/cacti mysql cacti_data < cacti.sql -u root -p
The above command will import the cacti.sql database into cacti_data using the user root. It will also ask you the password of root user before importing the database.
Now edit Cacti configuration by running the following command.
nano /var/www/html/cacti/include/config.php
Now find the following lines and edit them according to your MySQL database credentials.
/* make sure these values reflect your actual database/host/user/password */ $database_type = 'mysql'; $database_default = 'xxxxxxxx'; $database_hostname = 'localhost'; $database_username = '123456789'; $database_password = 'StrongPassword'; $database_port = '3306'; $database_ssl = false;
Step 5 - Configure Permissions and Firewall
Now you will need to provide the ownership of the application to web server user using the following command.
chown -R apache:apache /var/www/html/cacti
You may also need to allow HTTP traffic on port 80 through the firewall if you are running one. Run the following commands for same.
firewall-cmd --zone=public --permanent --add-service=http firewall-cmd --reload
Now you will need to disable your SELinux because Proxy configuration does not work with SELinux policies. To temporary disable SELinux without restarting the server, run the following command.
setenforce 0
To completely disable the SELinux you will need to edit /etc/selinux/config file.
nano /etc/selinux/config
Find the following line:
SELINUX=enforcing
Change it to:
SELINUX=disabled
Now complete the installation using a web browser, go to the following link using your favourite web browser.
http://Your_Server_IP/cacti
Now we will see the following page.
Accept the license agreement for further process.
In next interface we are going for pre-installation, all the required dependencies are met.
In installation type, choose New Primary Server and proceed next.
In next step, we want to provide the locations to the binaries. Path to RRDTool and PHP binaries are correct. For all other binaries, provide the path /usr/bin/binary_name.
Next change the permissions that the server want to access and wright all the required folders.
In template setup, choose Local Linux Machine and click Finish.
Next it will be taken to the login page. Login using username admin and password admin, you will be taken to dashboard.
Installation of Cacti is now finished, we can use the application to monitor the server using the interactive graphs.
If you know about LAMP in centos and how to configure it click here.