Oracle > Oracle Express Edition 11g を CentOS5.5 にインストール

更新日 2011-11-26
広告

Oracle Express Edition (XE) 11gをCentOS5.5にインストールする方法を紹介します。

参考URL: http://download.oracle.com/docs/cd/E17781_01/install.112/e18802/toc.htm

あらかじめ、以下のパッケージをyumなどでインストールしておきます(ex. sudo yum install xxx)。

  • glibc
  • make
  • binutils
  • gcc
  • libaio
  • bc

Oracleのサイトからoracle-xe-11.2.0-1.0.x86_64.rpm.zipをダウンロードします(ユーザ登録が必要かもしれません)。 そして、rootユーザになって、てきとうな場所に解凍します。

$ unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip
解凍されたrpmファイルをインストールし、その後、設定スクリプトを実行します。 設定スクリプトでは、ウェブアプリのポート番号や、データベースの接続ポート番号、systemアカウントのパスワードを聞かれます。 ここでは、ポート番号はデフォルトのままとします。 パスワードはてきとうに設定します。
$ rpm -ivh Disk1/oracle-xe-11.2.0-1.0.x86_64.rpm 
Executing post-install steps...
You must run '/etc/init.d/oracle-xe configure' as the root user to configure the database.

$ sudo /etc/init.d/oracle-xe configure

Oracle Database 11g Express Edition Configuration
-------------------------------------------------
This will configure on-boot properties of Oracle Database 11g Express 
Edition.  The following questions will determine whether the database should 
be starting upon system boot, the ports it will use, and the passwords that 
will be used for database accounts.  Press <Enter> to accept the defaults. 
Ctrl-C will abort.

Specify the HTTP port that will be used for Oracle Application Express [8080]:

Specify a port that will be used for the database listener [1521]:

Specify a password to be used for database accounts.  Note that the same
password will be used for SYS and SYSTEM.  Oracle recommends the use of 
different passwords for each database account.  This can be done after 
initial configuration:   # パスワードを入力
Confirm the password:    # パスワードを再入力

Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]:y

Starting Oracle Net Listener...Done
Configuring database...Done
Starting Oracle Database 11g Express Edition instance...Done
Installation completed successfully.

これでデータベースのインストールは完了です。

次に、データベースにアクセスするユーザを作成します。 (以下、rootユーザとoracleユーザは、CentOS上のユーザ名です。また、sysdbaユーザとtestuserユーザは、データベース上のユーザ名です。)

まず、シェル上でoracleユーザになります。 oracleユーザは、上記のインストールの過程で作成されています。 oracleユーザにならないと、sysdbaユーザでデータベースにログインできません(そして、sysdbaユーザでログインしないとユーザを作成できません)。

$ su - oracle

すでにrootユーザになっているのであれば、上記のコマンドでoracleユーザになれるはずです。

oracleユーザになったら、まず、環境設定用のスクリプトを実行しましょう。

$ /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh
ホームディレクトリに .bash_profile ファイルを作成して、以下のように記述しておくと、oracleユーザになったときにスクリプトを自動実行してくれるので楽です。例えば、以下のような内容です。
#!/bin/bash

export PATH=$PATH:/u01/app/oracle/product/11.2.0/xe/bin
. /u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh
ようやくデータベースへログインできます。ログインは、sqlplusコマンドを使います。
$ sqlplus / as sysdba
testuserユーザを作成します。 ユーザの作成時には、ユーザのパスワードや、テーブル空間を指定します。 以下の例では、パスワードをhogehoge、テーブル空間をusersとしています。
SQL> CREATE USER testuser IDENTIFIED BY hogehoge DEFAULT TABLESPACE users TEMPORARY TABLESPACE temp QUOTA UNLIMITED ON users;

User created.
次に、ユーザに権限を与えます。 Oracle XE 11gは、user/roleモデルを採用しているので、まずroleを作成し、roleに権限を付与し、ユーザにroleを割り当てる必要があります。
SQL> create role conn;

Role created.

SQL> GRANT CREATE session, CREATE sequence, CREATE trigger, CREATE table, CREATE view, CREATE procedure, CREATE synonym TO conn;

Grant succeeded.
上記の例では、connというroleに、複数の権限(データベースへの接続権限、シーケンステーブルの作成権限、トリガーの作成権限、テーブルの作成権限、などなど)を付与しています。 最後に、testuserユーザに、connを割り当てます。
SQL> GRANT conn TO testuser;

Grant succeeded.
いったんデータベースからログアウト(コントロール+Dなどで)し、testuserでログインしてみます。
$ sqlplus testuser

SQL*Plus: Release 11.2.0.2.0 Production on Tue Nov 22 21:18:06 2011

Copyright (c) 1982, 2011, Oracle.  All rights reserved.

Enter password:  # ここで hogehoge を入力

Connected to:
Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production
ログインできました。 試しにテーブルを作成してみます。
SQL> create table test (id int);

Table created.

SQL> drop table test;

Table dropped.

エラー

bcコマンドをインストールしていないと、rpmパッケージのインストール時にエラーが発生します。
$ rpm -ivh Disk1/oracle-xe-11.2.0-1.0.x86_64.rpm 
/var/tmp/rpm-tmp.pdSehr: line 186: bc: コマンドが見つかりません
また、CentOS6にインストールしようとすると、設定スクリプトの実行時にエラーになります。
$ sudo /etc/init.d/oracle-xe configure
    :
Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]:
    :
Starting Oracle Net Listener...Done
Configuring database...
Database Configuration failed.  Look into /u01/app/oracle/product/11.2.0/xe/config/log for details
広告
お問い合わせは sweng.tips@gmail.com まで。
inserted by FC2 system