でんかのブログ

テクニカル系ネタをメインに、つれづれなるままに書いていきます。

PuppetでOracleを自動インストール(Client編)

前回Databseの自動インストールと、Create Database後にサンプルスキーマ“scott/tiger”の作成までの自動化を紹介しました。今回は前回作ったスキーマへの接続テストとOracle Clientの自動インストールを紹介します!(`・ω・´)

マニフェストの実行

前回は実際にマニフェストを実行するところまで紹介していませんでしたが、あのままで問題なく実行できます。失敗すると面倒なので、まずはnoopオプション付けて実行します。

# puppet agent -t --noop
Info: Creating a new SSL key for cent65
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for cent65
Info: Certificate Request fingerprint (SHA256): 81:6A:FD:5C:1F:C7:99:02:67:0C:E5:70:45:50:A7:30:3C:B4:C9:1C:6C:C6:95:2E:DE:B1:81:20:7D:59:F2:E1
Info: Caching certificate for cent65
Info: Caching certificate_revocation_list for ca
Info: Caching certificate for ca
Info: Retrieving pluginfacts
Info: Retrieving plugin
Notice: /File[/var/lib/puppet/lib/puppet]/ensure: created
Notice: /File[/var/lib/puppet/lib/puppet/provider]/ensure: created
Notice: /File[/var/lib/puppet/lib/puppet/provider/db_rcu]/ensure: created
Notice: /File[/var/lib/puppet/lib/puppet/provider/db_directory_structure]/ensure: created
Notice: /File[/var/lib/puppet/lib/puppet/provider/file_line]/ensure: created
Notice: /File[/var/lib/puppet/lib/puppet/provider/sysctl]/ensure: created
Notice: /File[/var/lib/puppet/lib/puppet/provider/sysctl/darwin.rb]/ensure: defined content as '{md5}78e050af31aa8eefdca19d62c4fb4a3b'
   :
(すごく長いので中略)
   :
Notice: Node[cent65]: Would have triggered 'refresh' from 52 events
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 3 events
Info: Creating state file /var/lib/puppet/state/state.yaml
Notice: Finished catalog run in 43.59 seconds

エラーは出ませんでしたか?問題無ければnoopオプション無しで実行しましょう!(゚∀゚)

# puppet agent -t --noop

Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for cent65
Info: Applying configuration version '1432794309'
Notice: /Stage[main]/Main/Node[cent65]/Package[libstdc++-devel.x86_64]/ensure: created
Notice: /Stage[main]/Main/Node[cent65]/Sysctl[net.ipv4.tcp_fin_timeout]/value: value changed '60' to '30'
Notice: /Stage[main]/Main/Node[cent65]/Sysctl[net.ipv4.tcp_fin_timeout]/permanent: permanent changed 'false' to 'true'
Notice: /Stage[main]/Main/Node[cent65]/Package[libXtst.x86_64]/ensure: created
Notice: /Stage[main]/Main/Node[cent65]/Group[dba]/ensure: created
Notice: /Stage[main]/Main/Node[cent65]/Sysctl[fs.file-max]/value: value changed '97938' to '6815744'
Notice: /Stage[main]/Main/Node[cent65]/Sysctl[fs.file-max]/permanent: permanent changed 'false' to 'true'
Notice: /Stage[main]/Oradb::Prepareautostart/File[/etc/init.d/dbora]/ensure: created
Notice: /Stage[main]/Main/Node[cent65]/Package[unixODBC-devel]/ensure: created
Notice: /Stage[main]/Main/Node[cent65]/Group[oinstall]/ensure: created
Notice: /Stage[main]/Main/Node[cent65]/Package[gcc.x86_64]/ensure: created
Notice: /Stage[main]/Main/Node[cent65]/Package[compat-libcap1.x86_64]/ensure: created
Notice: /Stage[main]/Main/Node[cent65]/Sysctl[kernel.shmmni]/permanent: permanent changed 'false' to 'true'
Notice: /Stage[main]/Main/Node[cent65]/Sysctl[net.core.rmem_default]/value: value changed '124928' to '262144'
Notice: /Stage[main]/Main/Node[cent65]/Sysctl[net.core.rmem_default]/permanent: permanent changed 'false' to 'true'
Notice: /Stage[main]/Main/Node[cent65]/Package[glibc.i686]/ensure: created
Notice: /Stage[main]/Main/Node[cent65]/Sysctl[kernel.shmall]/value: value changed '4294967296' to '2097152'
Notice: /Stage[main]/Main/Node[cent65]/Sysctl[net.ipv4.tcp_keepalive_intvl]/value: value changed '75' to '30'
Notice: /Stage[main]/Main/Node[cent65]/Sysctl[net.ipv4.tcp_keepalive_intvl]/permanent: permanent changed 'false' to 'true'
   :
(やっぱりすごく長いので中略)
   :
Notice: /Stage[main]/Main/Node[cent65]/Oradb::Tnsnames[db01]/Concat[/oracle/product/11.2/db/network/admin/tnsnames.ora]/File[/oracle/product/11.2/db/network/admin/tnsnames.ora]/content: content changed '{md5}41e548fe965599806003592864c9b5d1' to '{md5}0e249f21b702a27c2e779902a848b396'
Notice: /Stage[main]/Main/Node[cent65]/Oradb::Tnsnames[db01]/Concat[/oracle/product/11.2/db/network/admin/tnsnames.ora]/File[/oracle/product/11.2/db/network/admin/tnsnames.ora]/mode: mode changed '0640' to '0774'
Notice: /Stage[main]/Main/Node[cent65]/Exec[install sample]/returns: executed successfully
Notice: Finished catalog run in 1447.18 seconds

問題なく実行できましたか?今回はcreate databaseまで実行されるので、そこそこの時間を要すると思います。不幸にしてエラーが発生した時はエラーメッセージをよく読んで対処してください。(´・ω・`)

サンプルスキーマへの接続

それではサンプルスキーマ“scott/tiger”に接続してみましょう!(`・ω・´)

# sudo su - oracle

-bash-4.1$ sqexport ORACLE_SID=db01 ; sqlplus scott/tiger

SQL*Plus: Release 11.2.0.1.0 Production on Thu May 28 15:51:05 2015
Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Release 11.2.0.1.0 - 64bit Production

SQL> select table_name from user_tables;

TABLE_NAME
------------------------------
SALGRADE
BONUS
EMP
DEPT

SQL> select * from EMP;

     EMPNO ENAME      JOB          MGR HIREDATE     SAL       COMM
---------- ---------- --------- ---------- --------- ---------- ----------
    DEPTNO
----------
      7369 SMITH      CLERK       7902 17-DEC-80        800
    20

      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300
    30

      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500
    30
   :
(長いので中略)
   :
14 rows selected.

SQL> quit
Disconnected from Oracle Database 11g Release 11.2.0.1.0 - 64bit Production

このように実行できましたか?無事実行できていればデータベースは問題なくインストールできています!(゚∀゚)

Oracle Clientの自動インストール

Oracle Databaseのインストールができていれば、Oracle Clientのインストールは簡単です!(゚∀゚)

マニフェストですが、グループとユーザ作成、必須パッケージのインストール、tnsnames.oraの設定はDatabaseと同じなので説明は省略します。あ、もちろん名前解決は適切にできるようにしておくのはDatabaseの場合と同じですので、マニフェストの中ではあえて触れませんが空気を読んでhostsなりdnsなり設定しておいてくださいね。(´・ω・`)

Client固有の部分は以下の“oradb::client”を呼び出すところです。

oradb::client{ '11.2.0.1_Linux-x86-64':
  version                => '11.2.0.1',
  file                   => 'linux.x64_11gR2_client.zip',
  oracleBase             => '/oracle',
  oracleHome             => '/oracle/product/11.2/client',
  user                   => 'oracle',
  group                  => 'dba',
  group_install          => 'oinstall',
  downloadDir            => '/install',
  puppetDownloadMntPoint => $puppetDownloadMntPoint,
  logoutput              => true,
  require                => [ User['oracle'],Package[$install] ],
}

属性値はDatabaseで説明したものと変わりはありませんね。ホントにこれだけなんです。ではその他必要な処理も加えてマニフェストを完成させましょう!(`・ω・´)

$all_groups = ['oinstall','dba' ,'oper']
 group { $all_groups :
  ensure      => present,
}

user { 'oracle' :
  ensure      => present,
  uid         => 500,
  gid         => 'oinstall',
  groups      => ['oinstall','dba','oper'],
  shell       => '/bin/bash',
  password    => 'xxxxxxxxxx', # openssl passwd -1で生成した値を記入
  home        => "/home/oracle",
  comment     => "This user oracle was created by Puppet",
  require     => Group[$all_groups],
  managehome  => true,
}

$install = [ 'binutils.x86_64', 'compat-libstdc++-33.x86_64', 'glibc.x86_64','ksh.x86_64','libaio.x86_64',
             'libgcc.x86_64', 'libstdc++.x86_64', 'make.x86_64','compat-libcap1.x86_64', 'gcc.x86_64',
             'gcc-c++.x86_64','glibc-devel.x86_64','libaio-devel.x86_64','libstdc++-devel.x86_64',
             'sysstat.x86_64','unixODBC-devel','glibc.i686','libXext.x86_64','libXtst.x86_64']
package { $install:
  ensure  => present,
}

oradb::client{ '11.2.0.1_Linux-x86-64':
  version                => '11.2.0.1',
  file                   => 'linux.x64_11gR2_client.zip',
  oracleBase             => '/oracle',
  oracleHome             => '/oracle/product/11.2/client',
  user                   => 'oracle',
  group                  => 'dba',
  group_install          => 'oinstall',
  downloadDir            => '/install',
  puppetDownloadMntPoint => $puppetDownloadMntPoint,
  logoutput              => true,
  require                => [ User['oracle'],Package[$install] ],
}

oradb::tnsnames{'cent65':
  oracleHome         => '/oracle/product/11.2/client',
  user               => 'oracle',
  group              => 'dba',
  server             => { myserver => { host => cent65, port => '1521', protocol => 'TCP' }},
  connectServiceName => 'db01.denka.orz.hm',
  connectServer      => 'DEDICATED',
  require            => Oradb::Client['11.2.0.1_Linux-x86-64'],
}

Client用マニフェストの実行

先のDatabaseの場合と同様に、最初はnoopで試しましょう。

# puppet agent -t --noop
Info: Creating a new SSL key for client
Info: Caching certificate for ca
Info: csr_attributes file loading from /etc/puppet/csr_attributes.yaml
Info: Creating a new SSL certificate request for client
Info: Certificate Request fingerprint (SHA256): 7F:A8:A1:DB:DA:82:F8:2F:0C:A4:CF:69:36:22:BE:B1:52:57:CF:30:04:BE:92:7C:6A:78:4C:FF:06:ED:58:B8
Info: Caching certificate for client
Info: Caching certificate_revocation_list for ca
Info: Caching certificate for ca
Info: Retrieving pluginfacts
Info: Retrieving plugin
Notice: /File[/var/lib/puppet/lib/puppet]/ensure: created
Notice: /File[/var/lib/puppet/lib/puppet/provider]/ensure: created
Notice: /File[/var/lib/puppet/lib/puppet/provider/db_rcu]/ensure: created
Notice: /File[/var/lib/puppet/lib/puppet/provider/db_directory_structure]/ensure: created
Notice: /File[/var/lib/puppet/lib/puppet/provider/file_line]/ensure: created
Notice: /File[/var/lib/puppet/lib/puppet/provider/sysctl]/ensure: created
Notice: /File[/var/lib/puppet/lib/puppet/provider/sysctl/darwin.rb]/ensure: defined content as '{md5}78e050af31aa8eefdca   :
(やっぱりすごく長いので中略)
   :
Notice: /oracle/product/11.2/client/network/admin/tnsnames.ora: Would have triggered 'refresh' from 1 events
Notice: Concat[/oracle/product/11.2/client/network/admin/tnsnames.ora]: Would have triggered 'refresh' from 1 events
Notice: Oradb::Tnsnames[test]: Would have triggered 'refresh' from 1 events
Notice: Node[client]: Would have triggered 'refresh' from 17 events
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Info: Creating state file /var/lib/puppet/state/state.yaml
Notice: Finished catalog run in 12.73 seconds

問題無ければnoop無しで実行です!(`・ω・´)

# puppet agent -t --noop
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for client
Info: Applying configuration version '1432796188'
Notice: /Stage[main]/Main/Node[client]/Package[libstdc++-devel.x86_64]/ensure: created
Notice: /Stage[main]/Main/Node[client]/Package[libXtst.x86_64]/ensure: created
Notice: /Stage[main]/Main/Node[client]/Group[dba]/ensure: created
Notice: /Stage[main]/Main/Node[client]/Package[unixODBC-devel]/ensure: created
Notice: /Stage[main]/Main/Node[client]/Group[oinstall]/ensure: created
Notice: /Stage[main]/Main/Node[client]/Package[gcc.x86_64]/ensure: created
Notice: /Stage[main]/Main/Node[client]/Package[compat-libcap1.x86_64]/ensure: created
   :
(やっぱりすごく長いので中略)
   :
Notice: /Stage[main]/Main/Node[client]/Oradb::Client[11.2.0.1_Linux-x86-64]/Exec[install oracle net 11.2.0.1_Linux-x86-64]/returns: Oracle Net Servicesの構成に成功しました。終了コードは次のとおりです。0
Notice: /Stage[main]/Main/Node[client]/Oradb::Client[11.2.0.1_Linux-x86-64]/Exec[install oracle net 11.2.0.1_Linux-x86-64]/returns: executed successfully
Notice: /Stage[main]/Main/Node[client]/Oradb::Client[11.2.0.1_Linux-x86-64]/Exec[remove oracle client file linux.x64_11gR2_client.zip 11.2.0.1_Linux-x86-64]/returns: executed successfully
Notice: /Stage[main]/Main/Node[client]/Oradb::Client[11.2.0.1_Linux-x86-64]/Exec[remove oracle client extract folder 11.2.0.1_Linux-x86-64]/returns: executed successfully
Notice: /Stage[main]/Main/Node[client]/Oradb::Tnsnames[test]/Concat[/oracle/product/11.2/client/network/admin/tnsnames.ora]/File[/oracle/product/11.2/client/network/admin/tnsnames.ora]/ensure: defined content as '{md5}b96d773e98aa6ab946c1fac0a5703208'
Notice: Finished catalog run in 358.49 seconds

無事実行できましたか?これだけでClientのインストールも完了です!(゚∀゚)

Oracle Clientからデータベースに接続

tnsnamaes.oraの設定さえ適切ならば、前述のサンプルスキーマでの手順と全く同じです。ただしsqlplusの接続文字列でtnsnames.oraに設定した名称を@に続けて記述する必要がありますので注意してください。

$ sqlplus scott/tiger@cent65

SQL*Plus: Release 11.2.0.1.0 Production on Mon Jun 8 00:12:18 2015
Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Release 11.2.0.1.0 - 64bit Production

SQL> select table_name from user_tables;

TABLE_NAME
------------------------------
DEPT
EMP
BONUS
SALGRADE

SQL> select ename from emp;

ENAME
----------
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS

ENAME
----------
JAMES
FORD
MILLER

14 rows selected.

SQL> quit

Disconnected from Oracle Database 11g Release 11.2.0.1.0 - 64bit Production

おわりに

駆け足ではありましたが、PuppetによるOracleの自動インストールを紹介しました。Puppetを使うと、あの面倒なOracleインストールが、ものすごく簡単にできる事がお分かりいただけた事でしょう。(゚∀゚)

今回使ったbiemond/oradb”モジュールは、Grid Infrastructureなどにも対応しているので、ぜひお試しくださいね!(゚∀゚)

そしてサポート入ってないとモノが手に入らないため、試せず淋しい思いしている僕にレポートください(´・ω・`)