Saturday, June 3, 2017

Solaris 10 - Creating zfs filesystem detail


Creating zfs filesystem

1. Find your disk to use for pool
# echo | format

2. Create a pool
# zpool create ppool c2t1d0

3. Create filesystem
# zfs create ppool/FS_opt-os

4. Mount the filesystem
# zfs set mountpoint=/opt/os ppool/FS_opt-os

1. Find your disk to use for pool
# echo | format

or
# zfs create -o mountpoint=/opt/os mypool/opt_os
or
# zfs create ppool/FS_opt-os
# zfs set mountpoint=/opt/os ppool/FS_opt-os

or
# df -h /opt/ns
ppool/fs_opt_ns         20G    31K    20G     1%    /opt/ns
# zfs umount ppool/fs_opt_ns
# zfs set mountpoint=/opt/OS_Image ppool/fs_opt_ns
# df -h
# zfs mount ppool/fs_opt_ns

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


How to change mount point on zfs

1. Check your mount point that you are going to change
# df -h /opt/OS_Image/
Filesystem             size   used  avail capacity  Mounted on
ppool/fs_opt_ns         20G    31K    20G     1%    /opt/OS_Image

2. Unmount old mountpoing
# zfs umount ppool/fs_opt_ns

3. Verify filesystem is unmounted
# df -h /opt/OS_Image/
Filesystem             size   used  avail capacity  Mounted on
/dev/dsk/c0d1s0        8.1G   4.0G   4.1G    50%    /

4. Check zfs filesystem
# zfs list
NAME             USED  AVAIL  REFER  MOUNTPOINT
pool              85K   976M    31K  /pool
ppool            142K  19.6G    31K  none
ppool/fs_opt_ns   31K  19.6G    31K  /opt/OS_Image

5. Change the mountpoint
# zfs set mountpoint=/opt/ns ppool/fs_opt_ns

6. Verify its changed
# zfs list
NAME             USED  AVAIL  REFER  MOUNTPOINT
pool              85K   976M    31K  /pool
ppool            142K  19.6G    31K  none
ppool/fs_opt_ns   31K  19.6G    31K  /opt/ns

# df -h /opt/ns
Filesystem             size   used  avail capacity  Mounted on
/dev/dsk/c0d1s0        8.1G   4.0G   4.1G    50%    /

7. Mount the filesystem and verify
# zfs mount ppool/fs_opt_ns
# df -h /opt/ns
Filesystem             size   used  avail capacity  Mounted on
ppool/fs_opt_ns         20G    31K    20G     1%    /opt/ns
#


^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Creating zfs filesystem

1. Find your disk to use for pool
# echo | format

2. Create a pool
# zpool create ppool c2t1d0

3. Create filesystem
# zfs create ppool/FS_opt-os

4. Mount the filesystem
# zfs set mountpoint=/opt/os ppool/FS_opt-os

1. Find your disk to use for pool
# echo | format

or
# zfs create -o mountpoint=/opt/os mypool/opt_os
or
# zfs create ppool/FS_opt-os
# zfs set mountpoint=/opt/os ppool/FS_opt-os

or
# df -h /opt/ns
ppool/fs_opt_ns         20G    31K    20G     1%    /opt/ns
# zfs umount ppool/fs_opt_ns
# zfs set mountpoint=/opt/OS_Image ppool/fs_opt_ns
# df -h
# zfs mount ppool/fs_opt_ns


--------------------Detail Steps----------------


# echo | format
Searching for disks...
Inquiry failed for this logical diskdone


AVAILABLE DISK SELECTIONS:
       0. c0d0 <▒x▒▒▒▒▒▒▒▒@▒▒▒ cyl 1566 alt 2 hd 255 sec 63>
          /pci@0,0/pci-ide@7,1/ide@0/cmdk@0,0
       1. c2t0d0 <VMware,-VMware Virtual -1.0 cyl 1020 alt 2 hd 64 sec 32>
          /pci@0,0/pci15ad,1976@10/sd@0,0
       2. c2t1d0 <VMware,-VMwareVirtualS-1.0 cyl 128 alt 2 hd 255 sec 63>
          /pci@0,0/pci15ad,1976@10/sd@1,0
       3. c2t2d0 <VMware,-VMware Virtual S-1.0-1.00GB>
          /pci@0,0/pci15ad,1976@10/sd@2,0
Specify disk (enter its number): Specify disk (enter its number):

2. Create a pool
# zpool create ppool c2t1d0
# zpool list
NAME       SIZE  ALLOC   FREE  CAP  HEALTH  ALTROOT
datapool  1008M  1.08M  1007M   0%  ONLINE  -
ppool     1008M    77K  1008M   0%  ONLINE  -
rpool     11.9G  6.39G  5.55G  53%  ONLINE  -

# zfs list
NAME                                USED  AVAIL  REFER  MOUNTPOINT
datapool                           1.08M   975M    31K  none
datapool/FS_opt-apps                970K  99.1M   948K  /opt/apps
datapool/FS_opt-apps@snap05272017    22K      -   948K  -
ppool                                70K   976M    31K  /ppool
rpool                              6.46G  5.30G  42.5K  /rpool
rpool/ROOT                         4.39G  5.30G    31K  legacy
rpool/ROOT/s10x_u11wos_24a         4.39G  5.30G  4.39G  /
rpool/dump                         1.00G  5.30G  1.00G  -
rpool/export                        286K  5.30G    32K  /export
rpool/export/home                   254K  5.30G   254K  /export/home
rpool/swap                         1.06G  5.36G  1.00G  -

# df -h
Filesystem             size   used  avail capacity  Mounted on
rpool/ROOT/s10x_u11wos_24a
                        12G   4.4G   5.3G    46%    /
/devices                 0K     0K     0K     0%    /devices
ctfs                     0K     0K     0K     0%    /system/contract
proc                     0K     0K     0K     0%    /proc
mnttab                   0K     0K     0K     0%    /etc/mnttab
swap                   1.9G   360K   1.9G     1%    /etc/svc/volatile
objfs                    0K     0K     0K     0%    /system/object
sharefs                  0K     0K     0K     0%    /etc/dfs/sharetab
/usr/lib/libc/libc_hwcap1.so.1
                       9.7G   4.4G   5.3G    46%    /lib/libc.so.1
fd                       0K     0K     0K     0%    /dev/fd
swap                   1.9G    76K   1.9G     1%    /tmp
swap                   1.9G    28K   1.9G     1%    /var/run
rpool/export            12G    32K   5.3G     1%    /export
rpool/export/home       12G   253K   5.3G     1%    /export/home
datapool/FS_opt-apps   100M   948K    99M     1%    /opt/apps
rpool                   12G    42K   5.3G     1%    /rpool
/vol/dev/dsk/c1t0d0/sol_10_113_x86
                       2.1G   2.1G     0K   100%    /cdrom/sol_10_113_x86
ppool                  976M    31K   976M     1%    /ppool

# zfs set mountpoint=none ppool
# df -h
Filesystem             size   used  avail capacity  Mounted on
rpool/ROOT/s10x_u11wos_24a
                        12G   4.4G   5.3G    46%    /
/devices                 0K     0K     0K     0%    /devices
ctfs                     0K     0K     0K     0%    /system/contract
proc                     0K     0K     0K     0%    /proc
mnttab                   0K     0K     0K     0%    /etc/mnttab
swap                   1.9G   360K   1.9G     1%    /etc/svc/volatile
objfs                    0K     0K     0K     0%    /system/object
sharefs                  0K     0K     0K     0%    /etc/dfs/sharetab
/usr/lib/libc/libc_hwcap1.so.1
                       9.7G   4.4G   5.3G    46%    /lib/libc.so.1
fd                       0K     0K     0K     0%    /dev/fd
swap                   1.9G    76K   1.9G     1%    /tmp
swap                   1.9G    28K   1.9G     1%    /var/run
rpool/export            12G    32K   5.3G     1%    /export
rpool/export/home       12G   253K   5.3G     1%    /export/home
datapool/FS_opt-apps   100M   948K    99M     1%    /opt/apps
rpool                   12G    42K   5.3G     1%    /rpool
/vol/dev/dsk/c1t0d0/sol_10_113_x86
                       2.1G   2.1G     0K   100%    /cdrom/sol_10_113_x86
# zfs list
NAME                                USED  AVAIL  REFER  MOUNTPOINT
datapool                           1.08M   975M    31K  none
datapool/FS_opt-apps                970K  99.1M   948K  /opt/apps
datapool/FS_opt-apps@snap05272017    22K      -   948K  -
ppool                                94K   976M    31K  none
rpool                              6.46G  5.30G  42.5K  /rpool
rpool/ROOT                         4.39G  5.30G    31K  legacy
rpool/ROOT/s10x_u11wos_24a         4.39G  5.30G  4.39G  /
rpool/dump                         1.00G  5.30G  1.00G  -
rpool/export                        286K  5.30G    32K  /export
rpool/export/home                   254K  5.30G   254K  /export/home
rpool/swap                         1.06G  5.36G  1.00G  -

3. Create filesystem
# zfs create ppool/FS_opt-os
# df -h
Filesystem             size   used  avail capacity  Mounted on
rpool/ROOT/s10x_u11wos_24a
                        12G   4.4G   5.3G    46%    /
/devices                 0K     0K     0K     0%    /devices
ctfs                     0K     0K     0K     0%    /system/contract
proc                     0K     0K     0K     0%    /proc
mnttab                   0K     0K     0K     0%    /etc/mnttab
swap                   1.9G   360K   1.9G     1%    /etc/svc/volatile
objfs                    0K     0K     0K     0%    /system/object
sharefs                  0K     0K     0K     0%    /etc/dfs/sharetab
/usr/lib/libc/libc_hwcap1.so.1
                       9.7G   4.4G   5.3G    46%    /lib/libc.so.1
fd                       0K     0K     0K     0%    /dev/fd
swap                   1.9G    76K   1.9G     1%    /tmp
swap                   1.9G    28K   1.9G     1%    /var/run
rpool/export            12G    32K   5.3G     1%    /export
rpool/export/home       12G   253K   5.3G     1%    /export/home
datapool/FS_opt-apps   100M   948K    99M     1%    /opt/apps
rpool                   12G    42K   5.3G     1%    /rpool
/vol/dev/dsk/c1t0d0/sol_10_113_x86
                       2.1G   2.1G     0K   100%    /cdrom/sol_10_113_x86
# zfs list
NAME                                USED  AVAIL  REFER  MOUNTPOINT
datapool                           1.08M   975M    31K  none
datapool/FS_opt-apps                970K  99.1M   948K  /opt/apps
datapool/FS_opt-apps@snap05272017    22K      -   948K  -
ppool                               132K   976M    31K  none
ppool/FS_opt-os                      31K   976M    31K  none
rpool                              6.46G  5.30G  42.5K  /rpool
rpool/ROOT                         4.39G  5.30G    31K  legacy
rpool/ROOT/s10x_u11wos_24a         4.39G  5.30G  4.39G  /
rpool/dump                         1.00G  5.30G  1.00G  -
rpool/export                        286K  5.30G    32K  /export
rpool/export/home                   254K  5.30G   254K  /export/home
rpool/swap                         1.06G  5.36G  1.00G  -

4. Mount the filesystem
# zfs set mountpoint=/opt/os ppool/FS_opt-os
# zfs list
NAME                                USED  AVAIL  REFER  MOUNTPOINT
datapool                           1.08M   975M    31K  none
datapool/FS_opt-apps                970K  99.1M   948K  /opt/apps
datapool/FS_opt-apps@snap05272017    22K      -   948K  -
ppool                               142K   976M    31K  none
ppool/FS_opt-os                      31K   976M    31K  /opt/os
rpool                              6.46G  5.30G  42.5K  /rpool
rpool/ROOT                         4.39G  5.30G    31K  legacy
rpool/ROOT/s10x_u11wos_24a         4.39G  5.30G  4.39G  /
rpool/dump                         1.00G  5.30G  1.00G  -
rpool/export                        286K  5.30G    32K  /export
rpool/export/home                   254K  5.30G   254K  /export/home
rpool/swap                         1.06G  5.36G  1.00G  -
# df -h
Filesystem             size   used  avail capacity  Mounted on
rpool/ROOT/s10x_u11wos_24a
                        12G   4.4G   5.3G    46%    /
/devices                 0K     0K     0K     0%    /devices
ctfs                     0K     0K     0K     0%    /system/contract
proc                     0K     0K     0K     0%    /proc
mnttab                   0K     0K     0K     0%    /etc/mnttab
swap                   1.9G   360K   1.9G     1%    /etc/svc/volatile
objfs                    0K     0K     0K     0%    /system/object
sharefs                  0K     0K     0K     0%    /etc/dfs/sharetab
/usr/lib/libc/libc_hwcap1.so.1
                       9.7G   4.4G   5.3G    46%    /lib/libc.so.1
fd                       0K     0K     0K     0%    /dev/fd
swap                   1.9G    76K   1.9G     1%    /tmp
swap                   1.9G    28K   1.9G     1%    /var/run
rpool/export            12G    32K   5.3G     1%    /export
rpool/export/home       12G   253K   5.3G     1%    /export/home
datapool/FS_opt-apps   100M   948K    99M     1%    /opt/apps
rpool                   12G    42K   5.3G     1%    /rpool
/vol/dev/dsk/c1t0d0/sol_10_113_x86
                       2.1G   2.1G     0K   100%    /cdrom/sol_10_113_x86
ppool/FS_opt-os        976M    31K   976M     1%    /opt/os
# df -h /export/home/prema/
Filesystem             size   used  avail capacity  Mounted on
rpool/export/home       12G   253K   5.3G     1%    /export/home





zfs mirror and creating swap on zfs filesystem

1. Remove the sub mirror from the pool
# zpool detach datapool c1t2d0
# zpool status datapool
  pool: datapool
 state: ONLINE
 scan: resilvered 454M in 0h0m with 0 errors on Sun Jun  4 09:00:42 2017
config:

        NAME        STATE     READ WRITE CKSUM
        datapool    ONLINE       0     0     0
          c1t0d0    ONLINE       0     0     0

errors: No known data errors

2. Mirror the disk
# zpool help attach
usage:
        attach [-f] <pool> <device> <new-device>
#  zpool attach datapool c1t0d0 c1t2d0


3. Create a swap volume
# zfs help
The following commands are supported:
allow       clone       create      destroy     diff        get
groupspace  help        hold        holds       inherit     list
mount       promote     receive     release     rename      rollback
send        set         share       snapshot    unallow     unmount
unshare     upgrade     userspace
For more info, run: zfs help <command>
# zfs help create
usage:
        create [-p] [-o property=value] ... <filesystem>
        create [-ps] [-b blocksize] [-o property=value] ... -V <size> <volume>
# zfs create -V 100m datapool/myswap

4. Locate your swap volume
# ls -l /dev/zvol/dsk/datapool/myswap
lrwxrwxrwx   1 root     root          35 Jun  4 09:09 /dev/zvol/dsk/datapool/myswap -> ../../../../devices/pseudo/zfs@0:1c
# zfs list
NAME                      USED  AVAIL  REFER  MOUNTPOINT
datapool                  557M   419M    32K  none
datapool/mydb             454M   419M   453M  /data/mydb
datapool/mydb/test         31K   419M    31K  /data/mydb/test
datapool/myswap           103M   522M    16K  -
mypool                    142K  1.95G    31K  none
mypool/opt_os              31K  1.95G    31K  /opt/os
yourpool                  189K  19.6G    31K  none
yourpool/FS_opt-OS_Image   31K  19.6G    31K  /opt/OS_Image
yourpool/fs-opt-os         31K  19.6G    31K  /opt/os


5. Add swap
# swap -l
swapfile             dev  swaplo blocks   free
/dev/dsk/c0d1s1     102,1       8 1076344 1076344
# swap -s
total: 273784k bytes allocated + 91588k reserved = 365372k used, 1264948k available
# swap -a /dev/zvol/dsk/datapool/myswap
# swap -l
swapfile             dev  swaplo blocks   free
/dev/dsk/c0d1s1     102,1       8 1076344 1076344
/dev/zvol/dsk/datapool/myswap 181,1       8 204792 204792
# swap -s
total: 273868k bytes allocated + 91572k reserved = 365440k used, 1366508k available
#

Monday, May 29, 2017

RHEL7.3 - Install NSCD - Name Service Cache Daemon


Install NSCD - Name Service Cache Daemon

[root@puppet puppet-enterprise-2017.2.1-el-7-x86_64]# yum install nscd

[root@puppet puppet-enterprise-2017.2.1-el-7-x86_64]# systemctl start nscd
[root@puppet puppet-enterprise-2017.2.1-el-7-x86_64]# systemctl status nscd
● nscd.service - Name Service Cache Daemon
   Loaded: loaded (/usr/lib/systemd/system/nscd.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2017-05-29 20:19:53 EDT; 7s ago
  Process: 13229 ExecStart=/usr/sbin/nscd $NSCD_OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 13230 (nscd)

To flush/clear DNS Cache you need to restart “nscd” service if installed.

[root@puppet puppet-enterprise-2017.2.1-el-7-x86_64]# systemctl restart nscd

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.