Thursday 18 August 2016

NAS backup setup in Linux

NAS backup setup in Linux::
====================

For setting up NAS backup, it should be supported by the OS.  CIFS should be enabled in the kernel. If not enabled, it can be enabled via kernel compilation, which comes under Network File Systems.

Make sure that cifs-util is installed on the box.

We need to mount the backup machine to run the backup or we will have to use the commands/protocols like ssh  to run the backup which won't be appropriate.

Use the nmap (network mapper) command to find the different host and the services running on the hosts.

nmap -sP

VMware 12 and Oracle VM Virtual Box

VMware 12 and Oracle VM Virtual Box Installation in Centos 7 and Windows 7
==========================================================

Creating virtual machines and managing them is simple via VMware Workstation Player.

Download the latest VMware Workstation player from VMware downloads ::

VMware download url::

https://my.vmware.com/en/web/vmware/free#desktop_end_user_computing/vmware_workstation_player/12_0

Virtual Box download url::

https://www.virtualbox.org/wiki/Downloads

You will be able to download the latest version  for Windows and Linux distributions.  Download and  just execute the file which will guide you to complete the installation.

Run yum update in linux box before executing the file.

Once the VMware /Virtual Box  is installed we can now create virtual machines.. The gui will guide you the installation if you are a system admin.

Select the iso image of the OS to be installed and also the path  where the OS that has to be installed. Select a partition or a folder for the installation and assign memory for each installations. Try installing multiple OS as virtual machines.

If you need any help in the installation process, comment below and I will be more than happy to assist..

Thanks

Server Cloning via rsync

Server Cloning and Manual Backup::
===========================
rsync is a file sync application which is faster than copy commands and retains the permissions which is best suited to clone a live server or while restoring a server from the backup.

When running an rsync command, the first thing that should come after rsync is the desired switch or switches. Common switches include:

-r :Recursive; includes sub-folders
-a :Archive mode; includes sub-folders, while preserving permissions, groups, users, and times
-v :Verbose; the entire process is printed to the terminal rather than remain hidden
-e :Execute; calls upon an application required to make a connection, such as SSH
-c :Sync based on checksum – takes a while for a lot of files, or large files.
-z : compress file data
-h : human-readable, output numbers in a human-readable format
 --delete : If the destination have new files than source, it will be deleted
 --include : include particular files during rsync
 --exclude : remove particular files from rsync
 --progress : shows the progress during rsync
 --max-size='100' : only the files have the maxfile size or lesser will rsynced
 --remove-source-files : delete the source file after the rsync
 --bwlimit=100 : Set the bandwidth limit of the rsync.

Eg: rsync  switches  source destination
       rsync -aveczh /source/  /destination/

Please try to understand the following commands with the switches added.  These are just examples as you could understand if you understood the logic.

# rsync –r /home/source/ /home/destination/
# rsync –a /home/source/ /home/destination/
# rsync –av /home/source /home/destination/ # rsync –av ––delete /home/source/ /home/destination/
# rsync –av ––delete -e ssh root@192.168.1.2:/home/source/ /path/destination/
# rsync –av ––delete -e ssh root@targetipaddress:/remotesource/ /localdestination/
# rsync -zvh /source/backup.tar /destination/backups/
# rsync -avzh /home/source /home/destination/
# rsync -avzhe ssh --progress /home/sourcefile  root@192.168.1.2:/root/destinationfile
# rsync -avze ssh --include 'R*' --exclude '*' root@192.168.1.2:/var/lib/rpm/ /root/rpm
# rsync -avz --delete root@192.168.1.2:/var/lib/rpm/ .
# rsync -avzhe ssh --max-size='200k' /var/lib/rpm/ root@192.168.1.2:/root/tmprpm
# rsync --remove-source-files -zvh backup.tar /tmp/backups/
# rsync --bwlimit=100 -avzhe ssh  /var/lib/rpm/  root@192.168.1.2:/root/tmprpm/

Some of the backup applications that does cloning are as follows::
1. Clonezilla - debian linux
2. Partimage

Tuesday 16 August 2016

Passwordless SSH keygen login and Bash History Logging

 Password-less SSH keygen login::
========================

Server : 192.168.1.1

# ssh-keygen -t rsa

This will generate 2 keys under the home directory.
1. /home/linuxgeeknotes/.ssh/id_rsa (private key)
2. /home/linuxgeeknotes/.ssh/id_rsa.pub (public key)

Client : 192.168.1.2

Copy the public key in  /home/linuxgeeknotes/.ssh/id_rsa.pub to the client's home directory who want to login with password.

# ssh-copy-id root@192.168.1.2
=======================
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.1.2's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.1.2'"
and check to make sure that only the key(s) you wanted were added.
=======================

You should be able to login without password now.

Disable ssh root login and allow login for a particular user only::
================================================
 Edit /etc/ssh/sshd_config and add the entries

PermitRootLogin no
AllowUsers user1
DenyUsers user2


Edit vi /etc/sudoers or visudo and add entry for user1 before logging out.

user1  ALL=(ALL)       ALL

Save and restart ssh.service

Now only user1 will be allowed to login to the server via ssh.


Bash History Logging::
=================
Usually when multiple terminals are opened simultaneously, the bash history will be over written by the last closed session.


Install psacct utility for process accounting. By default it get installed with GUI installation.
If you have done minimal installation then
# yum install psacct
# systemctl start psacct

The psacct  utilities for monitoring process,  activities are ac, lastcomm, accton and sa.

ac --> command displays statistics about how long users have been logged on.
lastcomm --> command displays information about previous executed commands.
accton --> command turns process accounting on or off.
sa --> command summarizes information about previously executed commands.

# ac -p    --> Prints connected time in hours by each user
# lastcomm --user linuxgeeknotes
# lastcomm --command  rm

Amanda Backup Server & Client Configuration on Centos 7 Server::

Amanda Backup Server & Client Configuration on Centos 7 Server::
=================================================

Setting up Amanda Backup Server on Centos 7

Install EPEL repository
#yum install epel-release


Set up the hostname on Amanda Server
#nmtui
or
#hostnamectl set-hostname amanda-server
#vi /etc/hosts
ip address amanda-server amanda-server.centos.com

Update the Centos OS
#yum update

Install Amanda Server
#yum install amanda*

Install Add on Packages
# yum install xinetd gnuplot perl-ExtUtils-Embed

Start Xinetd Service
# service xinetd restart
# service xinetd status

Done Amanda Installation
# amadmin --version

 Amanda Configurations Setup

Make some directories
# mkdir -p /amanda /etc/amanda
# chown amandabackup /amanda /etc/amand

Now switch to your 'amandabackup' user
and run the following commands.
# su amandabackup
# mkdir -p /amanda/vtapes/slot{1,2,3,4}
# mkdir -p /amanda/holding
# mkdir -p /amanda/state/{curinfo,log,index}
# mkdir -p /etc/amanda/MyConfig

Edit Amanda.conf file
#vi /etc/amanda/MyConfig/amanda.conf

Add the following lines as such

org "MyConfig"
infofile "/amanda/state/curinfo"
logdir "/amanda/state/log"
indexdir "/amanda/state/index"
dumpuser "amandabackup"

tpchanger "chg-disk:/amanda/vtapes"
labelstr "MyData[0-9][0-9]"
autolabel "MyData%%" EMPTY VOLUME_ERROR
tapecycle 4
dumpcycle 3 days
amrecover_changer "changer"

tapetype "TEST-TAPE"
define tapetype TEST-TAPE {
length 100 mbytes
filemark 4 kbytes
}

define dumptype simple-gnutar-local {
auth "local"
compress none
program "GNUTAR"
}

holdingdisk hd1 {
directory "/amanda/holding"
use 50 mbytes
chunksize 1 mbyte
}

Now, we need to add a 'disklist' file with a single disk list entry (DLE). The 'disklist' file determines which disks will be backed up by Amanda. The file contains includefile directive or disklist entry. General usage was to describe a DLE as a partition, or file system.

#vi /etc/amanda/MyConfig/disklist
Type the following

localhost /etc simple-gnutar-local

Save and close the file

Check Amanda Configuration
# amcheck MyConfig

Run Test Backup
#amdump MyConfig
It will take some seconds but no output would be there

#echo $?

You will get "0" as output"

#amreport MyConfig

Amanda Backup Scheduling
#crontab -e

Type the following
0 17 * * * amandabackup /usr/sbin/amcheck -m MyConfig
15 2 * * * amandabackup /usr/sbin/amdump MyConfig

Exit from User
#exit

Amanda Backup Client Installation
# yum install amanda-client xinetd
# vi /var/lib/amanda/.amandahosts

 amanada_server amandabackup


Some of the Amanda Commands are as follows::
===============================
# amadmin --version
# amcheck -s all
# amcheck -c all
# amdump all
# amadmin all tape
# amflush -f all 
# amadmin all find ivie /usr/people | head -6 

Grub Installation to dual boot windows 7 and centos 7 with GUI ::

Grub Installation to dual boot windows 7 and centos 7 :
=========================================

1. First Install Windows 7
2. Then Install Centos 7 in the free space available.


After Centos 7 Installation, system will automatically boot to Centos 7. We need to manually install grub2  to see the windows installation. Follow the exact steps below to install grub2.

#cd /boot/grub2
#ls -l
#cat device.map
#head grub.cfg
Edit the file /etc/default/grub as below::
#vi /etc/default/grub

GRUB_TIMEOUT=10
GRUB_DISABLE_LINUX_UUID="true"

Then generate /boot/grub2/grub.cfg using the tool grub2-mkconfig

grub2-mkconfig -o /boot/grub2/grub.cfg

Now remove the line GRUB_DISABLE_LINUX_UUID="true" from /etc/default/grub

Again run grub2-mkconfig -o /boot/grub2/grub.cfg

Dual boot windows7 and centos 7
---------------------------------------------------------
# fdisk -l | grep "Disk /dev"
# blkid  --  to see the block device attributes
we can see windows 7 in /dev/sda1 which is hd0,1 in grub2

# cat /boot/grub2/grub.cfg | grep msdos
Create the file /etc/grub.d/15_windows7 as follows::

# vi /etc/grub.d/15_windows7
! /bin/sh -e
echo "Adding Windows 7" >&2
cat <<EOF
menuentry "Windows 7" {
set root=(hd0,1)
chainloader +1
}
EOF

chmod +x /etc/grub.d/15_windows7
rerun grub2-mkconfig -o /boot/grub2/grub.cfg

If we want to make windows7 as default then run
grub2-set-default 2

GUI Installation in Centos 7::
=====================
# yum groupinstall "GNOME DESKTOP" "Graphical Administration Tools"
# yum update --exclude=kernel*

Command to boot directly to GUI in Centos 7
#  systemctl set-default graphical.target
#  systemctl start graphical.target
#  systemctl list-units (to see the installed services)