ablog

不器用で落着きのない技術者のメモ

CentOS5.3 に Oracle10gR2 をインストールする

インストーラを入手する

ハードウェア要件の確認

  • 物理RAMが1024MB以上あることを確認する。
# grep MemTotal /proc/meminfo
  • スワップ領域が物理RAMのサイズの1.5倍以上であることを確認する。
# grep SwapTotal /proc/meminfo
  • /tmp に400MB以上の空き領域があることを確認する。
# df -h /tmp
  • Oracleソフトウェアのインストール先に1.5GB以上の空き領域があることを確認する。
# df -h
  • Oracleデータベースの作成先に1.2GB以上の空き領域があることを確認する。
# df -h
# grep "model name" /proc/cpuinfo

ソフトウェア要件の確認

# cat /etc/issue
CentOS release 5.3 (Final)
Kernel \r on an \m
  • カーネルのバージョンが 2.6.18-8 以上であることを確認する。
# uname -r
  • SELinuxが無効(Disabled)であることを確認する。
# getenforce
Disabled
  • 無効(Disabled)でない場合は、無効(Disabled)に設定して再起動する。
# vi /etc/sysconfig/selinux
SELINUX=disabled
# shutdown -r now
  • 以下のパッケージがインストールされていることを確認する。
    • binutils-2.17.50.0.6-2.el5
    • compat-libstdc++-33-3.2.3-61
    • elfutils-libelf-0.125-3.el5
    • elfutils-libelf-devel-0.125
    • gcc-4.1.1-52
    • gcc-c++-4.1.1-52
    • glibc-2.5-12
    • glibc-common-2.5-12
    • glibc-devel-2.5-12
    • glibc-headers-2.5-12
    • libaio-0.3.106
    • libaio-devel-0.3.106
    • libgcc-4.1.1-52
    • libstdc++-4.1.1
    • libstdc++-devel-4.1.1-52.e15
    • make-3.81-1.1
    • sysstat-7.0.0
    • unixODBC-2.2.11
    • unixODBC-devel-2.2.11
# rpm -qa --queryformat "%{name}-%{version}-%{release}.%{arch}\n"|\
	egrep "binutils|compat-libstdc++|elfutils-libelf|elfutils-libelf-devel|gcc|glibc|\
	libaio|libgcc|libstdc++|make|sysstat|unixODBC"|sort
  • 不足しているパッケージをインストールする。
    • CentOS-5.3-i386-bin-1of6.iso 〜 CentOS-5.3-i386-bin-6of6.iso を順番にマウントして、必要な rpm を探す。
    • [VM]-[設定]-[ハードウェア]-[CD/DVD(IDE)]
      • [デバイスのステータス]-[接続中]: チェックする
      • [デバイスのステータス]-[起動時に接続]: チェックする
      • [ISOイメージファイルを使用]: iso ファイルのパスを指定する。
# mount -r -t iso9660 /dev/cdrom /media
# cd /media/CentOS
# ls|egrep "libaio-devel|libstdc++-devel|sysstat|unixODBC-devel"
# rpm -ivh libaio-devel-0.3.106-3.2.i386.rpm
# rpm -ivh sysstat-7.0.2-3.el5.i386.rpm
# rpm -ivh unixODBC-devel-2.2.11-7.1.i386.rpm 
# rpm -ivh libXp-1.0.0-8.1.el5.i386.rpm # ← これがないと OUI が起動しないので、インストールしておく。
# umount /media

設定いろいろ

  • カーネルパラメータの設定
    • kernel.shmmax は物理RAMの半分の512MBにする。
# vi /etc/sysctl.conf
kernel.shmall = 2097152
kernel.shmmax = 536870912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 1048576
net.core.rmem_max = 1048576
net.core.wmem_default = 262144
net.core.wmem_max = 262144
# sysctl -p # 設定値を反映させる
# sysctl -a # 設定値が反映されたていることを確認する。
  • oracle ユーザ・グループの作成
# groupadd -g 501 oinstall
# groupadd -g 502 dba
# groupadd -g 503 oper
# useradd -u 501 -g oinstall -G dba oracle
# passwd oracle
# mkdir -p /u01/app/oracle 
# chown -R oracle:oinstall /u01/app/oracle 
  • oracle ユーザのシェルの制限の設定
# vi /etc/security/limits.conf
oracle     soft      nproc      2047
oracle     hard      nproc     16384
oracle     soft      nofile     1024
oracle     hard      nofile    65536
  • /etc/pam.d/login ファイルに以下の通り記述する。
# vi /etc/pam.d/login
session required pam_limits.so
  • /etc/profileに以下の指定を追記する。
# vi /etc/profile
if [ $USER = "oracle" ]; then
	ulimit -u 16384
	ulimit -n 65536
fi
# vi /home/oracle/.bash_profile
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=orcl
unset ORACLE_HOME
  • nobody ユーザが存在することを確認する。
# id nobody
uid=99(nobody) gid=99(nobody) 所属グループ=99(nobody)
# service vsftpd start
vsftpd 用の vsftpd を起動中:                               [  OK  ]
# chkconfig vsftpd on
# chkconfig --list vsftpd
vsftpd          0:off   1:off   2:on    3:on    4:on    5:on    6:off

ネットワーク設定の確認

  • /etc/hostsファイルが名前解決に使用されることを確認する。
# cat /etc/nsswitch.conf | grep hosts
hosts:      files dns # ← files が先頭に記述されていれば OK。
  • hostname コマンドを実行するとホスト名が表示されることを確認する。
# hostname
centos51
  • ドメイン名が動的に設定されていないことを確認する。
# domainname
(none)
  • /etc/hosts に以下を追加する。
# vi /etc/hosts
192.168.135.101         centos51 centos51.yoheia.jp centos51
  • hosts に完全修飾ホスト名が含まれていることを確認する。
# cat /etc/hosts | grep `eval hostname`
192.168.135.101         centos51 centos51.yoheia.jp centos51
127.0.0.1               centos51 localhost.localdomain localhost

サイレント・モードでインストールする

  • ここでVMwareのスナップショットをとっておく。
  • oraInst.loc を作成する。
$ su -
# cd /etc
# vi oraInst.loc
inventory_loc=/u01/app/oracle/oraInventory
inst_group=oinstall
# chown oracle:oinstall oraInst.loc
# chmod 664 oraInst.loc
# su - oracle
$ mkdir software/oracle10gR2_linux # ← ここにインストーラをftpでアップロードする
$ cd /home/oracle/software/oracle10gR2_linux
$ unzip 10201_database_linux32.zip
$ mkdir oracle102010
$ mv database oracle102010/
  • レスポンスファイルを作成する。
$ startx
#[右クリック]-[端末を開く]
$ export LANG=C
$ export NLS_LANG=American.America_JA16EUC
$ cd /home/oracle/software/oracle10gR2_linux/oracle102010/database
$ ./runInstaller -ignoreSysPrereqs -record -destinationFile /home/oracle/software/oracle10gR2_linux/oracle102010/database/response/102010_ee.rsp
    • OUI で以下の通り指定する
      • Select Installation Type: Enterprise Edition
      • Product Languages: English, Japanese
      • Specify Home Details
        • Name: OraDb10g_home1
        • Path: /u01/app/oracle/product/10.2.0/db_1
      • Select Configuration Option: Install databse Software only
      • 最後に [Cancel] を押して終了する。
  • サイレント・モードでインストールする
$ export LANG=C
$ export NLS_LANG=American.America_JA16EUC
$ ./runInstaller -silent -noconfig -responseFile /home/oracle/software/oracle10gR2_linux/oracle102010/database/response/102010_ee.rsp
WARNING:The following configuration scripts 
/u01/app/oracle/product/10.2.0/db_1/root.sh
need to be executed as root for configuring the system. If you skip the exec
ution of the configuration tools, the configuration will not be complete and
 the product wont function properly. In order to get the product to function
 properly, you will be required to execute the scripts and the configuration
 tools after exiting the OUI.

The installation of Oracle Database 10g was successful.
Please check '/u01/app/oracle/oraInventory/logs/silentInstall2009-10-08_02-27-42PM.log' for more details.
  • root.sh を実行する。
$ su -
# /u01/app/oracle/product/10.2.0/db_1/root.sh
Running Oracle10 root.sh script...

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/app/oracle/product/10.2.0/db_1

Enter the full pathname of the local bin directory: [/usr/local/bin]: 
   Copying dbhome to /usr/local/bin ...
   Copying oraenv to /usr/local/bin ...
   Copying coraenv to /usr/local/bin ...


Creating /etc/oratab file...
Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created
Finished running generic part of root.sh script.
Now product-specific root actions will be performed.

PSR 10.2.0.4.0 を適用する

$ cd /home/oracle/software/oracle10gR2_linux
$ unzip p6810189_10204_Linux-x86.zip
$ mkdir psr102040
$ mv Disk1 psr102040/
$ mv README.html psr102040/
  • レスポンスファイルを作成する。
$ startx
#[右クリック]-[端末を開く]
$ export LANG=C
$ export NLS_LANG=American.America_JA16EUC
$ cd /home/oracle/software/oracle10gR2_linux/psr102040/Disk1
$ ./runInstaller -ignoreSysPrereqs -record -destinationFile /home/oracle/software/oracle10gR2_linux/oracle102010/database/response/102010_ee.rsp
    • OUI で以下の通り指定する
      • Specify Home Details
        • Name: OraDb10g_home1
        • Path: /u01/app/oracle/product/10.2.0/db_1
    • 最後に [Cancel] を押して終了する
  • サイレント・モードで適用する。
$ export LANG=C
$ export NLS_LANG=American.America_JA16EUC
$ ./runInstaller -silent -noconfig -responseFile /home/oracle/software/oracle10gR2_linux/psr102040/Disk1/response/102040_ee.rsp
End of install phases.(Thursday, October 8, 2009 9:48:56 PM JST)
WARNING:
The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root script to run
/u01/app/oracle/product/10.2.0/db_1/root.sh
To execute the configuration scripts:
    1. Open a terminal window
    2. Log in as "root"
    3. Run the scripts

The installation of Oracle Database 10g Release 2 Patch Set 3 was successful.
Please check '/u01/app/oracle/oraInventory/logs/silentInstall2009-10-08_09-42-04PM.log' for more details.
  • root.sh を実行する。
$ su -
# /u01/app/oracle/product/10.2.0/db_1/root.sh
Running Oracle10 root.sh script...

The following environment variables are set as:
    ORACLE_OWNER= oracle
    ORACLE_HOME=  /u01/app/oracle/product/10.2.0/db_1

Enter the full pathname of the local bin directory: [/usr/local/bin]:
The file "dbhome" already exists in /usr/local/bin.  Overwrite it? (y/n)
[n]: y
   Copying dbhome to /usr/local/bin ...
The file "oraenv" already exists in /usr/local/bin.  Overwrite it? (y/n)
[n]: y
   Copying oraenv to /usr/local/bin ...
The file "coraenv" already exists in /usr/local/bin.  Overwrite it? (y/n)
[n]: y
   Copying coraenv to /usr/local/bin ...

Entries will be added to the /etc/oratab file as needed by
Database Configuration Assistant when a database is created

Finished running generic part of root.sh script.
Now product-specific root actions will be performed.
  • oracle ユーザの .bash_profile を編集する。
$ vi ~/.bash_profile
# for oracle
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export PATH=.:$ORACLE_HOME/bin:$PATH
export ORA_NLS10=$ORACLE_HOME/nls/data
export LD_LIBRARY_PATH=.:$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export TNS_ADMIN=$ORACLE_HOME/network/admin
export NLS_LANG=American_America.JA16EUC
export ORACLE_SID=orcl
$ . ~/.bash_profile

データベースを作成する

$ mkdir -p $ORACLE_BASE/admin/orcl/scripts
$ mkdir -p $ORACLE_BASE/oradata/orcl
  • 初期化パラメータファイルを作成する。
$ cat <<EOF > $ORACLE_HOME/dbs/initorcl.ora
control_files = (/u01/app/oracle/oradata/orcl/control01.ctl)
db_name = orcl
db_block_size = 8192
undo_management = AUTO
undo_tablespace = undotbs
compatible = 10.2.0
shared_pool_size = 100M
EOF
$ cat <<EOF > $ORACLE_BASE/admin/orcl/scripts/create_database.sql
CREATE DATABASE orcl
   LOGFILE GROUP 1 ('/u01/app/oracle/oradata/orcl/redo01.log') SIZE 100M,
   GROUP 2 ('/u01/app/oracle/oradata/orcl/redo02.log') SIZE 100M,
   GROUP 3 ('/u01/app/oracle/oradata/orcl/redo03.log') SIZE 100M
   MAXLOGFILES 5
   MAXLOGMEMBERS 5
   MAXLOGHISTORY 1
   MAXDATAFILES 100
   MAXINSTANCES 1
   CHARACTER SET JA16EUC
   NATIONAL CHARACTER SET AL16UTF16
   DATAFILE '/u01/app/oracle/oradata/orcl/system01.dbf' SIZE 50M REUSE
      AUTOEXTEND ON
   SYSAUX DATAFILE '/u01/app/oracle/oradata/orcl/sysaux01.dbf' SIZE 50M REUSE
      AUTOEXTEND ON
   DEFAULT TEMPORARY TABLESPACE temp
      TEMPFILE '/u01/app/oracle/oradata/orcl/temp01.dbf' 
      SIZE 20M REUSE
      AUTOEXTEND ON
   UNDO TABLESPACE undotbs 
      DATAFILE '/u01/app/oracle/oradata/orcl/undotbs01.dbf'
      SIZE 50M REUSE AUTOEXTEND ON;
EOF
  • データベースを作成する。
$ cd /u01/app/oracle/admin/orcl/scripts
$ export ORACLE_SID=orcl
$ sqlplus / as sysdba
SQL> spool create_database.log
SQL> startup nomount
SQL> @create_database
SQL> spool off
  • 動的パフォーマンスビュー、データ・ディクショナリビューと標準PL/SQLパッケージを作成する。
SQL> spool build.log
SQL> @?/rdbms/admin/catalog
SQL> @?/rdbms/admin/catproc
  • 一般ユーザーでSQL*Plusでデータベースに接続時にエラーメッセージが表示されないようSQL*Plusの製品情報を作成する。
SQL> conn system/manager
SQL> @?/sqlplus/admin/pupbld
SQL> spool off
  • 表領域を作成する。
SQL> create bigfile tablespace users datafile '/u01/app/oracle/oradata/orcl/user01.dbf' size 5m;
SQL> alter database default tablespace users;
  • REDOロググループを追加する。
SQL> alter database add logfile group 4('/u01/app/oracle/oradata/orcl/redo04.log') size 10m;
  • REDOロググループを多重化する。
SQL> alter database add logfile member
'/u01/app/oracle/oradata/orcl/redo11.log' to group 1,
'/u01/app/oracle/oradata/orcl/redo12.log' to group 2,
'/u01/app/oracle/oradata/orcl/redo13.log' to group 3,
'/u01/app/oracle/oradata/orcl/redo14.log' to group 4;
  • 制御ファイルを多重化する。
SQL> shutdown immediate
SQL> exit
$ vi $ORACLE_HOME/dbs/initorcl.ora
control_files=(/u01/app/oracle/oradata/orcl/control01.ctl,/u01/app/oracle/oradata/orcl/control02.ctl,/u01/app/oracle/oradata/orcl/control03.ctl)
$ cd /u01/app/oracle/oradata/orcl
$ cp control01.ctl control02.ctl
$ cp control01.ctl control03.ctl
$ sqlplus / as sysdba
SQL> startup
  • ユーザを作成する。
SQL> create user scott identified by tiger
default tablespace users
temporary tablespace temp
quota unlimited on users;
SQL> grant create session, create table to scott;
  • SPFILEに変更する。
SQL> create spfile from pfile='?/dbs/initorcl.ora';
SQL> shutdown immediate
SQL> quit
$ cd $ORACLE_HOME/dbs
$ mv initorcl.ora initorcl.ora.org
$ sqlplus / as sysdba
SQL> startup
SQL> show parameter spfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
spfile                               string      /u01/app/oracle/product/10
                                                 .2.0/db_1/dbs/spfileorcl.ora