Install NodeJS on CentOS 6 – 7

Install Latest NodeJS on CentOS 6 or 7
————————————–

1. Add Repo and Install NodeJS

For Stable Release:-

$ yum install -y gcc-c++ make
$ curl -sL https://rpm.nodesource.com/setup_8.x | sudo -E bash –

$ yum install nodejs

 

2. Check the version for Node and NPM

$ node -v

v8.11.1

$ npm -v

5.6.0

 

3. Create a Demo Server

$ vim demo_server.js

add below lines

var http = require(‘http’);
http.createServer(function (req, res) {
res.writeHead(200, {‘Content-Type’: ‘text/plain’});
res.end(‘Welcome To EasyOraDBA’);
}).listen(3005, “127.0.0.1”);
console.log(‘Server is running at http://127.0.0.1:3005/’);

4. Start the Node Server

[root@easyoradba CordovaApps]# node demo_server.js
Server is running at http://127.0.0.1:3005/

Go to your Browser and Paste the URL, your WebServer has been started on port 3005

Execute Windows Commands from Linux using winexe. Connect from Linux to Windows without SSH

Winexe – is a software on Linux which uses RPC to run remote commands and might even come with your distribution’s packages. It depends on Samba for running rpc commands

Edit: even if your distro does not have it precompiled and you do not want to compile yourself, you should check out the Build Service – it is likely to have the binary version you would need for your system.

First Install samba-common on your Linux machine before beginning winexe

Use below article to check WinEXE installation

Using winexe on CentOS 7 to execute commands on remote Windows 7 machines

Winexe is a GNU/Linux based application that allows users to execute commands remotely on WindowsNT/2000/XP/2003/Vista/7/8 systems. It installs a service on the remote system, executes the command and uninstalls the service. Winexe allows execution of most of the windows shell commands.

How to install:
You can download the source package from here [Current version is winexe-1.00.tar.gz]

  1. tar -xvf winexe-1.00.tar.gz
  2. cd winexe-1.00/source4/
  3. ./autogen.sh
  4. ./configure
  5. make basics bin/winexe
  6. make “CPP=gcc -E -ffreestanding” basics bin/winexe (For X64 bit)

this will create a [ winexe ] binary file in the bin folder. You can use that binary to execute the windows commands from Linux.

or else there are some compiled version of binary itself available for download. You can download and use it from here.

The above version of winexe works only till version Windows Server 2012. For Windows Server 2012R2 requires below method to make winexe work with latest version of windows. Below method will get the code for samba and winexe from the github repository and we will have to build it for it to work.

Alternate Method (Best Method to Work with Latest Version of Windows 10 and Windows Server 2012R2)

http://rand0m.org/2015/08/05/winexe-1-1-centos-6-and-windows-2012-r2/

  1. Install Samba on Linux

yum install samba-common

2.      fixup a bunch of samba dependencies

yum install gcc perl mingw-binutils-generic mingw-filesystem-base mingw32-binutils mingw32-cpp mingw32-crt mingw32-filesystem mingw32-gcc mingw32-headers mingw64-binutils mingw64-cpp mingw64-crt mingw64-filesystem mingw64-gcc mingw64-headers libcom_err-devel popt-devel zlib-devel zlib-static glibc-devel glibc-static python-devel

yum install git gnutls-devel libacl1-dev libacl-devel libldap2-dev openldap-devel

  1. As per the docs, remove libbsd-devel if installed

yum remove libbsd-devel

  1. Clone the git repos. samba is huge, like 280MB

cd /usr/src

git clone git://git.code.sf.net/p/winexe/winexe-waf winexe-winexe-wafgit clone git://git.samba.org/samba.git samba

  1. per winexe bug 64, samba needs to be reverted to a6bda1f2bc85779feb9680bc74821da5ccd401c5

cd /usr/src/samba

git reset –hard a6bda1f2bc85779feb9680bc74821da5ccd401c5

  1. Fixup the build deps

cd /usr/src/winexe-winexe-waf/source

vi wscript_build

# modify ‘wscript_build’, and at the very end …stlib=’smb_static bsd z resolv rt’lib=’dl gnutls’

7.     Build it! his does a huge configure, then also compiles samba, which takes a while. 

./waf –samba-dir=../../samba configure build

8.     Executable should be  /usr/src/winexe-winexe-waf/source/build/winexe-static

cd /usr/src/winexe-winexe-waf/source/build/

cat </dev/null | ./winexe-static -U ‘domain\admin%$PWD’ //iihoserver01 “ipconfig -all”

cat </dev/null | ./winexe-static -U ‘domain\admin%$PWD’ //iihoserver01 “ipconfig -all” -d99

Sample on How to use it to Check Service on Linux :

export CHECK_COMMAND=’sc query “Notification Service”‘

export STOP_COMMAND=’sc stop “Notification Service”‘

export START_COMMAND=’sc start “Notification Service”‘

## Check Service Status ##

cat </dev/null | ./winexe-static -U ‘domain\admin%$PWD’ //iihoserver01 –interactive=0 “$CHECK_COMMAND”

## Check with Debug ##

cat </dev/null | ./winexe-static -U ‘domain\admin%$PWD’ //iihoserver01 –interactive=0 “$CHECK_COMMAND” -d99

## Run powershell script or command on windows then like below ##

winexe -U administrator%$PWD //$IP “powershell -Command & {(c:\User\administrator\powershell.ps1)}”

 

## Stop and Start Service ##

export CHECK_COMMAND=’sc query “Browser”‘

export STOP_COMMAND=’sc stop “Browser “‘

export START_COMMAND=’sc start “Browser “‘

cat </dev/null | ./winexe-static -U ‘domain\admin%$PWD’ //iihoserver01 –interactive=0 “$CHECK_COMMAND”

cat </dev/null | ./winexe-static –U ‘domain\admin%$PWD’ //iihoserver01 –interactive=0 “$STOP_COMMAND”

cat </dev/null | ./winexe-static -U ‘domain\admin%$PWD’ //iihoserver01 –interactive=0 “$START_COMMAND”

 

 

Compare 2 Servers RPM and Install RPM from Text File List

1. Generate RPM list on Old Server

rpm -qa –queryformat=’%{NAME}\n’ | sort > serverold.txt

2. Generate RPM list on New Server

rpm -qa –queryformat=’%{NAME}\n’ | sort > servernew.txt

3. Copy File to New Server and use diff comand to get differences

diff serverold.txt servernew.txt > diff.txt

4. Get list of packages missing in new Server

cat diff.txt | grep “<” > difference.txt

vi difference.txt

%s,< ,

## save and exit

5. Install missing packages on new server

yum -y install $(cat difference.txt)

Shell Script to Ping Hostnames and Send SMS if Host is not Available

We use the below procedure to ping hosts and based on availability send SMS to our team. The SMS is send by calling a web service from the BASH Shell script using curl 

The hosts are defined in a file called hosts.txt

— Shell Script —

#!/bin/bash
current_time=$(date “+%Y%m%d%H%M%S%3N”)
#### Above Date Format is in MilliSeconds Accuracy ###
cd /home/online
rm -rf /home/online/SMSHOST.TXT
date
#### Below Code Will Loop the Hosts.TXT file for the Ping Probes ####
cat /home/online/hosts.txt | while read output
do
ping -w 30 -c 1 $output > /dev/null
if [ $? -ne 0 ]
then
SMSTEXT=’The+Host+’$output’+is+not+reachable.+Please+Contact+the+Database+Team.’
echo “Host $output is Down”
curl “http://192.168.10.100:8080/SMSConnect/SendServlet?application=http_gw2&password=http_gw2&content=$SMSTEXT&destination=9998887190&source=97249&mask=COMPANY”
else
echo “Host $output is Up”
fi
done

 

— hosts.txt file containing list of hostnames —

proddb01

proddb02

proddb03

drdb01

drdb02

drdb03

Shell Script to Add Date to Filenames

Below Shell Script will append Date to all FileNames in Directory with extension .TXT. Also it will create a folder with the Date and move the files to it.

#!/bin/bash
FILE=”$(date +%Y%m%d)”
cd /bi_dataload
mkdir -p /bi_dataload/BI_$FILE
for f in *.TXT
do
mv -n “$f” /bi_dataload/BI_$FILE/”${f%%.*}”_”$FILE”.TXT
done

Linux Matrix Effects Shell Script

Sometimes to have a funky time on the BASH shell you can run the below shell script

[code language=”bash”]
#!/bin/bash
clear
virtcent=$((`tput lines`/2))
horcent=$((`tput cols`/2-10))
tput setf 6
tput cup $virtcent $horcent && echo "entering the matrix"
sleep 1
tput cup $virtcent $horcent && echo " "
sleep 1
tput cup $virtcent $horcent && echo "entering the matrix"
sleep 1
tput cup $virtcent $horcent && echo " "
sleep 1
tput cup $virtcent $horcent && echo "connecting. "
sleep .1
tput cup $virtcent $horcent && echo "connecting.. "
sleep .1
tput cup $virtcent $horcent && echo "connecting… "
sleep .1
tput cup $virtcent $horcent && echo "connecting…. "
sleep .1
tput cup $virtcent $horcent && echo "connecting….. "
sleep .1
tput cup $virtcent $horcent && echo "connecting…… "
sleep .1
tput cup $virtcent $horcent && echo "connecting……. "
sleep .1
tput cup $virtcent $horcent && echo "connecting……. "
sleep .1
tput cup $virtcent $horcent && echo "connecting……. "
sleep .1
tput cup $virtcent $horcent && echo "connecting…….. "
sleep .1
tput cup $virtcent $horcent && echo "connecting………"
sleep 1
tput cup $virtcent $horcent && echo " CONNECTED "
sleep 1
clear

echo -e "\033[2J\033[?25l"; R=`tput lines` C=`tput cols`;: $[R–] ; while true
do ( e=echo\ -e s=sleep j=$[RANDOM%C] d=$[RANDOM%R];for i in `eval $e {1..$R}`;
do c=`printf ‘\\\\0%o’ $[RANDOM%57+33]` ### http://easyoradba.com ###
$e "\033[$[i-1];${j}H\033[32m$c\033[$i;${j}H\033[37m"$c; $s 0.1;if [ $i -ge $d ]
then $e "\033[$[i-d];${j}H ";fi;done;for i in `eval $e {$[i-d]..$R}`; #[mat!rix]
do echo -e "\033[$i;${j}f ";$s 0.1;done)& sleep 0.05;done #(c) 2016 — [ ShadabMohammad ]
[/code]

Just chmod 750 on the script and execute

$ vi matrix.sh
$ chmod 750 matrix.sh
$ matrix.sh

This is a re-worked version of the shell script available below.

http://bruxy.regnet.cz/web/linux/EN/matrix-sh/

Create ACFS Filesystem Oracle 12c Linux 12.1.0.2

— Create ACFS filesystem on 12c Linux Exadata —
1. Create a volume in ASM

ASMCMD [+] > volcreate -G datac1 -s 500G ACFS_VOL

If you get like below error

ORA-15032: not all alterations performed
ORA-15479: ASM diskgroup does not support volumes
ORA-15221: ASM operation requires compatible.asm of 12.1.0.2.0 or higher (DBD ERROR: OCIStmtExecute

Check the Current Compatibility for the Diskgroup

select group_number, name,compatibility, database_compatibility from v$asm_diskgroup
GROUP_NUMBER NAME COMPATIBILITY DATABASE_COMPATIBILITY
———— —————————— ———————————————————— ————————————————————
1 DATAC1 12.1.0.1.0 11.2.0.2.0
2 DBFS_DG 12.1.0.0.0 11.2.0.2.0
3 RECOC1 12.1.0.1.0 11.2.0.2.0
SQL> alter diskgroup DATAC1 set attribute ‘compatible.asm’=’12.1.0.2.0’;

Diskgroup altered.

SQL> alter diskgroup RECOC1 set attribute ‘compatible.asm’=’12.1.0.2.0’;

Diskgroup altered.

SQL> alter diskgroup DBFS_DG set attribute ‘compatible.asm’=’12.1.0.2.0′;

Diskgroup altered.

SQL> select group_number, name,compatibility, database_compatibility from v$asm_diskgroup;

GROUP_NUMBER NAME COMPATIBILITY DATABASE_COMPATIBILITY
———— —————————— ———————————————————— ————————————————————
1 DATAC1 12.1.0.2.0 11.2.0.2.0
2 DBFS_DG 12.1.0.2.0 11.2.0.2.0
3 RECOC1 12.1.0.2.0 11.2.0.2.0

Run again the volcreate command
ASMCMD [+] > volcreate -G datac1 -s 500G ACFS_VOL
2. Check the volume information
ASMCMD [+] > volinfo -G datac1 ACFS_VOL

Diskgroup Name: DATAC1

Volume Name: ACFS_VOL
Volume Device: /dev/asm/acfs_vol-45
State: ENABLED
Size (MB): 512000
Resize Unit (MB): 64
Redundancy: MIRROR
Stripe Columns: 8
Stripe Width (K): 1024
Usage:
Mountpath:
sqlplus “/as sysasm”

SELECT volume_name, volume_device FROM V$ASM_VOLUME
WHERE volume_name =’ACFS_VOL’;

VOLUME_NAME
——————————
VOLUME_DEVICE
——————————————————————————–
ACFS_VOL
/dev/asm/acfs_vol-45

3. Create a file system with the Oracle ACFS mkfs command using output of above command

With root user run below command

/sbin/mkfs -t acfs /dev/asm/acfs_vol-45
mkfs.acfs: version = 12.1.0.2.0
mkfs.acfs: on-disk version = 39.0
mkfs.acfs: volume = /dev/asm/acfs_vol-45
mkfs.acfs: volume size = 536870912000 ( 500.00 GB )
mkfs.acfs: Format complete.
4. Register the file system with the acfsutil registry command.

Create a directory called ACFS

cd /
mkdir /ACFS

/sbin/acfsutil registry -a /dev/asm/acfs_vol-45 /ACFS

acfsutil registry: mount point /ACFS successfully added to Oracle Registry
Imp Note 1: Registering an Oracle ACFS file system also causes the file system to be mounted automatically whenever Oracle Clusterware or the system is restarted.
Imp Note 2: Oracle ACFS registration (acfsutil registry) is not supported in an Oracle Restart (standalone) configuration, which is a single-instance (non-clustered) environment.
5. Verify if ACFS filesystem mounted automatically

$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VGExaDb-LVDbSys1
30G 17G 12G 59% /
tmpfs 252G 22G 231G 9% /dev/shm
/dev/sda1 496M 54M 418M 12% /boot
/dev/mapper/VGExaDb-LVDbOra1
99G 57G 37G 61% /u01
/dev/mapper/VGExaDb-LVDbOra2
197G 68G 119G 37% /u02
/dev/mapper/VGExaDb-LVBkp1
985G 288G 648G 31% /u03
/dev/asm/acfs_vol-45 500G 1.1G 499G 1% /ACFS
As you can see from above output the ACFS filesystem moutned automatically after registration
6. If you did not register the ACFS filesystem it will not mount automatically, you can mount the ACFS filesystem manually using below command

As root user

/bin/mount -t acfs /dev/asm/acfs_vol-45 /ACFS

7. Give appropriate permissions to the filesystem required by Oracle users
chown -R oracle:dba /ACFS

su – oracle

cd /ACFS

touch abc.txt

Add a Disk and Extend FileSystem on RHEL7 on VMware Fusion 8 for Mac (El- Capitan)

Below is the Filesystem on our VM

Filesystem           Size  Used Avail Use% Mounted on

/dev/mapper/ol-root   18G   11G  7.0G  61% /

devtmpfs             476M     0  476M   0% /dev

tmpfs                491M  144K  491M   1% /dev/shm

tmpfs                491M  7.2M  484M   2% /run

tmpfs                491M     0  491M   0% /sys/fs/cgroup

/dev/sda1            497M  177M  320M  36% /boot

tmpfs                 99M   12K   99M   1% /run/user/0

Our aim is to grow the Filesystem /dev/mapper/ol-root

Filesystems in Linux are extended using the following steps

  1. Add a Physical Disk —> Needs a Shutdown
  2. Create a Physical Volume, using pvcreate —> Online
  3. Grow the Volume Group, using vgextend —> Online
  4. Grow the Logical Volume, using extend—> Online
  5. Extend the Filesystem(XFS) , using xfs_growfs—> Online

Let us continue and see each step in details now…

  1. Shutdown your VM and ddd the disk from option Virtual Machine—> Hard Disk (SCSI)
  2. Check from Disk Utility if the new Disk AppearsScreen Shot 2016-05-14 at 5.27.55 PM

$ pvdisplay

3. Create Physical Volume

root@localhost ~]# pvcreate /dev/sdc

WARNING: xfs signature detected on /dev/sdc at offset 0. Wipe it? [y/n]: y

  Wiping xfs signature on /dev/sdc.

  Physical volume “/dev/sdc” successfully created

4. Extend the Volume Group

$ vgdisplay

[root@localhost ~]# vgextend ol /dev/sdc

  Volume group “ol” successfully extended

5. Extend the Logical Volume

[root@localhost ~]# lvdisplay

  — Logical volume —

  LV Path                /dev/ol/root

  LV Name                root

  VG Name                ol

  LV UUID                nfBnYo-iJhh-fC0y-dWqD-A5Nf-SVHX-lBwioW

  LV Write Access        read/write

  LV Creation host, time localhost.localdomain, 2016-05-13 14:49:36 +0300

  LV Status              available

  # open                 1

  LV Size                17.47 GiB

  Current LE             4472

  Segments               1

  Allocation             inherit

  Read ahead sectors     auto

  – currently set to     8192

  Block device           252:0

[root@localhost ~]# lvextend –size 35G /dev/ol/root

  Size of logical volume ol/root changed from 17.47 GiB (4472 extents) to 35.00 GiB (8960 extents).

  Logical volume root successfully resized.

[root@localhost ~]# lvdisplay

  — Logical volume —

  LV Path                /dev/ol/root

  LV Name                root

  VG Name                ol

  LV UUID                nfBnYo-iJhh-fC0y-dWqD-A5Nf-SVHX-lBwioW

  LV Write Access        read/write

  LV Creation host, time localhost.localdomain, 2016-05-13 14:49:36 +0300

  LV Status              available

  # open                 1

  LV Size                35.00 GiB

  Current LE             8960

  Segments               2

  Allocation             inherit

  Read ahead sectors     auto

  – currently set to     8192

  Block device           252:0

Now the logical volume is extended

6. Resize the Filesystem

Since this is RHEL7 and the default FS for root is XFS, if we try to grow the FS using resize2fs like we did earlier on ext3 and ext4, it will give below error

[root@localhost ~]# resize2fs /dev/ol/root 35G

resize2fs 1.42.9 (28-Dec-2013)

resize2fs: Bad magic number in super-block while trying to open /dev/ol/root

Couldn’t find valid filesystem superblock

If you were using RHEL6 and ext4, you could use resize2fs, but we will continue with xfs_growfs

To grow the XFS filesystem we have to use command xfs_growfs

[root@localhost ~]# xfs_growfs /dev/ol/root

meta-data=/dev/mapper/ol-root    isize=256    agcount=4, agsize=1144832 blks

         =                       sectsz=512   attr=2, projid32bit=1

         =                       crc=0        finobt=0

data     =                       bsize=4096   blocks=4579328, imaxpct=25

         =                       sunit=0      swidth=0 blks

naming   =version 2              bsize=4096   ascii-ci=0 ftype=0

log      =internal               bsize=4096   blocks=2560, version=2

         =                       sectsz=512   sunit=0 blks, lazy-count=1

realtime =none                   extsz=4096   blocks=0, rtextents=0

data blocks changed from 4579328 to 9175040

Check to confirm

Filesystem           Size  Used Avail Use% Mounted on

/dev/mapper/ol-root   35G   11G   25G  31% /

devtmpfs             476M     0  476M   0% /dev

tmpfs                491M  144K  491M   1% /dev/shm

tmpfs                491M  7.2M  484M   2% /run

tmpfs                491M     0  491M   0% /sys/fs/cgroup

/dev/sda1            497M  177M  320M  36% /boot

tmpfs                 99M   16K   99M   1% /run/user/0

Resize Filesystem, Logical Volume in Linux for Virtual Machine using ext4

Often when you have a Linux up and running you run out of space. I use VMware Fusion on my Macbook Pro 13 inch to do a lot of testing. To increase the diskspace you can follow the below simple steps

  1. Shutdown the VM and Increase the Diskspace
  2. Go to Disk Utility and the device /dev/sda will show the additional space as empty
  3. Right click and say create partition, once partition created it will have a device name eg:  /dev/sda3
  4. $ vgdisplay
  5. $ lvdisplay
  6. $ lvextend /dev/VolGroup/lv_root /dev/sda3
  7. The logical volume is extended now resize the filesystem to reflect the new change
  8. $ resize2fs /dev/VolGroup/lv_root
  9. $ df -h

    There is thus a new partition /dev/sda3 created and the logical volume is extended to include this partition. And finally the filesystem has been resized to reflect the disk size