Published February 28, 2018 by

Install Nginx on CentOS/RedHat 7

Nginx is a high-performance web server software. It is a much more flexible and lightweight program than Apache Web Server.

It also works as a reverse proxy, standard mail, and TCP/UDP proxy server, and can additionally be configured as a load balancer. It is powering many sites on the web; well known for its high-performance, stability and feature-rich set.



In This tutorial, I will explain to you how to install and start Nginx on your CentOS 7 server.

Few things that you need to keep in mind about Nginx
  • Nginx installed in /etc/nginx.
  • Nginx Configuration file under /etc/nginx/nginx.conf.
  • Nginx virtual hosts configurations file under /etc/nginx/conf.d.
  • The default server document root directory (contains web files) in /usr/share/nginx/html.
      First, update server system

      # sudo yum update -y

      Add the CentOS 7 EPEL repository (For CentOS Only)

      # sudo yum install epel-release

      Add Redhat Nginx repository (For Redhat Only)

      rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

      Install Nginx

      # sudo yum install nginx

      Start Nginx

      # sudo systemctl start nginx
      # sudo systemctl enable nginx
      # sudo systemctl status nginx

      Setting firewall for run HTTP and HTTPS traffic

      # sudo firewall-cmd --permanent --zone=public --add-service=http
      # sudo firewall-cmd --permanent --zone=public --add-service=https
      # sudo firewall-cmd --reload

      Now Go to Browser and hit http://server_domain_name_or_IP/

      If you show this screen, that means you are successfully installed and configures Nginx.
      Read More
      Published February 23, 2018 by

      How to Change Hostname in Ubuntu

      This is a simple and short article for show How to Change Hostname (Computer Name) in Ubuntu/Debian based distribution Linux OS.

      1. Display current hostname

      # hostname

      2. Change Hostname

      # hostname new_host_name

      This command temporary set a hostname for your system until next reboot.


      3. To change the hostname permanently, run below command to edit the host files /etc/hostname.

      # sudo vim /etc/hostname

      In /etc/hostname file give new hostname what you want and save them.


      4. Finally, restart your system to apply the changes.

      # reboot
      Read More
      Published February 23, 2018 by

      Configure Master to Master MySQL Database Replication

      MySQL replication is the process of MySQL database live-copied to another MySQL server. master-master replication allows data to be copied from either server to the other one.This configuration adds redundancy and increases efficiency when dealing with accessing the data.



      In this example, I take two servers, named Server 1 and Server 2. and Ubuntu environment.

      Server 1:  192.168.0.11
      Server 2:  192.168.0.22

      Install Mysql

      Install MySQL on both servers using the following command

      # sudo apt-get update
      # sudo apt-get upgrade
      # sudo apt-get install mysql-server mysql-client

      Edit MySQL’s Configuration File

      Edit the /etc/mysql/mysql.conf.d/mysqld.cnf file on both servers.

      # vim /etc/mysql/mysql.conf.d/mysqld.cnf

      Add or modify the following data:

      Server 1:

      server_id           = 1
      log_bin             = /var/log/mysql/mysql-bin.log
      log_bin_index       = /var/log/mysql/mysql-bin.log.index
      relay_log           = /var/log/mysql/mysql-relay-bin
      relay_log_index     = /var/log/mysql/mysql-relay-bin.index
      expire_logs_days    = 10
      max_binlog_size     = 100M
      log_slave_updates   = 1
      auto-increment-increment = 2
      auto-increment-offset = 1
      bind-address = 192.168.0.11

      Server 2:

      server_id           = 2
      log_bin             = /var/log/mysql/mysql-bin.log
      log_bin_index       = /var/log/mysql/mysql-bin.log.index
      relay_log           = /var/log/mysql/mysql-relay-bin
      relay_log_index     = /var/log/mysql/mysql-relay-bin.index
      expire_logs_days    = 10
      max_binlog_size     = 100M
      log_slave_updates   = 1
      auto-increment-increment = 2
      auto-increment-offset = 2
      bind-address = 192.168.0.22

      Restart MySQL on both Servers

      # sudo service mysql restart

      Create Replication Users on Both Servers

      1. Log in to MySQL on servers 1

      # mysql -u root -p

      2. Configure the replication users on server 1

      # GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.0.22' IDENTIFIED BY 'password';

      3. Log in to MySQL on servers 2

      # mysql -u root -p

      4. Configure the replication users on server 2

      # GRANT REPLICATION SLAVE ON *.* TO 'replication'@'192.168.0.11' IDENTIFIED BY 'password';

      Configure Database Replication

      1. Log into MySQL on Server 1, query the master status:

      # SHOW MASTER STATUS;

      2. Log into MySQL on Server 2, and insert below command

      STOP SLAVE;
      CHANGE MASTER TO master_host='192.168.0.11', master_port=3306, master_user='replication', master_password='password', master_log_file='mysql-bin.000001', master_log_pos=460;
      START SLAVE;

      3. Query for the master status:

      # SHOW MASTER STATUS;

      4. Log into MySQL on Server 1, and insert below command









      STOP SLAVE;
      CHANGE MASTER TO master_host='192.168.0.22', master_port=3306, master_user='replication', master_password='password', master_log_file='mysql-bin.000001', master_log_pos=461;
      START SLAVE;

      Now master-master replication configuration done. it's time to test.

      Test Replication Configuration

      Server 1:

      create database Subhash;
      create table Subhash.serverkaka (`id` varchar(10));

      Server 2:

      show tables in Subhash;

      When queried, we should see the tables from Server 1 replicated on Server 2.
      Read More
      Published February 21, 2018 by

      Install Oracle JAVA 9 on CentOS/RedHat

      Oracle JAVA 9 stable release version is available to download and install.This tutorial will show you step by step instructions to install Oracle Java 9 on Centos/RedHat 7 system.
      Install Java 9

      Download latest Java SE Development Kit 9 release using following commands.

      # wget --no-cookies --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie"   http://download.oracle.com/otn-pub/java/jdk/9.0.4+11/c2514751926b4512b076cc82f959763f/jdk-9.0.4_linux-x64_bin.tar.gz

      # tar zxf jdk-9.0.4_linux-x64_bin.tar.gz -C /usr/local

      After extracting java file use alternatives command to install it. alternatives command is available in chkconfig package.

      # cd /usr/local/jdk-9.0.4/
      # alternatives --install /usr/bin/java java /usr/local/jdk-9.0.4/bin/java 2
      # alternatives --config java





      Setup javac and jar commands path using alternatives:

      # alternatives --install /usr/bin/jar jar /usr/local/jdk-9.0.4/bin/jar 2
      # alternatives --install /usr/bin/javac javac /usr/local/jdk-9.0.4/bin/javac 2
      # alternatives --set jar /usr/local/jdk-9.0.4/bin/jar
      # alternatives --set javac /usr/local/jdk-9.0.4/bin/javac

      Verify Installed Java Version

      # java -version







      Setup Java Environment

      Setup JAVA_HOME, PATH environment variables

      # export JAVA_HOME=/usr/local/jdk-9.0.4
      # export PATH=$PATH:/usr/local/jdk-9.0.4/bin

      Also insert above environment variables in /etc/environment file.
      Read More
      Published February 21, 2018 by

      Install Oracle JAVA 9 on Ubuntu/Linuxmint

      Oracle JAVA 9 stable release version is available to download and install.This tutorial will show you step by step instructions to install Oracle Java 9 on Ubuntu/Debian system using PPA.
      Install Java 9

      For Install JAVA 9 we need to add the webupd8team Java 9 PPA in our system. Install Oracle JAVA 9 using the following commands.

      # sudo add-apt-repository ppa:webupd8team/java
      # sudo apt-get update
      # sudo apt-get install oracle-java9-installer

      Verify Installed Java Version

      # java -version







      Setup Java Environment Variable

      # sudo apt-get install oracle-java9-set-default

      JAVA installation will create a configuration file /etc/profile.d/jdk.sh for the Java environment settings. The system will automatically load these settings on every reboot to set up Java environment.
      Read More
      Published February 20, 2018 by

      How To Change Windows Command Prompt Font and Background Color

      Here we show how to add a splash of color to Command Prompt and make it unique. By default, Windows Command Prompt is white text on a black background. It gets the job done, but maybe you want to add some color to it.


      To get an overview of what we can do with the color command, use below command:

      color /?


      If you want to get color Green type color A

      color A


      If you want to get purple color type color 5

      color 5 


      If you want to back with default color type only color

      color


      Customize cmd background color

      Click on the Command Prompt icon in the top left corner of the window and select Properties.

      Select the Colors tab, and then choose the color you want for the screen text and background.


      We can also change your Command Prompt font from the font tab.

      Read More
      Published February 16, 2018 by

      Install and Configure Nagios on Ubuntu/Debian



      Nagios is a free Monitoring Tool, It’s Provides you Monitoring environment to always keep an eye on your all Networks/systems from anywhere.

      With Nagios, you can monitor your remote hosts and their services remotely in a single window. It shows warnings and indicates if something goes wrong on your servers which eventually helps us to detect some problems before they occur. It helps us to reduce downtime and business losses.

      Few things that you need to keep in mind about Nagios
      • Nagios installed in /usr/local/nagios/.
      • Nagios Plugins are installed under /usr/local/nagios/libexec/.
      • Nagios will be configured to monitor few services of your local machine like Disk Usage, CPU Load, Current Users, Total Processes, etc...
      • Nagios main Page located under /usr/local/nagios/share/index.php
      • Nagios Templates are stored at /usr/local/nagios/etc/objects/templates.cfg
      • Nagios Configuration file under /usr/local/nagios/etc/objects/contacts.cfg
      • All Host files are added in this location /usr/local/nagios/etc/objects

      Install Required Dependencies

      We need to install Apache, PHP and some libraries like wget, unzip, gcc, glibc, glibc-common and GD libraries and its development libraries before installing Nagios 4.3.4 with the source.

      # sudo apt update
      # sudo apt install wget build-essential unzip openssl libssl-dev
      # sudo apt install apache2 php7.0 apache2-mod-php7.0 php7.0-gd libgd-dev 

      Create Nagios User and Group

      Create a new nagios user and nagcmd group account and add both the nagios user and the apache user to the nagcmd group.

      # adduser nagios
      # groupadd nagcmd
      # usermod -a -G nagcmd nagios
      # usermod -a -G nagcmd www-data

      Download Nagios Core and Nagios Plugin


      Create a directory for your Nagios installation.

      # mkdir /root/nagios
      # cd /root/nagios

      Download latest Nagios Core 4.3.4 and Nagios plugins 2.2.1 packages.

      # wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.4.tar.gz
      # wget http://www.nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

      Extract Nagios Core and its Plugins

      Extract downloaded package.

      # tar xzf nagios-4.3.4.tar.gz
      # tar xzf nagios-plugins-2.2.1.tar.gz

      Configure Nagios Core

      Now we will configure Nagios Core.

      # cd nagios-4.3.4/
      # ./configure --with-command-group=nagcmd

      After configuring, we need to compile and install all the binaries with make all and make install command, it will install all the needed libraries on your machine.

      # make all
      # make install

      Install the init scripts, command-mode and sample nagios file for Nagios.

      # make install-init
      # make install-commandmode
      # make install-config

      Copy event handlers scripts under libexec directory. These binaries provide multiple events triggers for your Nagios web interface.

      # cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
      # chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

      Create nagios apache2 configuration file.

      # sudo vim /etc/apache2/conf-available/nagios.conf

      Add the following lines in nagios.conf

      ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
       <Directory "/usr/local/nagios/sbin">
         Options ExecCGI
         AllowOverride None
         Order allow,deny
         Allow from all
         AuthName "Restricted Area"
         AuthType Basic
         AuthUserFile /usr/local/nagios/etc/htpasswd.users
         Require valid-user
      </Directory>
       Alias /nagios "/usr/local/nagios/share"
      <Directory "/usr/local/nagios/share">
         Options None
         AllowOverride None
         Order allow,deny
         Allow from all
         AuthName "Restricted Area"
         AuthType Basic
         AuthUserFile /usr/local/nagios/etc/htpasswd.users
         Require valid-user
      </Directory>

      using systemd for managing process can enable nagios with systemd using following commands.

      # sudo cp /etc/init.d/skeleton /etc/init.d/nagios
      # sudo vim /etc/init.d/nagios

      Add the following lines in nagios

      DESC="Nagios"
      NAME=nagios
      DAEMON=/usr/local/nagios/bin/$NAME
      DAEMON_ARGS="-d /usr/local/nagios/etc/nagios.cfg"
      PIDFILE=/usr/local/nagios/var/$NAME.lock

      Install and Configure Web Interface for Nagios

      The below command will Configure Web interface for Nagios and a web admin user will be created "nagiosadmin" also set password for "nagiosadmin"

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

      Restart Apache

      # sudo a2enconf nagios
      # sudo a2enmod cgi rewrite
      # sudo service apache2 restart

      Compile and Install Nagios Plugin

      We have downloaded Nagios plugins in /root/nagios, Go there and configure and install it.

      # cd /root/nagios/nagios-plugins-2.2.1/
      # ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
      # make
      # make install

      Verify Nagios Configuration Files

      We are done with the Nagios configuration.Now, It’s time to verify it

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

      Add Nagios Services to System Startup

      # systemctl enable nagios
      # systemctl enable apache2

      Restart Nagios

      # systemctl start nagios.service

      Login to the Nagios Web Interface

      Open a browser and hit "http://Server-IP-address/nagios" and Provide the username "nagiosadmin" and password.


      Read More
      Published February 16, 2018 by

      How to Fix "firewall-cmd: command not found" Error in RHEL/CentOS 7

      Firewalld uses runtime and permanent configuration options, which you can manage using firewall-cmd

      In this tutorial, I will explain how to solve "firewall-cmd: command not found" error on RHEL/CentOS 7.

      To fix this error, we need to install firewalld
       sudo yum install firewalld  
      

      Now, start firewalld service and enable it to auto-start at system reboot.
       # sudo systemctl start firewalld  
       # sudo systemctl enable firewalld  
       # sudo systemctl status firewalld  
      

      Open/Close Port

      Firewall rule settings are managed by firewalld service daemon. A command-line client called firewall-cmd can talk to this daemon to update firewall rules permanently.

      Open port

      For Example, To open a port TCP/443 permanently, use following commands.
       # firewall-cmd --zone=public --add-port=443/tcp --permanent  
       # firewall-cmd –reload  
      

      Close above port

       # firewall-cmd --zone=public --remove-port=443/tcp --permanent  
       # sudo firewall-cmd --reload  
      

      Adding and Removing Services in Firewalld

      By default, firewalld comes with pre-defined services, if we want to add any specific services so need adds using the command. like ftp, ssh, etc...

      For example, the following commands will add or remove SSH services.
       # firewall-cmd --zone=public --add-service=ssh  
       # firewall-cmd --zone=public --remove-service=ssh  
       # firewall-cmd --zone=public --list-services  
      

      For example, the following commands will add or remove FTP services.
       # firewall-cmd --zone=public --add-service=ftp  
       # firewall-cmd --zone=public --remove-service=ftp  
       # firewall-cmd --zone=public --list-services  
      
      Read More