目的
以下のような Oracle Golden Gate 環境をローカルに作っていきます。
STEP1.Oracle Database CUI インストール (この記事)
STEP2.Oracle Golden Gate インストール
STEP3.Oracle Golden Gate セットアップ
STEP4.Oracle Golden Gate を使ってみる
バージョンなど
対象 | バージョン |
---|---|
Host OS | Windows10 |
Client OS1 (name: myora1) | Centos-7.8 on virtual box |
Client OS2 (name: myora2) | Centos-7.8 on virtual box |
Virtual Box | Version 6.1.26 |
Vagrant | Version 2.2.5 |
Ansible (ansible_local) | Version 2.9 |
Oracle DB | 19c |
Oracle Golden Gate | 19.1.0.0 |
Oracle Database インストール手順
1.Vagrantfileを作成(1ファイルに2台分)
2.Ansible playbook ファイルを作成
3.Oracle DB をダウンロード
4.仮想環境を作成 (所要時間240分)
1.Vagrantfileを作成(1ファイルに2台分)
|-- Vagrantfile
|-- ansible
| |-- hosts
| |-- installer
| | `-- oracle-database-ee-19c-1.0-1.x86_64.rpm
| |-- myora1.yml
| `-- myora2.yml
# Vagrant::DEFAULT_SERVER_URL.replace('https://vagrantcloud.com')
# Vagrantfile
# coding: utf-8
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
# (A) For /sbin/mount.vboxsf: mounting failed with the error: No such device
if Vagrant.has_plugin?("vagrant-vbguest")
config.vbguest.auto_update = false
end
config.vm.box = "bento/centos-7.8"
config.vm.box_url = "https://app.vagrantup.com/bento/boxes/centos-7.8"
# (B) myora1 vm
config.vm.define "myora1" do |server|
server.vm.hostname = 'myora1'
server.vm.network :private_network,ip: "192.168.60.50"
server.vm.provider "virtualbox" do |vbox|
vbox.gui = false
vbox.name = "CentOs7.8-myora1"
vbox.cpus = 2
vbox.memory = 2048
vbox.customize [
"modifyvm", :id,
"--vram", "256", # video memory for full screen
"--clipboard", "bidirectional", # sharing clipboard
"--draganddrop", "bidirectional", # enable drag & drop
"--cpus", "2", # 2 cpu
"--ioapic", "on" # enable I/O APIC
]
end
# (C) ansible
server.vm.synced_folder "./ansible", "/ansible"
server.vm.provision "ansible_local" do |ansible|
ansible.playbook = "/ansible/myora1.yml"
ansible.version = "latest"
ansible.verbose = false
ansible.limit = "myora1"
ansible.inventory_path = "/ansible/hosts"
end
end
# (B) myora2 vm
config.vm.define "myora2" do |server|
server.vm.hostname = 'myora2'
server.vm.network :private_network,ip: "192.168.60.60"
server.vm.provider "virtualbox" do |vbox|
vbox.gui = false
vbox.name = "CentOs7.8-myora2"
vbox.cpus = 2
vbox.memory = 2048
vbox.customize [
"modifyvm", :id,
"--vram", "256", # video memory for full screen
"--clipboard", "bidirectional", # sharing clipboard
"--draganddrop", "bidirectional", # enable drag & drop
"--cpus", "2", # 2 cpu
"--ioapic", "on" # enable I/O APIC
]
end
# (C) ansible
server.vm.synced_folder "./ansible", "/ansible"
server.vm.provision "ansible_local" do |ansible|
ansible.playbook = "/ansible/myora2.yml"
ansible.version = "2.9.24"
ansible.verbose = false
ansible.limit = "myora2"
ansible.inventory_path = "/ansible/hosts"
end
end
end
- (A) "vagrant-vbguest" の自動更新が有効になっていると、失敗することがあるので、無効にしている
- (B) "myora1" と "myora2" という2つの仮想環境を定義している
- (C) ansible の playbook を "myora1.yml" と "myora2.yml" のそれぞれの仮想環境毎に用意している
2.Ansible playbook ファイルを作成
インベントリファイルに以下のように指定して、Ansible を localhost に対して SSH なしで実行するようにする。
myora1 ansible_connection=local
myora2 ansible_connection=local
- hosts: myora1
connection: local
become: yes
gather_facts: true
tasks:
## Install Oracle Preinstallation RPM
- name: Download Oracle preinstall rpm package
get_url:
url: https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
dest: /tmp
- name: Install Oracle Preinstallation
yum:
name: /tmp/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
state: present
- name: Copy file for Oracle installation
copy:
src: ./installer/oracle-database-ee-19c-1.0-1.x86_64.rpm
dest: /tmp/oracle-database-ee-19c-1.0-1.x86_64.rpm
mode: 0644
- name: Install Oracle DB
become: true
yum:
name: /tmp/oracle-database-ee-19c-1.0-1.x86_64.rpm
state: present
## Require to configure Oracle DB(deny to configure for "localhost")
- name: Replace a localhost ip address
replace:
path: /etc/hosts
regexp: '^127.0.0.1'
replace: '192.168.60.50'
- name: Make ansible setup status directory
file:
path: "/ansible_setup_status"
state: directory
owner: "root"
group: "root"
mode: 0755
- name: "check 'configured_oracle_db' if exist"
stat:
path: "/ansible_setup_status/configured_oracle_db"
register: configured_oracle_db_exist
- name: Configure Oracle DB
shell:
cmd: /etc/init.d/oracledb_ORCLCDB-19c configure
environment:
ORACLE_BASE: /opt/oracle
ORACLE_HOME: /opt/oracle/product/19c/dbhome_1
ORACLE_SID: ORCLCDB
ignore_errors: yes
when: not configured_oracle_db_exist.stat.exists
- name: Put file to indicate completed configure Oracle DB
file:
path: "/ansible_setup_status/configured_oracle_db"
state: touch
- name: bash_profile of oracle user
ansible.builtin.lineinfile:
path: /home/oracle/.bash_profile
state: present
line: "{{ item }}"
with_items:
- 'export ORACLE_SID=ORCLCDB'
- 'export ORACLE_BASE=/opt/oracle'
- 'export ORACLE_HOME=$ORACLE_BASE/product/19c/dbhome_1'
- 'export PATH=$PATH:$ORACLE_HOME/bin'
- (A) "Oracle DB" をインストールする前準備として、Preinstallation を行う。このRPMパッケージはOracleのダウンロードページにサインインしていなくてもダウンロード可能なため、仮想環境から直接ダウンロードするようにしている
- (B) "Oracle DB" のインストーラはOracleにサインインしないとダウンロードができないため、予めホストPCにダウンロードしておいたパッケージをコピーするようにしている
- (C) IPアドレスに対するホスト名を逆引きした時、"localhost"だと、Oracle configure が動作しないため、ホスト名が返却されるように /etc/hosts を編集している
- hosts: myora2
connection: local
become: yes
gather_facts: true
tasks:
## Install Oracle Preinstallation RPM
- name: Download Oracle preinstall rpm package
get_url:
url: https://yum.oracle.com/repo/OracleLinux/OL7/latest/x86_64/getPackage/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
dest: /tmp
- name: Install Oracle Preinstallation
yum:
name: /tmp/oracle-database-preinstall-19c-1.0-1.el7.x86_64.rpm
state: present
- name: Copy file for Oracle installation
copy:
src: ./installer/oracle-database-ee-19c-1.0-1.x86_64.rpm
dest: /tmp/oracle-database-ee-19c-1.0-1.x86_64.rpm
mode: 0644
- name: Install Oracle DB
become: true
yum:
name: /tmp/oracle-database-ee-19c-1.0-1.x86_64.rpm
state: present
## Require to configure Oracle DB(deny to configure for "localhost")
- name: Replace a localhost ip address
replace:
path: /etc/hosts
regexp: '^127.0.0.1'
replace: '192.168.60.60'
- name: Make ansible setup status directory
file:
path: "/ansible_setup_status"
state: directory
owner: "root"
group: "root"
mode: 0755
- name: "check 'configured_oracle_db' if exist"
stat:
path: "/ansible_setup_status/configured_oracle_db"
register: configured_oracle_db_exist
- name: Configure Oracle DB
shell:
cmd: /etc/init.d/oracledb_ORCLCDB-19c configure
environment:
ORACLE_BASE: /opt/oracle
ORACLE_HOME: /opt/oracle/product/19c/dbhome_1
ORACLE_SID: ORCLCDB
ignore_errors: yes
when: not configured_oracle_db_exist.stat.exists
- name: Put file to indicate completed configure Oracle DB
file:
path: "/ansible_setup_status/configured_oracle_db"
state: touch
- name: bash_profile of oracle user
ansible.builtin.lineinfile:
path: /home/oracle/.bash_profile
state: present
line: "{{ item }}"
with_items:
- 'export ORACLE_SID=ORCLCDB'
- 'export ORACLE_BASE=/opt/oracle'
- 'export ORACLE_HOME=$ORACLE_BASE/product/19c/dbhome_1'
- 'export PATH=$PATH:$ORACLE_HOME/bin'
myora1.yml との違いは、ホスト名とIPアドレスが異なるだけ。
3.Oracle DB をダウンロード
Oracle Database ダウンロードページ からダウンロードできます。
必ず Oracle Licence Agreement の内容をレビューし、承諾した上でダウンロードします。
ダウンロードした rpm パッケージは以下のように配置します。
|-- Vagrantfile
|-- ansible
| |-- hosts
| |-- installer
| | `-- oracle-database-ee-19c-1.0-1.x86_64.rpm ←これ
| |-- myora1.yml
| `-- myora2.yml
4.仮想環境を作成
それでは仮想環境をコマンドで作成していきます。
1.Vagrantfile があるディレクトリに移動
$ ls
Vagrantfile ansible/
2.vagrant up 実行
(手元の環境で約240分所要)
$ vagrant up --provision
==> vagrant: A new version of Vagrant is available: 2.2.18 (installed version: 2.2.5)!
==> vagrant: To upgrade visit: https://www.vagrantup.com/downloads.html
Bringing machine 'myora1' up with 'virtualbox' provider...
Bringing machine 'myora2' up with 'virtualbox' provider...
==> myora1: Importing base box 'bento/centos-7.8'...
(省略)
TASK [bash_profile of oracle user] *********************************************
changed: [myora2] => (item=export ORACLE_SID=ORCLCDB)
changed: [myora2] => (item=export ORACLE_BASE=/opt/oracle)
changed: [myora2] => (item=export ORACLE_HOME=$ORACLE_BASE/product/19c/dbhome_1)
changed: [myora2] => (item=export PATH=$PATH:$ORACLE_HOME/bin)
PLAY RECAP *********************************************************************
myora2 : ok=11 changed=9 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
3.仮想環境にログイン & sql client を使って oracle DBにログイン
$ vagrant ssh myora1
[vagrant@myora1 ~]$ sudo su - oracle
Last login: Sat Aug 14 02:22:46 UTC 2021
[oracle@myora1 ~]$ sql / as sysdba
SQLcl: Release 19.1 Production on Sat Aug 14 03:22:45 2021
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
SQL>
4.コンテナ確認
# 接続中のコンテナ確認
SQL> show con_name
CON_NAME
------------------------------
CDB$ROOT
# 利用可能なPDBの一覧
SQL> show pdbs
CON_ID CON_NAME OPEN MODE RESTRICTED
---------- ------------------------------ ---------- ----------
2 PDB$SEED READ ONLY NO
3 ORCLPDB1 READ WRITE NO
SQL>
以上