Wednesday, March 8, 2017

Create new database Oracle 12c Release 2



Execute dbca on the terminal to start DataBase Configuration Assistant

Below is the landing page after executing the dbca.



Select Create a database and click on Next to continue.

Select Typical Installation or Advance Installation option. Typical Installation goes with lot of default values whereas the Advance Installation have lot of options to be configured. This gives lot of options to customized the database product.


Select Advanced configuration and Click on Next to continue.

 Select appropriate template option and Click on Next to continue.


Select Global database name and the SID value. Uncheck Create as container database option if we want to create non container database.


Select Use template file for database storage attributes and Click on Next to continue.


Leave default or uncheck the Fast Recovery Area and Enable archiving option and click on Next to continue.

If there is already listener configured, it will use the existing Listener or Create a new listener Click on Next once Listener configuration completes.

Configure Vault and Security option. Click on Next to continue.

Configure Memory option, Sizing, Character sets, Connection mode and Sample Schemas option. Click on Next to continue.

Configure Oracle Express Manager port option. Click on Next to continue.

Enter database administrator password and Click on Next to continue.

Make sure to check the Create database option and Click on Next to create database. Additionally we can save a database template and generate script for database creation. Once options has been selected Click on Next to continue.

Click on Save Response File to save the options as the response file.


Save response file.

 Click on Finish to start database creation.


Database creation is on progress.

Click on Close once the database creation is completed.

Install Oracle 12c Release 2 on CentOS 6

Hardware Requirments

Disk Space Requirements on Linux x86-64


Database EditionDisk Space
Enterprise Edition7.5 GB
Standard Edition 27.5 GB


Memory Requirement


RAMSwap Space
Between 1 GB and 2 GB1.5 times the size of the RAM
Between 2 GB and 16 GBEqual to the size of the RAM
More than 16 GB16 GB

OS Requirement

  • Oracle Linux 7, Red Hat Enterprise Linux 7 Distributions Kernel 3.10.0-54.0.1.el7.x86_64 or later
  • Oracle Linux 6, Red Hat Enterprise Linux 6 Distributions Kernel 2.6.32-71.el6.x86_64 or later


Package for RHEL 7

  • binutils-2.23.52.0.1-12.el7.x86_64
  • compat-libcap1-1.10-3.el7.x86_64
  • compat-libstdc++-33-3.2.3-71.el7.i686
  • compat-libstdc++-33-3.2.3-71.el7.x86_64
  • gcc-4.8.2-3.el7.x86_64
  • gcc-c++-4.8.2-3.el7.x86_64
  • glibc-2.17-36.el7.i686
  • glibc-2.17-36.el7.x86_64
  • glibc-devel-2.17-36.el7.i686
  • glibc-devel-2.17-36.el7.x86_64
  • ksh
  • libaio-0.3.109-9.el7.i686
  • libaio-0.3.109-9.el7.x86_64
  • libaio-devel-0.3.109-9.el7.i686
  • libaio-devel-0.3.109-9.el7.x86_64
  • libgcc-4.8.2-3.el7.i686
  • libgcc-4.8.2-3.el7.x86_64
  • libstdc++-4.8.2-3.el7.i686
  • libstdc++-4.8.2-3.el7.x86_64
  • libstdc++-devel-4.8.2-3.el7.i686
  • libstdc++-devel-4.8.2-3.el7.x86_64
  • libXi-1.7.2-1.el7.i686
  • libXi-1.7.2-1.el7.x86_64
  • libXtst-1.2.2-1.el7.i686
  • libXtst-1.2.2-1.el7.x86_64
  • make-3.82-19.el7.x86_64
  • sysstat-10.1.5-1.el7.x86_64


Package for RHEL 6

  • binutils-2.20.51.0.2-5.11.el6 (x86_64)
  • compat-libcap1-1.10-1 (x86_64)
  • compat-libstdc++-33-3.2.3-69.el6 (x86_64)
  • compat-libstdc++-33-3.2.3-69.el6 (i686)
  • gcc-4.4.4-13.el6 (x86_64)
  • gcc-c++-4.4.4-13.el6 (x86_64)
  • glibc-2.12-1.7.el6 (i686)
  • glibc-2.12-1.7.el6 (x86_64)
  • glibc-devel-2.12-1.7.el6 (x86_64)
  • glibc-devel-2.12-1.7.el6 (i686)
  • ksh
  • libgcc-4.4.4-13.el6 (i686)
  • libgcc-4.4.4-13.el6 (x86_64)
  • libstdc++-4.4.4-13.el6 (x86_64)
  • libstdc++-4.4.4-13.el6 (i686)
  • libstdc++-devel-4.4.4-13.el6 (x86_64)
  • libstdc++-devel-4.4.4-13.el6 (i686)
  • libaio-0.3.107-10.el6 (x86_64)
  • libaio-0.3.107-10.el6 (i686)
  • libaio-devel-0.3.107-10.el6 (x86_64)
  • libaio-devel-0.3.107-10.el6 (i686)
  • libXext-1.1 (x86_64)
  • libXext-1.1 (i686)
  • libXtst-1.0.99.2 (x86_64)
  • libXtst-1.0.99.2 (i686)
  • libX11-1.3 (x86_64)
  • libX11-1.3 (i686)
  • libXau-1.0.5 (x86_64)
  • libXau-1.0.5 (i686)
  • libxcb-1.5 (x86_64)
  • libxcb-1.5 (i686)
  • libXi-1.3 (x86_64)
  • libXi-1.3 (i686)
  • make-3.81-19.el6
  • sysstat-9.0.4-11.el6 (x86_64)


Use Command below to verify rpm installed or not.

rpm -q binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libgcc libstdc++ libstdc++-devel libaio libaio-devel libXext libXtst libX11 libXau libxcb libXi make sysstat


List all the i686 packages installed

rpm -qa --queryformat '%{NAME} %{ARCH}\n' | grep 'i[6543]86' | cut -d' ' -f1

List of the i686 packages required

  • compat-libstdc++-33
  • glibc
  • glibc-devel
  • libgcc
  • libstdc++
  • libstdc++-devel
  • libaio
  • libaio-devel
  • libXext
  • libXtst
  • libX11
  • libXau
  • libxcb
  • libXi

Use command below to install required i686 packages

rpm -ivh glibc-devel-2.12-1.80.el6.i686.rpm libstdc++-4.4.6-4.el6.i686.rpm libstdc++-devel-4.4.6-4.el6.i686.rpm libaio-0.3.107-10.el6.i686.rpm libaio-devel-0.3.107-10.el6.i686.rpm libXext-1.1-3.el6.i686.rpm libXtst-1.0.99.2-3.el6.i686.rpm libX11-1.3-2.el6.i686.rpm libXau-1.0.5-1.el6.i686.rpm libxcb-1.5-1.el6.i686.rpm libXi-1.3-3.el6.i686.rpm


Kernel parameters required.


kernel.sem = 250 32000 100 128
kernel.shmall = 3355443
kernel.shmmax = 3986726912
kernel.shmmni = 4096

kernel.panic_on_oops = 1

fs.file-max = 6815744

fs.aio-max-nr = 1048576

net.ipv4.ip_local_port_range = 11000 65000

net.core.rmem_default = 262144

net.core.rmem_max = 4194304

net.core.wmem_default = 262144

net.core.wmem_max = 1048576


Execute command below to get new kernel setting in effect.

sysctl -p

Change Linux kernel setting on runtime

echo 11000 65500 > /proc/sys/net/ipv4/ip_local_port_range

Creating required Operating System Group and Users

Create Oracle Inverntory group
/usr/sbin/groupadd -g 1000 oinstall
Create Oracle dba group
/usr/sbin/groupadd -g 1001 dba
Create Oracle operator group
/usr/sbin/groupadd -g 1002 oper

Create Oracle software owner user

useradd -u 1000 -g oinstall -G oinstall,dba,oper oracle
passwd oracle

Checking Resource limits for Oracle software Installation user.

/etc/security/limits.conf
oracle   soft   nofile    1024
oracle   hard   nofile    65536
oracle   soft   nproc    2047
oracle   hard   nproc    16384
oracle   soft   stack    10240
oracle   hard   stack    32768

Set secure linux to permissive by editing /etc/selinux/config

SELINUX=permissive

Once modification is completed execute following command to set secure linux to Permissive

setenforce Permissive

Disable iptables firewall

/etc/init.d/iptables stop
chkconfig iptables off 345

Create Oracle Home directory

mkdir -p /u01/app/oracle/product/12.2.0.1/db_1
chown -R oracle:oinstall /u01/app

Configure oracle environment
Add following lines on .bash_profile file on /home/oracle

export ORACLE_HOSTNAME=core.localdomain
export ORACLE_UNQNAME=omrdb
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/12.2.0.1/db_1
export ORACLE_SID=oemrep

export PATH=/usr/sbin:$PATH
export PATH=$ORACLE_HOME/bin:$PATH

export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
Login as user oracle

Download Oracle Database 12c Release 2 from URL below:
http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index.html

Extract the downloaded source


Change directory to oracle staging
Execute runInstaller







Below is the landing page after you execute runInstaller.




























Uncheck I wish to receive security updates via My Oracle Support and Click on Next to continue















Warning window will be displayed. Click on Yes to continue.






























I am planning to install database later manually. So selecting Install database software only option.


Select Single Instance database installation and click on Next to continue.




Select database edition option and click on Next to continue.



Select oracle base and Software location. Click on Next to continue.




Select Inventory Directory and oraInventory group Name. Click on Next to continue.
































Select OS groups for OSDBA, OSOPER, OSBACKUPDBA, OSDGDBA, OSKMDBA. Click on Next to continue.






























If any requirement is failed while Prerequisite Check, fix the issue before moving a head. In my case there was a Swap Size issue. I can safely ignore it and move ahead.


Warning message will be displayed for any prerequisites failure and ignore.


Once you check Ignore All check box. Click on Next. On Summary page Click on Install to begin installation.

Installation is on progress. ##########























Execute Configuration Scripts window will be poped up. Make Sure all the script listed above is executed as user root before Pressing OK Button.































Once the script is executed successfully. Click on OK on the Execute Configuration Scripts window.




Once the installation is completed Click on Close to complete Installation.


Tuesday, February 21, 2017

Install OpenVPN on CentOS with Google OTP

OpenVPN is a full-featured open source SSL VPN solution. OpenVPN is a cost-effective, lightweight alternative to other VPN technologies. OpenVPN combines security with ease-of-use. OpenVPN runs on Linux, Windows XP/Vista/7 and higher, OpenBSD, FreeBSD, NetBSD, Mac OS X, and Solaris.

Modify SELinux policy policy


semanage port -a -t openvpn_port_t -p udp 1194






If you get Error message: "-bash: semanage: command not found" then install policycoreutils-python package via yum







yum -y install policycoreutils-python

























Make sure you have the EPEL repository installed. If it is not installed, install epel yum repository with command below.


rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm









Install openvpn and easy-rsa packages


yum install openvpn easy-rsa

































Create directory to store rsa keys and copy contents of easy-rsa executable to the directory


mkdir /etc/openvpn/rsa
cp -rf /usr/share/easy-rsa/2.0/* /etc/openvpn/rsa






Export variable and start building the keys.


export KEY_SIZE=4096
export CA_EXPIRE=3654
export KEY_EXPIRE=3654
export KEY_COUNTRY="NP"
export KEY_PROVINCE="Bagmati"
export KEY_CITY="Kathmandu"
export KEY_ORG="Organization"
export KEY_EMAIL="info@dilli.com.np"
export KEY_OU="Technical"
export KEY_NAME="vpnkeys"












cd /etc/openvpn/rsa/
source ./vars
./clean-all
./build-ca
./build-key-server server
./build-dh




















Create configuration file with the following settings.


cd /etc/openvpn
vi server.conf

port 1194 #- port
proto udp #- protocol
dev tun
tun-mtu 1500
tun-mtu-extra 32
mssfix 1450
reneg-sec 0
ca /etc/openvpn/rsa/keys/ca.crt
cert /etc/openvpn/rsa/keys/server.crt
key /etc/openvpn/rsa/keys/server.key
dh /etc/openvpn/rsa/keys/dh2048.pem
plugin /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so openvpn
client-cert-not-required
username-as-common-name
server 10.251.0.0 255.255.255.0
push "route 202.79.55.140 255.255.255.255" # Mailservers
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
keepalive 5 30
comp-lzo
persist-key
persist-tun
status 1194.log
verb 3
log-append /var/log/openvpn.log
client-connect /etc/openvpn/scripts/up.sh

Create symbolic link for the openvpn-auth-pam.so file.


mkdir -p /usr/share/openvpn/plugin/lib/
ln -s /usr/lib64/openvpn/plugin/lib/openvpn-auth-pam.so /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so





Modify /etc/sysctl.conf to allow ipv4 forwarding


vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
sysctl -p










Masquerade all the traffic via eth0(eth0 is my interface with public IP address)


iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
















Create OS user gauth that is the owner for the google authenticator. 


useradd gauth




Download google-authenticator-libpam from the URL below and compile it.


wget https://github.com/google/google-authenticator-libpam/archive/master.zip
unzip master.zip
cd  google-authenticator-libpam-master
./bootstrap.sh
./configure
make
make install

































Configure google authenticator.

Create directory to store google authenticator files and change ownership to gauth.


mkdir /etc/openvpn/google-authenticator
chown gauth:gauth /etc/openvpn/google-authenticator 
chmod 700 /etc/openvpn/google-authenticator








Create script file with the content below for the creation of the OTP username.


cat > /root/create-gauth.sh
#!/bin/sh

# Parse arguments
USERNAME="$1"

if [ -z "$USERNAME" ]; then
  echo "Usage: $(basename $0) "
  exit 2
fi

# Set the label the user will see when importing the token:
LABEL='OpenVPN Server'

su -c "google-authenticator -t -d -r3 -R30 -W -f -l \"${LABEL}\" -s /etc/openvpn/google-authenticator/${USERNAME}" - gauth

Make the script file executable for owner of the script file.


chmod 700 /root/create-gauth.sh















Create file /etc/pam.d/openvpn with the contents below.


cat > /etc/pam.d/openvpn
auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so
auth required /usr/local/lib/security/pam_google_authenticator.so secret=/etc/openvpn/google-authenticator/${USER} user=gauth forward_pass
auth include system-auth
account include system-auth
password include system-auth








Create vpn user with the OS command below


useradd -M -c "Mr. Dilli Raj Maharjan,email@dilli.com.np" -s /sbin/false vpn_dilliraj
passwd vpn_dilliraj

/root/create-gauth.sh vpn_dilliraj
















Create script file that will be automatically executed once the vpn connection is successful. This script file is helpful in send the email with the details. Following is the contents used for sending mail.


cat > /etc/openvpn/scripts/up.sh
#!/bin/bash
smtp="A.B.C.D"
from="vpnadmin@dilli.com.np"
full_name=$(/usr/bin/getent passwd $common_name | /usr/bin/cut -d: -f5 | /usr/bin/awk -F "," '{print $1}')
email_address=$(/usr/bin/getent passwd $common_name | /usr/bin/cut -d: -f5 | /usr/bin/awk -F "," '{print $2}')
subject="VPN connected from $untrusted_ip\nContent-Type: text/html"

date_n_time=$(date +%c)
Message=$(echo "Dear ${full_name},


Your VPN Username $common_name has been connected from IP Address: $untrusted_ip. Make sure it is you or you are aware of it.
Please change your password if it is not you and contact System administrator for further assistance.
Following is the details
==========================================
Connected Since: ${date_n_time}

Public Address: $untrusted_ip
Virtual Address: $ifconfig_pool_remote_ip
Name: $common_name

Full Name: $full_name
Email Address: $email_address


Regards,
IT Team
Idealab.")

echo $Message | /bin/mailx -r ${from} -s "$(echo -e ${subject})" -S smtp="${smtp}" ${email_address}

Make the file executable


chmod 755 /etc/openvpn/scripts/up.sh





















Start openvpn server process and make sure it will start automatically at run level 3,5


chkconfig openvpn --list
chkconfig openvpn on --level=35
chkconfig openvpn --list

/etc/init.d/openvpn start














Create configuration file for client with following details and copy ca.crt to client machine. Configure Google authenticator app on your smart phone. Use the key provided while creating the google authenticator account.


vi idealab_vpn.ovpn
client
dev tun
proto udp
remote 202.166.166.251 
resolv-retry infinite
nobind
tun-mtu 1500
tun-mtu-extra 32
mssfix 1450
persist-key
persist-tun
ca ca.crt
auth-user-pass
comp-lzo
reneg-sec 0
verb 3

We can login with the Password+OTP.