Monday, 16 May 2011

NFS


Network File System (NFS)

Network File System (NFS) is a way to share files between machines on a network as if the files were located on the client's local hard drive. Red Hat Linux can be both an NFS server and an NFS client, which means that it can export file systems to other systems and mount file systems exported from other machines.
The Network File System is certainly one of the most widely used network services. Network file system (NFS) is based on the Remote procedure call. It allows the client to mount and therefore, transparently access the remote file systems on the network.

NFS has 5 daemons:

Server Demon                                 Client Demon
1.    mountd                                          1.   statd
2.    statd                                              2.   lockd
3.    lockd
4.    nfsd
5.    nfslogd

Configuration file:
1.            /etc/exports

Sharing Method of Network File System:

# vi /etc/exports

(i)         /home/nfs     *
(ii)        /home/nfs     192.168.1.2
(iii)       /home/nfs     192.168.1.0/255.255.255.0(rw,sync)
(iv)      /home/nfs     192.168.1.0/24(rw,sync)
(v)       /home/nfs     *(rw,no_root_squash)

           Here are the most common export techniques and options:
/home/nfs/ 10.1.1.100(rw,sync)               export /home/nfs directory for host with IP 10.1.1.100 with read, write permissions, and synchronized mode
/home/nfs/ 10.1.1.0/24(ro,sync)               export /home/nfs directory for network 10.1.1.0 netmask 255.255.255.0 with read only permissions and synchronized mode
/home/nfs/ 10.1.1.100(rw,sync)               10.1.1.10(ro,sync)    export /home/nfs directory for host with IP 10.1.1.100 with read, write permissions, synchronized mode, and also export /home/nfs directory for hosts with IP 10.1.1.10 with read only permissions and synchronized mode
/home/nfs/ 10.1.1.100(rw,sync,no_root_squash)       export /home/nfs directory for host with IP 10.1.1.100 with read, write permissions, synchronized mode and the remote root user will be treated as a root and will be able to change any file and directory.
/home/nfs/ *(ro,sync)                                  export /home/nfs directory for any host with a read only permission and synchronized mode
/home/nfs/ *.linux.org(ro,sync)                export /home/nfs directory for any host within linux.org domain with a read only permission and synchronized mode
/home/nfs/ localhost(rw,sync)                 export /home/nfs directory for hostname localhost with read, write permissions and synchronized mode

# chkconfig nfs on
# chkconfig portmap on
# service nfs restart
# service portmap restart


Mount remote file system on client:
First we need to create a mount point
# mkdir /nfs

Mount remote file system on the mount point
# mount 192.168.1.3:/home/nfs /nfs


Note: Anytime when make any changes to the "/etc/exports" file on the nfs server, run the command to update the nfs server. 
# exportfs –avr






FTP Server


File Transfer Protocol (FTP)
           
                 FTP is a program that allows transferring the file between computers present in the network. It works on port number 20 and 21.
Configuration file:
1.                   /etc/vsftpd/vsftpd.conf                               (Main configuration file)
2.                   /etc/vsftpd/ftpusers                      (Deny user list file)
3.                   /etc/vsftpd/user_list                     (Allow user list file)

                Configure FTP Server:
# rpm –ivh --force vsftpd + <Tab>                    (For install FTP service forcefully)
# chkconfig --list vsftpd                                        (For check vsftpd configuration on run level)
# chkconfig vsftpd on                                            (For on vsftpd configuration on all run level)
# service vsftpd  restart                                        (For restart the vsftpd service)
# ps –ef | grep vsftpd                                            (For checking demon process run or not)

Note: Disable Firewall and SELinux in Firewall Setting.

Login on FTP Server: Open terminal in UNIX OS or open MS DOS in Windows OS and follow bellow instructions.
1. In UNIX OS:-
# ftp 192.168.1.3                                               (IP of FTP Server)
Name (192.168.1.3:root):                             (Enter user name)
Password:                                                           (Enter user password)
230 Login successful.
ftp>

Login as anonymous user:
# lftp 192.168.1.3                                             (IP of FTP Server)
lftp 192.168.1.3:~>                                          (There is not ask any password)

2. In Windows OS:-
C:\> ftp 192.168.1.3                                         (IP of FTP Server)
User (192.168.1.3:(none)):                           (Enter user name)
password:                                                           (Enter user password)
230 Login successful.
ftp>

Change FTP port number: To change FTP port number edit its main configuration file "vsftpd.conf" and find the line as "listen_port=21", Replace port number 21 with any desire available port number. If above line doesn't here, write this line in this file and save it.
# vi /etc/vsftpd/vsftpd.conf
 listen_port=210
:wq
# service vsftpd restart

            Check current FTP port number:
# netstat -lnp | grep ftp
tcp     0     0 0.0.0.0:210     0.0.0.0:*     LISTEN     1311/vsftpd

            Login on FTP server with different port number:
# ftp <ip_address> <port_number>
# ftp 192.168.1.3 210

                Allow a user to login through FTP server: Add a new line “userlist_deny=NO” in FTP main configuration file “/etc/vsftpd/vsftpd.conf” for allow all users of “user_list” file. Then add a user which you want to allow login through FTP server in “/etc/vsftpd/user_list” file.
# vim /etc/vsftpd.conf
                Go to bottom of this file and a new line.
userlist_deny=NO
:wq
# echo nilesh >> /etc/vsftpd/user_list  (Here nilesh is a user which allow to FTP Server)

                Deny a user to login through FTP server: Add the user which you want to deny login through FTP server in “/etc/vsftpd/ftpusers” file.
# echo rajesh >> /etc/vsftpd/ftpusers   (Here rajesh is a user which deny to FTP Server)

YUM


Configuration of Yum (Yellowdog Updater Modifier)

For configuration of yum firstly we insert the Linux bootable DVD or CD and mount the CD or DVD in /mnt through          
# mount /dev/cdrom /mnt     
# cd /mnt    
# ll     
# cd  /mnt/Server
# Server]#rpm –ivh --force vsftpd+tab
# cd ..
mnt]# cp –rav * /var/ftp/pub      (For copy all the DVD contents in pub
directory)
# vim /etc/yum.repos.d/Server.repo           (For open the Repository file and write
below lines in this file.)
[Server]
name=Server repository
baseurl=file:///var/ftp/pub/Server
gpgcheck=0
[VT]
name=VT repository
baseurl=file:///var/ftp/pub/VT
gpgcheck=0
[Update]
name=Update repository
baseurl=file:///var/ftp/pub/
gpgcheck=0
:wq!
# cd /var/ftp/pub/Server                                                (For go to Server dir)
# Server]# rpm –ivh createrepo + tab                     (Use the tab key for proper file.)
# createrepo –v /var/ftp/pub/Server     <Enter>
(After fire this command 2113 Server RPM arranged by alphabetically and one error will come remove that and fire above command again for arrange the files.)
If u get .olddata error run the command
# rm –rf /var/ftp/pub/Server/.olddata (Use the tab key for proper file.)
# createrepo –v /var/ftp/pub/VT     <Enter>
(After fire this command 31 VT RPM arranged by alphabetically and one error will come remove that and fire above command again for arrange the files.)
If u get .olddata error run the command
# rm –rf /var/ftp/pub/VT/.olddata      (Use the tab key for proper file.)
# createrepo –v /var/ftp/pub/     <Enter>
(After fire this command 2208 Server RPM arranged by alphabetically.)

            Install packages through yum:-
# yum install RPM name     (For install the particular RPM)
# yum remove RPM name   (For remove the particular RPM)  
# yum –u RPM name                  (For updating the RPM)

LVM

Logical Volume Management

            Logical Volume Management (LVM) can allow to manage active partitions. Before LVM, we had no easy way to increase or reduce the size of a partition after Linux was installed. For example, if find that we have extra space on the /home directory partition and need more space on /var directory partition for log files, LVM will let reallocate the space. Alternatively, if we are managing a server on a growing network, new users will be common. May reach the point at which we need more room on our /home directory partition. With LVM, we can add a new physical disk and allocate its storage capacity to an existing /home directory partition.


          Install Red Hat Linux with LVM

            Boot with Red Hat Linux DVD. Click on “Create custom layout” to create partitions.
            1st create a “/boot” partition of 200 MB.
            2nd create LVM partition of 50 GB or as per requirement.
            Select newly created LVM (Physical Volume) > Create > Select LVM Volume Group > Create. Click on Add > Select Mount Point “/” and set its size approx 10 GB > Ok.
            Same as create -
            /home             5 GB
            /tmp                 5 GB
            /usr                 5 GB
            /var                  5 GB
            /usr/local        5 GB
            /opt                  5 GB
            Then click on ok.
            Create a Swap partition, Select its size to double of RAM space.
            Click on Ok > Click on Write changes on disk.
            Follow the instructions and click on next. The installation is starting.

         
Extend a Logical Volume:
1. Unmount the logical volume if it’s mounted.  (Note necessary)
# umount /home

2. Extend the logical volume with 50GB.
# lvextend -L +50G /dev/vg1/log2

3. Check the volume group.
#e2fsck -f /dev/vg1/log2

4. Resize the filesystem on the logical volume (ext3 in this case).
# resize2fs /dev/vg1/log2

            5. Mount the logical volume again.
# mount /dev/vg1/log2 /home                              (Note necessary)


            Reduce a Logical Volume: Make a backup of logical volume before reduction and to use around 5 GB of safe space to avoid data loss.

1. Umount the logical volume.
# umount /home

            2. Check the filesystem integrity.
# fsck -f -y -v /dev/vg1/log2

3. Resize the file system to something smaller than the final size (around 30GB in this case):
# resize2fs /dev/vg1/log2 30000M

4. Check the filesystem integrity again.
# fsck -f -y -v /dev/vg1/log2

5. Reduce the logical volume
# lvreduce -L 30G /dev/vg1/log2

6. Resize the filesystem to fit the logical volume.
# resize2fs /dev/vg1/log2

7. Check the filesystem to know whether the reduction went fine.
# fsck -f -y -v /dev/vg1/log2

8. Mount the logical volume.
# mount /dev/vg1/log2 /home

            9. Check the /home file system size:
# df -h | grep /home

            NOTE: In LVM we can increase the size of any partitions on live system without un-mounting the partition but we can't decrease all partitions on live system. Because for decreasing the size of any partition that is necessary to un-mount that partition and then decrease partition size otherwise data will be lost, and we can't un-mount these partitions /, /var, /usr, /tmp. So we can decrease only /home, /opt, /usr/local partitions. If we want to decrease the size of /, /var, /usr, /tmp partitions then boot system in Rescue mode with Linux DVD and do this.


            Create LVM Partitions after installing OS

            To create a new LVM system, we need to create a new PV (Physical Volume), using a command such as pvcreate, assign the space to a VG (Volume Group) with a command such as vgcreate, and allocate the space from some part of available VGs to an LV (Logical Volume) with a command such as lvcreate.

            Creating a Physical Volume: The first step in creating an LVM is to start with a physical disk. In that disk create to partition for example /dev/sda10 and /dev/sda11.After creating partition which id is 8e we can configure it like this.
# fdisk /dev/sda
            Command (m for help) : t
            Partition number (1-11): 10           
            Partition ID (L to list options): 8e
            Command (m for help) : w

            Save the partition table with “w” and run the command partprobe.
# partprobe

            Creating Physical Volume: Run these command to create Physical Volume.
# pvcreate /dev/sda10 /dev/sda11                      (This command creates the physical volume)
# pvs                                                              (It show the physical volumes)

            Creating a Volume Group: Once we have two or more PVs, we can create a volume group (VG) by  the following command, substitute the name of our choice for volume group name.
# vgcreate vg1 /dev/sdb10 /dev/sdb11
            Where vg1 is a volume group name. When Volume Group successfully create then use this command to see the volume group.
# vgs

            We can add more physical volume to any VG. Assume there's an existing /dev/sda12 partition, using a Linux LVM type, and the pvcreate command has been applied to that partition. We can then add that partition to an existing VG with the following command:
# vgextend vg1 /dev/sda12

            Creating a Logical Volume: However, a VG doesn't create and mount a filesystem on it. So we need to create a logical volume (LV) for this purpose. The following command creates an LV. We can add as many chunks of disk space as our need.
# lvcreate –L +250M –n /dev/vg1/log1
           
            The following command creates a device named log1 in /dev/vg1 of 250 MB size. We can format this device as if it were a regular disk partition, and then mount on a newly created directory. Using the “df -h” command to check the size of the volume after we've mounted on a directory on.
#lvs                (Show the logical volume)

            After creating a logical volume, format that partition by running this command.
# mke2fs –j /dev/vg1/log1

            Then mount that partition and add its entry in fstab file like this.
            dev/vg1/log1 /nilesh ext3 defaults 0 0

            Removing a Logical Volume: Removing an existing LV requires a straightforward command. The basic command is lvremove. If you've created an LV in the previous section and want to remove it, the basic steps are simple. However, it will work only from a rescue environment such as the linux rescue mode from a CD/DVD-based system. Save any data in directories that are mounted on the LV.
1. Unmount any directories associated with the LV. Based on the example in the previous section; you would use the following command:
# umount /dev/vg1/log1
            2. Apply the lvremove command to the LV with a command such as:
# lvremove /dev/vg1/log1
            You should now have the PV from this LV free for use in other LV.

            Resize logical volume and their filesystem.
            1. Unmount your mounted lvm partition.
            2. Run the command
# lvextend –L2G /dev/iiht/log1     (It will extend lvm partition to 2 Gb)
            3. Then run the command
# e2fsck –f /dev/vg1/log1              (It will check ext3 partition)
            4. Now run the command
# resize2fs /dev/iiht/log1               (This will resize lvm partition)

            Then mount it again and run the command “df –h” to see it is extended or not.
# df -h

            Remove Physical Volume:
# pvremove /dev/sda11



Commands         Description
partprobe             To notify kernel about the change in device
pvcreate               To create physical volume
pvdisplay              To display the size and other information about physical volume
pvremove             To remove the physical volume
pvresize               To modify the size of physical volume
pvscan                 To scan the physical volume
vgextend              To extend the size of volume group
vgreduce             To reduce the size of volume group
vgscan                 To scan the volume group for change
vgdisplay             To display the status and information about volume group
lvdisplay               To display the status of lvm
lvreduce               To reduce the size of lvm
lvextend               To extend the size of lvm
lvcreate                To create the lvm
lvremove              To remove the lvm partition
lvscan                  To scan lvm for change


Boot to UEFI Mode or legacy BIOS mode

Boot to UEFI Mode or legacy BIOS mode Choose UEFI or legacy BIOS modes while installing Windows. After Windows is installed, if you nee...