How to install chrony in Linux

To install Chrony on CentOS, you can use the package manager yum. Here are the steps to install Chrony:

  1. Open a terminal on your CentOS system.
  2. Make sure your system is updated by running the following command:bashCopy codesudo yum update
  3. Install Chrony using the following command:bashCopy codesudo yum install chrony
  4. Once the installation is complete, you can start and enable the Chrony service to ensure it starts automatically on boot:bashCopy codesudo systemctl start chronyd sudo systemctl enable chronyd
  5. Check the status of the Chrony service to ensure it is running:bashCopy codesudo systemctl status chronyd If everything is set up correctly, you should see output indicating that the service is active and running.

Now, Chrony is installed and running on your CentOS system. You can configure Chrony by editing its configuration file located at /etc/chrony.conf. After making any changes to the configuration file, remember to restart the Chrony service:

bashCopy code

sudo systemctl restart chronyd

Make sure to adjust any firewall settings if necessary to allow NTP (Network Time Protocol) traffic if you want your system to synchronize its time with remote NTP servers.

Configure DHCP Failover on CentOS 7

Configuring DHCP (Dynamic Host Configuration Protocol) failover on CentOS 7 typically involves using the ISC DHCP server, which is a widely used DHCP server on Linux systems. DHCP failover ensures high availability and redundancy for DHCP services. Here’s a basic guide on how to set up DHCP failover on CentOS 7 using ISC DHCP:

Prerequisites:

  1. Install ISC DHCP Server: If you haven’t already installed the DHCP server, you can do so with the following command: sudo yum install dhcp

Configuration:

  1. Edit the DHCP Configuration File: Open the DHCP configuration file in a text editor. The default configuration file is usually located at /etc/dhcp/dhcpd.conf.
  2. sudo vi /etc/dhcp/dhcpd.conf
  3. Configure DHCP Server: Add or modify the following lines in the dhcpd.conf file for the primary DHCP server. Replace the placeholders with your network-specific values.plaintextCopy codeauthoritative; subnet <your_subnet> netmask <your_netmask> { range <start_ip_address> <end_ip_address>; option routers <gateway_ip_address>; option domain-name-servers <dns_server_ip>; }
  4. Configure Failover: Add the following lines to enable DHCP failover. Replace the placeholders with appropriate values.plaintextCopy codefailover peer "dhcp-failover" { primary; address <primary_ip>; port 647; peer address <secondary_ip>; peer port 647; max-response-delay 60; max-unacked-updates 10; load balance max seconds 3; }
    • primary_ip: IP address of the primary DHCP server.
    • secondary_ip: IP address of the secondary DHCP server.
  5. Restart DHCP Server: After making the changes, restart the DHCP server for the configuration to take effect.bashCopy codesudo systemctl restart dhcpd

Secondary DHCP Server Configuration:

  1. Follow the same steps as above for configuring the DHCP server on the secondary server.
  2. Make sure to change the primary keyword to secondary in the failover configuration.

Verification:

  1. Check the DHCP server logs for any errors or warnings.bashCopy codesudo journalctl -u dhcpd
  2. Verify that the failover status is as expected.bashCopy codesudo dhcpd -t This command tests the configuration and reports any syntax errors.

Notes:

  • Ensure that both primary and secondary DHCP servers have synchronized configuration files.
  • Adjust the failover settings and subnet parameters according to your network requirements.
  • Regularly monitor DHCP server logs to catch any potential issues early on.

This guide provides a basic configuration for DHCP failover. Depending on your network architecture and requirements, you may need to adjust the configuration accordingly. Always test the failover setup in a controlled environment before deploying it in a production network.

How to Configure kiosk on Ubuntu 14.04 and Chrome

Prerequisites

Step 1: Install Ubuntu Server with LTE

Step 2: Install apache2 on Ubuntu

Step 3: Set user login without password authentication

# vim /etc/sudoers
%sudo ALL=(ALL) NOPASSWD: ALL

Step 4: Install Packages

# sudo apt update
# sudo apt install --no-install-recommends xorg openbox google-chrome-stable pulseaudio

Step 5: Set user in audio group

# usermod -a -G audio $USER

Step 6: Create a kiosk file

# vim /opt/kiosk.sh

#!/bin/bash

xset -dpms
xset s off
openbox-session &
start-pulseaudio-x11

while true; do
rm -rf ~/.{config,cache}/google-chrome/
google-chrome --kiosk --no-first-run  'http://Website URL'
done

Step 7: Set execute permission

# chmod +x /opt/kiosk.sh

Step 8: Set Configurations

# vim /etc/init/kiosk.conf

start on (filesystem and stopped udevtrigger)
stop on runlevel [06]

console output
emits starting-x

respawn

exec sudo -u USERNAME startx /etc/X11/Xsession /opt/kiosk.sh --

Step 9: Start X Server

# dpkg-reconfigure x11-common
After screen appears select "Anybody" and press "OK"

Step 10: Start kiosk service

# cd /etc/init/
# start kiosk

Step 11: Set the service in grub configuration

# vim /etc/default/grub

GRUB_DEFAULT=0
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

Step 12: Update grub by executing command

# update-grub

Step 13: Install lightdm service

# apt-get install lightdm

Step 14: Disable Desktop by lightdm

# echo manual | sudo tee /etc/init/lightdm.override

Step 15: Start lightdm service

# start lightdm

Step 16: Create /etc/lightdm/lightdm.conf File

Create a file /etc/lightdm/lightdm.conf and add the following content:

# vim /etc/lightdm/lightdm.conf
[SeatDefaults]
autologin-user=<YOUR USER>
autologin-user-timeout=0
user-session=ubuntu
greeter-session=unity-greeter

Step 17: Add service in startup script

# vim /etc/init.d/kisok
# service kisok start

How to Install locate in Linux

Locate is very useful command to find the location of file/folder in linux.
Install mlocate package

# yum install mlocate

Update database by executing updatedb command

# updatedb

Now, locate any file/folder using “locate” command

# locate httpd

/etc/httpd
/etc/httpd/conf
/etc/httpd/conf.d
/etc/httpd/conf.modules.d
/etc/httpd/logs
/etc/httpd/modules
/etc/httpd/run
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/httpd/conf.d/README
/usr/sbin/httpd
/usr/share/httpd
/usr/share/doc/httpd-2.4.6
/usr/share/doc/httpd-tools-2.4.6
/var/cache/httpd
/var/cache/httpd/proxy
/var/log/httpd
/var/log/httpd/access_log
/var/log/httpd/error_log

How to check Database size in Linux

We can check all the sizes of databases through execute a simple query in mysql server

Step 1: Login with mysql server

Login to mysql server by putting the mysql server credentials

# mysql -u username -p
Enter Password: 

Step 2: Execute the Query

Execute the mysql query in mysql server.

mysql> SELECT table_schema "Data Base Name",
    -> sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",
    -> sum( data_free )/ 1024 / 1024 "Free Space in MB"
    -> FROM information_schema.TABLES
    -> GROUP BY table_schema ;

 +---------------------------------+----------------------+------------------+
 | Data Base Name | Data Base Size in MB | Free Space in MB |
 +---------------------------------+----------------------+------------------+ 
 | about_demo_conf | 0.11203384 | 0.02596664 |
 | appstore | 0.02434349 | 0.00234127 |
 | cacti | 0.95234585 | 0.00552368 |
 | growingfeet | 0.10937500 | 11765.00000000 |
 | information_schema | 0.00781250 | 0.00000000 |
 | lotus_to_mysql | 0.47713852 | 0.00000000 |
 | moderapp_log | 0.00230408 | 0.00000000 |
 | moedeogeventmessen | 0.13060379 | 0.00000000 |
 | mysql | 0.66061878 | 0.00000000 |
 | vsftpd | 0.00310898 | 0.00000000 |
 | what2do | 0.03068542 | 0.00035095 | 
+---------------------------------+----------------------+------------------+

How to Install PHP in nginx

Prerequisites

Install nginx web server

Step 1: Install PHP & PHP-FPM

Install packages php & php-fpm package on server using epel repository.

# yum --enablerepo=epel -y install php php-mbstring php-pear php-fpm

Step 2: Configure PHP-FPM

Modify user and group name in php-fpm configuration file.

# vi /etc/php-fpm.d/www.conf

user = nginx
group = nginx

Step 3: Start Service

Start php-fpm service.

# /etc/rc.d/init.d/php-fpm start

Starting php-fpm: [ OK ]
# chkconfig php-fpm on

Step 4: Configure default.conf file

Modify default.conf file.

# vi /etc/nginx/conf.d/default.conf
    # add follows in a "server" section

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        /etc/nginx/fastcgi_params;
    }

Step 5: Restart Service

Restart nginx server to execute the latest configurations.

# /etc/rc.d/init.d/nginx restart

Stopping nginx: [ OK ]
Starting nginx: [ OK ]

Step 6: Create a PHP Page

Create a PHP test page and save the file.

# echo "" > /usr/share/nginx/html/info.php

Open Your favorite browser and hit the URL: http://Your-IP-Address/info.php
phpinfo

How to Configure MySQL Master-Master Replication

Step 1: Install MySQL Server

Install MySQL Server on both machines.

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

Step 2: Configure MySQL Servers

Edit the /etc/mysql/my.cnf file on both machines. Add or modify the following values:

Server 1:

# vi /etc/mysql/my.cnf
        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

Server 2:

# vi /etc/mysql/my.cnf
        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

Step 3: Modify my.cnf file with bind-address

Edit or add bind-address in my.cnf

# vi /etc/mysql/my.cnf    	
        bind-address    = x.x.x.x

Step 4: Restart MySQL Server

After inserting the above entries restart mysql server.

# service mysqld restart

Step 5: Create Replication Users

Connect with mysql server as root

# mysql -u root -p

Configure the replication users on each Linode. Replace x.x.x.x with the private IP address of the opposing Linode, and password with a strong password:

mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'x.x.x.x' IDENTIFIED BY 'password';

Run the following command to test the configuration. Use the private IP address of the opposing Linode:

 mysql -ureplication -p -h x.x.x.x -P 3306

Step 6: Configure Database Replication

Server 1:

While logged into MySQL on Server 1, query the master status:

mysql> SHOW MASTER STATUS;
    +------------------+----------+--------------+------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+----------+--------------+------------------+
    | mysql-bin.000001 |      120 |              |                  |
    +------------------+----------+--------------+------------------+
    1 row in set (0.00 sec)

Server 2:

On Server 2 at the MySQL prompt, set up the slave functionality for that database. Replace x.x.x.x with the private IP from the first server. Also replace the value for master_log_file with the file value from the previous step, and the value for master_log_pos with the position value.

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

Step 7: Configure Database Replication Vice Versa

Server 2:

On Server 2, query the master status. Again note the file and position values.

mysql> SHOW MASTER STATUS;
    +------------------+----------+--------------+------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+----------+--------------+------------------+
    | mysql-bin.000001 |      160 |              |                  |
    +------------------+----------+--------------+------------------+
    1 row in set (0.00 sec)

Server 1:

Set the slave database status on Server 1, replacing the same values swapped in step 2 with those from the Server 2.

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

Step 8: Create Database

Test by creating a database and inserting a row:

Server 1:

mysql> create database test;
mysql> create table test.books (`id` varchar(10));

Server 2:

mysql> show tables in test;

How to create repository in Redhat 7 Linux

Introduction

Repository is database of application installation and up-gradation of packages which are available on different Linux distributions. The packages of distros are available on official websites or you can extract them from official CD/DVD. We can easily install, upgrade or delete packages from repository.

Step 1: Mount ISO from DVD or Folder

In order to create repository, first mount ISO image from Official DVD or download it from given websites.

# cd /root
# mount -o loop RHEL-7.0 Server.x86_64-dvd.iso /mnt/	(For Redhat 7)
# mount -r -t iso9660 -o loop -v rhel-server-6.4-x86_64-dvd.iso /mnt	(For Redhat 6)

Step 2: Create Repository

To create repository follow the following steps.

# cd /etc/yum.repos.d/
# vi rhel7.repo
[rhel7]
name=Redhat
baseurl=file:///mnt/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

Step 3: Install Packages

Install Packages using yum command.

# yum clean all
# yum install ftp httpd gcc

How to Configure Postfix, Dovecot, Virtual Domains, Virtual Users in CentOS

Step 1: Install Postfix

Install postfix using yum command:

# yum install postfix

Step 2: Run Postfix on Multi-Levels

Make sure run the postfix on multilevels:

# chkconfig postfix on

Step 3: Modify /etc/postfix/main.cf File

Make a copy of both these files main.cf & master.cf:

# cd /etc/postfix
# cp main.cf main.cf.bk
# cp master.cf master.cf.bk

Edit main.cf and change the following values:

# vi /etc/postfix/main.cf
myhostname = www.tecdistro.com
mydomain = tecdistro.com
myorigin = $mydomain
inet_interfaces = all
home_mailbox = Maildir/

Step 4: Create Postfix User

Create postfix user “userpostfix” on server with login shell as /sbin/nologin

# useradd -s /sbin/nologin userpostfix

Check the UID:GUID for the userpostfix user in /etc/passwd file

# tail /etc/passwd
userpostfix:x:1001:1001::/home/userpostfix:/sbin/nologin

Step 5: Configure Virtual domain

Add the following lines at the end of main.cf and replace the UID:GUID under virtual_minimum_uid, virtual_maximum_uid, virtual_uid_maps and virtual_gid_maps

# vi /etc/postfix/main.cf
virtual_mailbox_domains = /etc/postfix/virtual_domains
virtual_mailbox_base = /var/mail/vhosts
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_minimum_uid = 1001
virtual_maximum_uid = 1001
virtual_uid_maps = static:1001
virtual_gid_maps = static:1001
virtual_alias_maps = hash:/etc/postfix/virtual

Create /etc/postfix/virtual_domains. It contains all the domains that are pointed on server.

# vi /etc/postfix/virtual_domains
tecdistro1.com
tecdistro2.net
tecdistro3.org

Step 6: Create Mail Directories

Create the mail directory, sub directory for the domains and assign the proper permissions.

# mkdir /var/mail/vhosts
# chgrp -R userpostfix /var/mail
# cd /var/mail/vhosts
# mkdir tecdistro1.com
# mkdir tecdistro2.net
# mkdir tecdistro3.org
# cd ..
# chown -R userpostfix:userpostfix vhosts

Note: Postfix will create the “Maildir” directories automatically and assign the proper permissions.

Step 7: Create /etc/postfix/vmailbox File

Create a file /etc/postfix/vmailbox and add all of the users that will receive e-mails.

# touch /etc/postfix/vmailbox
# vi /etc/postfix/vmailbox
@tecdistro1.com          tecdistro1.com/catch-all/
user1@tecdistro1.com        tecdistro1.com/user1/
user2@tecdistro1.com       tecdistro1.com/user2/
user1@tecdistro2.net        tecdistro2.net/user1/
user1@tecdistro3.org        tecdistro3.org/user1/

Note: Make sure you end up each line with “/”.
Postfix will automatically create Maildir structure (cur, new, tmp).

Step 7: Execute postmap Command

Create the hashed file (.db) using postmap command.

	
# postmap /etc/postfix/virtual
# postmap /etc/postfix/vmailbox

Step 8: Check postfix Status

Make sure postfix service is running fine and port 25 is opened for postfix.

# ps -eaf | grep postfix
postfix   1219  1590  0 12:05 ?        00:00:00 pickup -l -t fifo -u
root      1353 30585  0 12:06 pts/0    00:00:00 grep postfix
root      1590     1  0 Mar05 ?        00:01:03 /usr/libexec/postfix/master
postfix  23181  1590  0 Apr13 ?        00:00:07 qmgr -l -t fifo -u
# netstat -an | grep :25
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN
tcp        0      0 :::25                       :::*                        LISTEN
tcp        0      0 ::ffff:159.8.18.154:80      ::ffff:157.55.39.57:25485   TIME_WAIT

Step 9: Reload postfix

Now reload the postfix service:

# service postfix reload

Step 10: Test Postfix

Test the mail using telnet command:

# telnet localhost smtp
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 server.tecdistro.com ESMTP Postfix
ehlo localhost
250-server.tecdistro.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:support@tecdistro.com
250 2.1.0 Ok
rcpt to:sales@tecdistro.com
250 2.1.5 Ok
data
354 End data with .
Test Mail
.
250 2.0.0 Ok: queued as E7E1F5A1F6
quit
221 2.0.0 Bye
Connection closed by foreign host.

How to Configure Dovecot

Dovecot is an open-source POP and IMAP client.

Step 1: Install Dovecot

Install dovecot using yum command:

# yum install dovecot

Step 2: Configure Dovecot on Multi-Levels

To Configure dovecot on multilevels:

# chkconfig dovecot on

Step 3: Configure Dovecot Files

Then, go to conf.d folder and change the following lines in the following files.

# cd /etc/dovecot/
# vi dovecot.conf
protocols = imap pop3
# cd /etc/dovecot/conf.d/
# vi 10-auth.conf
disable_plaintext_auth = no
#!include auth-system.conf.ext
!include auth-passwdfile.conf.ext
# vi 10-logging.conf
log_path = /var/log/dovecot.log
auth_verbose = no
auth_debug = no
verbose_ssl = no
# vi 10-mail.conf
mail_location = maildir:/var/mail/vhosts/%d/%n
mail_uid = 1001
mail_gid = 1001
mail_privileged_group = userpostfix
# vi 10-master.conf
unix_listener auth-userdb {
  mode = 0600
  user = postfix
  group =  postfix
}
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
  mode = 0666
  user = postfix
  group = postfix
}

Step 4: Reload Dovecot

Now reload the dovecot service:

 # service dovecot reload

Step 5: Test Dovecot

# telnet localhost pop3
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user sales@tecdistro.com
+OK
pass Test123
+OK Logged in.
list
+OK 1 messages:
1 3845
.
retr 1
+OK 3845 octets
Return-Path: <support@tecdistro.com>
X-Original-To: user1
Delivered-To: support@tecdistro.com
Received: from localhost (localhost [IPv6:::1])
by server.tecdistro.com (Postfix) with ESMTP id 117113FF18
for ; Thu, 7 Feb 2013 17:05:32 +0530 (IST)
Message-Id: <20130207113547.117113FF18@server.tecdistro.com>
Date: Thu, 7 Feb 2013 17:05:32 +0530 (IST)
From: support@tecdistro.com
To: undisclosed-recipients:;

.
test
quit
+OK Logging out.
Connection closed by foreign host.

How to Configure Squirrelmail

Step 1: Prerequisites

Step 2: Install Squirrelmail

Install EPEL repository and install SquirrelMail package from EPEL repository.

# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm 
# yum install squirrelmail
# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

Step 3: Configure Squirrelmail

Configure conf.pl according to the server as following:

# cd /usr/share/squirrelmail/config/
# ./conf.pl 
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1.  Organization Preferences
2.  Server Settings
3.  Folder Defaults
4.  General Options
5.  Themes
6.  Address Books
7.  Message of the Day (MOTD)
8.  Plugins
9.  Database
10. Languages
D.  Set pre-defined settings for specific IMAP servers
C   Turn color off
S   Save data
Q   Quit
Command >>2

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1.  Domain                 : tecdistro.com
2.  Invert Time            : false
3.  Sendmail or SMTP       : SMTP
A.  Update IMAP Settings   : localhost:143 (uw)
B.  Update SMTP Settings   : localhost:25
R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit
Command >> S

Press S to save datas and press Q to exit.

Step 4: Configure Squirrelmail with httpd.conf

Add the following lines in the httpd.conf file at the end.

# vi /etc/httpd/conf/httpd.conf
Alias /squirrelmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
    Options Indexes FollowSymLinks
    RewriteEngine On
    AllowOverride All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all
</Directory>

Restart the httpd service.

# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]