目次

CentOSのKickStartでOracleをインストールする

条件

ファイル構成

□isolinux
└□orainst
 ├oracle-xe-11.2.0-1.0.x86_64.rpm.zip
 ├oracle11gxe-recreate-database.sh
 ├oracle11gxe-silent-install.sh
 ├sql-create-database.sql
 ├sql-drop-database.sql
 ├bash_profile
 ├xe.rsp
 ├initORCL.ora
 ├□etc
 │├□init.d
 ││└oracle-xe
 │└□sysconfig
 │ └iptables
 ├□config
 │└□script
 │ ├sqlplus.sh
 │ ├backup.sh
 │ ├restore.sh
 │ ├stopall.sh
 │ ├startdb.sh
 │ └stopdb.sh
 └□network
  └□admin
   └listener.ora

%post --nochrootで実行するコマンド

CentOS Kickstart 設定ファイルから抜粋です。

%post --nochroot
#!/bin/sh
 
set -x -v
exec 1>/mnt/sysimage/root/kickstart-post-nochroot.log 2>&1
 
echo "==> copying files..."
cp -r /mnt/source/postinstall/* /mnt/sysimage/root/
%end

%postで実行するコマンド

CentOS Kickstart 設定ファイルから抜粋です。

# create working directory
mkdir /tmp/orainst
 
# create logging directory
mkdir /tmp/orainst/logs
 
cd /tmp/orainst
cp -r /root/orainst/* .
bash /tmp/orainst/oracle11gxe-silent-install.sh 2>&1 | tee /tmp/orainst/logs/oraxeinstall.log

oracle11gxe-recreate-database.sh

oracle.dbaユーザで実行する必要があります。 また、パスワードはマスクかけています。

#!/bin/bash
 
# drop instance
cd /tmp/orainst/
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=${ORACLE_BASE}/product/11.2.0/xe
export ORACLE_SID=XE
$ORACLE_HOME/bin/sqlplus /nolog @sql-drop-database.sql
 
# create database
cp -r /tmp/orainst/initORCL.ora /oradata/orcl/conf/initORCL.ora
export ORACLE_SID=ORCL
$ORACLE_HOME/bin/sqlplus /nolog @sql-create-database.sql
 
 
cd /u01/app/oracle/product/11.2.0/xe/oracore/
$ORACLE_HOME/bin/orapwd file=orapwORCL password=????????????
 
$ORACLE_HOME/bin/lsnrctl stop
cp -r /tmp/orainst/network/admin/listener.ora $ORACLE_HOME/network/admin/
$ORACLE_HOME/bin/lsnrctl start
 
cp -rf /tmp/orainst/config/scripts/*.sh $ORACLE_HOME/config/scripts/
exit

oracle11gxe-silent-install.sh

#!/bin/bash
 
cd /tmp/orainst
unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip
 
# setup silent install settings
mv -f /root/orainst/xe.rsp /tmp/orainst/Disk1/response/xe.rsp
mv -f /root/orainst/hosts /etc/hosts
 
# install oracle xe
rpm -ivh  /tmp/orainst/Disk1/oracle-xe-11.2.0-1.0.x86_64.rpm
/etc/init.d/oracle-xe configure responseFile=/tmp/orainst/Disk1/response/xe.rsp
 
# create new instance data directory 
mkdir /oradata
mkdir /oradata/orcl
mkdir /oradata/orcl/conf
mkdir /oradata/orcl/dbf
mkdir /oradata/orcl/dump
mkdir /oradata/orcl/dump/adump
mkdir /oradata/orcl/dump/bdump
mkdir /oradata/orcl/dump/cdump
mkdir /oradata/orcl/dump/udump
chown -R oracle.dba /oradata
chmod -R 775 /oradata
 
chmod -R 777 /tmp/orainst
 
# drop database -> create database
sudo -u oracle bash /tmp/orainst/oracle11gxe-recreate-database.sh
 
# .profile
cat /tmp/orainst/bash_profile >> /etc/profile
 
# oracle-xe service
cp -rf /tmp/orainst/etc/init.d/oracle-xe /etc/init.d/oracle-xe
 
# iptables setting
cp -rf /tmp/orainst/etc/sysconfig/iptables /etc/sysconfig/iptables

sql-create-database.sql

パスワードはマスクかけています。

CONNECT SYS/???????? AS sysdba
 
startup nomount pfile='/oradata/orcl/conf/initORCL.ora'
 
CREATE DATABASE ORCL
	logfile GROUP 1 ('/oradata/orcl/dbf/redo1.dbf') SIZE 32M,
	GROUP 2 ('/oradata/orcl/dbf/redo2.dbf') SIZE 32M,
	GROUP 3 ('/oradata/orcl/dbf/redo3.dbf') SIZE 32M
	CHARACTER SET JA16SJISTILDE
	NATIONAL CHARACTER SET utf8
	datafile '/oradata/orcl/dbf/system.dbf'
	SIZE 240M autoextend ON
	NEXT 16M maxsize unlimited
	extent management LOCAL
	sysaux datafile '/oradata/orcl/dbf/sysaux.dbf'
	SIZE 48M autoextend ON
	NEXT 8M maxsize unlimited
	undo tablespace undo
	datafile '/oradata/orcl/dbf/undo.dbf'
	SIZE 48M autoextend ON
	DEFAULT TEMPORARY tablespace temp
	tempfile '/oradata/orcl/dbf/temp.dbf'
	SIZE 8M autoextend ON;
 
@/u01/app/oracle/product/11.2.0/xe/rdbms/admin/catalog.sql
 
@/u01/app/oracle/product/11.2.0/xe/rdbms/admin/catblock.sql
 
@/u01/app/oracle/product/11.2.0/xe/rdbms/admin/catproc.sql
 
@/u01/app/oracle/product/11.2.0/xe/rdbms/admin/catoctk.sql
 
CONNECT SYSTEM/?????????
 
@/u01/app/oracle/product/11.2.0/xe/sqlplus/admin/pupbld.sql
 
@/u01/app/oracle/product/11.2.0/xe/sqlplus/admin/help/hlpbld.sql helpus.sql
 
 
CONNECT SYS/?????????? AS sysdba;
 
CREATE spfile FROM pfile='/oradata/orcl/conf/initORCL.ora';
 
quit

sql-drop-database.sql

パスワードはマスクかけています。

CONNECT SYS/????????? AS sysdba
 
shutdown abort
 
startup RESTRICT mount
 
DROP DATABASE;
 
quit

initORCL.ora

db_name='ORCL'
control_files=/oradata/orcl/dbf/control.dbf'
audit_file_dest=/oradata/orcl/dump/adump
core_dump_dest=/oradata/orcl/dump/cdump
dispatchers='(PROTOCOL=TCP)'
shared_pool_size=128M
undo_management='AUTO'
undo_tablespace='UNDO'

listener.ora

# listener.ora Network Configuration File:

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = ORCL)
      (ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
      (PROGRAM = ORCL)
    )
  )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
      (ADDRESS = (PROTOCOL = TCP)(HOST = localhost.localdomain)(PORT = 1521))
    )
  )

DEFAULT_SERVICE_LISTENER = (XE)

xe.rsp

パスワードはマスクかけています。

###############################################################################
#                                                                             #
# HTTP port that will be used to access APEX admin page                       #
# Default : 8080							      #	
#                                                                             #
###############################################################################
ORACLE_HTTP_PORT=8090

###############################################################################
#                                                                             #
# TNS port that will be used to configure listener 			      #
# Default : 1521							      #	
#                                                                             #
###############################################################################
ORACLE_LISTENER_PORT=1521

###############################################################################
#                                                                             #
# Passwords can be supplied for the following two schemas in the              #
# starter database:                                                           #
#   SYS                                                                       #
#   SYSTEM                                                                    #
#                                                                             #
###############################################################################
ORACLE_PASSWORD=????????????

###############################################################################
#                                                                             #
# Passwords can be supplied for the following two schemas in the              #
# starter database:                                                           #
#   SYS                                                                       #
#   SYSTEM                                                                    #
#                           						      #
#   ORACLE_CONFIRM_PASSWORD should be same as ORACLE_PASSWORD                 #
#                           						      #
###############################################################################
ORACLE_CONFIRM_PASSWORD=manager

###############################################################################
#                                                                             #
# To start/stop listener and database instance up on system boot	      #	
#                                                                             #
###############################################################################
ORACLE_DBENABLE=y

bash_profile

export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=${ORACLE_BASE}/product/11.2.0/xe
export ORACLE_SID=ORCL
export ORACLE_BASE=/u01/app/oracle
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib/:/lib:/usr/lib
export NLS_LANG=Japanese_Japan.AL32UTF8

iptables

Oracleだけの場合は、1521のみで大丈夫ですが、他のアプリケーションでも外部からの接続がある場合は、追加しなければなりません。

# Generated by iptables-save v1.4.7 on Tue Feb 26 15:06:43 2013
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [50:5400]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT 
-A INPUT -p icmp -j ACCEPT 
-A INPUT -i lo -j ACCEPT 
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT 
-A INPUT -p tcp -m tcp --dport 1521 -j ACCEPT 
-A INPUT -p udp -m udp --dport 1521 -j ACCEPT 
-A INPUT -j REJECT --reject-with icmp-host-prohibited 
-A FORWARD -j REJECT --reject-with icmp-host-prohibited 
COMMIT
# Completed on Tue Feb 26 15:06:43 2013

参考サイト