Friday, April 28, 2017

Script:- if test, usage

usage()
{
    echo "Usage: $command [-i|-u|-b|-h  ]"
    echo "-i : fresh install "
    echo "-u : upgrade install"
    echo "-b :Upgrade Agent only , no server info will be updated"
    echo "-h : show this help"
}

user=`id | cut -d'=' -f2 | cut -d\( -f1`
if [ $user -ne 0 ]; then
    echo "This package needs root authentication to install."
    exit 1
fi
###Validation: No args, go away
if [ $# -eq 0 ]; then
    usage
    exit 1
fi

Sunday, April 23, 2017

RHEL7 - NFS server, client and autofs


1. On nfs server, perform the following
[root@bishal certs]# vi /etc/exports
/home *(rw,sync)

[root@bishal certs]# exportfs -r

[root@bishal certs]# exportfs
/opt/OS_Image   <world>
/home           <world>
[root@bishal certs]#

[root@bishal prema]# groupadd -g 1050 dba
[root@bishal prema]# useradd -u 1050 -g 1050 gagan
[root@bishal prema]# passwd gagan
Changing password for user gagan.
New password:
BAD PASSWORD: The password fails the dictionary check - it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.



2. On Client system, perform the following tasks
[root@prema ~]# showmount -e 192.168.10.238
clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)
[root@prema ~]# showmount -e 192.168.10.238^C

[root@prema ~]# mount 192.168.10.238:/home /mnt

[root@prema ~]# df -h /mnt
Filesystem            Size  Used Avail Use% Mounted on
192.168.10.238:/home   18G   14G  4.6G  75% /mnt
[root@prema ~]#


3. Setting up auto-fs
Now, remove all the content from home directory on client system.

[root@prema home]# mkdir /var/tmp/all
[root@prema home]# ls
ahn  all  bau  bishal  dev  kamal  niv  pradip  prema  ram  sam

[root@prema home]# mv * /var/tmp/all

[root@prema home]# ls -l
total 0
[root@prema home]# pwd
/home


[root@prema home]# vi /etc/auto.master
/home   /etc/home.autofs

:wq


[root@prema home]# vi /etc/home.autofs
prema   192.168.10.238:/home/prema

[root@prema home]# groupadd -g 1050 dba

[root@prema home]#  useradd -u 1050 -g 1050 gagan
useradd: cannot create directory /home/gagan
[root@prema home]# ls
[root@prema home]# pwd
/home
[root@prema home]# passwd gagan
Changing password for user gagan.
New password:
BAD PASSWORD: The password fails the dictionary check - it is based on a dictionary word
Retype new password:
passwd: all authentication tokens updated successfully.

Now, login to the system with respective users

[root@prema home]# vi /etc/auto.master
[root@prema home]# vi /etc/home.autofs
[root@prema home]# cat /etc/home.autofs
*       192.168.10.238:/home/&
[root@prema home]# systemctl restart autofs
[root@prema home]# echo $?
0
[root@prema home]# pwd
/home
[root@prema home]# ls
[root@prema home]# cd /
[root@prema /]# cd /home
[root@prema home]# ls
gagan  prema
[root@prema home]# pwd
/home
[root@prema home]# pwd
/home
[root@prema home]# ls
bishal  gagan  pradip  prema
[root@prema home]#

[root@prema /]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
/dev/sda3                     18G  4.0G   14G  23% /
devtmpfs                     898M     0  898M   0% /dev
tmpfs                        912M  156K  912M   1% /dev/shm
tmpfs                        912M  9.2M  903M   2% /run
tmpfs                        912M     0  912M   0% /sys/fs/cgroup
/dev/sda1                    297M  152M  146M  51% /boot
/dev/mapper/datavg-datavol   2.0G   33M  2.0G   2% /opt/oracle
tmpfs                        183M   20K  183M   1% /run/user/1000
tmpfs                        183M     0  183M   0% /run/user/0
192.168.10.238:/home          18G   14G  4.6G  75% /mnt
tmpfs                        183M     0  183M   0% /run/user/1050
192.168.10.238:/home/gagan    18G   14G  4.6G  75% /home/gagan
192.168.10.238:/home/prema    18G   14G  4.6G  75% /home/prema
192.168.10.238:/home/bishal   18G   14G  4.6G  75% /home/bishal
192.168.10.238:/home/pradip   18G   14G  4.6G  75% /home/pradip
192.168.10.238:/home/kamal    18G   14G  4.6G  75% /home/kamal
[root@prema /]#

4. Disable autofs
[root@prema /]# systemctl stop autofs
[root@prema /]# df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/sda3                    18G  4.0G   14G  23% /
devtmpfs                    898M     0  898M   0% /dev
tmpfs                       912M  156K  912M   1% /dev/shm
tmpfs                       912M  9.2M  903M   2% /run
tmpfs                       912M     0  912M   0% /sys/fs/cgroup
/dev/sda1                   297M  152M  146M  51% /boot
/dev/mapper/datavg-datavol  2.0G   33M  2.0G   2% /opt/oracle
tmpfs                       183M   20K  183M   1% /run/user/1000
tmpfs                       183M     0  183M   0% /run/user/0
192.168.10.238:/home         18G   14G  4.6G  75% /mnt
tmpfs                       183M     0  183M   0% /run/user/1050
[root@prema /]#

5. Restore original home directory contents
# cd /home; mv /var/tmp/all/* .
or
[root@prema home]# pwd
/home
[root@prema home]# tar -xvzf /var/tmp/home-content.tar.gz

Monday, April 17, 2017

RHEL7 - NFS server share and mounting at client

RHEL7 - NFS server share and mounting at client



On NFS server
1. Install nfs server package
# yum install nfs-utils

2. Start nfs server service
# systemctl enable nfs-server.service
# systemctl start nfs-server.service

3. Disable to add nfs service to firewall
# systemctl stop firewalld
or
# firewall-cmd --permanent --zone=public --add-service=nfs
# firewall-cmd --reload

4. Now, Specify the share and add entry to config file
# mkdir /opt/myshare && chmod 777 /opt/myshare
# vi /etc/exports
/opt/myshare *(rw,sync)

5. Re-read the config
# exportfs -r

6. Verify the share
# exportfs


On client

1. Install the package if not installed
# yum install nfs-utils

2. Create a mount point
# mkdir /opt/www

3. Add entry to /etc/fstab
# vi /etc/fstab
nfsserver:/the_share /opt/www nfs defaults 0 0

4. Mount the share on the client
# mount -a
or
# mount /opt/www
or
# mount nfsserver:/shared_path /mountpoint
# mount 192.168.10.20:/opt/myshare /opt/www

Verify the mount
# df -h /opt/www
#


Troubleshooting steps
- most importantly the issue is because of firewall. Add nfs service to allow the connection to server or port 2049.
- Make sure both servers can ping each other.
- verify all the configuration files that there is no typo.

Solaris 10 - deleting user command history




HISTSIZE=0

for i in `ls /export/home/*/.*profile`; do echo ls -l $i; done
for i in `ls /export/home/*/.*profile`; do grep HISTSIZE $i; done
for i in `ls /export/home/*/.*profile`; do echo "export HISTSIZE=0" >> $i; done
for i in `ls /export/home/*/.*profile`; do grep HISTSIZE $i; done
for i in `ls /export/home/*/.bash_history`; do ls -l $i; done
for i in `ls /export/home/*/.bash_history`; do cat /dev/null > $i; ls -l $i; done


1. Change root password


2. Change users home dir
chmod 700 /export/home/*


3. Remove history file
ls /export/home/*/.bash_history
cat /dev/null > /export/home/*/.bash_history

for i in `ls /export/home/*/.bash_history`; do echo $i; done
for i in `ls /export/home/*/.bash_history`; do cat /dev/null > $i; done


4. Add following to users profile
ls -l /export/home/*/.profile | more
export HISTCONTROL=ignorespace
echo "export HISTCONTROL=ignorespace" >> /export/home/*/.profile
echo "export HISTCONTROL=ignorespace" >> /export/home/*/.bash_profile
for i in `ls /export/home/*/.profile /export/home/*/.bash_profile`; do echo $i; done
for i in `ls /export/home/*/.profile /export/home/*/.bash_profile`; do echo "export HISTCONTROL=ignorespace" >> $i; done
for i in `ls /export/home/*/.profile /export/home/*/.bash_profile`; do grep HISTCONTROL $i; done
passwd kbhusal
passwd root
chmod 700 /export/home/*
for i in `ls /export/home/*/.bash_history`; do ls -l $i; done
for i in `ls /export/home/*/.bash_history`; do cat /dev/null > $i; done
for i in `ls /export/home/*/.bash_history`; do ls -l $i; done
sleep 1
for i in `ls /export/home/*/.profile /export/home/*/.bash_profile`; do echo "export HISTCONTROL=ignorespace" >> $i; done
for i in `ls /export/home/*/.profile /export/home/*/.bash_profile`; do grep HISTCONTROL $i; done
sleep 1
ls -ld /export/home/*




You can add HISTFILE=~/.hist$$ to your .profile. This should generate a unique file per session.

You can add HISTFILE=~/.hist$$ to your .profile. This should generate a unique file per session.
You can remove these files automatically by adding the following.
trap 'rm ${HISTFILE}' exit
bash stores command entries in HISTFILE (by default ~/.bash_history) and has a fixed size of how many to keep - HISTFILESIZE (by default 500). If the commands, one types, exceed that number, then history of those is lost.
Commands can also be ignored, see HISTIGNORE, as well as commands that start with a leading space - see HISTCONTROL=ignorespace. Those are not ever stored in HISTFILE.
clears the history often (history -c
savehist with csh, HISTFILE/HISTSIZE with ksh and bash). ksh records the history in real time while bash records it on shell exit so you might lose the history if the shell dies abruptly. Bash has also some setting that would prevent some commands not to appear on the history (HISTCONTROL, HISTIGNORE, HISTFILESIZE). If you have more than one interactive shell running, commands will be lost if the histappend shell option is not set with bash.

Friday, April 7, 2017

RHEL7 - Initial Server set up


Summary

1. Add host entry to hosts file.
# vi /etc/hosts
2. Mount your ISO image and copy it locally
# mount -t iso9660 -o loop /home/kbhusal/rhel-server-7.3-x86_64-dvd.iso /mnt
# df -h /mnt
# cd /mnt
# mkdir /opt/OS_Image
# cp -a * /opt/OS_Image/
3. Create required user to the system if its local.
# useradd -c "John Smith" jsmith
# passwd jsmith
4. Grant user admin access to the system.
# visudo
5. Set up local repo
# cd /etc/yum.repos.d/
#  vi local.repo
# yum clean all
# yum repolist
# yum search httpd
# rpm -qa | grep httpd
# yum install httpd

Detail


1. Once you login to newly installed system, add host entry to hosts file.
[root@sgld-lx-v01 ~]# vi /etc/hosts
192.168.10.120    sgld-lx-v01.expanor.local    sgld-lx-v01

2. Create yum repo [ Mount your ISO image and copy it locally ]
[root@sgld-lx-v01 ~]# mount -t iso9660 -o loop /home/kbhusal/rhel-server-7.3-x86_64-dvd.iso /mnt
mount: /dev/loop0 is write-protected, mounting read-only
[root@sgld-lx-v01 ~]# df -h /mnt
Filesystem      Size  Used Avail Use% Mounted on
/dev/loop0      3.6G  3.6G     0 100% /mnt
[root@sgld-lx-v01 mnt]# mkdir /opt/OS_Image
[root@sgld-lx-v01 mnt]# cp -a * /opt/OS_Image/

3. Create required user to the system if its local.
[root@sgld-lx-v01 mnt]# useradd -c "Pradip Giri" pradip
[root@sgld-lx-v01 mnt]# passwd pradip
Changing password for user pradip.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

4. Grant user admin access to the system.
[root@sgld-lx-v01 mnt]# visudo
User_Alias ADMINS = sam, pradip
ADMINS  ALL=(ALL)       NOPASSWD: ALL

5. Set up local repo
[root@sgld-lx-v01 yum.repos.d]# vi local.repo
[root@sgld-lx-v01 yum.repos.d]# cat local.repo
[LOCAL]
name = Local Redhat Repo
baseurl = file:///opt/OS_Image
enabled = 1
gpgcheck = 0
[root@sgld-lx-v01 yum.repos.d]# yum clean all
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: LOCAL
Cleaning up everything
[root@sgld-lx-v01 yum.repos.d]# yum repolist
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
LOCAL                            | 4.1 kB  00:00:00
(1/2): LOCAL/group_gz            | 136 kB  00:00:00
(2/2): LOCAL/primary_db          | 3.9 MB  00:00:00
repo id                      repo name             status
LOCAL                        Local Redhat Repo    4,751
repolist: 4,751
[root@sgld-lx-v01 yum.repos.d]# yum search httpd
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
============================================== N/S matched: httpd ===============================================
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
libmicrohttpd.i686 : Lightweight library for embedding a webserver in applications
libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in applications
mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server

  Name and summary matches only, use "search all" for everything.
[root@sgld-lx-v01 yum.repos.d]# yum install httpd
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-45.el7 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-45.el7 for package: httpd-2.4.6-45.el7.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-45.el7.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-45.el7.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-45.el7.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-45.el7 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================
 Package                      Arch                    Version                       Repository              Size
=================================================================================================================
Installing:
 httpd                        x86_64                  2.4.6-45.el7                  LOCAL                  1.2 M
Installing for dependencies:
 apr                          x86_64                  1.4.8-3.el7                   LOCAL                  103 k
 apr-util                     x86_64                  1.5.2-6.el7                   LOCAL                   92 k
 httpd-tools                  x86_64                  2.4.6-45.el7                  LOCAL                   84 k
 mailcap                      noarch                  2.1.41-2.el7                  LOCAL                   31 k

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

Total download size: 1.5 M
Installed size: 4.3 M
Is this ok [y/d/N]: n
Exiting on user command
Your transaction was saved, rerun it with:
 yum load-transaction /tmp/yum_save_tx.2017-04-05.15-16.l571TA.yumtx
[root@sgld-lx-v01 yum.repos.d]#


This completes the set up on yum repo on RHEL7.