Friday 30 June 2017

Linux-5

                                                          Linux Commands

When dealing with the Linux operating system, commands are required as inputs to inform or direct a computer program to perform a specific operation. Understanding the most basic Linux commands will allow you to successfully navigate directories, manipulate files, change permissions, display information such as disk space, and more. Obtaining basic knowledge of the most common commands will help you easily execute tasks via the command line.


[root@server1 dhoni]# ls –ll file1

-rwxrwxrwx. 1 dhoni dhoni   18 Jun 30 05:11 file1

àThe chown command is used to change the owner and group of files, directories and links. ... new_owner is the user name or the numeric user ID (UID) of the new owner, and object is the name of the target file, directory or link. The ownership of any number of objects can be changed simultaneously.

Chown user:group filename

 [root@server1 dhoni]# chown root:root file1
[root@server1 dhoni]# ls –ll file1
-rwxrwxrwx. 1 root  root    18 Jun 30 05:11 file1



àtouch is a standard Unix command-line interface program which is used to update the access date and / or modification date of a file or directory. In its default usage, it is the equivalent of creating or opening a file and saving it without any change to the file contents

[root@server1 ~]# touch file22

àThe cat (short for “concatenate“) command is one of the most frequently used command in Linux/Unix like operating systems. cat command allows us to create single or multiple files, view contain of file, concatenate files and redirect output in terminal or files.Then press ctrl+d to stop

[root@server1 ~]# cat> file22

Hai this is information for you

àto show the file contents.

[root@server1 ~]# cat file22

Hai this is information for you

àto store data into variable like var1 stores  text as hai 

[dhoni@server1 ~]$ var1="hai"


à to display the var content use $ symbol and echo to print the content

[dhoni@server1 ~]$ echo $var1

Hai

àBy default most Linux distro displays hostname and current working directory. You can easily customize your prompt to display information . 
Prompt is control via a special shell variable. You need to set PS1, PS2, PS3 and PS4 variable. If set, the value is executed as a command prior to issuing each primary prompt.
PS1 – The value of this parameter is expanded (see PROMPTING below) and used as the primary prompt string. The default value is \s-\v\$ .
PS2 – The value of this parameter is expanded as with PS1 and used as the secondary prompt string. The default is >
PS3 – The value of this parameter is used as the prompt for the select command
PS4 – The value of this parameter is expanded as with PS1 and the value is printed before each command bash displays during an execution trace. The first character of PS4 is replicated multiple times, as necessary, to indicate multiple levels of indirection. The default is +

# now the $ changed to =>

[dhoni@server1 ~]$ PS1='=>'

=>

=>

àto change prompt test as follows

Here

u for username

h for host name

t  for time

[dhoni@server1]=>PS1='[\u@\h \t]$'


àto display the date use the below command

[dhoni@server1 09:02:13 Fri Jun 30]$date

Fri Jun 30 09:02:19 UTC 2017

àto display the calendar for the month use the following command

[dhoni@server1 09:02:19 Fri Jun 30]$cal

      June 2017
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30


àlook here incomplete echo statement will display > symbol in second line after we press enter until 

it closes properly.

 [dhoni@server1]$echo "hai

> kdk

> ldldl"

hai

kdk

ldldl


à to change the symbol ‘>’ to ‘–‘ use the following command with PS2

[dhoni@server1]$PS2='-'

[dhoni@server1]$echo hai

-how

- are you“

Hai

How

are you.


à to change to ‘>’ follow below

[dhoni@server1]$PS2='>’

[dhoni@server1]$echo "ggg
>g
>hgg"
ggg
g
hgg


à Grep command is used to search for a file using pattern maching as below

Here iam searching for file having Jun characters in it

[dhoni@server1]$ls -l | grep "Jun"

drwx------. 4 dhoni   dhoni   4096 Jun 30 07:15 dhoni

drwx------. 5 test    test    4096 Jun 18 16:31 test

drwx------. 2 test2   test2   4096 Jun 30 07:23 test2



If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.If you like this share with your friends.Follow us by email for our new posts 

Thanks

Devops Desk Team

Thursday 29 June 2017

Linux-4

                                                             The Unix File System
A filesystem is the methods and data structures that an operating system uses to keep track of files on a disk or partition; that is, the way the files are organized on the disk. The word is also used to refer to a partition or disk that is used to store thefiles or the type of the filesystem.

A file system is a group of files and relevant information regarding them.The disk space alloted to a unix file system is madeup of 'blocks'.
The Boot Block:
This represents the beginning of the file system. It contains a program called 'bootstrap loader'. This program is executed when we 'boot the host machine.only one block is needed to start up the system, all file systems contain one boot block.
The Super Block:
The super block describes the state of the file system-how large it is how many maximum files can it accomodate, how many more files can be created.
The Inode Table:
All the entities in unix system are treated as files. The information related to all these files is stored in an Inode Table on the disk.The Detailes will be
·         Owner of the file
·         Group to which the owner belongs
·         Type of the file
·         File access permissions
·         Date and time  of the last acces
·         Number of links to the file
·         Size of the file
·         Address of the block Where the file actually present.
Data Blocks:
These contains the actual  file contents. An allocated block belong to one file in the file system. This block cannot be used  for storing any other  files contents.
How Does unix acces a file:
Internally a file is identified by the inode number.we can obtain inode number as follows.
[dhoni@server1 ~]$ ls -i ckt.txt
915756 ckt.txt

# To  check disk Free space
[dhoni@server1 ~]$ df
Filesystem           1K-blocks     Used Available Use% Mounted on
/dev/mapper/VolGroup-lv_root
                      39645804   866232  36759016   3% /
tmpfs                   251020        0    251020   0% /dev/shm
/dev/sda1               487652    29789    432263   7% /boot
vagrant              218488828 69148548 149340280  32% /vagrant
# To check disk usage
[dhoni@server1 ~]$ du
4       ./dir1
4       ./best
32      .

To set the user limit when creating a file
[dhoni@server1 ~]$ ulimit

unlimited

Key directories in the file system:
  • */: Root directory (base of file system)
  • /bin: Executable programs
  • /boot: Linux kernel and boot loader
  • /dev: Special device files
  • /etc: System configuration files
  • /home: Home directories of all users
  • /lib: Library files for programs
  • /media: Mount points for CD-ROM and other media
  • /root: Home directory of the root user
  • */sbin: System administration commands
  • /srv: Data for services such as Web and FTP
  • */tmp: Temporary directory
  • /usr: Many of the important administration programs
  • /var: Various system files, such as logs


Wednesday 28 June 2017

Linux-3(bc)


Let we go a littile deeper into the Linux

We have a option like bc (best calucaltor) which provides good way of caluculations
using linux .Below i did some mathematical calculations.The Linux program bc can be used as a convenient desktop calculator. For interactive use you simply type "bc" at the command prompt in a terminal window and start typing arithmetic expressions.
When performing a series of calculations repeatedly it makes sense to use the bc calculator as part of a script.To open the calculator type bc. Exit from calculator type exit.
à
[dhoni@server1 ~]$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
10/2
5
11*32
352
quit

à
[dhoni@server1 ~]$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
45544*96556
4397546464
32+35+356+

3323
3323
quit

à
[dhoni@server1 ~]$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
10.23+1
11.23
scale=1(Here Scale option is used to restrict the precision points for float values)
10.23+2
12.23
quit

àto find the square root

[dhoni@server1 ~]$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
sqrt(25)
5
quit

à
To execute the logic
[dhoni@server1 ~]$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
for(i=0;i<10;i++)i
0
1
2
3
4
5
6
7
8
9
quit
Shows the login name

à
[dhoni@server1 ~]$ logname
vagrant

Shows the id of the user

à
[dhoni@server1 ~]$ id
uid=502(dhoni) gid=502(dhoni) groups=502(dhoni) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023

à
[dhoni@server1 ~]$ uname
Linux

à
[dhoni@server1 ~]$ uname --help
Usage: uname [OPTION]...
Print certain system information.  With no OPTION, same as -s.

  -a, --all                print all information, in the following order,
                             except omit -p and -i if unknown:
  -s, --kernel-name        print the kernel name
  -n, --nodename           print the network node hostname
  -r, --kernel-release     print the kernel release
  -v, --kernel-version     print the kernel version
  -m, --machine            print the machine hardware name
  -p, --processor          print the processor type or "unknown"
  -i, --hardware-platform  print the hardware platform or "unknown"
  -o, --operating-system   print the operating system
      --help     display this help and exit
      --version  output version information and exit

Report uname bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'uname invocation'

[dhoni@server1 ~]$ uname -i
x86_64
[dhoni@server1 ~]$ uname -m
x86_64
[dhoni@server1 ~]$ uname -p
x86_64
[dhoni@server1 ~]$ uname -o
GNU/Linux
[dhoni@server1 ~]$ uname -n
server1.abc.com
[dhoni@server1 ~]$ uname -v
#1 SMP Thu Jul 23 15:44:03 UTC 2015

àThe tty command will display the file name of the terminal connected to
standard input i.e. the name of the current terminal. It displays not a
tty message if standard input is not a terminal.

[dhoni@server1 ~]$ tty
/dev/pts/0
#Tells the date

[dhoni@server1 ~]$ date
Wed Jun 28 16:36:10 UTC 2017

àWe can cusomize it as follow
[dhoni@server1 ~]$ date '+DATE: %d-%m-%y %n TIME: %H:%M:%S'
DATE: 28-06-17
 TIME: 16:39:13

[dhoni@server1 ~]$ date '+D: %d-%m-%y'
D: 28-06-17



If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.

If you like this share with your friends.Follow us by email for our new posts 

Thanks

Devops Desk Team


Linux-2(File Permissions)

                                                           File permissions



Permission Groups

Each file and directory has three user based permission groups:
owner - The Owner permissions apply only the owner of the file or directory, they will not impact the actions of other users.
group - The Group permissions apply only to the group that has been assigned to the file or directory, they will not effect the actions of other users.
all users - The All Users permissions apply to all other users on the system, this is the permission group that you want to watch the most.

Permission Types
Each file or directory has three basic permission types:
read - The Read permission refers to a user's capability to read the contents of the file.
write - The Write permissions refer to a user's capability to write or modify a file or directory.
execute - The Execute permission affects a user's capability to execute a file or view the contents of a directory.

Viewing the Permissions
You can view the permissions by checking the file or directory permissions in your favorite GUI File Manager (which I will not cover here) or by reviewing the output of the \"ls -l\" command while in the terminal and while working in the directory which contains the file or folder.

The permission in the command line is displayed as: _rwxrwxrwx 1 owner:group

User rights/Permissions
The first character that I marked with an underscore is the special permission flag that can vary.
The following set of three characters (rwx) is for the owner permissions.
The second set of three characters (rwx) is for the Group permissions.
The third set of three characters (rwx) is for the All Users permissions.
Following that grouping since the integer/number displays the number of hardlinks to the file.
The last piece is the Owner and Group assignment formatted as Owner:Group.

Modifying the Permissions
When in the command line, the permissions are edited by using the command chmod. You can assign the permissions explicitly or by using a binary reference as described below.
Explicitly Defining Permissions

To explicity define permissions you will need to reference the Permission Group and Permission Types.

The Permission Groups used are:
u - Owner
g - Group
o - Others
a - All users

The potential Assignment Operators are + (plus) and - (minus); these are used to tell the system whether to add or remove the specific permissions.

The Permission Types that are used are:
r - Read
w - Write
x - Execute

So for an example, lets say I have a file named file1 that currently has the permissions set to _rw_rw_rw, which means that the owner, group and all users have read and write permission. Now we want to remove the read and write permissions from the all users group.

To make this modification you would invoke the command: chmod a-rw file1
To add the permissions above you would invoke the command: chmod a+rw file1

Every Permission has a value
read --4
write --2
execute --1

Default permission for file is 666
Default permission for directory is 777
When you create a file it will contains 3 types of users to access it they are

-rw-rw-r--. 1 dhoni dhoni 281 Jun 27 10:31 ckt.txt
 ---|---|---
owner|group|allusers

Each one have rwx permissions

when we create  a file using root then the file permissions will be 644.
Because here we having umask value 022 for root account.when you create file using
root this umask value will be deducted from the default file permissiosn that is(666-022=644)
644 stands(rw-r--r--).

when we create a file using normal user then the file permissions will be 664.
Because here we having umask value 002 for normal user account.when you create file using
normal user this umask value will be deducted from the default file permissiosn that is(666-002=664)
664 stands(rw-rw-r--).

à the below command will remove read permission for group,other users of dir1

[dhoni@server1 ~]$ chmod go-r dir1
[dhoni@server1 ~]$ ls
ckt.txt  dir1
[dhoni@server1 ~]$ ls -la ckt.txt

drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

àThe below command add write permissions whereever it require
[dhoni@server1 ~]$ chmod +w ckt.txt
[dhoni@server1 ~]$ ls -la

-rw-rw-r--. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

[dhoni@server1 ~]$ chmod +x ckt.txt
[dhoni@server1 ~]$ ls -la

-rwxrwxr-x. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

àThis will give write permission to the others
and removes execute permissions for group and others

[dhoni@server1 ~]$ chmod go-x,o+w ckt.txt

[dhoni@server1 ~]$ ls -la

-rwxrw-rw-. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

[dhoni@server1 ~]$ chmod g+x,o+w ckt.txt

[dhoni@server1 ~]$ ls -la

-rwxrwxrw-. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

[dhoni@server1 ~]$ ls -la ckt.txt
-rwxrwxrw-. 1 dhoni dhoni 281 Jun 27 10:31 ckt.txt

[dhoni@server1 ~]$ chmod g-x,o+x ckt.txt

[dhoni@server1 ~]$ ls -la ckt.txt
-rwxrw-rwx. 1 dhoni dhoni 281 Jun 27 10:31 ckt.txt

[dhoni@server1 ~]$ chmod u-r,g-x,o+x ckt.txt

[dhoni@server1 ~]$ ls -la

--wxrw-rwx. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

# Here another way to give permissions
 below command we gave permissions as 762(4+2+1,4+2,2)
stands for (user(rwx),group(rw),other(w))

[dhoni@server1 ~]$ chmod 762 ckt.txt

[dhoni@server1 ~]$ ls -la
-rwxrw--w-. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

[dhoni@server1 ~]$ touch sample

[dhoni@server1 ~]$ ls -la sample
-rw-rw-r--. 1 dhoni dhoni 0 Jun 27 12:20 sample

àShows the present working directory

[dhoni@server1 ~]$ pwd
/home/dhoni

àTo Exit from the present user account
[dhoni@server1 ~]$ exit
exit
[root@server1 ~]# su dhoni
[dhoni@server1 root]$ cd
[dhoni@server1 ~]$ ls
ckt.txt  dir1  sample

To check the umask value normal user

[dhoni@server1 ~]$ umask
0002
[dhoni@server1 ~]$ exit
exit
àThe umask value of root user

[root@server1 ~]# umask
0022
[root@server1 ~]# su dhoni

[dhoni@server1 ~]$ umask
0002
àTo change the umask value

[dhoni@server1 ~]$ umask 242

[dhoni@server1 ~]$ umask
0242
à now create a file it will be created with changed permissions like(666-242=424)
i.e -r---w-r--
[dhoni@server1 ~]$ touch sample2

[dhoni@server1 ~]$ ls -la sample2
-r---w-r--. 1 dhoni dhoni 0 Jun 27 12:26 sample2

àif you remove execute permission to the directory you can not list its contents

[dhoni@server1 ~]$ chmod u-x dir1

[dhoni@server1 ~]$ ls -la dir1
ls: cannot access dir1/..: Permission denied
ls: cannot access dir1/.: Permission denied
total 0
d????????? ? ? ? ?            ? .
d????????? ? ? ? ?            ? ..

[dhoni@server1 ~]$ chmod u+x dir1
[dhoni@server1 ~]$ ls -la dir1
total 8
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 .
drwx------. 3 dhoni dhoni 4096 Jun 27 12:26 ..
[dhoni@server1 ~]$ ls -la

àTo remove the file or directory use rm command

Here -rf option because to remove the file recursive and forcefully.

[dhoni@server1 ~]$ rm -rf sample2
[dhoni@server1 ~]$ ls -la

-rwxrw--w-. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwx-wx--x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1
-rw-rw-r--. 1 dhoni dhoni    0 Jun 27 12:20 sample

àls command having different options try it

[dhoni@server1 ~]$ ls -i
915756 ckt.txt  915755 dir1  915757 sample

[dhoni@server1 ~]$ ls -s
total 8
4 ckt.txt  4 dir1  0 sample
[dhoni@server1 ~]$ ls -r
sample  dir1  ckt.txt

If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.

If you like this share with your friends.Follow us by email for our new posts 

Thanks

Devops Desk Team

Linux-1

Linux is Mulituser Operating system.
It is open-source, free, has a variety of options regarding distributions, and you can be in full control of how you use your computer’s memory; as well as your entire graphic interface, also known as X.
Linux is the best-known and most-used open source operating system. As an operating system, Linux is software that sits underneath all of the other software on a computer, receiving requests from those programs and relaying these requests to the computer’s hardware.

For the purposes of this page, we use the term “Linux” to refer to the Linux kernel, but also the set of programs, tools, and services that are typically bundled together with the Linux kernel to provide all of the necessary components of a fully functional operating system. Some people, particularly members of the Free Software Foundation, refer to this collection as GNU/Linux, because many of the tools included are GNU components. However, not all Linux installations use GNU components as a part of their operating system. Android, for example, uses a Linux kernel but relies very little on GNU tools.
Moreover, it is less vulnerable to viruses and cyber-attacks.
In many ways, Linux is similar to other operating systems you may have used before, such as Windows, OS X, or iOS. Like other operating systems, Linux has a graphical interface, and types of software you are accustomed to using on other operating systems, such as word processing applications, have Linux equivalents. In many cases, the software’s creator may have made a Linux version of the same program you use on other systems. If you can use a computer or other electronic device, you can use Linux.

But Linux also is different from other operating systems in many important ways. First, and perhaps most importantly, Linux is open source software. The code used to create Linux is free and available to the public to view, edit, and—for users with the appropriate skills—to contribute to.

Linux is also different in that, although the core pieces of the Linux operating system are generally common, there are many distributions of Linux, which include different software options. This means that Linux is incredibly customizable, because not just applications, such as word processors and web browsers, can be swapped out. Linux users also can choose core components, such as which system displays graphics, and other user-interface components.
Here you will found basic commands.Slowly we will move to advance  level to shell script  also.

Login using Vagrant Vm
login as: vagrant
vagrant@127.0.0.1's password:
Last login: Mon Jun 26 11:55:23 2017 from 10.0.2.2

[vagrant@server1 ~]$ sudo su

[root@server1 vagrant]# cd

àadding user with useradd command.Linux has a super user account by default it is root user with this account we can create users and install the packages and do all the things which an admin can do in normal windows system.
[root@server1 ~]# useradd dhoni
[root@server1 ~]# passwd dhoni
Changing password for user dhoni.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.

àGiving Sudo permission using visudo file.Above i had created a user name dhoni i am giving sudo permissions so he can do some admin level work when require.

[root@server1 ~]# visudo

àNow i would like to change the user account as dhoni so i can do using su command.It is nothing but switch user account.

[root@server1 ~]# su dhoni

àchange directory command.This command is used to change the present directory to another directory or file
[dhoni@server1 root]$ cd

àDisplays a list of files.This command displays the all the files which were in that directory.
[dhoni@server1 ~]$ ls

àTo open a create a file with vi editor.Write some text.This is like notepad in our windows operating system.
[dhoni@server1 ~]$ vi cricket

[dhoni@server1 ~]$ ls
cricket

à To Rename file cricket to ckt.txt we use  mv command.

[dhoni@server1 ~]$ mv cricket ckt.txt

àNow check using ls command to know wheater the file changes or not.
[dhoni@server1 ~]$ ls
ckt.txt

#ls -la Shows hidden files
# The file starts with . Known as hidden file
# file starts with d known as directory
# file starts with - known as file

[dhoni@server1 ~]$ ls -la
total 24
drwx------. 2 dhoni dhoni 4096 Jun 27 10:35 .
drwxr-xr-x. 7 root  root  4096 Jun 27 10:11 ..
-rw-r--r--. 1 dhoni dhoni   18 Jul 23  2015 .bash_logout
-rw-r--r--. 1 dhoni dhoni  176 Jul 23  2015 .bash_profile
-rw-r--r--. 1 dhoni dhoni  124 Jul 23  2015 .bashrc
-rw-rw-r--. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt

àWho am i Tells the present user detailes logged in.
[dhoni@server1 ~]$ who am i
vagrant  pts/0        2017-06-27 08:25 (10.0.2.2)

àWho command tells the same as above.
[dhoni@server1 ~]$ who
vagrant  pts/0        2017-06-27 08:25 (10.0.2.2)

àmkdir used to make directory Here i am creating dir1.

[dhoni@server1 ~]$ mkdir dir1

[dhoni@server1 ~]$ ls
ckt.txt  dir1

[dhoni@server1 ~]$ cd dir1

[dhoni@server1 dir1]$ ls

[dhoni@server1 dir1]$ ls -la
total 8
drwxrwxr-x. 2 dhoni dhoni 4096 Jun 27 12:05 .
drwx------. 3 dhoni dhoni 4096 Jun 27 12:05 ..

[dhoni@server1 dir1]$ cd

[dhoni@server1 ~]$ ls -la
total 28
drwx------. 3 dhoni dhoni 4096 Jun 27 12:05 .
drwxr-xr-x. 7 root  root  4096 Jun 27 10:11 ..
-rw-r--r--. 1 dhoni dhoni   18 Jul 23  2015 .bash_logout
-rw-r--r--. 1 dhoni dhoni  176 Jul 23  2015 .bash_profile
-rw-r--r--. 1 dhoni dhoni  124 Jul 23  2015 .bashrc
-rw-rw-r--. 1 dhoni dhoni  281 Jun 27 10:31 ckt.txt
drwxrwxr-x. 2 dhoni dhoni 4096 Jun 27 12:05 dir1

àTo find out specific file detailes use following command.

[dhoni@server1 ~]$ ls -la ckt.txt
-rw-rw-r--. 1 dhoni dhoni 281 Jun 27 10:31 ckt.txt



If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.

If you like this share with your friends.Follow us by email for our new posts 

Thanks

Devops Desk Team

Monday 19 June 2017

Vagrant Setup

Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity.

Vagrant provides easy to configure, reproducible, and portable work environments built on top of industry-standard technology and controlled by a single consistent workflow to help maximize the productivity and flexibility

For DevOps engineer, Vagrant gives a disposable environment and consistent workflow for developing and testing infrastructure management scripts.we can quickly test things like shell scripts, Chef cookbooks, Puppet modules, and more using local virtualization such as VirtualBox or VMware. Then, with the same configuration, we can test these scripts on remote clouds such as AWS or RackSpace with the same workflow. 


Setting Vagrant Envioronment Step By Step:

To setup vagrant we first need to download the vagrant and oracle virtual box softwares as follow

Step1:
Install oracle virtual box.To install the virtual box  First go to the website virtualbox.org then download the version you prefer for your work.Then install it on your pc by following simple steps.



Step2:
Download the vagrant software from vagrantup.com and install it.it will ask for restart.


Step3:

Then we need to choose a box to install the centos on the vm .To download the centos on virtual machines follow below steps.

Click on FINDBOXES. Then type Centos 6 and select virtualbox and Enter.Click on Centos/6 (Depends on your requirement)

Step4:
Copy the highlated line(vagrant init centos/6) and paste in cmd. It will downloads the the required OS as per your command.





Step5:

Open command prompt and create a directory. In vagrant we place all the project related files in one folder.so it makes easier to find all the project files in a single directory.

C:\Users\user1> mkdir project1

C:\Users\user1>cd project1

C:\Users\user1\project1> vagrant init centos/6



Now Your Vagrant is ready


If you want to create multiple vms just follow as below
In Vagrant main configuration file is vagrant file.It will be used to configure the vagarant vms easily  with in minutes.To set up multiple vms we need to edit the vagrant file it will be opened in notepad from cmd as follow

C:\Users\user1\project1> notepad Vagrantfile

It will open a file as follow with little configuration .You can play with this configuration file.This is not default one i did some changes.By typing above command you will get default vagrant file with one vm configuration.You can increase  vms  by changing as follow.




# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "bento/centos-6.7"
  config.vm.define "centos1" do |centos1|
               centos1.vm.box= "bento/centos-6.7"
               centos1.vm.hostname="server1.abc.com" 
               centos1.vm.network "public_network", ip: "192.168.33.10"          
        end
   config.vm.define "centos2" do |centos2|
               centos2.vm.box= "bento/centos-6.7"
centos2.vm.hostname="server2.abc.com"
  centos2.vm.network "public_network", ip: "192.168.33.11" 
           
  end
  config.vm.define "centos3" do |centos3|
               centos3.vm.box= "bento/centos-6.7"
centos3.vm.hostname="server3.abc.com" 
centos3.vm.network "public_network", ip: "192.168.33.12"  
  end
  
  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # NOTE: This will enable public access to the opened port
  #config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via 127.0.0.1 to disable public access
  #config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
   #config.vm.network "public_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  #config.vm.network "public_network", type:"dhcp"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
  # such as FTP and Heroku are also available. See the documentation at
  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "atlas" do |push|
  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
  # end

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL

end




If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.

If you like this share with your friends.Follow us by email for our new posts 

Thanks

Devops Desk Team


Sunday 18 June 2017

Working With Ansible



Ansible Playbook contains mainly 4 sections.They are
1.Setup
2.Variables
3.Tasks
4.Handlers

Setup section contains the information about Host name(Which we are going to connect),User info(by which user account ansible should establish connection with Managed Machine),Sudo permissions,Connection is ssh or not.These type info will be available in Setup section.



Variables,Tasks and Handlers will be discussed in later posts.

After writing inventory file.we must check SSH connection between the controller machine(CM) and managed machines(MM).We must create SSH connection between CM and MM as follow
create a user name with test in all the 3 VMS and give visudo permissions to it or you can work with root also.Then from server1 generate SSH key and copy it to server2,server3 as follow.

[test@server1 ~]$ ssh-keygen

[test@server1 ~]$ ssh-copy-id server2.abc.com

[test@server1 ~]$ ssh-copy-id server3.abc.com

Now you setup a password less authentication for server1 to server2,server3.It makes to communicate server1 to server2,server3 very simple.

The following command checks ansible connection between CM and MM .Here "webservers" is group name defind in inventory file.Now i can start working with ansible.

This below command confirms the Controler machne and managed machines are having connection.
[test@server1 ~]$ ansible webservers -m ping

server3.abc.com | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
server2.abc.com | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

or i can ping individual server as follow

[test@server1 ~]$ ansible server2.abc.com -m ping


First Playbook

To write the playbook we have some rules to follow
The first line should start with ---
And every comment should start with #.These comments are not be executable.
Every item contains - symbol and space before it starts.The playbook follow a structer. If we doesn't follow that structer it will shows the errors. Every line should follow indentation and spaces at required places.It follows Key:Value Rule.

[test@server1 ansible]$ vi web.yml
To Run the playbook we use following command:

Using syntax check option  will checks the syntax of the playbook like the playbook following indentation and spacing correctly. Check option for dry run means it won't do anything on servers but displays the resulted output.

[test@server1 ansible]$ ansible-playbook web.yml --syntax-check
[test@server1 ansible]$ ansible-playbook web.yml --check 

[test@server1 ansible]$ ansible-playbook web.yml 

This command effects on the servers.output will be as follow

If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.

If you like this share with your friends. Follow us by email for our new posts 

Thanks

Devops Desk Team

Saturday 17 June 2017

Ansible Installation

To work with ansible we require some basic Linux commands. Ansible can be installed on linux based systems. Ansible has different versions.I am using  Ansible 2.3 .We can install Ansible in  different ways.In this tutorial i will tell you installation for linux based systems.

First we need to install a repository  "epel-release" before installing ansible. epel-release is a repository with tuns of packages for yum.Then just see the files in the epel-release repository you can see different files in that.
To install epel-release 


To install ansible

Now the actual step comes in  .It will installs latest version of  ansible in your system. goto ansible directory you will see some files.






In above ansible.cfg is called  main configuration file for anisible and inventory file(hosts) contains info about hosts (Managed Machines Ipaddress, hostname). To open the host file we need give the command as follow.

[root@server1 ansible]# vi hosts

It will display a file with a lot of stuff commented.in that give your managed machine name and ipaddress to work with it.you can give any number of machines and you can group those machines also.
Ansible Inventories:
 Ansible is used for managing multiple servers in the Infrastructure. The collection of hosts is known as “Ansible Inventory”.

[root@server1 ~]# more /etc/ansible/hosts

The inventory file can be in any format , The format for /etc/ansible/hosts like (one of Ansible’s defaults) and looks like below.These are the hostnames of the servers i am working with.To know the hostname of your managed machines type the command hostname .These hostnames should be fully qualified domain name(fqdn) like below.

It is ok to put systems in more than one group, for instance a server could be both a webserver and a dbserver. 

if things are not running on the default port then you can provide port number also as follow:
server3.abc.com:5309
Suppose you have static IPs and want to set up some aliases . You can also describe hosts like this:
server2 ansible_port=5309 ansible_host=192.0.2.50
If you have a lot of hosts having the same patterns you can do this:
[webservers]
server1[01:50].abc.com
Host Variables:
it is easy to assign variables to hosts that will be used later in playbooks.These variables known as host variables.
[webservers]
server2 http_port=80 maxRequestsPerChild=808
server3 http_port=303 maxRequestsPerChild=909
Group Variables:
Variables can also be applied to an entire group at once.
If you face any problem while practicing feel free to comment it and Bookmark this blog for quick reference.We will try to help you.

If you like this share with your friends.Follow us by email for our new posts 

Thanks

Devops Desk Team