Friday, 24 February 2017

Session Auditing in Oracle Database - 10g/11g/12c

Oracle session auditing has its importance derived from requirements of keeping track of users logging on to the database and logging off.

At times it becomes important to know which users were available on the system as a part of auditing to determine:

1. Accountability of users
2. Intruders Detection
3. Problem Detection
4. Visibility on system

Since auditing is a vast topic and its study and implementation varies according to requirements, I am only taking up session auditing in this blog as it is most basic and crucial to a database environment.

Steps to Enable Session Auditing

1. Set auditing parameters to enable audit feature of Oracle RDBMS

Ø  audit_trail
 



AUDIT_TRAIL = { none | os | db | db,extended | xml | xml,extended }
The following list provides a description of each setting:
·         none or false - Auditing is disabled.
·         db or true - Auditing is enabled, with all audit records stored in the database audit trial (SYS.AUD$).
·         db,extended - As db, but the SQL_BIND and SQL_TEXT columns are also populated.
·         xml- Auditing is enabled, with all audit records stored as XML format OS files.
·         xml,extended - As xml, but the SQL_BIND and SQL_TEXT columns are also populated.
·         os- Auditing is enabled, with all audit records directed to the operating system's audit trail.

Syntax:
ALTER SYSTEM SET AUDIT_TRAIL=DB SCOPE=SPFILE;


 
Ø  audit_file_dest
 
The AUDIT_FILE_DEST parameter specifies the OS directory used for the audit trail when the os, xml and xml,extended options are used. It is also the location for all mandatory auditing specified by the AUDIT_SYS_OPERATIONS parameter.

Since I am using AUDIT_TRAIL=DB, I am not concerned about this parameter.
 

Ø  audit_sys_operations


The AUDIT_SYS_OPERATIONS static parameter enables or disables the auditing of operations issued by users connecting with SYSDBA or SYSOPER privileges, including the SYS user. All audit records are written to the OS audit trail.

Its your choice to log sys operations in audit log or not.



2.  Enable Auditing of Sessions

Run below command to enable Oracle instance to log each session logon and logoff in audit tables

AUDIT SESSION;

This would starting creating records for each logon/logoff in AUD$ table. This has been validated to work on 10gR2, 11gR1/11gR2 and 12c.

3. View session audit details

To view details Oracle provides below views that gives most appropriate details: DBA_AUDIT_TRAIL and DBA_AUDIT_SESSION

A query to use:

COL OSUSER FOR A20
COL DBUSER FOR A20
COL TERMINAL FOR A15
SET LINESIZE 150
SET PAGESIZE 1000
SELECT os_username "OSUSER",
     username "DBUSER",
     terminal,
     returncode,
     TO_CHAR(timestamp,   'DD-MON-YYYY HH24:MI:SS') LOGON_TIME,
     TO_CHAR(logoff_time, 'DD-MON-YYYY HH24:MI:SS') LOGOFF_TIME
FROM dba_audit_session;

4. Maintenance

It is important to keep check on usage of AUD$ table, it starts flooding with records and in no time can grow into gigabytes. It is strongly advised to decide a retention period of auditing records and purge what is not needed.

Refer to my other post about AUD$ maintenance for detailed steps.

Cheers!
Anurag

Friday, 20 January 2017

Oracle Database 12c and OEM Cloud Control 12c Installation on Ubuntu



Oracle Database and Enterprise Manager Cloud Control 12c Installation on Ubuntu

Pre-Requisites

1.     Perform pre-requisites as listed in Linux install of Oracle Database and Oracle Enterprise Manager for 12c version, this would include:
  • Linux Packages required 

    apt-get -y install elfutils libaio1 libaio-dev libstdc++* numactl pdksh sysstat unixodbc-dev unixodbc build-essential gawk ksh libmotif* libXtst* alien libtool glibc-* binutils cpp-* debhelper g++* gcc* gcc-*-base gettext html2text lib32z1 lib32ncurses5 intltool-debian lib32z1-dev libc6 libc6-dev libc6-dev-i386 libelf-dev libelf1 libltdl-dev libltdl7 libodbcinstq4-1 libodbcinstq4-1:i386 libqt*-core libqt*-gui libsqlite3-0 lsb lsb-core make odbcinst pax po-debconf rpm rpm-common unzip lib*crypt xorg* glibc-devel.i386 setarch rng-utils
  • Kernel Configuration 

    echo "#" | sudo tee -a /etc/sysctl.conf
    echo "# Oracle 12C entries" | sudo tee -a /etc/sysctl.conf
    echo "fs.aio-max-nr=1048576" | sudo tee -a /etc/sysctl.conf
    echo "fs.file-max=6815744" | sudo tee -a /etc/sysctl.conf
    echo "kernel.shmall=2097152" | sudo tee -a /etc/sysctl.conf
    echo "kernel.shmmni=4096" | sudo tee -a /etc/sysctl.conf
    echo "kernel.sem=250 32000 100 128" | sudo tee -a /etc/sysctl.conf
    echo "net.ipv4.ip_local_port_range=9000 65500" | sudo tee -a /etc/sysctl.conf
    echo "net.core.rmem_default=262144" | sudo tee -a /etc/sysctl.conf
    echo "net.core.rmem_max=4194304" | sudo tee -a /etc/sysctl.conf
    echo "net.core.wmem_default=262144" | sudo tee -a /etc/sysctl.conf
    echo "net.core.wmem_max=1048586" | sudo tee -a /etc/sysctl.conf
    echo "kernel.shmmax=1073741824" | sudo tee -a /etc/sysctl.conf 

    Run command to make changes effective:
    sysctl -p
  • Security Limits

    cp /etc/security/limits.conf /etc/security/limits.conf.original
    echo "#Oracle 12C shell limits:" | sudo tee -a /etc/security/limits.conf
    echo "oracle soft nproc 2048" | sudo tee -a /etc/security/limits.conf
    echo "oracle hard nproc 16384"| sudo tee -a /etc/security/limits.conf
    echo "oracle soft nofile 1024" | sudo tee -a /etc/security/limits.conf
    echo "oracle hard nofile 65536" | sudo tee -a /etc/security/limits.conf
  • It is required to create softlinks to below lib files to avoid installation failure when Oracle looks up for them

    mkdir /usr/lib64
    ln -s /usr/lib /usr/lib/lib64
    ln -s /lib/x86_64-linux-gnu/libgcc_s.so.1 /lib64/
    ln -s /usr/bin/awk /bin/awk
    ln -s /usr/bin/basename /bin/basename
    ln -s /usr/bin/rpm /bin/rpm
    ln -s /usr/lib/x86_64-linux-gnu/libc_nonshared.a /usr/lib64/
    ln -s /usr/lib/x86_64-linux-gnu/libpthread_nonshared.a /usr/lib64/
    ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /lib64/
    ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /usr/lib64/
    ln /usr/lib/x86_64-linux-gnu/libpthread_nonshared.a /usr/lib64/libpthread_nonshared.a

    In case if you get missing reference for below library, make soft link and try relinking: (you may verify using ldd command for references of library that fails linking)
    ln -s <ORACLE_HOME>/lib/libclntshcore.so.12.1 /usr/lib/

As Ubuntu is not a certified Linux for Oracle, it would require to make additional changes in ins_rdbms.mk and env_rdbms.mk files for installation to complete (not failing at relink step).  All credits for these changes goes to a post that I found on internet (can't remember the name though), without their post I could not have get past this hurdle.
  
To make it short I have summarized the changes below, you would require to add "-Wl,--no-as-needed" for modules that fail in compiling.

<ORACLE_HOME>/rdbms/lib$ cat env_rdbms.mk | grep "-Wl,--no-as-needed"
ORACLE_LINKLINE=$(ORACLE_LINKER) -Wl,--no-as-needed $(PL_FLAGS) $(ORAMAI) $(SSORED) $(TTCSOI) \
EXTPROC_LINKLINE=$(LINK) $(OPT) -Wl,--no-as-needed $(EXTPMAI) $(PROD_EXTPROC_OPT) \
HSDEPXA_LINKLINE=$(LINK) $(OPT) -Wl,--no-as-needed $(HSDEPMAI) $(HSALIB_SUBSET1) \
HSOTS_LINKLINE=$(LINK) $(OPT) -Wl,--no-as-needed $(HSOTSMAI) $(HSALIB_SUBSET1) \
KFED_LINKLINE=$(LINK) $(S0MAIN) -Wl,--no-as-needed $(SSKFEDED) $(SKFEDPT) \
KFOD_LINKLINE=$(LINK) $(S0MAIN) -Wl,--no-as-needed $(SSKFODED) $(SKFODPT) $(KFODOBJ) \
KFNDG_LINKLINE=$(LINK) $(S0MAIN) -Wl,--no-as-needed $(SSKFNDGED) $(SKFNDGPT) $(KFNDGOBJ) \
AMDU_LINKLINE=$(LINK) $(S0MAIN) -Wl,--no-as-needed $(SSKFMUED) $(SKFMUPT) $(LLIBCLNTSH) \





Specify library file names for below modules in ins_rdbms.mk, and the ones that may fail, if any, during linking.

<ORACLE_HOME>/rdbms/lib$ cat ins_rdbms.mk | grep lnnz12
        $(ORAPWD_LINKLINE) -lnnz12
        $(TG4PWD_LINKLINE) -lnnz12
<ORACLE_HOME>/rdbms/lib$ cat ins_rdbms.mk | grep lons
        $(PLSHPROF_LINKLINE) -lons
        $(RMAN_LINKLINE) -lons
<ORACLE_HOME>/rdbms/lib$ cat ins_rdbms.mk | grep lagtsh
        $(EXTPROC_LINKLINE) -lagtsh
        $(HSOTS_LINKLINE) -lagtsh


<ORACLE_HOME>/network/lib$ cat ins_net_server.mk | grep "\-l"
        $(TNSLSNR_LINKLINE) -lnnz12 -lons


Installation


1.    Downloaded softwares

Database -> /u01/stage/DB12c
OEM -> /u01/stage/OMS

2.    Add user “oracle” and groups “dba” and “oinstall” and prepare directories

# groupadd -g 202 dba
# groupadd -g 203 oinstall
# useradd -m -d /home/oracle -u 203 -g oinstall -G dba -s /bin/bash -p <pass> oracle
# mkdir -p /u01/{oem12c,db12c,admin}
# mkdir -p /u01/oem12c/{middleware,agent12c}
# chown -R oracle:oinstall /u01/*
# chmod 755 -R /u01/*


3.    Install Oracle Database Software and create database EMREP to be used as OEM repository
 

a. Unzip software as “oracle”

$ cd /u01/stage/DB12c
$ unzip linuxamd64_12102_database_1of2.zip
$ unzip linuxamd64_12102_database_2of2.zip


b. After unzipping prepare response file

$ cd /u01/stage/DB12c/database/response
$ vi oemdb.rsp


db_install.rsp is sample file provided by Oracle that can be used as a template after modification, the parameters that I used are:
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v12.1.0
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=symgrNCS01
UNIX_GROUP_NAME=oinstall
SELECTED_LANGUAGES=en
ORACLE_HOME=/u01/db12c
ORACLE_BASE=/u01/admin
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
oracle.install.db.BACKUPDBA_GROUP=dba
oracle.install.db.DGDBA_GROUP=dba
oracle.install.db.KMDBA_GROUP=dba
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
DECLINE_SECURITY_UPDATES=true


c. Invoke Silent Installation

$ cd /u01/stage/DB12c/database
$  ./runInstaller -ignoreSysPrereqs -silent -responseFile /u01/stage/DB12c/database/response/oemdb.rsp


d. Prepare pfile and create spfile for instance
Although DBUA can be used to create database, I preferred to go with manual method.

*.compatible='12.1.0.2'
*.control_files='/u02/oradb/control01.ctl'
*.db_block_size=8192
*.db_create_file_dest='/u02/oradb/'
*.db_create_online_log_dest_1='/u02/oradb/redologs/'
*.db_create_online_log_dest_2='/u02/oradb/mirrlogs/'
*.db_name='EMREP'
*.db_securefile='PERMITTED'
*.diagnostic_dest='/u02/data/admin/'
*.job_queue_processes=50
*.log_archive_dest='/u02/oradb/arch/'
*.log_archive_format='log%t_%s_%r.arc'
*.memory_target=6G
*.open_cursors=350
*.parallel_max_servers=8
*.processes=300
*.undo_tablespace='UNDOTBS1'


e. Startup nomount instance and run create database script

$ sqlplus / as sysdba
SQL> CREATE DATABASE EMREP ARCHIVELOG
DATAFILE SIZE 500M AUTOEXTEND ON
SYSAUX DATAFILE SIZE 300M AUTOEXTEND ON
UNDO TABLESPACE UNDOTBS1 DATAFILE SIZE 200M AUTOEXTEND ON
DEFAULT TEMPORARY TABLESPACE TEMP1 TEMPFILE SIZE 200M AUTOEXTEND ON
LOGFILE
GROUP 1 SIZE 500M,
GROUP 2 SIZE 500M,

GROUP 3 SIZE 500M
CHARACTER SET AL32UTF8;


Run catalog.sql, catproc.sql and pupbld.sql respectively.

f. Create password file and listener for database

$ cd $ORACLE_HOME/dbs
$ orapwd file=orapwEMREP password=<pass> ignorecase=y

$ vi $ORACLE_HOME/network/admin/listener.ora
EMREP =
 (DESCRIPTION=
   (ADDRESS=(PROTOCOL=TCP)(HOST=srv01)(PORT=1521)
    (CONNECT_DATA=(SID=EMREP))
   )
 )

SID_LIST_EMREP=
 (SID_LIST=
  (SID_DESC=
   (ORACLE_HOME=/u01/db12c)
   (SID_NAME=EMREP)
  )
 )


$ lsnrctl start EMREP


4.    Install Oracle Enterprise Manager

a. Unzip software and prepare response file

$ cd /u01/stage/OMS/
$ unzip em12105_linux64_disk1.zip
$ unzip em12105_linux64_disk2.zip
$ unzip em12105_linux64_disk3.zip

$ cd /u01/stage/OMS/em12105_linux/response
$ vi oms_new_install.rsp





new_install.rsp is sample file provided by Oracle that can be used as a template after modification, the parameters that I used are:

RESPONSEFILE_VERSION=2.2.1.0.0
UNIX_GROUP_NAME="dba"
INVENTORY_LOCATION="/u01/oraInventory"
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
DECLINE_SECURITY_UPDATES=true
INSTALL_UPDATES_SELECTION="skip"
ORACLE_MIDDLEWARE_HOME_LOCATION=/u01/oem12c/middleware
ORACLE_HOSTNAME=srv01
AGENT_BASE_DIR=/u01/oem12c/agent12c
WLS_ADMIN_SERVER_USERNAME="weblogic"
WLS_ADMIN_SERVER_PASSWORD="oracle12"
WLS_ADMIN_SERVER_CONFIRM_PASSWORD="oracle12"
NODE_MANAGER_PASSWORD="oracle12"
NODE_MANAGER_CONFIRM_PASSWORD="oracle12"
ORACLE_INSTANCE_HOME_LOCATION=/u01/oem12c/middleware/gc_inst
CONFIGURE_ORACLE_SOFTWARE_LIBRARY=false
DATABASE_HOSTNAME="srv01"
LISTENER_PORT="1521"
SERVICENAME_OR_SID="EMREP"
SYS_PASSWORD="oracle12"
SYSMAN_PASSWORD="oracle12"
SYSMAN_CONFIRM_PASSWORD="oracle12"
DEPLOYMENT_SIZE="SMALL"
MANAGEMENT_TABLESPACE_LOCATION="/media/itadmin/oradb/EMREP/datafile/mgmt01.dbf"
CONFIGURATION_DATA_TABLESPACE_LOCATION="/media/itadmin/oradb/EMREP/datafile/mgmt_emc_depot01.dbf"
JVM_DIAGNOSTICS_TABLESPACE_LOCATION="/media/itadmin/oradb/EMREP/datafile/mgmt_deepdive01.dbf"
AGENT_REGISTRATION_PASSWORD="oracle12"
AGENT_REGISTRATION_CONFIRM_PASSWORD="oracle12"
FROM_LOCATION="../oms/Disk1/stage/products.xml"
DEINSTALL_LIST={"oracle.sysman.top.oms","12.1.0.5.0"}
b_upgrade=false
EM_INSTALL_TYPE="NOSEED"
CONFIGURATION_TYPE="ADVANCED"
TOPLEVEL_COMPONENT={"oracle.sysman.top.oms","12.1.0.5.0"}


b. Invoke OEM installation

$ cd /u01/stage/OMS/em12105_linux/
$ ./runInstaller -silent -responseFile /u01/stage/OMS/em12105_linux/response/oms_new_install.rsp


c. Obtain Oracle Management Agent for AIX


Since this OEM is a Linux install and all monitored servers are running AIX, we would require OEM to be equipped with software of Oracle Management Agent 12c for AIX to monitor them, this can be obtained using ONLINE method or OFFLINE method.
ONLINE method: https://docs.oracle.com/cd/E24628_01/install.121/e39876/downloading_agent_sw.htm#EMGSG111
OFFLINE method: https://docs.oracle.com/cd/E24628_01/install.121/e22624/install_agent.htm#EMBSC294

d. Add Targets for Monitoring


After downloading agent software using any of above two methods, proceed with deployment using “Add Targets” menu

5.    Configure Alerts and Notification Methods.
We are all done with installation, you may proceed with configuring alerts and notifications!


Enjoy.
-Anurag