如题所示,我们会通过Ansible,在CentOS7上安装Oracle database 11g

首先,为我们的系统安装Ansible:

yum install -y epel-release
yum install -y ansible

具体如下:

[root@oracle ~]# ls -ltr /etc/yum.repos.d/
total 12
-rw-r--r--. 1 root root  358 Nov 23 19:26 redhat.repo
-rw-r--r--. 1 root root 2380 Nov 23 19:26 Centos-7.repo
-rw-r--r--. 1 root root 1891 Nov 23 19:26 docker-ce.repo
[root@oracle ~]#
[root@oracle ~]# yum install -y epel-release
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
base                                                                                                                                                      | 3.6 kB  00:00:00
docker-ce-stable                                                                                                                                          | 3.5 kB  00:00:00
extras                                                                                                                                                    | 2.9 kB  00:00:00
updates                                                                                                                                                   | 2.9 kB  00:00:00
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================================================
 Package                                        Arch                                     Version                                  Repository                                Size
=================================================================================================================================================================================
Installing:
 epel-release                                   noarch                                   7-11                                     extras                                    15 k

Transaction Summary
=================================================================================================================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Downloading packages:
warning: /var/cache/yum/x86_64/7Server/extras/packages/epel-release-7-11.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY    ]  0.0 B/s |    0 B  --:--:-- ETA
Public key for epel-release-7-11.noarch.rpm is not installed
epel-release-7-11.noarch.rpm                                                                                                                              |  15 kB  00:00:05
Retrieving key from http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 From       : http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-11.noarch                                                                                                                                      1/1
  Verifying  : epel-release-7-11.noarch                                                                                                                                      1/1

Installed:
  epel-release.noarch 0:7-11

Complete!
[root@oracle ~]#
[root@oracle ~]# yum install -y ansible
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
epel/x86_64/metalink                                                                                                                                      | 4.3 kB  00:00:00
epel                                                                                                                                                      | 4.7 kB  00:00:00
(1/3): epel/x86_64/group_gz                                                                                                                               |  96 kB  00:00:00
(2/3): epel/x86_64/updateinfo                                                                                                                             | 1.0 MB  00:00:01
(3/3): epel/x86_64/primary_db                                                                                                                             | 7.0 MB  00:00:01
Resolving Dependencies
--> Running transaction check
---> Package ansible.noarch 0:2.9.25-1.el7 will be installed
--> Processing Dependency: python-httplib2 for package: ansible-2.9.25-1.el7.noarch
--> Processing Dependency: python-jinja2 for package: ansible-2.9.25-1.el7.noarch
--> Processing Dependency: python-paramiko for package: ansible-2.9.25-1.el7.noarch
--> Processing Dependency: python2-cryptography for package: ansible-2.9.25-1.el7.noarch
--> Processing Dependency: python2-jmespath for package: ansible-2.9.25-1.el7.noarch
--> Processing Dependency: sshpass for package: ansible-2.9.25-1.el7.noarch
--> Running transaction check
---> Package python-jinja2.noarch 0:2.7.2-4.el7 will be installed
--> Processing Dependency: python-babel >= 0.8 for package: python-jinja2-2.7.2-4.el7.noarch
--> Processing Dependency: python-markupsafe for package: python-jinja2-2.7.2-4.el7.noarch
---> Package python-paramiko.noarch 0:2.1.1-9.el7 will be installed
--> Processing Dependency: python2-pyasn1 for package: python-paramiko-2.1.1-9.el7.noarch
---> Package python2-cryptography.x86_64 0:1.7.2-2.el7 will be installed
--> Processing Dependency: python-idna >= 2.0 for package: python2-cryptography-1.7.2-2.el7.x86_64
--> Processing Dependency: python-cffi >= 1.4.1 for package: python2-cryptography-1.7.2-2.el7.x86_64
--> Processing Dependency: python-enum34 for package: python2-cryptography-1.7.2-2.el7.x86_64
---> Package python2-httplib2.noarch 0:0.18.1-3.el7 will be installed
---> Package python2-jmespath.noarch 0:0.9.4-2.el7 will be installed
---> Package sshpass.x86_64 0:1.06-2.el7 will be installed
--> Running transaction check
---> Package python-babel.noarch 0:0.9.6-8.el7 will be installed
---> Package python-cffi.x86_64 0:1.6.0-5.el7 will be installed
--> Processing Dependency: python-pycparser for package: python-cffi-1.6.0-5.el7.x86_64
---> Package python-enum34.noarch 0:1.0.4-1.el7 will be installed
---> Package python-idna.noarch 0:2.4-1.el7 will be installed
---> Package python-markupsafe.x86_64 0:0.11-10.el7 will be installed
---> Package python2-pyasn1.noarch 0:0.1.9-7.el7 will be installed
--> Running transaction check
---> Package python-pycparser.noarch 0:2.14-1.el7 will be installed
--> Processing Dependency: python-ply for package: python-pycparser-2.14-1.el7.noarch
--> Running transaction check
---> Package python-ply.noarch 0:3.4-11.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================================================
 Package                                            Arch                                 Version                                      Repository                            Size
=================================================================================================================================================================================
Installing:
 ansible                                            noarch                               2.9.25-1.el7                                 epel                                  17 M
Installing for dependencies:
 python-babel                                       noarch                               0.9.6-8.el7                                  base                                 1.4 M
 python-cffi                                        x86_64                               1.6.0-5.el7                                  base                                 218 k
 python-enum34                                      noarch                               1.0.4-1.el7                                  base                                  52 k
 python-idna                                        noarch                               2.4-1.el7                                    base                                  94 k
 python-jinja2                                      noarch                               2.7.2-4.el7                                  base                                 519 k
 python-markupsafe                                  x86_64                               0.11-10.el7                                  base                                  25 k
 python-paramiko                                    noarch                               2.1.1-9.el7                                  base                                 269 k
 python-ply                                         noarch                               3.4-11.el7                                   base                                 123 k
 python-pycparser                                   noarch                               2.14-1.el7                                   base                                 104 k
 python2-cryptography                               x86_64                               1.7.2-2.el7                                  base                                 502 k
 python2-httplib2                                   noarch                               0.18.1-3.el7                                 epel                                 125 k
 python2-jmespath                                   noarch                               0.9.4-2.el7                                  epel                                  41 k
 python2-pyasn1                                     noarch                               0.1.9-7.el7                                  base                                 100 k
 sshpass                                            x86_64                               1.06-2.el7                                   extras                                21 k

Transaction Summary
=================================================================================================================================================================================
Install  1 Package (+14 Dependent packages)

Total download size: 21 M
Installed size: 119 M
Downloading packages:
(1/15): python-cffi-1.6.0-5.el7.x86_64.rpm                                                                                                                | 218 kB  00:00:00
(2/15): python-enum34-1.0.4-1.el7.noarch.rpm                                                                                                              |  52 kB  00:00:00
(3/15): python-idna-2.4-1.el7.noarch.rpm                                                                                                                  |  94 kB  00:00:00
(4/15): python-jinja2-2.7.2-4.el7.noarch.rpm                                                                                                              | 519 kB  00:00:00
(5/15): python-markupsafe-0.11-10.el7.x86_64.rpm                                                                                                          |  25 kB  00:00:00
(6/15): python-paramiko-2.1.1-9.el7.noarch.rpm                                                                                                            | 269 kB  00:00:00
(7/15): python-babel-0.9.6-8.el7.noarch.rpm                                                                                                               | 1.4 MB  00:00:00
(8/15): python-ply-3.4-11.el7.noarch.rpm                                                                                                                  | 123 kB  00:00:00
(9/15): python2-cryptography-1.7.2-2.el7.x86_64.rpm                                                                                                       | 502 kB  00:00:00
(10/15): python-pycparser-2.14-1.el7.noarch.rpm                                                                                                           | 104 kB  00:00:00
warning: /var/cache/yum/x86_64/7Server/epel/packages/ansible-2.9.25-1.el7.noarch.rpm: Header V4 RSA/SHA256 Signature, key ID 352c64e5: NOKEY   ] 4.7 MB/s |  18 MB  00:00:00 ETA
Public key for ansible-2.9.25-1.el7.noarch.rpm is not installed
(11/15): ansible-2.9.25-1.el7.noarch.rpm                                                                                                                  |  17 MB  00:00:02
(12/15): python2-httplib2-0.18.1-3.el7.noarch.rpm                                                                                                         | 125 kB  00:00:00
(13/15): python2-jmespath-0.9.4-2.el7.noarch.rpm                                                                                                          |  41 kB  00:00:00
(14/15): python2-pyasn1-0.1.9-7.el7.noarch.rpm                                                                                                            | 100 kB  00:00:00
(15/15): sshpass-1.06-2.el7.x86_64.rpm                                                                                                                    |  21 kB  00:00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                            6.4 MB/s |  21 MB  00:00:03
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Importing GPG key 0x352C64E5:
 Userid     : "Fedora EPEL (7) <epel@fedoraproject.org>"
 Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
 Package    : epel-release-7-11.noarch (@extras)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : python2-pyasn1-0.1.9-7.el7.noarch                                                                                                                            1/15
  Installing : python-enum34-1.0.4-1.el7.noarch                                                                                                                             2/15
  Installing : sshpass-1.06-2.el7.x86_64                                                                                                                                    3/15
  Installing : python2-httplib2-0.18.1-3.el7.noarch                                                                                                                         4/15
  Installing : python-babel-0.9.6-8.el7.noarch                                                                                                                              5/15
  Installing : python2-jmespath-0.9.4-2.el7.noarch                                                                                                                          6/15
  Installing : python-ply-3.4-11.el7.noarch                                                                                                                                 7/15
  Installing : python-pycparser-2.14-1.el7.noarch                                                                                                                           8/15
  Installing : python-cffi-1.6.0-5.el7.x86_64                                                                                                                               9/15
  Installing : python-markupsafe-0.11-10.el7.x86_64                                                                                                                        10/15
  Installing : python-jinja2-2.7.2-4.el7.noarch                                                                                                                            11/15
  Installing : python-idna-2.4-1.el7.noarch                                                                                                                                12/15
  Installing : python2-cryptography-1.7.2-2.el7.x86_64                                                                                                                     13/15
  Installing : python-paramiko-2.1.1-9.el7.noarch                                                                                                                          14/15
  Installing : ansible-2.9.25-1.el7.noarch                                                                                                                                 15/15
  Verifying  : python-idna-2.4-1.el7.noarch                                                                                                                                 1/15
  Verifying  : python-markupsafe-0.11-10.el7.x86_64                                                                                                                         2/15
  Verifying  : python-ply-3.4-11.el7.noarch                                                                                                                                 3/15
  Verifying  : python-paramiko-2.1.1-9.el7.noarch                                                                                                                           4/15
  Verifying  : python2-jmespath-0.9.4-2.el7.noarch                                                                                                                          5/15
  Verifying  : python-babel-0.9.6-8.el7.noarch                                                                                                                              6/15
  Verifying  : ansible-2.9.25-1.el7.noarch                                                                                                                                  7/15
  Verifying  : python2-httplib2-0.18.1-3.el7.noarch                                                                                                                         8/15
  Verifying  : python-cffi-1.6.0-5.el7.x86_64                                                                                                                               9/15
  Verifying  : sshpass-1.06-2.el7.x86_64                                                                                                                                   10/15
  Verifying  : python-jinja2-2.7.2-4.el7.noarch                                                                                                                            11/15
  Verifying  : python2-pyasn1-0.1.9-7.el7.noarch                                                                                                                           12/15
  Verifying  : python-enum34-1.0.4-1.el7.noarch                                                                                                                            13/15
  Verifying  : python-pycparser-2.14-1.el7.noarch                                                                                                                          14/15
  Verifying  : python2-cryptography-1.7.2-2.el7.x86_64                                                                                                                     15/15

Installed:
  ansible.noarch 0:2.9.25-1.el7

Dependency Installed:
  python-babel.noarch 0:0.9.6-8.el7         python-cffi.x86_64 0:1.6.0-5.el7               python-enum34.noarch 0:1.0.4-1.el7          python-idna.noarch 0:2.4-1.el7
  python-jinja2.noarch 0:2.7.2-4.el7        python-markupsafe.x86_64 0:0.11-10.el7         python-paramiko.noarch 0:2.1.1-9.el7        python-ply.noarch 0:3.4-11.el7
  python-pycparser.noarch 0:2.14-1.el7      python2-cryptography.x86_64 0:1.7.2-2.el7      python2-httplib2.noarch 0:0.18.1-3.el7      python2-jmespath.noarch 0:0.9.4-2.el7
  python2-pyasn1.noarch 0:0.1.9-7.el7       sshpass.x86_64 0:1.06-2.el7

Complete!
[root@oracle ~]#
[root@oracle ~]# ansible --version
ansible 2.9.25
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Sep 12 2018, 05:31:16) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
[root@oracle ~]#

修改Ansible的配置:

[root@oracle ~]# cat /etc/ansible/ansible.cfg | grep "checking"
# uncomment this to disable SSH key host checking
#host_key_checking = False
# host key checking setting above.
[root@oracle ~]#
[root@oracle ~]# sed -i "s/#host_key_checking/host_key_checking/g" /etc/ansible/ansible.cfg
[root@oracle ~]#
[root@oracle ~]# cat /etc/ansible/ansible.cfg | grep "checking"
# uncomment this to disable SSH key host checking
host_key_checking = False
# host key checking setting above.
[root@oracle ~]#

然后,上传Ansible脚本:

[root@oracle ~]# mkdir /software
[root@oracle ~]# ls -ltr /software
total 0
[root@oracle ~]# ls -ltr /software
total 2295620
-rw-r--r-- 1 root root 2350714639 Nov 25 22:24 ansible-database-oracle.zip
[root@oracle ~]#
[root@oracle ~]# cd /software
[root@oracle software]#
[root@oracle software]# unzip ansible-database-oracle.zip
Archive:  ansible-database-oracle.zip
   creating: ansible-database-oracle/
   creating: ansible-database-oracle/inventory/
   creating: ansible-database-oracle/inventory/group_vars/
  inflating: ansible-database-oracle/inventory/group_vars/all
  inflating: ansible-database-oracle/inventory/group_vars/all.bak
  inflating: ansible-database-oracle/inventory/hosts
   creating: ansible-database-oracle/playbooks/
  inflating: ansible-database-oracle/playbooks/deploy_database_oracle.yml
  inflating: ansible-database-oracle/playbooks/deploy_database_oracle.yml.bak
   creating: ansible-database-oracle/playbooks/roles/
   creating: ansible-database-oracle/playbooks/roles/linux/
   creating: ansible-database-oracle/playbooks/roles/linux/files/
   creating: ansible-database-oracle/playbooks/roles/linux/files/yum/
  inflating: ansible-database-oracle/playbooks/roles/linux/files/yum/CentOS-7.repo
   creating: ansible-database-oracle/playbooks/roles/linux/tasks/
  inflating: ansible-database-oracle/playbooks/roles/linux/tasks/linux_directory.yml
  inflating: ansible-database-oracle/playbooks/roles/linux/tasks/linux_hosts.yml
  inflating: ansible-database-oracle/playbooks/roles/linux/tasks/linux_kernel.yml
  inflating: ansible-database-oracle/playbooks/roles/linux/tasks/linux_security.yml
  inflating: ansible-database-oracle/playbooks/roles/linux/tasks/linux_user_group.yml
  inflating: ansible-database-oracle/playbooks/roles/linux/tasks/linux_yum.yml
  inflating: ansible-database-oracle/playbooks/roles/linux/tasks/main.yml
  inflating: ansible-database-oracle/playbooks/roles/linux/tasks/main.yml.bak
   creating: ansible-database-oracle/playbooks/roles/linux/templates/
   creating: ansible-database-oracle/playbooks/roles/linux/templates/etc/
  inflating: ansible-database-oracle/playbooks/roles/linux/templates/etc/hosts.j2
  inflating: ansible-database-oracle/playbooks/roles/linux/templates/etc/hosts.j2.bak
   creating: ansible-database-oracle/playbooks/roles/linux/templates/user/
  inflating: ansible-database-oracle/playbooks/roles/linux/templates/user/bash_profile.j2
   creating: ansible-database-oracle/playbooks/roles/linux/vars/
  inflating: ansible-database-oracle/playbooks/roles/linux/vars/main.yml
  inflating: ansible-database-oracle/playbooks/roles/linux/vars/main.yml.bak
   creating: ansible-database-oracle/playbooks/roles/oracle/
   creating: ansible-database-oracle/playbooks/roles/oracle/files/
   creating: ansible-database-oracle/playbooks/roles/oracle/files/install_media/
 extracting: ansible-database-oracle/playbooks/roles/oracle/files/install_media/V17530-01_1of2.zip
 extracting: ansible-database-oracle/playbooks/roles/oracle/files/install_media/V17530-01_2of2.zip
   creating: ansible-database-oracle/playbooks/roles/oracle/tasks/
  inflating: ansible-database-oracle/playbooks/roles/oracle/tasks/main.yml
  inflating: ansible-database-oracle/playbooks/roles/oracle/tasks/main.yml.bak
  inflating: ansible-database-oracle/playbooks/roles/oracle/tasks/oracle_install.yml
   creating: ansible-database-oracle/playbooks/roles/oracle/templates/
   creating: ansible-database-oracle/playbooks/roles/oracle/templates/response/
  inflating: ansible-database-oracle/playbooks/roles/oracle/templates/response/dbca.rsp.j2
  inflating: ansible-database-oracle/playbooks/roles/oracle/templates/response/db_install.rsp.j2
  inflating: ansible-database-oracle/playbooks/roles/oracle/templates/response/netca.rsp.j2
   creating: ansible-database-oracle/playbooks/roles/oracle/vars/
  inflating: ansible-database-oracle/playbooks/roles/oracle/vars/main.yml
  inflating: ansible-database-oracle/playbooks/roles/oracle/vars/main.yml.bak
[root@oracle software]#
[root@oracle software]# ls -ltr
total 2295620
drwxr-xr-x 4 root root         40 Nov 24 16:02 ansible-database-oracle
-rw-r--r-- 1 root root 2350714639 Nov 25 22:24 ansible-database-oracle.zip
[root@oracle software]#

测试连通性:

[root@oracle software]# cat ansible-database-oracle/inventory/hosts
[oracle]
127.0.0.1
[root@oracle software]#
[root@oracle software]# ansible -i ansible-database-oracle/inventory/hosts all -m ping
127.0.0.1 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
[root@oracle software]#

开始使用Ansible执行安装:

[root@oracle software]# id oracle
id: oracle: no such user
[root@oracle software]#
[root@oracle software]# ls -ltr / | grep u01
[root@oracle software]#
[root@oracle software]# ansible-playbook -i ansible-database-oracle/inventory/hosts ansible-database-oracle/playbooks/deploy_database_oracle.yml

PLAY [linux] ********************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************
ok: [127.0.0.1]

TASK [linux : account: group] ***************************************************************************************************************************************************
changed: [127.0.0.1] => (item={u'name': u'oracle', u'id': u'2000'})
changed: [127.0.0.1] => (item={u'name': u'oinstall', u'id': u'2001'})
changed: [127.0.0.1] => (item={u'name': u'oper', u'id': u'2002'})
changed: [127.0.0.1] => (item={u'name': u'dba', u'id': u'2003'})

TASK [linux : account: user] ****************************************************************************************************************************************************
changed: [127.0.0.1] => (item={u'comment': u'Oracle Database OS User', u'shell': u'/bin/bash', u'group': u'oracle', u'name': u'oracle', u'id': u'2000', u'groups': [u'oinstall', u'oper', u'dba'], u'password': u'oracle', u'dir_home': u'/home/oracle'})

TASK [linux : .bash_profile: oracle] ********************************************************************************************************************************************
changed: [127.0.0.1]

TASK [linux : direcotry] ********************************************************************************************************************************************************
ok: [127.0.0.1] => (item={u'owner': u'root', u'path': u'/software', u'group': u'root', u'mode': u'0755'})
changed: [127.0.0.1] => (item={u'owner': u'root', u'path': u'/iso', u'group': u'root', u'mode': u'0755'})
changed: [127.0.0.1] => (item={u'owner': u'root', u'path': u'/data', u'group': u'root', u'mode': u'0755'})
changed: [127.0.0.1] => (item={u'owner': u'root', u'path': u'/temp_me', u'group': u'root', u'mode': u'0755'})
changed: [127.0.0.1] => (item={u'owner': u'root', u'path': u'/coding', u'group': u'root', u'mode': u'0755'})
changed: [127.0.0.1] => (item={u'owner': u'oracle', u'path': u'/u01/app/oracle', u'group': u'oinstall', u'mode': u'0755'})
changed: [127.0.0.1] => (item={u'owner': u'oracle', u'path': u'/u01/app/oracle/product/11.2.0.1/dbhome_1', u'group': u'oinstall', u'mode': u'0755'})
changed: [127.0.0.1] => (item={u'owner': u'oracle', u'path': u'/u01/app/oracle/common/oracle/sql', u'group': u'oinstall', u'mode': u'0755'})
changed: [127.0.0.1] => (item={u'owner': u'oracle', u'path': u'/data/oracle', u'group': u'oinstall', u'mode': u'0755'})
changed: [127.0.0.1] => (item={u'owner': u'oracle', u'path': u'/data/oracle/oradata', u'group': u'oinstall', u'mode': u'0755'})
changed: [127.0.0.1] => (item={u'owner': u'oracle', u'path': u'/data/oracle/oraInventory', u'group': u'oinstall', u'mode': u'0755'})
changed: [127.0.0.1] => (item={u'owner': u'oracle', u'path': u'/data/oracle/fast_recovery_area', u'group': u'oinstall', u'mode': u'0755'})

TASK [linux : /etc/hosts] *******************************************************************************************************************************************************
changed: [127.0.0.1]

TASK [linux : /etc/sysctl.conf] *************************************************************************************************************************************************
changed: [127.0.0.1] => (item={u'key': u'net.core.rmem_max', u'value': 4194304})
changed: [127.0.0.1] => (item={u'key': u'net.core.rmem_default', u'value': 262144})
changed: [127.0.0.1] => (item={u'key': u'fs.file-max', u'value': 6815744})
changed: [127.0.0.1] => (item={u'key': u'fs.aio-max-nr', u'value': 1048576})
changed: [127.0.0.1] => (item={u'key': u'kernel.sem', u'value': u'250 32000 100 128'})
changed: [127.0.0.1] => (item={u'key': u'net.core.wmem_default', u'value': 262144})
changed: [127.0.0.1] => (item={u'key': u'kernel.shmall', u'value': 2097152})
changed: [127.0.0.1] => (item={u'key': u'net.core.wmem_max', u'value': 1048576})
changed: [127.0.0.1] => (item={u'key': u'kernel.shmmax', u'value': 4294967295})
changed: [127.0.0.1] => (item={u'key': u'kernel.shmmni', u'value': 4096})
changed: [127.0.0.1] => (item={u'key': u'vm.overcommit_memory', u'value': 1})
changed: [127.0.0.1] => (item={u'key': u'net.ipv4.ip_local_port_range', u'value': u'9000 65500'})

TASK [linux : /etc/security/limits.conf] ****************************************************************************************************************************************
changed: [127.0.0.1] => (item={u'dest': u'/etc/security/limits.conf', u'domain': u'oracle', u'limit_item': u'stack', u'value': u'10240', u'limit_type': u'soft'})
changed: [127.0.0.1] => (item={u'dest': u'/etc/security/limits.conf', u'domain': u'oracle', u'limit_item': u'stack', u'value': u'10240', u'limit_type': u'hard'})
changed: [127.0.0.1] => (item={u'dest': u'/etc/security/limits.conf', u'domain': u'oracle', u'limit_item': u'nofile', u'value': u'1024', u'limit_type': u'soft'})
changed: [127.0.0.1] => (item={u'dest': u'/etc/security/limits.conf', u'domain': u'oracle', u'limit_item': u'nofile', u'value': u'65536', u'limit_type': u'hard'})
changed: [127.0.0.1] => (item={u'dest': u'/etc/security/limits.conf', u'domain': u'oracle', u'limit_item': u'nproc', u'value': u'2047', u'limit_type': u'soft'})
changed: [127.0.0.1] => (item={u'dest': u'/etc/security/limits.conf', u'domain': u'oracle', u'limit_item': u'nproc', u'value': u'16384', u'limit_type': u'hard'})

TASK [linux : Linux hugepage] ***************************************************************************************************************************************************
changed: [127.0.0.1] => (item=echo never > /sys/kernel/mm/transparent_hugepage/enabled)
changed: [127.0.0.1] => (item=echo -e '
# disable Transparent Hugepage.
echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local)

TASK [linux : Linux pam.d] ******************************************************************************************************************************************************
changed: [127.0.0.1]

TASK [linux : firewalld] ********************************************************************************************************************************************************
ok: [127.0.0.1]

TASK [selinux: /etc/selinux/config] *********************************************************************************************************************************************
ok: [127.0.0.1]

TASK [selinux: disable] *********************************************************************************************************************************************************
fatal: [127.0.0.1]: FAILED! => {"changed": true, "cmd": "setenforce 0", "delta": "0:00:00.008099", "end": "2021-11-25 22:28:30.154837", "msg": "non-zero return code", "rc": 1, "start": "2021-11-25 22:28:30.146738", "stderr": "setenforce: SELinux is disabled", "stderr_lines": ["setenforce: SELinux is disabled"], "stdout": "", "stdout_lines": []}
...ignoring

TASK [selinux: check status] ****************************************************************************************************************************************************
changed: [127.0.0.1]

TASK [selinux: show status] *****************************************************************************************************************************************************
ok: [127.0.0.1] => {
    "msg": "SELinux status:                 disabled"
}

TASK [linux : /etc/yum.conf] ****************************************************************************************************************************************************
changed: [127.0.0.1]

TASK [linux : YUM Repo File] ****************************************************************************************************************************************************
changed: [127.0.0.1] => (item={u'dest': u'/etc/yum.repos.d/CentOS-7.repo', u'src': u'yum/CentOS-7.repo'})

TASK [linux : YUM makecache] ****************************************************************************************************************************************************
[WARNING]: Consider using the yum module rather than running 'yum'.  If you need to use command because yum is insufficient you can add 'warn: false' to this command task or
set 'command_warnings=False' in ansible.cfg to get rid of this message.
changed: [127.0.0.1]

TASK [linux : YUM install] ******************************************************************************************************************************************************
changed: [127.0.0.1]

PLAY [oracle] *******************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************
ok: [127.0.0.1]

TASK [oracle : Oracle install media] ********************************************************************************************************************************************
changed: [127.0.0.1] => (item=install_media/V17530-01_1of2.zip)
changed: [127.0.0.1] => (item=install_media/V17530-01_2of2.zip)

TASK [oracle : Oracle Response file] ********************************************************************************************************************************************
changed: [127.0.0.1] => (item={u'dest': u'/software/db_install.rsp', u'src': u'response/db_install.rsp.j2'})
changed: [127.0.0.1] => (item={u'dest': u'/software/dbca.rsp', u'src': u'response/dbca.rsp.j2'})
changed: [127.0.0.1] => (item={u'dest': u'/software/netca.rsp', u'src': u'response/netca.rsp.j2'})

TASK [oracle : Oracle runInstaller / mode: silent] ******************************************************************************************************************************
[WARNING]: Consider using 'become', 'become_method', and 'become_user' rather than running su
changed: [127.0.0.1]

TASK [oracle : Messages] ********************************************************************************************************************************************************
ok: [127.0.0.1] => {
    "msg": "Waiting for Oracle runInstaller finished,... This may take several time."
}

PLAY RECAP **********************************************************************************************************************************************************************
127.0.0.1                  : ok=24   changed=18   unreachable=0    failed=0    skipped=0    rescued=0    ignored=1

[root@oracle software]#
[root@oracle software]# id oracle
uid=2000(oracle) gid=2000(oracle) groups=2000(oracle),2001(oinstall),2002(oper),2003(dba)
[root@oracle software]#
[root@oracle software]# ls -ltr /u01
total 0
drwxr-xr-x 3 oracle oinstall 20 Nov 25 22:28 app
[root@oracle software]#
[root@oracle software]# du -sh /u01
3.9G    /u01
[root@oracle software]#

Ansible的脚本虽然跑完了,但是Oracle的建库仍然在继续:

[root@oracle ~]# ps -ef | grep dbca
oracle    26664  23942  4 22:37 ?        00:00:03 /u01/app/oracle/product/11.2.0.1/dbhome_1/jdk/jre/bin/java -DORACLE_HOME=/u01/app/oracle/product/11.2.0.1/dbhome_1 -DSET_LAF= -Dsun.java2d.font.DisableAlgorithmicStyles=true -Dice.pilots.html4.ignoreNonGenericFonts=true -DDISPLAY= -DJDBC_PROTOCOL=thin -mx128m -classpath /u01/app/oracle/product/11.2.0.1/dbhome_1/assistants/dbca/jlib/dbca.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/assistants/jlib/assistantsCommon.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/ewt3.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/ewtcompat-3_3_15.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/share.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/help4.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/jewt4.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/oracle_ice5.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/kodiak.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/lib/xmlparserv2.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/orai18n.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/ldapjclnt11.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/netcfg.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/ojmisc.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/oraclepki103.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/opm.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jdbc/lib/ojdbc5.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/srvm.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/srvmhas.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/srvmasm.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/classes:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/oemlt.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/emca.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/sysman/jlib/emCORE.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/oc4j/j2ee/home/oc4j.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/oc4j/j2ee/home/db_oc4j_deploy.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/emConfigInstall.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/oui/jlib/OraInstaller.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/oui/jlib/OraPrereq.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/inventory/prereqs/oui/OraPrereqChecks.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/oui/jlib/OraPrereqChecks.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/oui/jlib/OraCheckPoint.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/jlib/cvu.jar:/u01/app/oracle/product/11.2.0.1/dbhome_1/dv/jlib/dvca.jar oracle.sysman.assistants.dbca.Dbca -silent -createDatabase -templateName General_Purpose.dbc -sid ORCL -gdbName ORCL.example.com -emConfiguration LOCAL -storageType FS -datafileDestination /data/oracle/oradata -datafileJarLocation /u01/app/oracle/product/11.2.0.1/dbhome_1/assistants/dbca/templates -responseFile /software/db_install.rsp -characterset ZHS16GBK -obfuscatedPasswords false -sampleSchema true -oratabLocation /u01/app/oracle/product/11.2.0.1/dbhome_1/install/oratab -automaticMemoryManagement true -totalMemory 512 -maskPasswords false -oui_internal
oracle    27150  26998  0 22:38 ?        00:00:00 imp                          transport_tablespace=y file=/u01/app/oracle/product/11.2.0.1/dbhome_1/assistants/dbca/templates/example.dmp log=/u01/app/oracle/cfgtoollogs/dbca/ORCL/tts_example_imp.log datafiles=/data/oracle/oradata/ORCL/example01.dbf tablespaces=EXAMPLE tts_owners=hr,oe,pm,ix,sh
root      27179  18690  0 22:39 pts/0    00:00:00 grep --color=auto dbca
[root@oracle ~]#
[root@oracle ~]# du -sm /data/oracle/
1405    /data/oracle/
[root@oracle ~]#
[root@oracle ~]# du -sm /data/oracle/
1405    /data/oracle/
[root@oracle ~]#
[root@oracle ~]# du -sm /data/oracle/
1452    /data/oracle/
[root@oracle ~]#

因此,需要等待一段时间之后,自动部署才会结束。

这个过程中,可以去看Oracle的DBCA的静默日志,位置在:$ORACLE_BASE/cfgtoollogs/dbca/SID

[user:oracle@host:oracle, SID:ORCL | /u01/app/oracle/cfgtoollogs/dbca/ORCL]$ pwd
/u01/app/oracle/cfgtoollogs/dbca/ORCL
[user:oracle@host:oracle, SID:ORCL | /u01/app/oracle/cfgtoollogs/dbca/ORCL]$
[user:oracle@host:oracle, SID:ORCL | /u01/app/oracle/cfgtoollogs/dbca/ORCL]$ ls -ltr
total 716
-rw-r----- 1 oracle oracle   1358 Nov 25 22:37 rmanRestoreDatafiles.sql
-rw-r----- 1 oracle oracle    330 Nov 25 22:38 CloneRmanRestore.log
-rw-r----- 1 oracle oracle   3648 Nov 25 22:39 tts_example_imp.log
-rw-r----- 1 oracle oracle  21738 Nov 25 22:41 cloneDBCreation.log
-rw-r----- 1 oracle oracle  17410 Nov 25 22:41 mkplug_v3_ORCL.log
-rw-r----- 1 oracle oracle      8 Nov 25 22:41 postScripts.log
-rw-r----- 1 oracle oracle     24 Nov 25 22:41 lockAccount.log
-rw-r----- 1 oracle oracle    357 Nov 25 22:41 postDBCreation.log
-rw-r----- 1 oracle oracle 430572 Nov 25 22:43 emConfig.log
-rw-r----- 1 oracle oracle    930 Nov 25 22:43 OraDb11g_home1_ORCL_creation_checkpoint.xml
-rw-r----- 1 oracle oracle  92137 Nov 25 22:43 trace.log
-rw-r----- 1 oracle oracle   1486 Nov 25 22:43 ORCL.log
[user:oracle@host:oracle, SID:ORCL | /u01/app/oracle/cfgtoollogs/dbca/ORCL]$

[user:oracle@host:oracle, SID:ORCL | /u01/app/oracle/cfgtoollogs/dbca/ORCL]$ cat ORCL.log
Copying database files
DBCA_PROGRESS : 1%
DBCA_PROGRESS : 3%
DBCA_PROGRESS : 37%
Creating and starting Oracle instance
DBCA_PROGRESS : 40%
DBCA_PROGRESS : 45%
DBCA_PROGRESS : 50%
DBCA_PROGRESS : 55%
DBCA_PROGRESS : 56%
DBCA_PROGRESS : 57%
DBCA_PROGRESS : 60%
DBCA_PROGRESS : 62%
Completing Database Creation
DBCA_PROGRESS : 66%
DBCA_PROGRESS : 70%
DBCA_PROGRESS : 73%
DBCA_PROGRESS : 85%
Enterprise manager configuration succeeded with the following warning -


Error securing Database Control, Database Control has been brought up in non-secure mode. To secure the Database Control execute the following command(s):

 1) Set the environment variable ORACLE_SID to ORCL
 2) /u01/app/oracle/product/11.2.0.1/dbhome_1/bin/emctl stop dbconsole
 3) /u01/app/oracle/product/11.2.0.1/dbhome_1/bin/emctl config emkey -repos -sysman_pwd < Password for SYSMAN user >
 4) /u01/app/oracle/product/11.2.0.1/dbhome_1/bin/emctl secure dbconsole -sysman_pwd < Password for SYSMAN user >
 5) /u01/app/oracle/product/11.2.0.1/dbhome_1/bin/emctl start dbconsole

 To secure Em Key, run /u01/app/oracle/product/11.2.0.1/dbhome_1/bin/emctl config emkey -remove_from_repos -sysman_pwd < Password for SYSMAN user >
DBCA_PROGRESS : 96%
DBCA_PROGRESS : 100%
Database creation complete. For details check the logfiles at:
 /u01/app/oracle/cfgtoollogs/dbca/ORCL.
Database Information:
Global Database Name:ORCL.example.com
System Identifier(SID):ORCLThe Database Control URL is http://oracle:1158/em


[user:oracle@host:oracle, SID:ORCL | /u01/app/oracle/cfgtoollogs/dbca/ORCL]$

可以看到,建库成功;

DB Control:http://192.168.11.200:1158/em

在命令行中查看:

[user:oracle@host:oracle, SID:ORCL | ~]$ ps -ef | grep ora_
oracle    27410      1  0 22:41 ?        00:00:00 ora_pmon_ORCL
oracle    27412      1  0 22:41 ?        00:00:00 ora_vktm_ORCL
oracle    27416      1  0 22:41 ?        00:00:00 ora_gen0_ORCL
oracle    27418      1  0 22:41 ?        00:00:00 ora_diag_ORCL
oracle    27420      1  0 22:41 ?        00:00:00 ora_dbrm_ORCL
oracle    27422      1  0 22:41 ?        00:00:00 ora_psp0_ORCL
oracle    27424      1  0 22:41 ?        00:00:00 ora_dia0_ORCL
oracle    27426      1  0 22:41 ?        00:00:00 ora_mman_ORCL
oracle    27428      1  0 22:41 ?        00:00:00 ora_dbw0_ORCL
oracle    27430      1  0 22:41 ?        00:00:00 ora_lgwr_ORCL
oracle    27432      1  0 22:41 ?        00:00:00 ora_ckpt_ORCL
oracle    27434      1  0 22:41 ?        00:00:00 ora_smon_ORCL
oracle    27436      1  0 22:41 ?        00:00:00 ora_reco_ORCL
oracle    27438      1  0 22:41 ?        00:00:00 ora_mmon_ORCL
oracle    27440      1  0 22:41 ?        00:00:00 ora_mmnl_ORCL
oracle    27442      1  0 22:41 ?        00:00:00 ora_d000_ORCL
oracle    27444      1  0 22:41 ?        00:00:00 ora_s000_ORCL
oracle    27496      1  0 22:41 ?        00:00:00 ora_qmnc_ORCL
oracle    27536      1  0 22:41 ?        00:00:00 ora_cjq0_ORCL
oracle    27629      1  0 22:42 ?        00:00:00 ora_q000_ORCL
oracle    27631      1  0 22:42 ?        00:00:00 ora_q001_ORCL
oracle    27633      1  0 22:42 ?        00:00:00 ora_smco_ORCL
oracle    27635      1  0 22:42 ?        00:00:00 ora_w000_ORCL
oracle    36635  28762  0 22:52 pts/1    00:00:00 grep --color=auto ora_
[user:oracle@host:oracle, SID:ORCL | ~]$
[user:oracle@host:oracle, SID:ORCL | ~]$ sqlplus / as sysdba

SQL*Plus: Release 11.2.0.1.0 Production on Thu Nov 25 22:52:47 2021

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


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> select instance_name,status from v$instance;

INSTANCE_NAME    STATUS
---------------- ------------
ORCL             OPEN

SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
[user:oracle@host:oracle, SID:ORCL | ~]$
[user:oracle@host:oracle, SID:ORCL | ~]$ lsnrctl status

LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 25-NOV-2021 22:53:14

Copyright (c) 1991, 2009, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date                25-NOV-2021 22:37:31
Uptime                    0 days 0 hr. 15 min. 42 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /u01/app/oracle/product/11.2.0.1/dbhome_1/network/admin/listener.ora
Listener Log File         /u01/app/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening Endpoints Summary...
  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle)(PORT=1521)))
Services Summary...
Service "ORCL.example.com" has 1 instance(s).
  Instance "ORCL", status READY, has 1 handler(s) for this service...
Service "ORCLXDB.example.com" has 1 instance(s).
  Instance "ORCL", status READY, has 1 handler(s) for this service...
The command completed successfully
[user:oracle@host:oracle, SID:ORCL | ~]$

至此,通过Ansible自动化的部署Oracle,完成。


以上,Ansible脚本的压缩包,可以留言留下邮箱或联系方式,批量发放。

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

隐藏
变装