Saturday 19 December 2015

Version Control - 04.GitHub_Pull&Fork

GitHub Pull & Fork

Git Pull Request


When ever we forked another users repository and if we want to collaborate with them we can generate a pull request. After forking and cloning to our local computer if we do changes or some new codes have been added to the repository locally the same will be taking effect to the main repository as well. If we need these changes to made permanent to that repository as well then we need to generate a Pull request. Which will be notified to the owner of the main repository. After reviewing that person can accept or reject that request. If that request has been accepted then our changes will be merged to the main repository and committed.

To do this we need to login to our git account in the WebUI after that click on the "Pull Request" button and there after click on "Create Pull Request" button enter some info regarding the pull and click on "Send Pull Request" button.


Updating your Fork


It is also important to know why should we update our forks. Because so many users might be collaborating to the repository you are working and making changes on. In such case you might not know what the changes that have done by the other users. So if we have enabled upstream then every user can know what the other users have done to that repository. As enabling upstream will upload the changes made on their forks will let the other users know the changes.

Adding remote for upstream

# git remote add upstream <PATH_TO_REPO>
# git remote add upstream https://github.com/vmsnivas/bss.git

Fetch the Changes

# git fetch upstream

Merge them into master

# git merge upstream/master master 

Push the changes

# git push origin master

Friday 18 December 2015

Version Control - 03.GitHub_Forks

Git Forks


We might be seeing lots of repositories on github from other users. Most
of the users will secure their repositories. In that case we can't add -
or modify code in their repositories. In such cases we need to fork the-
ir repositories and can make changes. On forking someone's repositories 
we will have a copy of their repositories into our account.

How to Fork?
We need to login to the GitHub WebUI and go to a specific repos-
itory of a person that you want. In the right most area you can a Fork 
button. On clicking on that button you can get a copy of that repository
into your account.

After forking that repository you can clone that repository locally fro-
m your account and you can modify those codes as you need.

Ex : We have 2 users namely USER1 and USER2. User2 want some code from 
User1's repository. First User2 need to go to the WebUI and after to th-
e repository needed. 

https://github.com/user1/repository

Click on the fork button. Once the fork completes then he can have that
repository in his account.

https://github.com/user2/repository

Now he can clone to his local system.

# git clone https://github.com/user2/repository.git

Here we need to know one thing that user2 can even clone user1's reposi-
tory but he can't push the changes until he is permitted to do so.

Tuesday 15 December 2015

Version Control - 02.GitHub_Configs

Configuring your GitHub


Before working with GitHub we need to know that we can make the changes at 3 different levels.
 1. Local
While making the changes locally those changes will take effect to the local user or for a single repo
by which we configured git.
 2. System
If we make any changes at a system level then those changes will take effect to all the users
on that system.
 3. Global
If we make any changes at a global level then those changes will take effect to the repository
globally. In the sense those will be effected to the repository in our global account at Git.

USAGE
git config [<file-option>] [type] [-z|--null] name [value [value_regex]]
git config [<file-option>] [type] --add name value
git config [<file-option>] [type] --replace-all name value [value_regex]
git config [<file-option>] [type] [-z|--null] --get name [value_regex]
git config [<file-option>] [type] [-z|--null] --get-all name [value_regex]
git config [<file-option>] [type] [-z|--null] [--name-only] --get-regexp name_regex [value_regex]
git config [<file-option>] [type] [-z|--null] --get-urlmatch name URL
git config [<file-option>] --unset name [value_regex]
git config [<file-option>] --unset-all name [value_regex]
git config [<file-option>] --rename-section old_name new_name
git config [<file-option>] --remove-section name
git config [<file-option>] [-z|--null] [--name-only] -l | --list
git config [<file-option>] --get-color name [default]
git config [<file-option>] --get-colorbool name [stdout-is-tty]
git config [<file-option>] -e | --edit

We will have several configs like configuring the username, user email address, our terminal appearence
settings and configuring some alias to the commands we wish. These changes will be stored in the .git/config
file. We can do the same thing by editing this file too.

1. Configuring a user name
It is important to configure a username as if we do any commit then everyone using that repository
can know that who made the changes. If we don't the changes will be committed as the user we locally
login with.

# git config --global user.name "<FULL NAME>"
Ex : # git config --global user.name "Arjun Shrinivas"

2. Configuring user's email address

# git config --global user.email emailid@domain.com
# git config --global user.email vmsnivas@gmail.com

3. Configure your default editor for Git
This is the default editor used to edit our git configs.

# git config --global core.editor "/bin/vi"

After doing this try to use the below command to edit your git config. Now you will be able to use
vi editor to edit your git config. In this way you can use any editor. All you need to do is you
should specify the complete path of the editor. You can get it by using like "which vi"

# git config --global --edit

4. Configure alias commands
We can also configure some aliases to use them instead of running some long commands.

# git config --global alias.s "status s" --> Shows the status in silent mode
# git config --global alias.lg "log --oneline --decorate --all --graph"

5. Colorizing display for all users of the system

# git config --global color.ui true

6. Configure Carriage return / Line feed (crlf)
If it is true then it will adds the CRs back in when you check files out to the working directory,
making them easier to edit in some Windows apps which require CRs.

# git config --global core.autocrlf true
7. Configure Push Default
Matching - Pushes all matching branches up to GitHub
Simple - Just pushes current branch up to GitHub

# git config --global push.default simple

8. Configure Pull Default

# git config --global pull.rebase true

9. Configure Reuse Recorded Resolution (ReReRe)
This will records all fixes to merge conflicts and reuses them automatically if the same conflict recurs.

# git config --global rerere.enabled true

10. Configure Git URL

# git remote add -t <BRANCH> -f origin https://<username>@github.com/<username>/<repository>.git
# git remote add -t master -f origin https://vmsnivas@github.com/vmsnivas/bss.git

11. List you Git configs

# git config --global --list

Friday 11 December 2015

Provisioning - 01.Vagrant_Intro

Vagrant for Provisioning


Vagrant is a provisioning tool. If we are about to use Vagrant for provisioning then we need to have one of the provider.
Provider is nothing but a Cloud or Hypervisor environment. We have several providers.
 1. Virtual Box (Most popular to use with Vagrant)
 2. VMware
 3. Open Stack
 4. Docker
 5. AWS

To start using Vagrant you need to download vagrant. Go to the following link and download Vagrant respective to your OS
and its architecture. In my case i am using RHEL6 32-bit, Ubuntu 14.04. So i have downloaded for those

FOR RHEL6 Visit below links and download the packages

https://www.vagrantup.com/downloads.html

Also download VirtualBox with respective to your OS from the below link.
https://www.virtualbox.org/wiki/Linux_Downloads

Now let us install these both.

# cd ~/Downloads
# rpm -ivh vagrant_1.7.4_i686.rpm 
# rpm -ivh VirtualBox-5.0-5.0.10_104061_el6-1.i686.rpm

FOR UBUNTU 14.04 try the following

# apt-get update
# apt-get install vagrant
# apt-get install virtualbox

I am preferring RHEL or CentOS in my case as I have been facing some issues working with Vagrant in Ubuntu.
I'll be updating soon on complete procedure working with Ubuntu as well.

Now let us come to the case of RHEL.
While installing VirtualBox if you found any dependency failure for libSDL feel free to install that through YUM.
And try installing VirtualBox then. You will also need to install the kernel modules which are required for VirtualBox.
Please install the following packages, after that VirtualBox package and reboot your machine.

# yum install kernel* dkms gcc libSDL*

Once you are done then create a directory for Vagrant as your Vagrant workspace.

# mkdir /vagrantProject
# cd /vagrantProject

Now initialize your first VM using vagrant.
In this case i am using Ubuntu to be installed through Vagrant.

# vagrant init ubuntu/trusty64

You are ready with your first setup config which is stored in the Vagrantfile in your Vagrant Project directory.
Start your VM with "vagrant up". It will first download the ubuntu image from virtualbox and once the download finishes
it will start it up.

# vagrant up

Now you can ssh to your ubuntu box by using "vagrant ssh"

# vagrant ssh

If you want to shutdown your VM you can use
# vagrant suspend
(or)
# vagrant halt

If in case you don't need that VM then you can destroy that VM.
# vagrant destroy

Tuesday 8 December 2015

Version Control - 01.GitHub_Intro

GitHub Intro


Step 1
Login to github.com and signup for a free account.
If you need a private repository then you need to signup for paid account.

Step 2
Login to your Linux machine and create a direcotry for git
# mkdir /git

Step 3
Configure your username and email. So that if someone did any commit then everyone will know who have made it.
# git config --global user.name "User Name"
# git config --global user.email <email_id>

Step 4
Go to that directory and create a new directory for your repository if you
have multiple branches within the repository in your git account.
Else you can add your repository directly.
Case 1: Repository with default branch or a single branch.
Go to your git directory
# cd /git
Update the origin of your repository
# git remote add -t <Branch_Name> -f origin https://<username>@github.com/<username>/<Repo_name>.git
# git remote add -t master -f origin https://vmsnivas@github.com/vmsnivas/ansible.git
Clone your repository now.
# git clone https://vmsnivas@github.com/vmsnivas/ansible.git
Case 2: Repository with multiple branches.
Go to your git directory.
# cd /git
Create a direcotry with the name of the repository and child direcotries with the name of the branches you have.
# mkdir -p <repo_name>/{branch1,branch2,....}
# mkdir -p python/{master,notes,programs}
Go to the repo dir and initialize git.
# cd python
# git init
Set the origin of your repo.
# git remote set-url origin https://<username>@github.com/<username>/<Repo_name>.git
# git remote set-url origin https://vmsnivas@github.com/vmsnivas/python.git
Go to one of your branches and initialize git.
# cd master
# git init
Update the origin of your branch
# git remote add -t branch1 -f origin https://<username>@github.com/<username>/<Repo_name>.git
# git remote add -t master -f origin https://vmsnivas@github.com/vmsnivas/python.git
Now clone the contents of that specific branch from the repo.
# git clone -b branch1 https://<username>@github.com/<username>/<Repo_name>.git
# git clone -b master https://vmsnivas@github.com/vmsnivas/python.git

Click here to view in GitHub

Friday 21 August 2015

Nagios

Nagios an open-source computer-software application, monitors systems, networks and infrastructure. Nagios offers monitoring and alerting services for servers, switches, applications and services. It alerts users when things go wrong and alerts them a second time when the problem has been resolved.


Ethan Galstad and a group of developers originally wrote Nagios as NetSaint. As of 2015 they actively maintain both the official and unofficial plugins. Nagios is a recursive acronym: "Nagios Ain't Gonna Insist On Sainthood" - "sainthood" makes reference to the original name NetSaint, which changed in response to a legal challenge by owners of a similar trademark.

Nagios is open source software licensed under the GNU GPL V2. It provides:

  • Monitoring of network services (SMTP, POP3, HTTP, NNTP, ICMP, SNMP, FTP, SSH)
  • Monitoring of host resources (processor load, disk usage, system logs) on a majority of network operating systems, including Microsoft Windows with the  NSClient++ plugin or Check MK.
  • Monitoring of anything else like probes (temperature, alarms,etc.) which have the ability to send collected data via a network to specifically written plugins
  • Monitoring via remotely run scripts via Nagios Remote Plugin Executor
  • Remote monitoring supported through SSH or SSL encrypted tunnels.
  • A simple plugin design that allows users to easily develop their own service checks depending on needs, by using their tools of choice (shell scripts, C++, Perl,  Ruby, Python, PHP, C#, etc.)
  • Available data graphing plugins
  • Parallelized service checks
  • The ability to define network host using 'parent' hosts, allowing the detection of and distinction between hosts that are down or unreachable
  • Contact notifications when service or host problems occur and get resolved (via e-mail, pager, SMS, or any user-defined method through plugin system)
  • The ability to define event handlers to be run during service or host events for proactive problem resolution
  • Automatic log file rotation
  • Support for implementing redundant monitoring hosts
  • An optional web-interface for viewing current network status, notifications, problem history, log files, etc.
  • Data storage via text files rather than database
Nagios Agents

NRPE
       Nagios Remote Plugin Executor (NRPE) is a Nagios agent that allows remote system monitoring using scripts that are hosted on the remote systems. It allows for  monitoring of resources such as disk usage, system load or the number of users currently logged in. Nagios periodically polls the agent on remote system using  the check_nrpe plugin.
      NRPE allows you to remotely execute Nagios plugins on other Linux/Unix machines. This allows you to monitor remote machine metrics (disk usage, CPU load,  etc.). NRPE can also communicate with some of the Windows agent addons, so you can execute scripts and check metrics on remote Windows machines as well.

NRDP
       Nagios Remote Data Processor (NRDP) is a Nagios agent with a flexible data transport mechanism and processor. It is designed with an architecture that allows  it to be easily extended and customized. NRDP uses standard ports and protocols (HTTP(S) and XML) and can be implemented as a replacement for NSCA.

NSClient++
       This program is mainly used to monitor Windows machines. Being installed on a remote system NSClient++ listens to port TCP 12489. Nagios plugin that is used to
 collect information from this addon is called check_nt. As NRPE, NSClient++ allows to monitor the so-called 'private services' (memory usage, CPU load, disk
 usage, running processes, etc.) Nagios is a host and service monitor. which is designed to inform your network problems.

Configure Nagios

Visit the below link to configure your Nagios Server
Visit the below link to configure your Nagios Client
Visit the below link to troubleshoot your Nagios Server / Client


Monday 17 August 2015

Red Hat Enterprise Linux Release Dates



To find your Red Hat Enterprise Linux release please:
cat /etc/redhat-release  

To find your kernel version please:
uname -a  

Red Hat Enterprise Linux 2.1  -  Codename: Pensacola (AS) / Panama (ES) (based on Red Hat Linux 7.2)
Release/Update          General Availability Date        Kernel Version  
 RHEL 2.1 GA               2002-03-23                    2.4.9-e.3  
 RHEL 2.1 Update 1         2003-02-14                    2.4.9-e.12  
 RHEL 2.1 Update 2         2003-03-29                    2.4.9-e.24  
 RHEL 2.1 Update 3         2004-12-19                    2.4.9-e.34  
 RHEL 2.1 Update 4         2004-04-21                    2.4.9-e.40  
 RHEL 2.1 Update 5         2004-08-18                    2.4.9-e.49  
 RHEL 2.1 Update 6         2004-12-13                    2.4.9-e.57  
 RHEL 2.1 Update 7         2005-04-28                    -  

Red Hat Enterprise Linux 3  -  Codename: Taroon (based on Red Hat Linux 9)
Release/Update          General Availability Date        Kernel Version  
 RHEL 3 GA                 2003-10-22                     2.4.21-4  
 RHEL 3 Update 1           2004-01-16                     2.4.21-9  
 RHEL 3 Update 2           2004-05-12                     2.4.21-15  
 RHEL 3 Update 3           2004-09-03                     2.4.21-20  
 RHEL 3 Update 4           2004-12-12                     2.4.21-27  
 RHEL 3 Update 5           2005-05-18                     2.4.21-32  
 RHEL 3 Update 6           2005-09-28                     2.4.21-37  
 RHEL 3 Update 7           2006-03-17                     2.4.21-40  
 RHEL 3 Update 8           2006-07-20                     2.4.21-47  
 RHEL 3 Update 9           2007-06-20                     2.4.21-50  

Red Hat Enterprise Linux 4  -  Codename: Nahant (based on Fedora Core 3)
Release/Update    General Availability Date   redhat-release Errata Date*    Kernel Version  
 RHEL 4 GA          2005-02-15                   -                             2.6.9-5  
 RHEL 4 Update 1    2005-06-08               2005-06-08 RHEA-2005:318          2.6.9-11  
 RHEL 4 Update 2    2005-10-05               2005-10-05 RHEA-2005:786          2.6.9-22  
 RHEL 4 Update 3    2006-03-12               2006-03-07 RHBA-2006:0149         2.6.9-34  
 RHEL 4 Update 4    2006-08-10               2006-08-10 RHBA-2006:0601         2.6.9-42  
 RHEL 4 Update 5    2007-05-01               2007-04-27 RHBA-2007:0196         2.6.9-55  
 RHEL 4 Update 6    2007-11-15               2007-11-15 RHBA-2007:0897         2.6.9-67  
 RHEL 4 Update 7    2008-07-29               2008-07-24 RHEA-2008:0769         2.6.9-78  
 RHEL 4 Update 8    2009-05-19               2009-05-18 RHEA-2009:1002         2.6.9-89  
 RHEL 4 Update 9    2011-02-16               2011-02-16 RHEA-2011:0251         2.6.9-100  

Red Hat Enterprise Linux 5  -  Codename: Tikanga (based on Fedora Core 6)
 Release/Update    General Availability Date   redhat-release Errata Date*   Kernel Version  
 RHEL 5 GA          2007-03-15               -                               2.6.18-8  
 RHEL 5 Update 1    2007-11-07               2007-11-07 RHEA-2007:0854       2.6.18-53  
 RHEL 5 Update 2    2008-05-21               2008-05-20 RHEA-2008:0436       2.6.18-92  
 RHEL 5 Update 3    2009-01-20               2009-01-20 RHEA-2009:0133       2.6.18-128  
 RHEL 5 Update 4    2009-09-02               2009-09-02 RHEA-2009:1400       2.6.18-164  
 RHEL 5 Update 5    2010-03-30               2010-03-30 RHEA-2010:0207       2.6.18-194  
 RHEL 5 Update 6    2011-01-13               2011-01-12 RHEA-2011:0020       2.6.18-238  
 RHEL 5 Update 7    2011-07-21               2011-07-20 RHEA-2011:0977       2.6.18-274  
 RHEL 5 Update 8    2012-02-20               2012-02-20 RHEA-2012:0315       2.6.18-308  
 RHEL 5 Update 9    2013-01-07               2013-01-07 RHEA-2013-0021       2.6.18-348  
 RHEL 5 Update 11   2014-09-16               2014-09-16 RHEA-2014-1238       2.6.18-398  
 RHEL 5 Update 10   2013-10-01               2013-09-30 RHEA-2013-1311       2.6.18-371  

Red Hat Enterprise Linux 6  -  Codename: Santiago (based on a mix of Fedora 12, Fedora 13, and several modifications)
 Release/Update      General Availability Date      redhat-release Errata Date*      Kernel Version  
 RHEL 6 GA            2010-11-09                      -                              2.6.32-71  
 RHEL 6 Update 1      2011-05-19                  2011-05-19 RHEA-2011:0540          2.6.32-131.0.15  
 RHEL 6 Update 2      2011-12-06                  2011-12-06 RHEA-2011:1743          2.6.32-220  
 RHEL 6 Update 3      2012-06-20                  2012-06-19 RHSA-2012-0862          2.6.32-279  
 RHEL 6 Update 4      2013-02-21                  2013-02-21 RHSA-2013-0496          2.6.32-358  
 RHEL 6 Update 5      2013-11-21                  2013-11-20 RHSA-2013:1645-2        2.6.32-431  
 RHEL 6 Update 6      2014-10-14                  2014-10-13 RHEA-2014:1608          2.6.32-504  
 RHEL 6 Update 7      2015-07-22                  2015-07-22 RHEA-2015:1423          2.6.32-573  
 RHEL 6 Update 8      TBA                         TBA                                TBA  

Red Hat Enterprise Linux 7  -  Codename: Maipo (based on a mix of Fedora 19, Fedora 20, and several modifications)
 Release/Update   General Availability Date   redhat-release Errata Date*   Kernel Version  
 RHEL 7 Beta       2013-12-11                 -                             3.10.0-54.0.1  
 RHEL 7 RC         2014-04-23                 -                             3.10.0-121  
 RHEL 7 GA         2014-06-09                 -                             3.10.0-123  
 RHEL 7 Update 1   2015-03-05                 2015-03-05 RHEA-2015:0524     3.10.0-229  
 RHEL 7 Update 2   TBA                        TBA                           TBA  



Wednesday 25 March 2015

SWAP Configuration in Linux

Features:
  1. Generates additional virtual memory
  2. Temporary fix for RAM-Shortage. Permanent fix is to add more RAM.
  3. Requires no system downtime.
  4. Works with dedicated partitions.
  5. Works with existing file systems.
  6. Works accross disks, consequently improving performance.

Tasks:
  1. Define swap partition and provision
    a. 'fdisk /dev/sdb'
      ( Define a new partition and change the partition to 82 i.e., Linux swap )
    b. 'mkswap /dev/sdb2' ( The newly created partition )
    Note: If necessary reboot the system after using fdisk or parted.
    c. Add a new entry in /etc/fstab for the new swap file.
    d. 'swapon -s' displays all current swap devices.
    e. 'swapon -a' turns all the listed swap devices.
    f. 'swapon -v /dev/sdb3' Verbosely turns on the swap device.
    g. 'swapoff /dev/sdb3' disables the swap device.

  2. Define swap storage on existing file system.
    a. 'dd if=/dev/zero of=/swapfile1G bs=1024 count=1048576' (1024x1024=1048576) Creates 1G file That we can overlay a swap file system on of size : 1G
    b. 'mkswap /swapfile1G'
    c. 'swapon -v /swapfile1G'
    d. Add an entry in the /etc/fstab for permanent mounting
    e. 'swapon -a'

Sunday 22 March 2015

Access Control Lists in Linux

ACL (Access Control Lists) :
----------------------------

ACL is a utility for managing advanced level permissions on a file or dir
It has two modes
 1. To display the permissions of a file or directory ---> getfacl
 2. To set the permissions of a file or directory ---> setfacl
In this mode we have two other modes
a. Set or modify permissions ---> (Option -m)
b. Remove permissions ---> (Option -x)

Task 1 : At first we need to enable ACL on the partition which we need to configure.
We want to enable ACL for "/" filesystem
Step 1 :
# vi /etc/fstab
Find the entry for the "/" filesystem and add ",acl" after defaults as like below.
Before : UUID=9dbab158-e9c1-401e-b819-9a26cb5bc82a /                       ext4    defaults        1 1
After  : UUID=9dbab158-e9c1-401e-b819-9a26cb5bc82a /                       ext4    defaults,acl        1 1
Save and quit the file.

Step 2 :
Remount the filesystem for the changes to be effected
# mount -o remount,rw /

Now we have done with enabling ACL on "/" filesystem.

Task 2 : Modify or remove perms on Files or directories
Ensure to have 2 users (Ex. arjun, omkar)
Created a directory under "/" filesystem (ex. kits)
Login with omkar and create a text file and provide full permissions.
Login with arjun and create a directory and provide full permissions.

Requirements :
1. Arjun should not be able to access the file created by omkar.
  a. Know the ACL perms for the file created by omkar
# getfacl acltest.txt
  b. Now set the permissions on the file to restrict access to arjun
   # setfacl -m u:arjun:--- acltest.txt
  c. Recheck the permissions again
   # getfacl acltest.txt

2. Omkar should not be able to access the dir created by arjun.
  a. Know the ACL perms for the dir created by arjun
# getfacl acltestdir
  b. Now set the permissions on the dir to restrict access to omkar
   # setfacl -m u:omkar:--- acltestdir
  c. Recheck the permissions again
   # getfacl acltestdir

3. Create a group and add arjun, omkar to that group. Provide full permissions for everyone(User, Group, Others). This group should only able to access the file (provide perms through ACL)
   a. Create group "aclgroup" and add arjun, omkar to it
# groupadd aclgroup
# usermod -G aclgroup arjun
# usermod -G aclgroup omkar
b. Provide full permissions for everyone(User, Group, Others)
# chmod 666 acltest.txt
c. Provide permissions for the group to have read and write perms on it.
# getfacl acltest.txt
# setfacl -m g:aclgroup:rw- acltest.txt
Remove the ACL perms set earlier for user arjun
# setfacl -x u:arjun acltest.txt
d. Restrict access for others.
# getfacl acltest.txt
# setfacl -m o:--- acltest.txt
Create a new user (ex. nivas) and try to access the file with user nivas

4. Add nivas to aclgroup and restrict access for him.
a. Add nivas to aclgroup
# usermod -G aclgroup nivas
b. Try to access the file as nivas and ensure that he is able to access
c. Restrict access for nivas
# getfacl acltest.txt
# setfacl -m u:nivas:--- acltest.txt