Tuesday, August 26, 2014

Install Oracle Sun Java to CentOS


Install Oracle Sun Java to CentOS

Download Oracle Java 7 JDK for Linux:
http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html
I prefer RPM. The tar.gz is an alternative available mainly for non-root users.

Note for x86 and x64
You can choose between x86 and x64 versions. You cannot install both together from RPM package. You can install one from RPM and the second manually from tar.gz.

Download (accept licence):
http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm

Download (shell command)
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u67-b01/jdk-7u67-linux-x64.rpm

Install java from rpm:
rpm -i *.rpm

Upgrade Java (optional):
rpm -Uvh jdk-7u-linux-x64.rpm

Setup Java
## java
alternatives --install /usr/bin/java java /usr/java/latest/jre/bin/java 200000

## javaws
alternatives --install /usr/bin/javaws javaws /usr/java/latest/jre/bin/javaws 200000

## Install javac only if you installed JDK (Java Development Kit) package
alternatives --install /usr/bin/javac javac /usr/java/latest/bin/javac 200000
alternatives --install /usr/bin/jar jar /usr/java/latest/bin/jar 200000

Choose Oracle Java as default
alternatives --config java
alternatives --config javaws
alternatives --config javac

Setup path
Add to /etc/profile file or ~/.bash_profile or to ~/.bashrc
export JAVA_HOME="/usr/java/latest"
Java JDK and JRE absolute version (/usr/java/jdk1.7.0_67)

Check version
java -version
javac -version

Resources

Oracle Java install doc:
http://docs.oracle.com/javase/7/docs/webnotes/install/
http://docs.oracle.com/javase/7/docs/webnotes/install/linux/linux-jdk.html

All steps in detail at:
http://www.if-not-true-then-false.com/2010/install-sun-oracle-java-jdk-jre-7-on-fedora-centos-red-hat-rhel/

Auto accept licence:
http://stackoverflow.com/questions/10268583/how-to-automate-download-and-installation-of-java-jdk-on-linux

Done


Install Jenkins in CentOS Linux


Install Jenkins in CentOS Linux

Jenkins
Jenkins is successor of Hudson project. It serves as continuous integration platform. Jenkins integrates with CVS, SVN, Git, Mercurial hg. Supports MVN, cron-like scheduling, shell commands, remote deployment and more.

Install Oracle Java
JBoss requires original Oracle Sun Java or compatible VM. As first step, Install Oracle Java.

Install Jenkins
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key
yum install jenkins

Change port
/etc/sysconfig/jenkins
JENKINS_AJP_PORT="7009"
JENKINS_PORT="7070"

Start Jenkins
service jenkins start

Configure authentication
http://www.linuxfunda.com/2013/11/17/how-to-install-and-configure-jenkins-on-centos-6-4/

Done

Resources
src: https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+RedHat+distributions

Further step:

Install Mercurial
yum search mercurial
yum install mercurial.x86_64

Install JBoss in CentOS Linux


How to install JBoss in CentOS Linux


Install Oracle Java
JBoss requires original Oracle Sun Java or compatible VM. As first step, Install Oracle Java.

Download JBoss 7.1.1 Final
http://jbossas.jboss.org/downloads/
wget http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.zip

Install JBoss
I followed this step by step how to:
http://www.davidghedini.com/pg/entry/install_jboss_7_on_centos


Changes against above doc

Java settings moved from bash_profile to bashrc to let it work after sudo su

We have original Java from Oracle, therefore I edited /etc/init.d/jboss and commented Java setup:
# Load Java configuration.
# [ -r /etc/java/java.conf ] && . /etc/java/java.conf
# export JAVA_HOME

In /etc/init.d/jboss change setting for chkconfig (no hyphen):
chkconfig: 234 80 20


Additional setup commands:
mkdir -p /var/run/jboss-as/ /etc/jboss-as/ /var/log/jboss-as/
chown jboss.jboss /var/run/jboss-as/ /etc/jboss-as/ /var/log/jboss-as/
cp /usr/share/jboss-as/bin/init.d/jboss-as.conf /etc/jboss-as/jboss-as.conf

Note for Jenkins and Oracle
To prevent interference with Jenkins and Oracle XE ports I did following changes:
In Jenkins I changed AJP port to 7009.
In Jenkins I changed web port to 7070.
In Oracle XE I changed web admin port to 6060.

Change in /etc/sysconfig/jenkins
JENKINS_AJP_PORT="7009"
JENKINS_PORT="7070"

Add user in JBoss
cd /usr/share/jboss-as/bin
./add-user.sh
./add-user.sh
login: jboss
pass: jboss_admin_password
Added user 'jboss' to file '/usr/share/jboss-as/standalone/configuration/mgmt-users.properties'
Added user 'jboss' to file '/usr/share/jboss-as/domain/configuration/mgmt-users.properties'

Done
You can access JBoss in local address: http://localhost:7070/
Or by using port forwarding http://localhost:7000/ and http://localhost:7009/



Solving errors


Error:
jboss Context initialization failed: java.lang.OutOfMemoryError: PermGen space

Solution:
Open file /usr/share/jboss-as/bin/standalone.conf
Insert following line at the beginning of this file:

export JAVA_OPTS="-server -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -Xms256m -Xmx1g -XX:PermSize=64M -XX:MaxPermSize=1g"

This will change settings for garbage collector, heap size and perm size. You can adjust memory settings as you need. After configuration, save file, restart jboss:

/etc/init.d/jboss restart



Data Source configuration


Open /usr/share/jboss-as/standalone/configuration/standalone.xml

Find datasources and add datasource section for Oracle:

            <datasources>
                <datasource jndi-name="java:jboss/yourDataSourceName" pool-name="yourDataSourceName" enabled="true">
                    <connection-url>jdbc:oracle:thin:@127.0.0.1:1521:xe</connection-url>
                    <driver>com.oracle</driver>
                    <pool>
                        <min-pool-size>3</min-pool-size>
                        <max-pool-size>5</max-pool-size>
                    </pool>
                    <security>
                        <user-name>oracle_user</user-name>
                        <password>oracle_password</password>
                    </security>
                    <validation>
                        <exception-sorter class-name="org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter"/>
                    </validation>
                    <timeout>
                        <blocking-timeout-millis>5000</blocking-timeout-millis>
                        <idle-timeout-minutes>5</idle-timeout-minutes>
                    </timeout>
                </datasource>
                <drivers>
                    <driver name="com.oracle" module="com.oracle">
                        <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
                    </driver>
                </drivers>
            </datasources>


Add Oracle JARs to JBoss

mkdir -p /usr/share/jboss-as/modules/com/oracle/main
cp /u01/app/oracle/product/11.2.0/xe/jdbc/lib/*.jar /usr/share/jboss-as/modules/com/oracle/main
chown -R jboss.jboss /usr/share/jboss-as/modules/com/oracle

Create modules configuration

Create file /usr/share/jboss-as/modules/com/oracle/main/module.xml as follows:

<module xmlns="urn:jboss:module:1.0" name="com.oracle">
    <resources>
        <resource-root path="ojdbc6.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
    </dependencies>
</module>


Restart JBoss:

/etc/init.d/jboss restart

You can also check your data sources in JBoss admin console.

Done.


Oracle XE database configuration failed


Oracle XE 11g (Express edition) installation error in CentOS Linux

Error:

/etc/init.d/oracle-xe configure
Starting Oracle Net Listener...Done
Configuring database...
Database Configuration failed.  Look into /u01/app/oracle/product/11.2.0/xe/config/log for details

Solution:

Your host was not specified in /etc/hosts. You can solve it by command executed under root user:
sudo su
echo "127.0.0.1   "`hostname` >> /etc/hosts



Solve Dependencies:

Install required packages by entering commands:
sudo su
yum install libaio bc flex
rpm -i oracle-xe-11.2.0-1.0.x86_64.rpm

Install Oracle XE express edition


Oracle XE 11g (Express edition) installation steps in CentOS Linux

This article will show you how to install and configure Oracle XE 11g in CentOS Linux step by step.

Setup hosts file
echo "127.0.0.1   "`hostname` >> /etc/hosts

Install required packages
yum install libaio bc flex

Download Oracle XE 11g R2 installation package:
You can choose from enterprise, standard or express:
http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index-092322.html
I chose express for our project.

Download page:
http://www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index.html

Direct link (accept licence):
http://download.oracle.com/otn/linux/oracle11g/xe/oracle-xe-11.2.0-1.0.x86_64.rpm.zip

Install Oracle XE
unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip
cd Disk1
rpm -i oracle-xe-11.2.0-1.0.x86_64.rpm


Auto configuration (optional):
ORACLE_LISTENER_PORT=1521
ORACLE_HTTP_PORT=8080 # or 6060
ORACLE_PASSWORD=enter_admin_password_here
ORACLE_CONFIRM_PASSWORD=enter_admin_password_here
ORACLE_DBENABLE=y
export ORACLE_LISTENER_PORT ORACLE_HTTP_PORT ORACLE_PASSWORD \
ORACLE_CONFIRM_PASSWORD ORACLE_DBENABLE

Start configuration:
/etc/init.d/oracle-xe configure

Configuration options:
If you have not set up auto install, you can change following settings:
http port 8080 (changed to 6060)
database port 1521
credentials: SYS and SYSTEM
pass: enter_admin_password_here
start database when system starts: yes


Add oracle to path
Add following command to global /etc/profile for all users or to .bashrc or .bash_profile for current user:
source /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh

Change password for unix user oracle:
passwd oracle
enter_admin_password_here

Login as oracle:
su oracle

Start sqlplus
su oracle
sqlplus / as sysdba

Connect using role sysdba (optional)
# you can start and connect in two following steps:
su oracle
sqlplus /nolog
connect / as sysdba

Enter SQL commands
-- just FYI:
SELECT * FROM V$LOGFILE;
show parameter DB_RECOVERY_FILE_DEST;
show parameters sessions;
show parameters processes;

Setup Oracle params:
-- Enable remote access:
EXEC DBMS_XDB.SETLISTENERLOCALACCESS(FALSE);
-- max sessions:
alter system set sessions=250 scope=spfile;
shutdown immediate
startup
show parameters sessions;
-- max processes:
alter system set processes=200 scope=spfile;
shutdown immediate
startup
show parameters processes;
shutdown immediate
startup mount
-- archivelog:
alter database archivelog;
alter database open;
SELECT LOG_MODE FROM SYS.V$DATABASE;
-- Oracle replies
--  LOG_MODE
--  ------------
--  ARCHIVELOG
-- exit SQLplus:
EXIT

Setup password for APEX admin console (optional):
sqlplus / as sysdba
@/u01/app/oracle/product/11.2.0/xe/apex/apxchpwd.sql
-- enter password for admin user
-- exit SQLplus:
EXIT

Open APEX web admin:
http://localhost:8080/apex/f?p=4550:1
Note: I am currently using port 6060:
http://localhost:6060/apex/f?p=4550:1
Note2: Due to port forwarding, I am accessing:
http://localhost:7006/apex/f?p=4550:1
Workspace: Internal
User Name: admin
Password: your_password_from_previous_step
Note3: Admin interface link:
http://localhost:7006/apex/apex_admin

Environment variables check:
# check XE listener:
find /u01/app/oracle/product/11.2.0/xe/ | grep listener.ora
cat /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
# env check:
set | grep -i ^oracle

Create Oracle user (prerequisities)
You have to create user in Linux and in Oracle DB to enable successfull authentication.
Oracle user names contain by default specific prefix. You can change this setting or you need to add this prefix to each new user created in Oracle.

Check user prefix in Oracle (optional, recommended)
su oracle
sqlplus / as sysdba
SHOW PARAMETER os_authent_prefix
-- by default, user prefix is set to ops$

Remove username prefix
(optional, recommended)
You can remove prefix and work without "ops$":

su oracle
sqlplus / as sysdba
create pfile='/tmp/pfile.txt' from spfile;
shutdown immediate;
exit
echo "os_authent_prefix=''" >> /tmp/pfile.txt

sqlplus / as sysdba
create spfile from pfile='/tmp/pfile.txt';
startup
show parameter os_authent_prefix

Create user in Linux
sudo su
useradd sqluser1
passwd sqluser1
su oracle
sqlplus / as sysdba

Create user in Oracle
(Linux authentication)
-- User identified by Linux password
CREATE USER sqluser1 IDENTIFIED EXTERNALLY;

Create user in Oracle
(with prefix, not recommended)
-- User with name prefix - not recommended
CREATE USER ops$sqluser1 IDENTIFIED EXTERNALLY;

Create user in Oracle
(Oracle authentication)
-- User identified by Oracle password
CREATE USER sqluser1 IDENTIFIED BY sqluser1_password;
GRANT CREATE SESSION, CREATE TABLE TO sqluser1;
-- alter user sqluser1 quota 100m on system ;
GRANT UNLIMITED TABLESPACE TO sqluser1 ;

Create user in Oracle
(all in one example)
su oracle
sqlplus / as sysdba
-- User identified by Oracle password
CREATE USER sqluser1 IDENTIFIED BY sqluser1_password;
-- ALTER USER sqluser1 QUOTA 100m ON system ;
GRANT UNLIMITED TABLESPACE TO sqluser1 ;
GRANT CREATE SESSION, ALTER SESSION, CREATE DATABASE LINK, -
  CREATE MATERIALIZED VIEW, CREATE PROCEDURE, CREATE PUBLIC SYNONYM, -
  CREATE ROLE, CREATE SEQUENCE, CREATE SYNONYM, CREATE TABLE, -
  CREATE TRIGGER, CREATE TYPE, CREATE VIEW, UNLIMITED TABLESPACE -
  TO sqluser1 ;

Grant rights to user
GRANT CONNECT TO username;
GRANT resource TO username;
GRANT EXECUTE on schema.procedure TO username;
GRANT SELECT [, INSERT] [, UPDATE] [, DELETE] on schema.table TO username;

grant CREATE SESSION, ALTER SESSION, CREATE DATABASE LINK, -
  CREATE MATERIALIZED VIEW, CREATE PROCEDURE, CREATE PUBLIC SYNONYM, -
  CREATE ROLE, CREATE SEQUENCE, CREATE SYNONYM, CREATE TABLE, -
  CREATE TRIGGER, CREATE TYPE, CREATE VIEW, UNLIMITED TABLESPACE -
  to sqluser1 ;

Grant role sysdba to user
GRANT SYSDBA to sqluser1;

Error
ORA-01950: no privileges on tablespace 'SYSTEM'
Solution
alter user sqluser1 quota 100m on system ;
alter user sqluser1 quota unlimited on system ;
or
GRANT UNLIMITED TABLESPACE TO sqluser1 ;

Resources

Installation steps inspired by:
http://www.davidghedini.com/pg/entry/install_oracle_11g_xe_on

User name prefix settings:
src: http://www.oracle-base.com/articles/misc/os-authentication.php

Useful commands

-- Show users
SELECT username, account_status FROM dba_users ;

-- Show current user name
show user

-- Change default schema for user
ALTER USER sqluser1 WITH DEFAULT_SCHEMA = sqluser1_schema1 ;

-- Drop all user data in schema
http://stackoverflow.com/questions/1690404/how-to-drop-all-user-tables

-- Show tables for users
SELECT owner, table_name FROM all_tables ;

-- Describe table
DESC table_name ;

-- Drop all tables
select 'drop table '||table_name||' cascade constraints;' from user_tables;

-- Drop sequences
set head off feed off verify off
define owner=sql_user_name
SELECT 'DROP TABLE &owner..' || TABLE_NAME || ' CASCADE CONSTRAINTS;' FROM DBA_TABLES WHERE OWNER=UPPER('&owner');

Useful DB tools

Oracle SQL Developer Download
SQLplus
Squirrel SQL Download