Tuesday, February 16, 2016

[iSCSI Disks: CentOS7]: How to create an iSCSI Target in Centos7

How to create an iSCSI Target in CentOS7



An iSCSI target can be a dedicated physical device in a network, or it can be an iSCSI software-configured logical device on a networked storage server. The target is the end point in SCSI bus communication. Storage on the target, accessed by an initiator, is defined by LUNs. (Redhat)
Lets start

Lets   know  the status of the  machine

Server    =   Centos 7
IP = 192.168.183.129
[root@storage-unixmen ~]# fdisk  -l 

Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00047725

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    62914559    30944256   8e  Linux LVM

Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-root: 29.5 GB, 29490151424 bytes, 57597952 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@storage-unixmen ~]#
lets  use  /dev/sdb  like  iscsi  target
make file  system Ext4  on this  device
[root@storage-unixmen ~]# mkfs.ext4   /dev/sdb
 mke2fs 1.42.9 (28-Dec-2013)
 /dev/sdb is entire device, not just one partition!
 Proceed anyway? (y,n) y
 Filesystem label=
 OS type: Linux
 Block size=4096 (log=2)
 Fragment size=4096 (log=2)
 Stride=0 blocks, Stripe width=0 blocks
 327680 inodes, 1310720 blocks
 65536 blocks (5.00%) reserved for the super user
 First data block=0
 Maximum filesystem blocks=1342177280
 40 block groups
 32768 blocks per group, 32768 fragments per group
 8192 inodes per group
 Superblock backups stored on blocks:
 32768, 98304, 163840, 229376, 294912, 819200, 884736Allocating group tables: done
 Writing inode tables: done
 Creating journal (32768 blocks): done
 Writing superblocks and filesystem accounting information: done[root@storage-unixmen ~]#
you can   also  use  fdisk  /dev/sdb to  created separated   partitions
Create  /storage  directory and  mount  the  sdb device  to this  partition
mkdir   /storage 
mount  -t ext4  /deb/sdb  /storage 

Lets  check  the   directory  mounted
root@storage-unixmen ~]# df  -h 
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   28G  1.1G   27G   4% /
devtmpfs                 479M     0  479M   0% /dev
tmpfs                    489M     0  489M   0% /dev/shm
tmpfs                    489M  6.8M  483M   2% /run
tmpfs                    489M     0  489M   0% /sys/fs/cgroup
/dev/sda1                497M  168M  330M  34% /boot
tmpfs                     98M     0   98M   0% /run/user/0
/dev/sdb                 4.8G   20M  4.6G   1% /storage
[root@storage-unixmen ~]#
 to  make this  mount  permanant    .  please  add  to   /etc/fstab
/dev/sdb  /storage  ext4 defaults  0 0

I- Lets  start  Iscsi admin tool

[root@storage-unixmen ~]# yum -y install targetcli

II- Access   Admin console

[root@storage-unixmen ~]# targetcli 
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb41
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> 

and go  to this directory 
cd backstores/fileio
> cd  /backstores/fileio 

III- create a disk-image with the name “disk01” on /storage/disk01.img with 3G

/>/backstores/fileio> create disk01 /storage/disk01.img 3G 
Created fileio disk01 with size 3221225472
/backstores/fileio>

IV-create  Target  iqn.2016-02.unixmen.com:storage.target00

/backstores/fileio> cd   /iscsi 
/iscsi> ls
o- iscsi .............................................................................................................. [Targets: 0]
/iscsi> create iqn.2016-02.unixmen.com:storage.target00
Created target iqn.2016-02.unixmen.com:storage.target00.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi>

V- Set  ip   adres   of the target under  Portals folder

/iscsi> cd  iqn.2016-02.unixmen.com:storage.target00/tpg1/portals/
/iscsi/iqn.20.../tpg1/portals>
iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/iscsi/iqn.20.../tpg1/portals> create 192.168.183.129
Using default IP port 3260
Created network portal 192.168.183.129:3260.
/iscsi/iqn.20.../tpg1/portals> ls
o- portals .................................................................................... [Portals: 1]
  o- 192.168.183.129:3260.................................................................................. [OK]
/iscsi/iqn.20.../tpg1/portals>

VI- Set  LUN

/iscsi/iqn.20…/tpg1/portals> cd   ../luns
/iscsi/iqn.20…t00/tpg1/luns> create /backstores/fileio/disk01
Created LUN 0.
/iscsi/iqn.20…t00/tpg1/luns>

VII  authorize  access .

in this  method  , we will  open access  for every machine and  without  identification

set attribute authentication=0
set attribute generate_node_acls=1
set attribute demo_mode_write_protect=0
exit

/iscsi/iqn.20...t00/tpg1/luns> cd  ../
/iscsi/iqn.20...target00/tpg1> set attribute authentication=0
Parameter authentication is now '0'.
/iscsi/iqn.20...target00/tpg1> set attribute generate_node_acls=1
Parameter generate_node_acls is now '1'.
/iscsi/iqn.20...target00/tpg1> set attribute demo_mode_write_protect=0
Parameter demo_mode_write_protect is now '0'.
/iscsi/iqn.20...target00/tpg1> exit 
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@storage-unixmen ~]# 

VIII- the machine is ready

[root@storage-unixmen ~]# netstat   -an  |  grep -i    3260 
tcp        0      0 192.168.183.129:3260    0.0.0.0:*               LISTEN     
[root@storage-unixmen ~]# 


[root@storage-unixmen ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   30G  0 disk 
├─sda1            8:1    0  500M  0 part /boot
└─sda2            8:2    0 29.5G  0 part 
  ├─centos-root 253:0    0 27.5G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0    5G  0 disk /storage
sr0              11:0    1    4G  0 rom  
[root@storage-unixmen ~]# 


Screenshot_20160214_232944

IX- Connect  from the Clietnt

Server is also centos7  with IP 192.168.183.21
first    iscsi initiator
yum install iscsi-initiator-utils.x86_64
My actual Disks
[root@node1 ~]# df  -h 
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   28G  1.1G   27G   4% /
devtmpfs                 479M     0  479M   0% /dev
tmpfs                    489M     0  489M   0% /dev/shm
tmpfs                    489M  6.7M  483M   2% /run
tmpfs                    489M     0  489M   0% /sys/fs/cgroup
/dev/sda1                497M  168M  330M  34% /boot
/dev/sdb                 5.0G   33M  5.0G   1% /glusterfs/storage1
tmpfs                     98M     0   98M   0% /run/user/0
Connect  the ISCSCI   target
Discover  the  target
[root@node1 ~]# iscsiadm   --mode discoverydb --type sendtargets --portal  192.168.183.129   --discover 
192.168.183.129:3260,1 iqn.2016-02.unixmen.com:storage.target00
Add the  disk
 
[root@node1 ~]# iscsiadm   --mode node --targetname  iqn.2016-02.unixmen.com:storage.target00 --portal  192.168.183.129:3260   --login

Logging in to [iface: default, target: iqn.2016-02.unixmen.com:storage.target00, portal: 192.168.183.129,3260] (multiple)
Login to [iface: default, target: iqn.2016-02.unixmen.com:storage.target00, portal: 192.168.183.129,3260] successful.

Congratulation  you have now  an  extra  disk
[root@node1 ~]# fdisk  -l 

Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00047725

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    62914559    30944256   8e  Linux LVM

Disk /dev/mapper/centos-root: 29.5 GB, 29490151424 bytes, 57597952 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk /dev/sdc: 3221 MB, 3221225472 bytes, 6291456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 8388608 bytes

[root@node1 ~]# lsblk 
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   30G  0 disk 
├─sda1            8:1    0  500M  0 part /boot
└─sda2            8:2    0 29.5G  0 part 
  ├─centos-root 253:0    0 27.5G  0 lvm  /
  └─centos-swap 253:1    0    2G  0 lvm  [SWAP]
sdb               8:16   0    5G  0 disk /glusterfs/storage1
sdc               8:32   0    3G  0 disk 
sr0              11:0    1    4G  0 rom  
[root@node1 ~]#
Now   you  can fdisk    /dev/sdc   to   make  partitions 
[root@node1 ~]# fdisk    /dev/sdc 
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xcc2a4d65.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (16384-6291455, default 16384): 
Using default value 16384
Last sector, +sectors or +size{K,M,G} (16384-6291455, default 6291455): 
Using default value 6291455
Partition 1 of type Linux and of size 3 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 83
Changed type of partition 'Linux' to 'Linux'

Command (m for help): p

Disk /dev/sdc: 3221 MB, 3221225472 bytes, 6291456 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 8388608 bytes
Disk label type: dos
Disk identifier: 0xcc2a4d65

   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1           16384     6291455     3137536   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@node1 ~]#
create a  folder  /iscsi-disk
root@node1 ~]# mkdir /iscsi-disk 
Format  the disk  /dev/sdc1  with ext4
[root@node1 ~]# mkfs.ext4   /dev/sdc1 
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=2048 blocks
196224 inodes, 784384 blocks
39219 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=803209216
24 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 

[root@node1 ~]#

Mount  the  dormated  partion  to  /iscsi-disk
[root@node1 ~]# mount /dev/sdc1  /iscsi-disk/
[root@node1 ~]# df -h 
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   28G  1.1G   27G   4% /
devtmpfs                 479M     0  479M   0% /dev
tmpfs                    489M     0  489M   0% /dev/shm
tmpfs                    489M  6.8M  483M   2% /run
tmpfs                    489M     0  489M   0% /sys/fs/cgroup
/dev/sda1                497M  168M  330M  34% /boot
/dev/sdb                 5.0G   33M  5.0G   1% /glusterfs/storage1
tmpfs                     98M     0   98M   0% /run/user/0
/dev/sdc1                2.9G  9.0M  2.8G   1% /iscsi-disk
[root@node1 ~]#
Screenshot_20160214_232807
To make    mount htis  disk  permanntly   every   reboot  please   add this to  your  /etc/fstab file

/dev/sdc1  /iscsi-disk/   ext4    defaults,_netdev   0 0
save and exit

Done

Friday, February 5, 2016

[Quick Tips - PING]: All About PING Command

All About PING Command


All network administrators and IT professionals are well known with the ping command. It’s a life saving command to check the basic connectivity between two hosts like host to server or host to host.
Let’s jump into it and know more in details.

What is Ping & how it works

PING stands for Packet InterNet Groper. A utility or program to determine whether a specific IP address or host / server is accessible from your network or not. The ping utility is commonly used to check for network errors & to diagnosis that problem. It’s working mechanism is simple but life saving. It works by sending a packet to the specified IP address / host / server address and waiting for a reply from that host and measured the delay of that response. This is also known as latency.
So, you can know whether a host is reachable from your network and how fast you get a response from that host after you’ve sent out a PING request. A fast ping or low latency means a more responsive connection, especially in applications where time is everything (like online web games). Normally, ping is measured in milliseconds (ms). higher latency means you have some problem with your network for sure. Though this latency varies a lot depending or routing and Geo location. If you are in USA and you are pinging a host of USA then the delay will be lower. But if you are in USA and you are pining a host of Bangladesh then definitely your latency will be higher due to Geo location and number of HOPs for that routing.
PING is the primary troubleshoot technique for any connections. It will reply or echo for a response. Ping send a message to a server / host that contains the message “PING” and receive a copy of the message back from that host / server. Ping calculate the “Round Trip Time” (or RTT) that it takes a packet to reach a particular server / host.
Every modern operating system has this ping tool pre installed. So, you can find this utility program on every OS just from the terminal ( If you are running like UNIX / Linux operating System ) or from the  ( Command prompt / MS DOS Prompt ) if you are running a MS Windows operating system.
Note: Some host or server may block or not allow any ping or ICMP request for security.
Here, I will show you ping examples by using an Ubuntu 14.04.3 LTS Linux OS. You can use whatever Linux distribution you have.

Getting ping version

To know the version, open a terminal and issue the below command.
sudo ping -V
PingUnixmenV
It will give you the currently installed ping versions to you.

Ping Execution

There are few differences while you are performing a ping test or pining from a MS Windows based OS and UNIX / Linux like OS.
Simple ping command takes only one parameter and the parameter is the host name or the host IP address that you want to ping. A simple ping example is just like below. Open a terminal and type the following
ping unixmen.com
Here unixmen.com is the host name or a host.
With the above command you will see something like this
PingUbuntuunixmen01
You need to stop the ping command by pressing CTRL+C. Else it will ping for infinite time until you stopped it. After every ping commands, it will display a summery report with these following.
Min: Minimum time that takes to get a respond from the host that has been pinged from your end.
Avg: Average time that takes to get a respond from the host that has been pinged from your end.
Max: Maximum time that takes to get a respond from the host that has been pinged from your end.
Also you will see TTL which stands for Time To Live. Ping use a numerical TTL value to attempt to reach a given host computer via the route path. This is also known as hop limit. TTL limits the time of data over a network for different purposes such as DNS records, HTTP, ICMP etc.

Ping from local / private network

To ping a host of your local / private network , you need to type the IP address of that host
ping 192.168.1.5 -c 5
Here, 192.168.1.5 is the host that I want to ping from my local network. This is a host of my local network. I hope that you know all the blocks of private network and those hosts as well.
You will see something like this.
pingunixmen1.5

Ping count / numbers

Normally, when you run a simple ping command without passing any additional parameters, it will ping that host for infinite time while you are using any Linux OS.
So say, I want ping a host for 10 times, so I will type the following on my terminal.
ping -c 10 unixmen.com
You will see something like below image.
PingUbuntuunixmenC10
report to you.
If you are running from a MS Windows OS, type this on the command prompt
ping -n 10 unixmen.com
MSWINDOWSPINGN10

Different packet size

By default, it sends 64 bytes of a ping request to a host if you are using any Linux OS and it will send 32 bytes if you used any MS Windows OS. If you want to change it and want to send heavy packet then do the following
ping -s 100 -c 6 unixmen.com
pings100c6unixmen
Here, you can see that It is not sending 64 bytes. It is sending 108 bytes.
or
From MS Windows OS , type the following
ping -l 100 unixmen.com
MSWINDOWSl100

Increase or decrease the time interval

By default ping waits for 1 second before sending the next packet towards the destination host. You can increase or decrease this using option -i if you wish according to meet your requirements.
Let’s Increase ping time interval by 3 seconds so that it send ping request after each 3 seconds
ping -i 3 unixmen.com
pingunixmeni3
It will send a ping request with a 3 seconds interval time.
If you want to decrease ping time interval, issue the below command
sudo ping -i 0.2 unixmen.com

Flood with ping

This is used to send packets soonest. This is used to test network performance. To do so, issue the below command in the terminal.
sudo ping -f unixmen.com
pingunixmenf
Press CTRL+C to stop this. You will see something like this and it may differ one host to another and how good your internet connection is.

Ping with summary statistics

If you want to see the ping summary statistics report only then use the following method. Use option -q to view only the ping statistics summary.
ping -c 5 -q unixmen.com
You will see something like this just below image.
pingunixmenq
Here, you can see that it is not echoing or replying the acknowledgment from the host. It’s just showing the report.

Ping timeout

If you pass the parameter -w with your ping command then it will specifies the deadline to terminate the ping output. This specifies the total number of seconds the ping command should send packets to that remote host.
ping -w 6 unixmen.com
So, the above command will ping the host for 6 seconds and then it will be terminated automatically and will display the result.

Ping output explanation

While pining a host you will find different output from the ping results.
Destination Host Unreachable 
If the message is simply “Destination Host Unreachable,” then possible best reason is there is no route from the local host system and between the packets that has been sent to the destination desired destination host or a remote router reports that it has no route to the destination host.
Request timed out
If you see Request timed out it means or indicates that no Echo Reply messages were received within the default time of 1 second or the time that you set while you are pining that host. This can be due to many different causes; the most common include network congestion, failure of the ARP request, packet filtering / firewall, routing error, cable fault or switch / router port problem etc etc.
Unknown host / Ping Request Could Not Find Host
ping unixmens.com
May be you misspelled the host name or the host does not exits at all in the real internet cloud. Note that, I intentionally misspelled the host name while I ping.
For every ping results you must have 0% packet loss with a good latency or lower response time. Depending of which transmission medium ( UTP, Fiber Optics Cable, Wi-Fi ) you are using your latency will differ.
Hope it will help you a lot. Thanks for reading.
Have a great day.