Wednesday, December 23, 2015

Performance Analysis in solaris 10- Memory

In real world memory performance issues plays a major role in system performance. Unix system memory contains 2 types , one is physical memory which is attached to the DIMM modules of the hardware and second is swap space which is a dedicated space in the disk which is treated as a memory by OS ( since the disk I/O is much slower than the I/O to the memory in generic way we will prefer to use swap space less frequently as possible).
tivity
Swap space is only used when the physical memory is too small to accommodate system memory requirements . At that time space is freed in physical memory by paging (moving) it out to swap space ( also keep it in mind that if the increase in paging to swap space will degrade system CPU performance )

vmstat command
***********






vmstat reports virtual memory statics regarding kernel thread, virtual memory,disk,thread,cpu activity etc. Also note that in multiple CPU systems this will show the average of the number of CPU output. 

The details of the command is given below 

kthr - This indicates the kernel threads details in 3 states . 
    r - The number of kernel threads in run queue
    b - The number of blocked threads which are waiting for I/O paging 
    w - Number of swapped out lightweight processes (LWP - processes which is running under same kernel thread and shares its system resources and addresses with other lwp's)  that are waiting for resources to finish 

memory - Report the usage of real and virtual memory 
    swap - available swap space ( in kb)
    free - size of the free list (in kb)

page - Report about the page faults and paging activity . Details of this section is given below 
    re - page reclaims 
    mf - minor faults 
    pi - kilobytes paged in 
    po - kilobytes paged out
    fr - kilibytes freed
    de - anticipated short term memory shortfall ( in KB)
    sr- pages scanned by clock algorithm 

disk - Reports the number of disk operations per second . There are slots up to 4 disks with a letter and number ( letter indicates the disk type like scsi.ide ) and number is the logical number

faults - Reports trap/interrupt rates 
    in - interrupts
    sy - system calls
    cs- cpu context switches 

cpu - Breakdown usage of the cpu time. In multi processor systems it will be average of all the CPU's

    us - user time
    sys - system time
    id - idle time

swap usage analysis
****************
If you concentrate in swap analysis we need to use below mentioned two commands . 

bash-3.2# swap -s
total: 267032k bytes allocated + 86184k reserved = 353216k used, 964544k available

bash-3.2# swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 181,1 8 2097144 2097144

But there is major difference between these two commands , in the first one we are using 353216k of (964544 + 353216)k  which means of 26% in use. In the second one you can see as all the 2097144 is free means 0% is used.  In the first command (swap -s ) includes the  portion of physical memory also which is using as swap. The major difference in usage of these two commands are in generic if you are checking the swap usage over time you can use swap -s. (if the system performance is good). But if the system performance is degraded you need to concentrate more  about  the change in swap usage and what causes that change  ( also keep it in mind that swap -l displays output in 512 bytes and swap -s displays in 1024 byte blocks) .

If the system run's out of swap space it will show the error messages given below and we might think about expanding the same using creating the swap file. In general while creating the swap you have to provide size as half of the system physical memory

for example if the system memory is 8GB the ideal swap size should be 4GB

***********************************************************
application is out of memory

malloc error O

messages.1:Sep 21 20:52:11 mars genunix: [ID 470503 kern.warning]
WARNING: Sorry, no swap space to grow stack for pid 100295 (myprog)
***********************************************************

Creating the swap file

1.Login as super user
2. Create the swap file using mkfile <name> <size in k/m/g> filename
3. Activate the swap file using /usr/sbin/swap -a /path/filename
4. Add the entry at /etc/vfstab 

   /path/filename - - swap - no -

5. Verify the swap file using /usr/bin/swap -l

As a nutshell while configuring the swap , please keep it in below points 

  • Never allocate swap with size less then 30% of RAM.
  • Determine whether large applications (such as compilers and databases) will be using the /tmp  directory. If one or several of your application have a huge demand for swap space, use the swap -s  command to monitor swap resources on a similar existing system tro get estimate of the actual requirements.

Cache

If we check the free -m command in a unix box we can see major portion of the memory is in cached column. So what is mean by that cache, is it currently used by system?

[root@testserver ~]# free -m
             total       used       free     shared    buffers     cached
Mem:         15976      15195        781          0        167       9153
-/+ buffers/cache:       5874      10102
Swap:         2000          0       1999


In this case you can see 9GB is cached . These caches are called page caches / dirty caches which will act as a temporary memory for read and write process. During the write process the contents of these dirty cache will be periodically transferred to the system storage . Till 2.6.31 version , the process called pdflush will ensure that the data is transferring to system storage and clearing the dirty pages periodically. But after this kernel version there will be a thread for each device ( like sda/sdb) will monitor this mechanism 

root@pc:~# ls -l /dev/sda
brw-rw---- 1 root disk 8, 0 2011-09-01 10:36 /dev/sda
root@pc:~# ls -l /dev/sdb
brw-rw---- 1 root disk 8, 16 2011-09-01 10:36 /dev/sdb
root@pc:~# ps -eaf | grep -i flush
root       935     2  0 10:36 ?        00:00:00 [flush-8:0]
root       936     2  0 10:36 ?        00:00:00 [flush-8:16]



This same mechanism is applicable for reading also, file blocks will be transferred from disk to page cache for reading . For example if you access 100MB file twice , in second time the access will be faster as it is fetching from the cache. If Linux needs more memory for normal applications than is currently available, areas of the Page Cache that are no longer in use will be automatically deleted.

Mostly log files or database dump file ( data files) are mostly accumulated by page cache as it is accessed continuously . So configuring perfect log rotate or zipping it periodically will release the page cache when it will be really needed for system performance .







 


    











Tuesday, December 15, 2015

Performance analysis in solaris 10 - CPU

Performance analysis is one of the key task for every system admins which is an important point for the  the system availability ( especially production systems with SLA basis).We should do the periodical check for the various system parameters and ensure nothing is getting in to wrong way which is hampering the normal operations of the production systems .

The main factores we should consider for system performance analysis are disk IO, CPU,Memory & Swap,network and zones ( i am omitting other service components like  name services , NFS, kernel tuning etc.. which can be discussed separately).

CPU Loading

Load average is the average over time the number of processes in run queue. This is used to represent the load on CPU and  load average refers to three numbers with 1-5-15 minutes intervals . Typically the load average divided by the number of cpu cores are used to find the load per cpu and the load average above 1 per cpu is considered as cpu is fully utilized . Also a general rule of thumb in load average is "average value which is 4 times the number of cpu results a sluggish performance".

Load average can be monitored by the command uptime or monitoring the run queue time of the processors using sar -q command

uptime
*******
bash-3.2# uptime
4:29pm  up 34 day(s), 14:45,  2 users,  load average: 0.45, 0.49, 0.54

The last 3 numbers are the load average which will be 1,5,15 minutes interval. Now we need to find what is load metric . This metric for a particular load at given point of time is  how many processes are queued per the running process ( including the current running ones). For example in last minute if the load average is 0.50 means half of the time of the last minute CPU was idle with out any running processes. Another example of the load average is 2.50 in last minute means average of 1.5 processes are waiting to run in the queue and the CPU was overloaded by 150%

The load average can be monitored by analyzing the run queue length and amount of time to take for that using the sar -q command .

Using the sar-q command we will getto know the following information
1. The average  queue length while the queue is occupied
2. The percentage of time that the queue is occupied.

If you check the command output header you will get below details from sar -q 

SunOS testsolaris 5.10 Generic_144488-05 sun4v    12/15/2015

00:00:00 runq-sz %runocc swpq-sz %swpocc
01:00:01     1.0       1     0.0       0
02:00:00     1.0       1     0.0       0
03:00:01     1.0       1     0.0       0
04:00:00     1.0       1     0.0       0
05:00:00     1.1       1     0.0       0
06:00:00     1.0       1     0.0       0
07:00:00     1.0       1     0.0       0

08:00:01     1.1       5     0.0       0
............................................

Average      1.0       3     0.0       0

run-sz - This indicates the number of kernel threads in the memory which is waiting to occupy the CPU. Normal value of this should be less than 2 and if it is consistently become high the system CPU is fully utilized ( can consider about adding more CPU)

%runocc - This indicates the run queue (dispatch) occupancy . The consistent run queue occupancy is the CPU saturation .

swap-sz - The average number of swapped out processes

%swapocc- The percentage of time in which the processes are swapped out.

So by over all if the %runocc is greater than 90 and runq-sz value is greater than 2 we should consider about adding more CPU for a consistent system performance.

Prstate
***********
This is one of the most widely utilized system utility for below cases

1. How much my system utilized in case of CPU & memory
2. Utilization of the system ( zone wise,user wise,process wise )
3. How are the processes/threads utilizing the system ( user bond, I/O bond)


















PID: the process ID of the process.


USERNAME: the real user (login) name or real user ID.


SIZE: the total virtual memory size of the process, including all mapped files and devices, in kilobytes (K), megabytes (M), or gigabytes (G).


RSS: the resident set size of the process (RSS), in kilobytes (K), megabytes (M), or gigabytes (G).


STATE: the state of the process (cpuN/sleep/wait/run/zombie/stop).


PRI: the priority of the process. Larger numbers mean higher priority.


NICE: nice value used in priority computation. Only processes in certain scheduling classes have a nice value.


TIME: the cumulative execution time for the process.


CPU: The percentage of recent CPU time used by the process. If executing in a non-global zone and the pools facility is active, the percentage will be that of the processors in the processor set in use by the pool to which the zone is bound.


PROCESS: the name of the process (name of executed file).


NLWP: the number of lwps in the process.

Also you can sort the prstat by ascending ( S option) or descending (s option) with respect to below parameters 

cpu - sort by cpu usage ( by default this option is applicable)
pri - By process priority 
rss- Set by resident set size
size- By size of the process image
time- Sort by execution time

If you want the utilization report according to zone wise use prstat -Z . Here you can see global zone and testzone separately 


















Also one more option in prstat which is called microstat accounting (prstat -m) and it will provide the CPU latency , system time, etc


















In nutshell we can assume CPU performance issues as below

1. The number of processes in run queue is greater than the number of CPU's in the system
2. If the process queue is 4 times more than the number of available CPU's in the system
3. Also if the CPU idle time is 0 and system time is double than the user time , then the system is facing some major CPU shrink.

Also we have 3rd party performance analysis tools like Dtrace which will be discussed separately in other occasion .



Tuesday, December 8, 2015

Unix useful Tips & Tricks

Python script to check dependency services of a particular service in RHEL 7

Below is a sample python script to check dependency services of a particular service in RHEL 7.  It will prompt you to enter the service need to be verified 
******************************************
#!/usr/bin/python

import os
import subprocess

servname = raw_input ("Please enter servicename need to be checked:")
os.system ("systemctl list-dependencies --after $servname")
************************************************
as an example it prompted me to enter the service and i have entered gdm.service

[root@redhat7-test ~]# python2.7 service_dep.py
Please enter servicename need to be checked:gdm.service

output is below 
************
├─accounts-daemon.service
├─gdm.service
├─network.service
├─rhnsd.service
├─rtkit-daemon.service
└─multi-user.target
  ├─abrt-ccpp.service
  ├─abrt-oops.service
  ├─abrt-vmcore.service
  ├─abrt-xorg.service
  ├─abrtd.service
  ├─atd.service
  ├─avahi-daemon.service
  ├─brandbot.path
  ├─chronyd.service
  ├─crond.service
  ├─cups.path
  ├─dbus.service
  ├─hypervkvpd.service
  ├─hypervvssd.service
  ├─irqbalance.service
  ├─kdump.service
  ├─ksm.service
  ├─ksmtuned.service
  ├─libstoragemgmt.service
  ├─libvirtd.service
  ├─mdmonitor.service
  ├─ModemManager.service
  ├─netcf-transaction.service
  ├─network.service
  ├─NetworkManager.service
  ├─plymouth-quit-wait.service
  ├─plymouth-quit.service
  ├─postfix.service
  ├─rescue.service
  ├─rhel-configure.service
  ├─rhnsd.service
  ├─rhsmcertd.service
  ├─rngd.service
  ├─rsyslog.service
  ├─smartd.service
  ├─sshd.service
  ├─sysstat.service
  ├─systemd-logind.service
  ├─systemd-user-sessions.service
  ├─tuned.service
  ├─vmtoolsd.service
  ├─basic.target
  │ ├─rhel-import-state.service
  │ ├─systemd-ask-password-plymouth.path
  │ ├─paths.target
  │ │ ├─brandbot.path
  │ │ ├─cups.path
...........................................( to be continued)......................................


ASM driver issue after  RHEL patching

In most of the cases we used to face Oracle ASM module loading issue after patching. when we try to /etc/init.d/oracleasm listdisks, we will get the message as unable to load the oracle ASM. So in this case we have patched the server from RHEL 5.6 to RHEL 5.11 which is upgraded the kernel from 2.6.18-238.9.1.el5 to 2.6.18-398.el5.

1. First create a directory in below structure 

#mkdir  /lib/modules/2.6.18-398.el5/kernel/drivers/addon/oracleasm/

2. copy the oracle ASM module from old kernel structure to the new one 

#cp /lib/modules/2.6.18-238.9.1.el5/kernel/drivers/addon/oracleasm/oracleasm.ko lib/modules/2.6.18-398.el5/kernel/drivers/addon/oracleasm/

3. Then load the new module using below command 

#modprobe /lib/modules/2.6.18-398.el5/kernel/drivers/addon/oracleasm/oracleasm.ko

4. Install the module using below command 
#insmod /lib/modules/2.6.18-398.el5/kernel/drivers/addon/oracleasm/oracleasm.ko

5. Now if we check the oracle ASM  rpms you can see below output 

# rpm -qa | grep oracleasm
oracleasm-2.6.18-238.9.1.el5-2.0.5-1.el5
oracleasm-support-2.1.4-1.el5
oracleasmlib-2.0.4-1.el5

6. We need to get the manual installation script from RPM which is need to be executed 
#rpm -q --scripts oracleasm-2.6.18-238.9.1.el5-2.0.5-1.el5
postinstall scriptlet (using /bin/sh):
depmod -ae 2.6.18-238.9.1.el5

7. Now install the depmod script 
#depmod -ae 2.6.18-238.9.1.el5

8. After this installation once you reboot the server and check the oracle ASM status we can see all the disks are visible 
#/etc/init.d/oracleasm listdisks
ASMDATA01
ASMDATA02
ASMDATA03
ASMDATA04
ASMDATA05
ASMDATA06
ASMDATA07
ASMDATA08
ASMDATA09
ASMDATA10
ASMDATA11
ASMDATA12
ASMDATA13
ASMDATA14
ASMDATA15
ASMDATA16
ASMDATA17
ASMDATA18
ASMDATA19
ASMDATA20
ASMDATA21
ASMDATA22
******************************************************************************

Linux Password reuse configuration is not working in RHEL 5 & 6

Generally if we configure password remember option in /etc/pam.d/system-auth our assumption is it should work as expected. But unfortunately in RHEL 5/6 system it will not work 

For example the default /etc/pam.d/system-auth file in RHEL 6 is given below 


The configuration for password remember/reuse is 

password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok remember=1                        
 This will create a file called /etc/security/opasswd and used passwords will be stored in encripted format in side this file. But in this case the file is generated but it will not get updated as expected . So what ever we will configure as remember count it will not update. 

-rw-------. 1 root root    0 Aug 15  2011 opasswd_old

So in this case the solution which is working is we need to load one more module inside system-auth called 
pam_pwhistory.so 

[root@rhel6 security]# locate pam_pwhistory.so

/lib64/security/pam_pwhistory.so

So the updated system-auth file will be shown as  below 



Now if you check the /etc/security/opasswd file it is getting updated as expected 

[root@rhel6 security]# cat opasswd
ratheesh:500:4:$6$tL/oHK6s$1lHNvcvFT03XB7r6BiWGSppsra9aU3/dRpXykLr9VXZuNxbB6upACW1iBipLFv3gWrM/neG884MM17ifeijSG/,$6$zkCpe2ES$Fabn1qFnLROzHI7iCDOIbKLnUzhH6kCDj5SARVzEUQ7u4DzlrlBOqmE3snXSXSnRLlhYppRlF4fa1woQtHv.o0,$6$e/AlfJGO$6B0X7zKZMwWZ0ldVg99XqjuvtyM5q3RS/M1ZLIfbOUvz77GgU2B87PijTh.ZE7DkRVUz5TNGZVni4mkZzpDNp0,$6$XNOH1T4B$545KhPkth4nfVEkFBaSJsQk/rbmoZ5JDyyws3PCftInxxmxRaRvHF9bklxRiu6raNJKGEJA5FfkJVssCDEp9c0

Thats it....
********************************************************************************

RHEL7 Graphical User Interface (GUI) is not coming

By default when you install RHEL 7 , GUI will not come up as default and same need to be installed separately. In this case we need to install  Gnome packages and it's dependencies  using the yum repository .

1. Login to the RHEL 7 system

2. We need to check the groups available from yum repository 

[root@redhat7-test tmp]# yum grouplist
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Available environment groups:
   Minimal Install
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done

3. Now we need to install the group called "Server with GUI" 

[root@redhat7-test tmp]# yum groupinstall 'Server with GUI'

...........................output will be omitted......................................


 xorg-x11-drv-void.x86_64 0:1.4.0-23.el7                                          xorg-x11-drv-wacom.x86_64 0:0.23.0-6.el7
  xorg-x11-font-utils.x86_64 1:7.5-18.1.el7                                        xorg-x11-fonts-Type1.noarch 0:7.5-9.el7
  xorg-x11-glamor.x86_64 0:0.6.0-2.20140918git347ef4f.el7                          xorg-x11-server-common.x86_64 0:1.15.0-32.el7
  xorg-x11-server-utils.x86_64 0:7.7-4.el7                                         xorg-x11-xkb-utils.x86_64 0:7.7-9.1.el7
  yajl.x86_64 0:2.0.4-4.el7                                                        yelp-libs.x86_64 1:3.8.1-7.el7
  yelp-xsl.noarch 0:3.8.1-2.el7                                                    zenity.x86_64 0:3.8.0-4.el7

Complete!

4. In RHEL7 init run levels are mentioned as "targets" , so we need to check the current target using below command 

[root@redhat7-test tmp]# systemctl get-default
multi-user.target

5. Modify the target as "graphical target" using below command 

[root@redhat7-test tmp]# systemctl enable graphical.target --force
rm '/etc/systemd/system/default.target'
ln -s '/usr/lib/systemd/system/graphical.target' '/etc/systemd/system/default.target'

[root@redhat7-test tmp]# systemctl get-default
graphical.target

6. Reboot the system and Accept the licence agreement ( bit confusing this option, select carefully with respect to instructions)









That's it ....................

*********************************************************************************

Space cleanup


Sometime while doing the cleanup of filesystem we used to face as , if we compress or delete the big files also it will not reflect in the partition,which will be a big confusion as what is happening .

1. First we need to compress or delete the files which is big in size. Here we need to compress the root .

[root@testserver mail]# ls -lrt
total 660744
----
-rw------- 1 root     root 3131137980 Dec  8 16:30 root.

[root@testserver mail] # df -h /var

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/rootvg-varvol
                      3.9G  3.5G  300M  95% /var

[root@testserver mail]# gzip root

[root@testserver mail]# df -h /var

Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/rootvg-varvol
                      3.9G  3.9G  0  100% /var
2. From the above exercise we found that the size of the /var is increased to 100 even though we had compressed the root mail. so what will do on next

3. We need to find the process which is doing the cleanup of root mail using below command

[root@testserver mail]#lsof | grep -i deleted
.........................output is omitted............
gdm-rh-se  6085      root  txt       REG              253,1      49184    3801116 /usr/libexec/gdm-rh-security-token-helper.#prelink#.LcSyru (deleted)
yum-updat  6119      root  txt       REG              253,1       4736     263076 /usr/bin/python.#prelink# (deleted)
gzip      10101      root    3r      REG              253,2 3038580296     458776 /var/spool/mail/root (deleted)
gzip      10102      root    3r      REG              253,2 3038580296     458776 /var/spool/mail/root (deleted)
.............................output is omitted ...................

here the pid is 10101 and 10102 which is pointing deleted process

4.So get in to the proc and pid
[root@testserver mail]#cd /proc/10101/fd

[root@testserver fd]# ls -l
total 0
lrwx------ 1 root root 64 Dec  8 16:40 0 -> /dev/pts/1
lrwx------ 1 root root 64 Dec  8 16:40 1 -> /dev/pts/1
lrwx------ 1 root root 64 Dec  8 16:40 2 -> /dev/pts/1
lr-x------ 1 root root 64 Dec  8 16:40 3 -> /var/spool/mail/root (deleted)

5. Now we need to clean up the respective pointers from these PID's

[root@testserver fd]# > 3

6. Just try to check the size of the /var partition again . It is cleaned

[root@ testserver fd]# df -h /var
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/rootvg-varvol
                      3.9G  974M  2.8G  26% /var
*******************************************************************************

How to change hostname and ip address in RHEL 7



RHEL 7 is entirely different than other versions of the redhat and here i am providing the steps to change hostname and ip address in RHEL 7


1. In RHEL7 hostname details are saved in /etc/hostname . So changing the hostname is made easy in RHEL7

[root@redhat7-test ~]# cat /etc/hostname
redhat7-test


2. We need to change the ip in below file for RHEL 7 

[root@redhat7-test ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s3
UUID=d65c34f9-dd5d-4190-9e4f-f7f89c4df01f
IPADDR=192.168.1.19
NETMASK=255.255.255.0
DEVICE=enp0s3
ONBOOT=yes

3. Once we update the ipaddress restart the network service using below command 

[root@redhat7-test ~]#systemctl restart network

4. check the ipaddress using below command 

[root@redhat7-test ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:6d:64:e7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.19/24 brd 192.168.1.255 scope global enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe6d:64e7/64 scope link
       valid_lft forever preferred_lft forever
*************************************************************************

Creating local repo in RHEL 7


1. first mount the rhel 7 DVD in the local mount point from the drive 

[root@redhat7-test /]#mount -o loop /dev/cdrom /tmp/

[root@redhat7-test /]# df -h
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   14G  4.6G  9.5G  33% /
devtmpfs               488M     0  488M   0% /dev
tmpfs                  497M     0  497M   0% /dev/shm
tmpfs                  497M  6.6M  491M   2% /run
tmpfs                  497M     0  497M   0% /sys/fs/cgroup
/dev/sda1              4.7G  125M  4.6G   3% /boot
/dev/loop0             3.7G  3.7G     0 100% /tmp

2. Create a directory for RHLE 7 repository 

 [root@redhat7-test /]#mkdir -p /var/www/html/rhel7

3. Now we need to copy the contents to the local directory 

 [root@redhat7-test /]#cd /tmp

[root@redhat7-test /]#tar cvf - . | (cd /var/www/html/rhel7/; tar xvf -)

 [root@redhat7-test /]#cd /; umount /tmp/

4. Go to the directory where the repository configuration is 

[root@redhat7-test tmp]# cd /etc/yum.repos.d/

configure the file as below (file name is rhel7.repo)

[rhel7]
name=rhel7
baseurl=file:///var/www/html/rhel7/
enabled=1
gpgcheck=0

5. Now execute below commands 

[root@redhat7-test /]#yum clean all

[root@redhat7-test /]#yum repolist all

..............output is omitted...................................................

6. Now we need to install create repo command 

[root@redhat7-test /]yum install -y createrepo

Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel7                                                                                                                                            | 4.1 kB  00:00:00
Resolving Dependencies
--> Running transaction check
---> Package createrepo.noarch 0:0.9.9-23.el7 will be installed
--> Processing Dependency: deltarpm for package: createrepo-0.9.9-23.el7.noarch
--> Processing Dependency: python-deltarpm for package: createrepo-0.9.9-23.el7.noarch
--> Running transaction check
---> Package deltarpm.x86_64 0:3.6-3.el7 will be installed
---> Package python-deltarpm.x86_64 0:3.6-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                                      Arch                                Version                                      Repository                          Size
========================================================================================================================================================================
Installing:
 createrepo                                   noarch                              0.9.9-23.el7                                 rhel7                               92 k
Installing for dependencies:
 deltarpm                                     x86_64                              3.6-3.el7                                    rhel7                               82 k
 python-deltarpm                              x86_64                              3.6-3.el7                                    rhel7                               31 k

Transaction Summary
========================================================================================================================================================================
Install  1 Package (+2 Dependent packages)

Total download size: 205 k
Installed size: 553 k
Downloading packages:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                   9.1 MB/s | 205 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : deltarpm-3.6-3.el7.x86_64                                                                                                                            1/3
  Installing : python-deltarpm-3.6-3.el7.x86_64                                                                                                                     2/3
  Installing : createrepo-0.9.9-23.el7.noarch                                                                                                                       3/3
rhel7/productid                                                                                                                                  | 1.6 kB  00:00:00
  Verifying  : python-deltarpm-3.6-3.el7.x86_64                                                                                                                     1/3
  Verifying  : deltarpm-3.6-3.el7.x86_64                                                                                                                            2/3
  Verifying  : createrepo-0.9.9-23.el7.noarch                                                                                                                       3/3

Installed:
  createrepo.noarch 0:0.9.9-23.el7

Dependency Installed:
  deltarpm.x86_64 0:3.6-3.el7                                                     python-deltarpm.x86_64 0:3.6-3.el7

Complete!

7. Create the repository at /var/www/html/rhel7 ( this command will take some time to execute) 

[root@redhat7-test yum.repos.d]# createrepo /var/www/html/rhel7
Spawning worker 0 with 4432 pkgs

Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

Our local repository is ready ..