Search H3r3

Tuesday 26 March 2019

Install NFS Server

Environment

Here, I will be using CentOS 7 minimal and Fedora 27 system. This guide is also applicable for Oracle Linux and older version of Fedora systems.
Here are my demo nodes details.
NFS Server Hostname: server.itzgeek.local (CentOS 7)

NFS Server IP Address: 192.168.12.5/24
NFS Client Hostname: client.itzgeek.local (Fedora 27)

NFS Client IP Address: 192.168.12.7/24

Usage of NFS

  • File / Folder sharing between *nix systems
  • Allows to mount remote filesystems locally
  • Can be acted as Centralized Storage system
  • It can be used as a Storage Domain ( Datastore) for VMware and other Virtualization Platform.
  • Allows applications to share configuration and data files with multiple nodes.
  • Allows to have updated files across the share.

Important Services

The following are the important NFS services, included in nfs-utils packages.
rpcbind : The rpcbind server converts RPC program numbers into universal addresses.
nfs-server :  It enables the clients to access NFS shares.
nfs-lock / rpc-statd : NFS file locking. Implement file lock recovery when an NFS server crashes and reboots.
nfs-idmap : It translates user and group ids into names, and to translate user and group names
into ids

Important Configuration Files

You would be working mainly on below configuration files, to setup NFS server and Clients.
/etc/exports : It is the main configuration file, controls which file systems are exported to remote hosts and specifies options.
/etc/fstab : This file is used to control what file systems including NFS directories are mounted when the system boots.
/etc/sysconfig/nfs : This file is used to control which ports the required RPC services run on.
/etc/hosts.allow, and /etc/hosts.deny : These files are called TCP wrappers, controls the access to NFS server. It is used by NFS to decide whether or not to accept a connection coming in from another IP address

Install NFS Server

We need to install NFS packages on NFS server, install it using the following command.
[root@server ~]# yum install nfs-utils libnfsidmap
Once the packages are installed, enable and start NFS services.
systemctl enable rpcbind
systemctl enable nfs-server
systemctl start rpcbind
systemctl start nfs-server
systemctl start rpc-statd
systemctl start nfs-idmapd

Create NFS Share

Now, let’s create a directory to share with client servers. Here I will be creating a new directory named “nfsfileshare” in “/” partition.
Note: You can also share your existing directory with NFS.
[root@server ~]# mkdir /nfsfileshare
Allow client servers to read and write to the created directory.
[root@server ~]# chmod 777 /nfsfileshare/
We have to modify “/etc/exports“file to make an entry of directory “/nfsfileshare” that you want to share.
[root@server ~]# vi /etc/exports

/nfsfileshare 192.168.12.7(rw,sync,no_root_squash)
/nfsfileshare : shared directory
192.168.12.20 IP address of client machine. We can also use the hostname instead of an IP address. It is also possible to define the range of clients with subnet like 192.168.12.0/24.
rw : Writable permission to shared folder
sync :  all changes to the according filesystem are immediately flushed to disk; the respective write operations are being waited for.
no_root_squash : By default, any file request made by user root on the client machine is treated as by user nobody on the server. (Exactly which UID the request is mapped to depends on the UID of user “nobody” on the server, not the client.) If no_root_squash is selected, then root on the client machine will have the same level of access to the files on the system as root on the server.
You can get to know all the option in the man page (man exports) or here.
Export the shared directories using the following command.
[root@server ~]# exportfs -r
Extras:
exportfs -v : Displays a list of shares files and export options on a server
exportfs -a : Exports all directories listed in /etc/exports
exportfs -u : Unexport one or more directories
exportfs -r : Reexport all directories after modifying /etc/exports
After configuring NFS server, we need to mount that shared directory in the client-server.

Configure Firewall

We need to configure firewall on NFS server to allow client servers to access NFS shares. To do that, run the following commands on the NFS server.
firewall-cmd --permanent --zone public --add-service mountd
firewall-cmd --permanent --zone public --add-service rpc-bind
firewall-cmd --permanent --zone public --add-service nfs
firewall-cmd --reload

Configure NFS client

We need to install NFS packages on NFS client-server to mount remote filesystem, install NFS packages using below command.
[root@client ~]# yum -y install nfs-utils libnfsidmap
Once the packages are installed, enable and start NFS services.
systemctl enable rpcbind
systemctl start rpcbind

Mount NFS shares on clients

Before mounting the NFS share, we need to check the available shares on the NFS server. To do that,  run the following command on the client-server.
[root@client ~]# showmount -e 192.168.12.5

Export list for 192.168.12.5:
/nfsfileshare 192.168.12.7
As per the command, the /nfsfileshare is available on 192.168.12.5.
Extras:
showmount -e : Shows the available shares on your local machine (NFS Server).
showmount -e <server-ip or hostname>: Lists the available shares on the remote server
Now, create a mount point to mount the shared folder ‘/nfsfileshare’ which we’ve created before in the server.
[root@client ~]# mkdir /mnt/nfsfileshare
Use below command to mount a shared directory “/nfsfileshare” from NFS server “192.168.12.5” in “/mnt/nfsfileshare” on client-server.
[root@client ~]# mount 192.168.12.5:/nfsfileshare /mnt/nfsfileshare
Verify the mounted share on client server using “mount” command.
[root@client ~]# mount | grep nfs

sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
192.168.12.5:/nfsfileshare on /mnt/nfsfileshare type nfs4 (rw,relatime,vers=4.1,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.12.7,local_lock=none,addr=192.168.12.5)
Also, you can use “df” command to check the mounted NFS share.
[root@client ~]# df -hT

Filesystem                 Type      Size  Used Avail Use% Mounted on
devtmpfs                   devtmpfs  478M     0  478M   0% /dev
tmpfs                      tmpfs     489M     0  489M   0% /dev/shm
tmpfs                      tmpfs     489M  620K  488M   1% /run
tmpfs                      tmpfs     489M     0  489M   0% /sys/fs/cgroup
/dev/mapper/fedora-root    xfs        18G  1.3G   17G   8% /
tmpfs                      tmpfs     489M  4.0K  489M   1% /tmp
/dev/sda1                  ext4      477M   93M  355M  21% /boot
tmpfs                      tmpfs      98M     0   98M   0% /run/user/0
192.168.12.5:/nfsfileshare nfs4       50G  858M   50G   2% /mnt/nfsfileshare
Create a test file on the mounted directory to verify the read and write access on NFS share.
[raj@client ~]$ touch /mnt/nfsfileshare/test
If the above command returns no error, you have working NFS setup.

Automount NFS Shares

To mount the shares automatically on every reboot, need to modify “/etc/fstab” file of your client system.
Add “green” line at the end.
[root@client ~]# vi /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue May 26 21:30:49 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/fedora-root /                       xfs     defaults        0 0
UUID=f748af6c-0de9-4dc0-98e6-959ffc400f2f /boot                   ext4    defaults        1 2
/dev/mapper/fedora-swap swap                    swap    defaults        0 0
192.168.12.5:/nfsfileshare/ /mnt/nfsfileshare nfs rw,sync,hard,intr 0 0
save and close the file.
Reboot the client machine and check the share whether it is automatically mounted or not.
[root@client ~]# reboot
Verify the mounted share on client server using “mount” command.
[root@client ~]# mount | grep nfs
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
192.168.12.5:/nfsfileshare on /mnt/nfsfileshare type nfs4 (rw,relatime,sync,vers=4.1,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.12.7,local_lock=none,addr=192.168.12.5)
If you want to unmount that shared directory from your client server after you are done with the file sharing, you can unmount that particular directory using“umount” command.
[root@client ~]# umount /mnt/nfsfileshare
If you wish not to use static mounts, you can configure AutoFS on CentOS 7 to mount NFS share only when they are accessed by a user.
That’s All. You have successfully setup NFS Server on CentOS 7 / RHEL 7 / Fedora 26.

Monday 25 February 2019

Samba – How to set up a Samba client on CentOS/RHEL 7

Samba – How to set up a Samba client on CentOS/RHEL 7

If you have directories on your machine that you want to share out to other machines then you can do this by setting up your machine as an NFS server. However with NFS you can only share out folders to machine that are in the same private network. If you want share folders to other machines over the public internet, then that’s where you need to use the Samba/CIFS protocol. You can follow along this article using this vagrant project on Github.
We will walk through the following example:

+--------------------------+              +--------------------------+
|                          |              |                          |
|      samba-storage       |              |       samba-client       |
|     (IP: 10.0.4.10)      |              |                          |
|                          |              |                          |
|                          |              |                          |
|                          |              |                          |
|  +------------------+    |              |     +---------------+    |
|  | /samba/export_rw |<----------------------->| /mnt/dcp |    |
|  +------------------+    |              |     +---------------+    |
|                          |              |                          |
|                          |              |                          |
+--------------------------+              +--------------------------+
In this article we’ll cover setting up the samba client side. We cover setting up a Samba server in a separate article.

First you need to install the samba software:

$ yum -y install samba samba-client cifs-utils
 
Note: It’s recommended to install the samba server software on all samba
clients.

Then we create our mount point:

$ mkdir -p /mnt/dcp
 
Then we create a group that mirrors the same group that existing on the samba server:

$ groupadd --gid 2000 sambagroup
 
Now we need to add members to that group, in our case we’ll add the root user:

$ usermod -aG sambagroup root
 
Next we need check if we can connect to the samba server, and if we can to also check what shares are available:

$ smbclient -L //samba-storage.local -U samba_user1
Enter SAMBA\samba_user1's password:
 
 
 Domain=[SAMBA-STORAGE] OS=[Windows 6.1] Server=[Samba 4.6.2]

 Sharename       Type      Comment
 ---------       ----      -------
 print$          Disk      Printer Drivers
 bckp_storage    Disk      Folder for storing backups
 IPC$            IPC       IPC Service (Samba server samba-storage)
 samba_user1     Disk      Home Directories
Domain=[SAMBA-STORAGE] OS=[Windows 6.1] Server=[Samba 4.6.2]

 Server               Comment
 ---------            -------

 Workgroup            Master
 ---------            -------
Now we can test this by manually mounting this share like this:

$ mount -t cifs -o user=samba_user1,password=password123 //samba-storage.local/export_rw /mnt/dcp/
 
You can check if this command has worked using the mount or df -h commands.

To unmount this, do:

$ umount /mnt/dcp

If you has, then you automount this samba share at boot time by adding the following entry to the vi/etc/fstab file:

//samba-storage.local/bckp_storage /mnt/dcp  cifs  username=samba_user1,password=password123,soft,rw  0 0
 
To test this line, just run:

$ mount -a

Then check again if this has mounted successfully using mount or df -h commands. If all is well try creating dummy content in the mountpoint and see if the content also shows up on the samba server.

Monday 18 February 2019

Mount Windows Share From Centos

The mount.cifs file is provided by the samba-client package. This can be installed from the standard CentOS yum repository by running the following command:


yum install samba samba-client
 
 
Once installed, you can mount a Windows SMB share on your CentOS server by running the following command:


Syntax:
mount.cifs //SERVER_ADDRESS/SHARE_NAME MOUNT_POINT -o user=USERNAME
 
SERVER_ADDRESS: Windows system’s IP address or hostname

SHARE_NAME: The name of the shared folder configured on the Windows system

USERNAME: Windows user that has access to this share

MOUNT_POINT: The local mount point on your CentOS server
I am mounting to a share from \\10.11.10.26\snaps
Make a directory under mount for your reference

mkdir /mnt/mymount
 
Now I am mounting the snaps folder from indiafps02, User name is the Domain credentials, i.e. Mydomain in this case

mount.cifs //10.11.10.26/snaps /mnt/mymount -o user=ajeeth,password=curve,dir_mode=0777,file_mode=0777
 
Now you could see the content by typing

ls /mnt/mymount
 
So, after performing your task, just fire umount command

umount /mnt/mymount
 
That's it. You are done.


Thursday 7 February 2019

Remote Desktop CentOS7

RUN THIS CODING FIRST


1)  rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro 
 
2)  rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm
 
3)  yum install rdesktop
 
 
CHECK RDESKTOP VERSION 
 
4)  rpm -qa rdesktop 
 
CONNECT REMOTE DESKTOP PC 

5)  rdesktop -u Ajeeth 192.168.50.5

Monday 28 January 2019

Install TeamViewer on CentOS 5.x/6.x/7.x

Install TeamViewer on CentOS 5.x/6.x, RHEL, Fedora 15/16/17/18/19

 

1. cd /opt

2. wget http://download.teamviewer.com/download/version_9x/teamviewer_linux.rpm

3.  yum localinstall teamviewer_linux.rpm

Start TeamViewer:

4.  teamviewer