Tag Archives: Linux

Install LAMP Stack on Rocky Linux

Introduction

In this tutorial, How to Install LAMP Stack on Rocky Linux. A LAMP stack, which stands for Linux, Apache, MySQL (or MariaDB), and PHP, is a popular software bundle that provides the necessary components for hosting dynamic websites and web applications. In this tutorial, we’ll walk you through the steps to set up a LAMP stack on a Rocky Linux server.

Prerequisites

Before we begin, ensure that you have:

  • A running Rocky Linux instance
  • Root or sudo privileges
  • A stable internet connection

How to install LAMP Stack on Rocky Linux

Install Apache on Rocky Linux

Apache HTTP Server is one of the most widely used web servers in the world. To install it, run the following command:

dnf install -y httpd httpd-devel httpd-tools

Enable Apache start at boot time

systemctl enable httpd

start the Apache HTTPd daemon

systemctl start httpd

To check Apache running on Rocky Linux

systemctl status httpd

The output terminal is below

Opens a browser that can access your Server’s IP address

http://Your-IP-address
OR
http://domain.com

Install MariaDB on Rocky Linux

Next, you’ll need a database server. You can choose between MariaDB and MySQL. In this example, we’ll use MariaDB. Install it with the following command:

dnf install mariadb-server mariadb

The output terminal as below

Enable MariaDB to start at boot time

systemctl enable --now mariadb

Start the MariaDB daemon

systemctl start mariadb

To check MariaDB running on Rocky Linux

systemctl status mariadb

Additional steps to harden the database server. Run the MariaDB security script to secure your installation:

mysql_secure_installation
Set root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Follow the on-screen prompts to set a root password and improve the security of your database server.

Install PHP on Rocky Linux

The default PHP stream is PHP 7.2. PHP is a server-side scripting language commonly used in web development. Install PHP and the PHP MySQL extension with the following command:

To install the latest module Stream. We will reset the PHP streams.

dnf module reset php

Install PHP 7.4

dnf module install php:7.4

The output terminal is below

Install additional PHP extensions

dnf install php-cli php-gd php-curl php-zip php-mbstring php-opcache php-intl php-mysqlnd

Confirm the version of PHP installed

php -v

The output terminal is below

Test Your Install LAMP Stack

To verify that your LAMP stack is installed and running correctly, create a test PHP file in the Apache web root directory. We’ll use info.php as an example:

We create a test PHP file in the /var/www/html path.

vi /var/www/html/info.php

The content info.php is below

<?php
phpinfo();
?>

Save the changes and restart the webserver.

systemctl restart httpd

Open back browser

http://server-ip/info.php

The output is below

Remove file test PHP

rm -f /var/www/html/info.php

Conclusion

Congratulations! You’ve successfully install LAMP stack on your Rocky Linux server. You now have a powerful platform for hosting websites and web applications. Remember to secure your server, keep your software up to date, and regularly back up your data to ensure a stable and reliable web hosting environment. I hope will this your helpful. Thank you for reading the DevopsRoles page!

This comprehensive guide should equip you with the knowledge to manage and expand your LAMP stack setup. For any further customization or troubleshooting, refer to the official documentation and community forums. Happy coding!

Refer to:

Managing and monitoring swap on Linux

Introduction

This tutorial covers how to manage and monitor swap on Linux, including how to determine the amount of swap space available and how much is currently in use.

Swap space plays an important role in system performance, so it’s crucial to understand how to manage it effectively.

How much swap on Linux do you need?

The recommendation is to swap the space used to double your RAM. If your system has a lot of memory, you may never need to use swap space.

RAM         Swap        Swap (with hibernation)
256MB       256MB       512MB
512MB       512MB       1GB
1GB         1GB         2GB
2GB         1GB         3GB
3GB         2GB         5GB
4GB         2GB         6GB
6GB         2GB         8GB
8GB         3GB         11GB
12GB        3GB         15GB
16GB        4GB         20GB
24GB        5GB         29GB
32GB        6GB         38GB
64GB        8GB         72GB

To determine if your system can hibernate

$ which pm-hibernate

You can test it by running this command:

$ sudo pm-hibernate

View the amount of swap space on Linux

$ swapon --show
$ free -m 
$ sar -S 1 3
$ lsblk

The output terminal is as follows

[vagrant@localhost ~]$ swapon --show
NAME      TYPE SIZE USED PRIO
/swapfile file   2G   9M   -2
[vagrant@localhost ~]$ free -m
              total        used        free      shared  buff/cache   available
Mem:            486         146          93           2         247         325
Swap:          2047           9        2038
[vagrant@localhost ~]$ sar -S 1 3
Linux 3.10.0-1127.el7.x86_64 (localhost.localdomain)    09/13/2021      _x86_64_        (1 CPU)

09:51:08 PM kbswpfree kbswpused  %swpused  kbswpcad   %swpcad
09:51:09 PM   2087884      9264      0.44       416      4.49
09:51:10 PM   2087884      9264      0.44       416      4.49
09:51:11 PM   2087884      9264      0.44       416      4.49
Average:      2087884      9264      0.44       416      4.49
[vagrant@localhost ~]$ lsblk
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda      8:0    0  40G  0 disk
└─sda1   8:1    0  40G  0 part /
[vagrant@localhost ~]$

Creating a swap file

$ sudo dd if=/dev/zero of=/swapfile bs=1M count=8192
$ sudo chmod 600 /swapfile
$ sudo mkswap /swapfile
$ sudo swapon -a
$ swapon --show

Turn to swap off.

$ sudo swapoff -v /swapfile

# The output terminal
[vagrant@localhost ~]$ sudo swapoff -v /swapfile
swapoff /swapfile
[vagrant@localhost ~]$

Turn to swap on Linux.

$ sudo swapon -v /swapfile
$ swapon --show

Conclusion

You have a Managing and monitoring swap on Linux. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Guide to Install Python 3.6 on Centos 6

Introduction

OS Centos 6 is the default Python version 2. How to Install Python 3.6 on Centos 6. Python is a powerful and flexible programming language widely used in various fields such as web development, data science, artificial intelligence, and DevOps. Python 3.6 brings many improvements and new features, enhancing performance and security.

In this article, we will guide you through the process of installing Python 3.6 on CentOS 6, one of the popular Linux operating systems for server environments. This installation will allow you to take full advantage of Python 3.6 in your projects.

Installation packages pre-requisites

sudo yum -y install gcc openssl-devel bzip2-devel wget

How to Install Python 3.6 on Centos 6

cd /tmp/
wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz
tar xzf Python-3.6.6.tgz
cd Python-3.6.6
./configure --enable-optimizations
sudo make altinstall

Create symbolic link

sudo ln -sfn /usr/local/bin/python3.6 /usr/bin/python3.6

Python verifying new version.

[huupv2@server1 ~]$ python -V
Python 3.6.6

The result is Python 3.6 on Centos 6.

[huupv2@server1 ~]$ cat /etc/redhat-release
CentOS release 6.5 (Final)
[huupv2@server1 ~]$ ll /usr/bin/python*
-rwxr-xr-x 2 root root 4864 Aug 18  2016 /usr/bin/python
lrwxrwxrwx 1 root root    6 Jul 19  2018 /usr/bin/python2 -> python
-rwxr-xr-x 2 root root 4864 Aug 18  2016 /usr/bin/python2.6
lrwxrwxrwx 1 root root    9 Mar  8 13:26 /usr/bin/python3 -> python3.4
-rwxr-xr-x 2 root root 6088 Oct  5  2019 /usr/bin/python3.4
-rwxr-xr-x 2 root root 6088 Oct  5  2019 /usr/bin/python3.4m
lrwxrwxrwx 1 root root   24 Mar  8 14:45 /usr/bin/python3.6 -> /usr/local/bin/python3.6

Configure alias python on .bashrc file

[huupv2@server1 ~]$ cat .bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# User specific aliases and functions
alias python='/usr/bin/python3.6'

Check Python version 3.6 on Centos 6

[huupv2@server1 ~]$ python
Python 3.6.6 (default, Mar  8 2021, 14:41:43)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
[huupv2@server1 ~]$

Conclusion

You have to install Python 3.6 on Centos 6. Installing Python 3.6 on CentOS 6 may present some challenges, but with this detailed guide, you can easily accomplish it. Python 3.6 will open up many new opportunities for your projects, from web application development to data processing and automating DevOps workflows.

We wish you success in installing and leveraging the full potential of Python 3.6 on CentOS 6. If you encounter any difficulties, don’t hesitate to contact us or refer to community support resources. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to change MySQL Data Directory on Ubuntu: A Step-by-Step Guide

Introduction

In this tutorial, How To Move a MySQL Data Directory to a New Location on Ubuntu. I will change MySQL Data Directory on Ubuntu. Managing databases efficiently is crucial for any application, and sometimes this involves changing the data directory for MySQL. Whether you need to move your MySQL data to a different partition for better performance or to manage storage, this task can seem daunting.

This guide will walk you through the process of changing the MySQL data directory on an Ubuntu system, ensuring your database remains secure and operational. Let’s dive in and make this transition smooth and straightforward.

Change MySQL Data Directory on Ubuntu

Identify Current MySQL Data Directory

mysql -u username -p -e “SELECT @@datadir”

For example, the current data directory is ‘/var/lib/mysql

Stop MySQL service

service mysql stop

Backup existing MySQL data directory or copy recursively the contents of ‘/var/lib/mysql’ to ‘/data/mysql-data’

tar -cvf mysql.tar /var/lib/mysql
#or
cp -rap /var/lib/mysql/* /data/mysql-data

Create a new data directory with proper permissions

mkdir -p /data/mysql
chown mysql:mysql /data/mysql

Using the Rsync command Migrate existing data into the new location

nohup rsync -avp /var/lib/mysql/ /data/mysql

Configure the new MySQL Data Directory

Edit the MySQL default configuration file /etc/my.cnf

datadir = /data/mysql

Change the AppArmor data directory in file /etc/apparmor.d/usr.sbin.mysqld

# Replace the lines beginning with /var/lib/mysql into /data/mysql
:%s/\/var\/lib\/mysql/\/data\/mysql/g

Start MySQL service

service mysql start

Verify the location change of the new data directory as the command follows

mysql -u username -p -e “SELECT @@datadir”

Checking issue during MySQL startup check MySQL log file /var/log/mysqld.log for any errors.

Conclusion

You have change MySQL Data Directory on Ubuntu. By following this guide, you have learned how to safely relocate your MySQL data, ensuring your system’s efficiency and reliability. Regular maintenance and updates, along with proper data management, are key to sustaining the performance and security of your MySQL databases. Keep these practices in mind to maintain a robust and scalable database environment. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Install PIP on Centos 8

Introduction

In this tutorial. How to install pip on Centos 8. Pip is a package management system that allows you to install, remove, and otherwise manage software packages written in Python.

How to Install PIP on Centos 8

Two Python versions are Python 2 and Python 3.

Install pip3 for Python 3

sudo dnf install python3

The output is as below:

[devopsroles@server1 ~]$ sudo dnf install python3
[sudo] password for devopsroles: 
Last metadata expiration check: 0:07:32 ago on Wed 02 Sep 2020 09:15:00 PM +07.
Dependencies resolved.
==========================================================================================================
 Package                  Architecture Version                                      Repository       Size
==========================================================================================================
Installing:
 python36                 x86_64       3.6.8-2.module_el8.1.0+245+c39af44f          AppStream        19 k
Installing dependencies:
 python3-pip              noarch       9.0.3-16.el8                                 AppStream        19 k
 python3-setuptools       noarch       39.2.0-5.el8                                 BaseOS          162 k
Enabling module streams:
 python36                              3.6                                                               

Transaction Summary
==========================================================================================================
Install  3 Packages

Total download size: 201 k
Installed size: 466 k
Is this ok [y/N]: y
Downloading Packages:
(1/3): python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64.rpm            7.3 kB/s |  19 kB     00:02    
(2/3): python3-pip-9.0.3-16.el8.noarch.rpm                                7.1 kB/s |  19 kB     00:02    
(3/3): python3-setuptools-39.2.0-5.el8.noarch.rpm                          52 kB/s | 162 kB     00:03    
----------------------------------------------------------------------------------------------------------
Total                                                                      43 kB/s | 201 kB     00:04     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                  1/1 
  Installing       : python3-setuptools-39.2.0-5.el8.noarch                                           1/3 
  Installing       : python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64                              2/3 
  Running scriptlet: python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64                              2/3 
  Installing       : python3-pip-9.0.3-16.el8.noarch                                                  3/3 
  Running scriptlet: python3-pip-9.0.3-16.el8.noarch                                                  3/3 
  Verifying        : python3-pip-9.0.3-16.el8.noarch                                                  1/3 
  Verifying        : python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64                              2/3 
  Verifying        : python3-setuptools-39.2.0-5.el8.noarch                                           3/3 

Installed:
  python3-pip-9.0.3-16.el8.noarch                            python3-setuptools-39.2.0-5.el8.noarch       
  python36-3.6.8-2.module_el8.1.0+245+c39af44f.x86_64       

Complete!

Check version pip

pip3 --version

The output as below

[devopsroles@server1 ~]$ pip3 --version
pip 9.0.3 from /usr/lib/python3.6/site-packages (python 3.6)

To install and build Python modules with pip, you need to install the Development tools:

sudo yum install python3-devel
sudo yum groupinstall 'development tools'

Installing pip2 for Python 2

sudo dnf install python2
pip2 --version
sudo yum install python2-devel
sudo yum groupinstall 'development tools'

For example, I have installed two python3 and python2 on Centos 8 as below

[devopsroles@server1 ~]$ sudo yum list installed | grep pip
libpipeline.x86_64                          1.5.0-2.el8                           @anaconda 
platform-python-pip.noarch                  9.0.3-16.el8                          @anaconda 
python2-pip.noarch                          9.0.3-16.module_el8.2.0+381+9a5b3c3b  @AppStream
python2-pip-wheel.noarch                    9.0.3-16.module_el8.2.0+381+9a5b3c3b  @AppStream
python3-pip.noarch                          9.0.3-16.el8                          @AppStream
python3-pip-wheel.noarch                    9.0.3-16.el8                          @anaconda 

Managing Python Packages with pip

Typically, you should use pip inside a virtual environment only. It is used when separating the Python execution environment, such as when you want to change the Python execution environment for each project or you do not want to keep the local environment dirty venv.

In this section, we will go through several basic pip commands.

To install a package

pip install flask

If you want to install a specific version of the package

pip install flask==1.0.0

Uninstall a package

pip uninstall package_name

Search packages

pip search "package_name"

View the full list of packages

pip list

List outdated packages:

pip list --outdated

To upgrade an already installed package

pip3 install --upgrade package_name

Check pip dependencies

pip check

List of packages that need updating

pip list -o

Show packages by package name == version

pip freeze

Useful when outputting to requirements.txt

pip freeze > requirements.txt

Package update

pip install  -U package_name

Update pip itself

pip install  -U pip

Checking the details of the package

pip show package-name

Conclusion

How to install pip on CentOS 8 and how to easily install and uninstall Python modules with pip. Thank you for reading the DevopsRoles page!

Initial Server Setup Centos 8

Introduction

When launching a new server with CentOS 8, ensuring a secure and properly configured foundation is essential. Whether you’re setting up a VPS for the first time or deploying infrastructure for production, a systematic initial server setup will help harden your system and prepare it for future installations. In this guide, we’ll walk through the essential steps to Initial Server Setup CentOS 8 server – from creating a non-root sudo user to configuring your firewall and installing core utilities.

Update Your System

Before any configuration, ensure that your system is up to date. This not only secures your server but also ensures compatibility with future installations:

sudo dnf update -y
sudo dnf upgrade -y

Create a Sudo User and Granting Administrative Privileges

useradd devopsroles
passwd devopsroles
usermod -aG wheel devopsroles
su - devopsroles

The output terminal as below

Open a new terminal window

ssh devopsroles@SERVER_IP_ADDRESS

Disable SSH Root Login

We have new account. so, I can secure our server by disabling remote SSH account to the root account.

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_BK
sudo sed -i -e 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
sudo cat /etc/ssh/sshd_config | grep PermitRootLogin

The output terminal as below

we need to restart the SSH

sudo systemctl reload sshd

Changing the hostname

sudo hostnamectl set-hostname server1.devopsroles.com

Setting Up a Basic Firewall CentOS 8

Firewalld is a firewall management tool for Linux operating systems. you need to make sure that the server firewall allows web access.

sudo firewall-cmd --add-service=http --permanent
sudo systemctl enable firewalld
sudo systemctl start firewalld
sudo systemctl status firewalld

Update CentOS 8 System

sudo yum check-update
sudo yum upgrade -y
sudo yum clean all

Install System Utilities

sudo yum -y install bind-utils net-tools  psmisc traceroute tree vim-enhanced wget

Conclusion

By following this initial server setup guide for CentOS 8, you’ve established a secure and functional baseline for your system. Creating a non-root user with sudo privileges, securing SSH access, enabling the firewall, and installing essential tools are critical steps to ensure stability, security, and readiness for production workloads. With this solid foundation, you’re now well-prepared to deploy applications, configure services, or automate infrastructure tasks confidently.

For ongoing security, remember to regularly update your system and monitor user access and services. If you’re planning to install a web server, database, or other services next, this setup ensures you start from a well-configured environment. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Using Netdata to Monitor PHP-FPM

In this tutorial, How to Monitor the PHP-fpm using Netdata on Centos 7. Netdata is a free open source. It is very easy to install and configure for real-time monitoring. Now, let’s go to Netdata to Monitor PHP-FPM.

PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI. It is commonly used in LEMP ( Linux Nginx MySQL/MariaDB PHP) stack; Nginx uses PHP FastCGI for serving dynamic HTTP content.

Steps install and configure

  • Centos 7 Server or RHEL 7 Server
  • Install PHP and enable PHP-FPM status
  • Install Netdata and configure Monitor for PHP-FPM status.

1. How to Install PHP

For example, How to install PHP version 7.3 on Centos 7.

2. Enable the PHP-FPM status page.

Check php-fpm running on your system.

[root@DevopsRoles vagrant]# netstat -nplt | grep php-fpm
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      4328/php-fpm: maste 
[root@DevopsRoles vagrant]# ps -ef | grep php
root      4328     1  0 21:50 ?        00:00:00 php-fpm: master process (/etc/opt/remi/php73/php-fpm.conf)
apache    4329  4328  0 21:50 ?        00:00:00 php-fpm: pool www
apache    4330  4328  0 21:50 ?        00:00:00 php-fpm: pool www
apache    4331  4328  0 21:50 ?        00:00:00 php-fpm: pool www
apache    4332  4328  0 21:50 ?        00:00:00 php-fpm: pool www
apache    4333  4328  0 21:50 ?        00:00:00 php-fpm: pool www
root      4381  3003  0 21:52 pts/0    00:00:00 grep --color=auto php

Configure file php-fpm status as shown.

$ sudo vim /etc/php-fpm.d/www.conf 
OR
$ sudo vim /etc/opt/remi/php73/php-fpm.d/www.conf	#for PHP versions 7.0, 7.1,7.3 vvv

You find and uncomment the variable pm.status_path = /status as shown in the screenshot.

[root@DevopsRoles vagrant]# cat /etc/opt/remi/php73/php-fpm.d/www.conf | grep pm.status_path
pm.status_path = /status

Save the changes and exit the file.

Check the PHP-FPM configuration file for any errors

$ sudo php-fpm -t
OR
$ sudo systemctl restart php73-php-fpm

Create a new Nginx config for PHP-FPM as shown

[root@DevopsRoles ~]# vi /etc/nginx/conf.d/php-fpm.conf

# The content as below:

    server {

        listen       80;
        #listen       [::]:80 default_server;
        server_name  127.0.0.1;

    location  /status {
        access_log off;
        allow 127.0.0.1;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index index.php;
        deny all;
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
   }
   }

Reload PHP-FPM and Nginx config for changes to take effect.

[root@DevopsRoles ~]# systemctl reload php73-php-fpm
[root@DevopsRoles ~]# systemctl reload nginx

Now, Use the curl command to check php-fpm status.

root@DevopsRoles ~]# curl http://127.0.0.1/status
pool:                 www
process manager:      dynamic
start time:           18/Jul/2020:10:16:17 +0700
start since:          878
accepted conn:        14
listen queue:         0
max listen queue:     0
listen queue len:     128
idle processes:       4
active processes:     1
total processes:      5
max active processes: 1
max children reached: 0
slow requests:        0

Memo: meaning of different values of PHP-FPM Status

-pool – the name of the pool.
-process manager – possible values static, dynamic or ondemand. We never use static.  Trying ondemand is on todo list.
-start time – the date and time FPM has started or reloaded.
-start since – number of seconds since FPM has started
-accepted conn – the number of request accepted by the pool
-listen queue – the number of request in the queue of pending connections. If this number is non-zero, then you better increase number of process FPM can spawn.
-max listen queue – the maximum number of requests in the queue of pending connections since FPM has started
-listen queue len – the size of the socket queue of pending -connections
-idle processes – the number of idle processes
-active processes – the number of active processes
-total processes – the number of idle + active processes
-max active processes – the maximum number of active processes since FPM has started
-max children reached – number of times, the process limit has been reached, when pm tries to start more children. If that value is not zero, then you may need to increase max process limit for your PHP-FPM pool. Like this, you can find other useful information to tweak your pool better way.
-slow requests – Enable php-fpm slow-log before you consider this. If this value is non-zero you may have slow php processes. Poorly written mysql queries are generally culprit.

3. Install Netdata on Centos 7 here

4. Configure Netdata to Monitor PHP-FPM

The Netdata configure for Nginx in folder /etc/netdata/python.d which is written in YAML format.

You can open it or create a new file php-fpm.conf as shown

[root@DevopsRoles python.d]# cat /etc/netdata/python.d/php-fpm.conf 
# The output as below:
localhost:
  name : 'local'
  url  : 'http://localhost/status'

localipv4:
  name : 'local'
  url  : 'http://127.0.0.1/status'

Restart Netdata Server

[root@DevopsRoles ~]# systemctl restart netdata 

5. Using Netdata to Monitor PHP-FPM

Open a web browser access the netdata web UI.

http://NETDATA_SERVER_IP:19999
or
http://DOMAIN_NAME:19999

The result as the picture below

Conclusion

Through the article, you can use Netdata to monitor PHP-FPM. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Using Netdata to Monitor Nginx

In this tutorial, How to Monitor the Nginx using Netdata on Centos 7. Netdata is a free open source. It is very easy to install and configure for real-time monitoring.

Steps install and configure

  • Centos 7 Server or RHEL 7 Server
  • Install Web Server Nginx
  • Install Netdata and configure Monitor for Web Server Nginx.

1. Install Web Server Nginx

Enable EPEL repository

[root@DevopsRoles ~]# yum install epel-release

Install the Nginx package, as follows.

[root@DevopsRoles ~]# yum install nginx

Start and enable Nginx Web Server, as follows.

[root@DevopsRoles ~]# systemctl start nginx
[root@DevopsRoles ~]# systemctl enable nginx
[root@DevopsRoles ~]# systemctl status nginx

If you are running a firewall. You need to open port 80/443 for Nginx Webserver.

Enable Nginx Stub_Status Module

I will enable the stub_status module which netdata uses to collect metrics from your Nginx web server.

[root@DevopsRoles ~]# vi /etc/nginx/nginx.conf

Copy and paste the location configuration as below

location /server_status {
 	stub_status;
 	allow 127.0.0.1;	#only allow requests from localhost
 	deny all;		#deny all other hosts	
 }

restart the Nginx service to effect

[root@DevopsRoles ~]# nginx -t
[root@DevopsRoles ~]# systemctl restart nginx

Now, Use curl command to check

curl http://127.0.0.1/server_status

# The output terminal as below:
[root@DevopsRoles ~]# curl http://127.0.0.1/server_status
Active connections: 1 
server accepts handled requests
 1 1 1 
Reading: 0 Writing: 1 Waiting: 0

3. Install Netdata on Centos 7 here

4. Configure Netdata to Monitor Nginx

The Netdata configure for Nginx in folder /etc/netdata/python.d which is written in YAML format.

You can open it or create a new file nginx.conf as below

[root@DevopsRoles python.d]# cat /etc/netdata/python.d/nginx.conf 
# The output as below:
localhost:
  name : 'local'
  url  : 'http://localhost/server_status'

localipv4:
  name : 'local'
  url  : 'http://127.0.0.1/server_status'

Restart Netdata Server

[root@DevopsRoles ~]# systemctl restart netdata 

5. Using Netdata to Monitor Nginx Web Server

Open a web browser access the netdata web UI.

http://NETDATA_SERVER_IP:19999
or
http://DOMAIN_NAME:19999

The result as the picture below

Conclusion

Through the article, you can use Netdata to monitor Nginx. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Using Netdata to Monitor MariaDB Database

In this tutorial, How to Monitor the MariaDB database using Netdata on Centos 7. Netdata is a free open source. It is very easy to install and configure for real-time monitoring.

Steps install and configure

  • Centos 7 Server or RHEL 7 Server
  • Install MariaDB Database
  • Install Netdata and configure Monitor for MariaDB Database.

1. Install MariaDB Database

Adding MariaDB YUM software repository.

[root@DevopsRoles ~]# vim /etc/yum.repos.d/MariaDB.repo

The content file MariaDB.repo is as follows.

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

Install the MariaDB package, as follows.

[root@DevopsRoles ~]# yum install MariaDB-server MySQL-python MariaDB-client -y

Start and enable MariaDB Database Server, as follows.

[root@DevopsRoles ~]# systemctl start mariadb
[root@DevopsRoles ~]# systemctl enable mariadb
[root@DevopsRoles ~]# systemctl status mariadb

By default, the MySQL installation is unsecure and you need to secure it, as follows

[root@DevopsRoles ~]# mysql_secure_installation

To create this user MariaDB

MariaDB [(none)]> create user 'netdata'@'localhost'; 
MariaDB [(none)]> grant usage on *.* to 'netdata'@'localhost'; 
MariaDB [(none)]> flush privileges; 

If you are running a firewall. You need to open the port 3306 for MariaDB Database

3. Install Netdata on Centos 7 here

4. Configure Netdata to Monitor MariaDB

The netdata configure for MariaDB in folder /etc/netdata/python.d which is written in YAML format.

You can open it or create a new file mysql.conf as below

[root@DevopsRoles python.d]# cat /etc/netdata/python.d/mysql.conf 
localhost:
  name : 'local'
  user : 'netdata'
  port : '3306'

Restart Netdata Server

[root@DevopsRoles ~]# systemctl restart netdata 

5. Using Netdata to Monitor MariaDB Database

Open a web browser access the netdata web UI.

http://NETDATA_SERVER_IP:19999
or
http://DOMAIN_NAME:19999

The result as the picture below

Netdata debug for mariadb

/usr/libexec/netdata/plugins.d/python.d.plugin 1 debug mysql

Error netdata for MariaDB code (Fixed)

2020-07-05 16:32:37: python.d ERROR: mysql[localhost] : MySQLdb or PyMySQL module is needed to use mysql.chart.py plugin

On My Centos missing MySQL-python package

Conclusion

Through the article, you can use Netdata to Monitor MariaDB Database. I hope will this your helpful.

Using Netdata to Monitor Apache Performance

In this tutorial, How to Monitor Apache Performance using Netdata on Centos 7. Netdata is a free open source. It is very easy to install and configure for real-time monitoring.

Steps install and configure

  • Centos 7 Server or RHEL 7 Server
  • Install Apache HTTP Server with mod_status_module enabled
  • Install Netdata and configure Monitor for Apache HTTP Server.

1. Install Apache HTTP server

First, install the Apache HTTP server on Centos. I will Yum package manager to install Apache.

[root@DevopsRoles ~]# yum install httpd

Start and enable Apache HTTP server.

[root@DevopsRoles ~]# systemctl start httpd
[root@DevopsRoles ~]# systemctl enable httpd
[root@DevopsRoles ~]# systemctl status httpd

If you are running a firewall. You need to open ports 80 and 443 for Apache.

2. Enable mod_status module in Apache

You need to enable and configure the mod_status module in apache, This is required by Netdata.

[root@DevopsRoles ~]# cat /etc/httpd/conf.modules.d/00-base.conf | grep mod_status
LoadModule status_module modules/mod_status.so

Create a server-status.conf for the Apache server-status page as below

[root@DevopsRoles ~]# cat /etc/httpd/conf.d/server-status.conf
<Location "/server-status">
    SetHandler server-status
    #Require host localhost           #uncomment to only allow requests from localhost 
</Location>

Restart Apache HTTP Server

[root@DevopsRoles ~]# systemctl restart httpd

Test working Apache Server status page.

[root@DevopsRoles ~]# curl http://localhost/server-status  

3. Install Netdata on Centos 7 here

4. Configure Netdata to Monitor Apache Performance

The Netdata configure for Apache in folder /etc/netdata/python.d

You can open it or create new file apache.conf as below

[root@DevopsRoles ~]# cat /etc/netdata/python.d/apache.conf
localhost:
  name : 'local'
  url  : 'http://localhost/server-status?auto'

localipv4:
  name : 'local'
  url  : 'http://127.0.0.1/server-status?auto'

Restart netdata server

[root@DevopsRoles ~]# systemctl restart netdata 

5. Using Netdata to Monitor Apache Performance

Open a web browser access the Netdata web UI.

http://NETDATA_SERVER_IP:19999
or
http://DOMAIN_NAME:19999

The result as below

Conclusion

Thought the article, you can use Netdata to monitor Apache Performance. I hope will this your helpful.