CentOS7静默安装oracle11g

操作系统:

[root@docker ~]# uname -m
x86_64
[root@docker ~]# cat /etc/redhat-release
CentOS Linux release 7.1. (Core)

安装前的准备:

1. 修改主机名

#sed -i "s/HOSTNAME=localhost.localdomain/HOSTNAME=oracledb.01/" /etc/sysconfig/network

2.添加主机名与IP对应记录

# vim /etc/hosts 
192.168.0.71 oracledb.01

3.关闭Selinux

#sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config

# setenforce 0

安装软件包:

参考官方:http://docs.oracle.com/cd/E11882_01/install.112/e24326/toc.htm#BHCCADGD

  • The following or later version of packages for Oracle Linux 7, and Red Hat Enterprise Linux 7 must be installed:
binutils-2.23.52.0.-.el7.x86_64
compat-libcap1-1.10-.el7.x86_64
compat-libstdc++--3.2.-.el7.i686
compat-libstdc++--3.2.-.el7.x86_64
gcc-4.8.-.el7.x86_64
gcc-c++-4.8.-.el7.x86_64
glibc-2.17-.el7.i686
glibc-2.17-.el7.x86_64
glibc-devel-2.17-.el7.i686
glibc-devel-2.17-.el7.x86_64
ksh
libaio-0.3.-.el7.i686
libaio-0.3.-.el7.x86_64
libaio-devel-0.3.-.el7.i686
libaio-devel-0.3.-.el7.x86_64
libgcc-4.8.-.el7.i686
libgcc-4.8.-.el7.x86_64
libstdc++-4.8.-.el7.i686
libstdc++-4.8.-.el7.x86_64
libstdc++-devel-4.8.-.el7.i686
libstdc++-devel-4.8.-.el7.x86_64
libXi-1.7.-.el7.i686
libXi-1.7.-.el7.x86_64
libXtst-1.2.-.el7.i686
libXtst-1.2.-.el7.x86_64
make-3.82-.el7.x86_64
sysstat-10.1.-.el7.x86_64
unixODBC-2.3.1-6.el7.x86_64 or later
unixODBC-2.3.1-6.el7.i686 or later
unixODBC-devel-2.3.1-6.el7.x86_64 or later
unixODBC-devel-2.3.1-6.el7.i686 or later

用yum进行安装

yum -y install binutils compat-libcap1 compat-libstdc++- compat-libstdc++-*i686 compat-libstdc++-*.devel compat-libstdc++- compat-libstdc++-*.devel gcc gcc-c++ glibc glibc*.i686 glibc-devel glibc-devel*.i686 ksh libaio libaio*.i686 libaio-devel libaio-devel*.devel libgcc libgcc*.i686 libstdc++ libstdc++*.i686 libstdc++-devel libstdc++-devel*.devel libXi libXi*.i686 libXtst libXtst*.i686 make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686

检测是否31个包都有安装

[root@docker ~]# rpm -q binutils compat-libcap1 compat-libstdc++- gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst  make sysstat  unixODBC unixODBC-devel
binutils-2.23.52.0.-.el7.x86_64
compat-libcap1-1.10-.el7.x86_64
compat-libstdc++--3.2.-.el7.x86_64
compat-libstdc++--3.2.-.el7.i686
gcc-4.8.-.el7.x86_64
gcc-c++-4.8.-.el7.x86_64
glibc-2.17-.el7_2..x86_64
glibc-2.17-.el7_2..i686
glibc-devel-2.17-.el7_2..x86_64
glibc-devel-2.17-.el7_2..i686
ksh--.el7_1..x86_64
libaio-0.3.-.el7.x86_64
libaio-0.3.-.el7.i686
libaio-devel-0.3.-.el7.x86_64
libaio-devel-0.3.-.el7.i686
libgcc-4.8.-.el7.x86_64
libgcc-4.8.-.el7.i686
libstdc++-4.8.-.el7.x86_64
libstdc++-4.8.-.el7.i686
libstdc++-devel-4.8.-.el7.x86_64
libstdc++-devel-4.8.-.el7.i686
libXi-1.7.-2.1.el7.x86_64
libXi-1.7.-.el7.i686
libXtst-1.2.-2.1.el7.x86_64
libXtst-1.2.-2.1.el7.i686
make-3.82-.el7.x86_64
sysstat-10.1.-.el7.x86_64
unixODBC-2.3.-.el7.x86_64
unixODBC-2.3.-.el7.i686
unixODBC-devel-2.3.-.el7.x86_64
unixODBC-devel-2.3.-.el7.i686

版本号只能大于规定的版本,不能小于。

创建oinstall和dba组

/usr/sbin/groupadd oinstall
/usr/sbin/groupadd dba

创建oracle用户

/usr/sbin/useradd -g oinstall -G dba oracle

设置oracle用户密码

passwd oracle

验证创建是否正确

[root@docker ~]# id oracle
uid=(oracle) gid=(oinstall) groups=(oinstall),(dba)

配置内核参数

[root@docker ~]# vim /etc/sysctl.conf 

# System default settings live in /usr/lib/sysctl.d/-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/<name>.conf file
#
# For more information, see sysctl.conf() and sysctl.d().
fs.aio-max-nr =
fs.file-max =
kernel.shmall =
kernel.shmmax = 536870912 #最低:536870912,最大值:比物理内存小1个字节的值,建议超过物理内存的一半
kernel.shmmni =
kernel.sem =
net.ipv4.ip_local_port_range =
net.core.rmem_default =
net.core.rmem_max =
net.core.wmem_default =
net.core.wmem_max =

参数的值不能小于上面的配置,这是oracle官方建议的最小值,生产环境建议调整这些参数,以优化系统性能。

修改后使之生效

/sbin/sysctl -p

修改用户限制

vim  /etc/security/limits.conf

#在末尾添加
oracle soft nproc
oracle hard nproc
oracle soft nofile
oracle hard nofile
oracle soft stack 10240
oracle hard stack 10240
 
在/etc/pam.d/login 文件中,使用文本编辑器或vi命令增加或修改以下内容
session required /lib64/security/pam_limits.so
session required pam_limits.so

在/etc/profile 文件中,使用文本编辑器或vi命令增加或修改以下内容

if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p
ulimit -n
else
ulimit -u -n
fi
fi

使之生效

source /etc/profile

创建安装目录

mkdir -p /u01/app/
chown -R oracle:oinstall /u01/app/
chmod -R /u01/app/

配置环境变量

[oracle@docker ~]$ vim ~/.bash_profile 

export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=dbsrv2

使之生效

source ~/.bash_profile

解压oracle软件

[root@docker src]# unzip linux.x64_11gR2_database_1of2.zip
[root@docker src]# unzip linux.x64_11gR2_database_2of2.zip

复制响应文件模板

[oracle@docker ~]$ mkdir etc
[oracle@docker ~]$ cp /usr/local/src/database/response/* /home/oracle/etc/
[oracle@docker ~]$ ls etc
dbca.rsp db_install.rsp netca.rsp

设置响应文件权限

[oracle@docker ~]$ su - root

[root@docker ~]# chmod  /home/oracle/etc/*.rsp

静默安装Oracle软件

su - oracle
修改安装Oracle软件的响应文件/home/oracle/etc/db_install.rsp
oracle.install.option=INSTALL_DB_SWONLY     // 安装类型
ORACLE_HOSTNAME=docker // 主机名称(hostname查询)
UNIX_GROUP_NAME=oinstall // 安装组
INVENTORY_LOCATION=/u01/app/oraInventory //INVENTORY目录(不填就是默认值)
SELECTED_LANGUAGES=en,zh_CN,zh_TW // 选择语言
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 //oracle_home
ORACLE_BASE=/u01/app/oracle //oracle_base
oracle.install.db.InstallEdition=EE     // oracle版本
oracle.install.db.isCustomInstall=false   //自定义安装,否,使用默认组件
oracle.install.db.DBA_GROUP=dba /  / dba用户组
oracle.install.db.OPER_GROUP=oinstall // oper用户组
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE //数据库类型
oracle.install.db.config.starterdb.globalDBName=orcl //globalDBName
oracle.install.db.config.starterdb.SID=dbsrv2 //SID
oracle.install.db.config.starterdb.memoryLimit= //自动管理内存的内存(M)
oracle.install.db.config.starterdb.password.ALL=oracle //设定所有数据库用户使用同一个密码
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false //(手动写了false)
DECLINE_SECURITY_UPDATES=true   //设置安全更新(貌似是有bug,这个一定要选true,否则会无限提醒邮件地址有问题,终止安装。PS:不管地址对不对)

开始静默安装

[oracle@docker database]$ ./runInstaller -silent -responseFile /home/oracle/etc/db_install.rsp

查看安装日志

tail -f /u01/app/oraInventory/logs/installActions2016--31_06--29PM.log
出现类似如下提示表示安装完成:
------------------------------------------------------------------------

The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root scripts to run

/u01/app/oraInventory/orainstRoot.sh
/u01/app/oracle/product/11.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
4. Return to this window and hit "Enter" key to continue

Successfully Setup Software.

-----------------------------------------------------------------------------

使用root用户执行脚本
su - root
/u01/app/oraInventory/orainstRoot.sh
/u01/app/oracle/product/11.2./db_1/root.sh

增加或修改oracle的环境变量

su  - oracle
vim ~/.bash_profile

#for oracle
export ORACLE_BASE=/u01/app/oracle
export ORACLE_SID=dbsrv2
export ROACLE_PID=ora11g
#export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
export PATH=$PATH:$ORACLE_HOME/bin

export LANG="zh_CN.UTF-8"
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'

配置监听程序

[oracle@docker ~]$ netca /silent /responsefile /home/oracle/etc/netca.rsp

Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /home/oracle/etc/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
/u01/app/oracle/product/11.2.0/db_1/bin/lsnrctl start LISTENER
Listener Control complete.
Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0

启动监控程序

[oracle@docker ~]$ lsnrctl start

LSNRCTL for Linux: Version 11.2.0.1. - Production on -SEP- ::

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

Starting /u01/app/oracle/product/11.2./db_1/bin/tnslsnr: please wait...

TNSLSNR for Linux: Version 11.2.0.1. - Production
System parameter file is /u01/app/oracle/product/11.2./db_1/network/admin/listener.ora
Log messages written to /u01/app/oracle/diag/tnslsnr/docker/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=docker)(PORT=))) Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1. - Production
Start Date -SEP- ::
Uptime days hr. min. sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/oracle/product/11.2./db_1/network/admin/listener.ora
Listener Log File /u01/app/oracle/diag/tnslsnr/docker/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=docker)(PORT=)))
The listener supports no services
The command completed successfully

静默dbca建库

编辑应答文件

[oracle@docker ~]$ vi etc/dbca.rsp

[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "dbsrv2"
SID = "dbsrv2"
TEMPLATENAME = "General_Purpose.dbc"
CHARACTERSET = "AL32UTF8"

建库

[oracle@docker ~]$ dbca -silent -responseFile etc/dbca.rsp

Enter SYS user password: 

Enter SYSTEM user password: 

sh: /bin/ksh: No such file or directory
sh: /bin/ksh: No such file or directory
Copying database files
% complete
% complete
% complete
% complete
% complete
% complete
Creating and starting Oracle instance
% complete
% complete
% complete
% complete
% complete
% complete
% complete
% complete
Completing Database Creation
% complete
% complete
% complete
% complete
% complete
% complete
% complete
Look at the log file Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/orcl11g/orcl11g.log" for further details.

查看输出日志

[oracle@docker ~]$ cat /u01/app/oracle/cfgtoollogs/dbca/orcl11g/orcl11g.log
Copying database files
DBCA_PROGRESS : %
DBCA_PROGRESS : %
DBCA_PROGRESS : %
DBCA_PROGRESS : %
DBCA_PROGRESS : %
DBCA_PROGRESS : %
Creating and starting Oracle instance
DBCA_PROGRESS : %
DBCA_PROGRESS : %
DBCA_PROGRESS : %
DBCA_PROGRESS : %
DBCA_PROGRESS : %
DBCA_PROGRESS : %
DBCA_PROGRESS : %
Completing Database Creation
DBCA_PROGRESS : %
DBCA_PROGRESS : %
DBCA_PROGRESS : %
DBCA_PROGRESS : %
DBCA_PROGRESS : %
DBCA_PROGRESS : %
Database creation complete. For details check the logfiles at:
/u01/app/oracle/cfgtoollogs/dbca/orcl11g.
Database Information:
Global Database Name:orcl11g.us.oracle.com
System Identifier(SID):dbsrv2

至此完成数据库实例的创建。

-----------------------------------------------------------------------------------

-----------------------------------------------------------------------------------

附:

删除实例:

[oracle@docker ~]$ dbca -silent -deleteDatabase -sourcedb dbsrv2

oracle云在RedHat 6上的一些参数文件,内存是8G,供参考:

/etc/sysctl.conf

# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, is disabled, is enabled. See sysctl() and
# sysctl.conf() for more details. # Controls IP packet forwarding
net.ipv4.ip_forward = # Controls source route verification
net.ipv4.conf.default.rp_filter = # Do not accept source routing
net.ipv4.conf.default.accept_source_route = # Controls the System Request debugging functionality of the kernel
kernel.sysrq = # Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = # Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = # Disable netfilter on bridges.
net.bridge.bridge-nf-call-ip6tables =
net.bridge.bridge-nf-call-iptables =
net.bridge.bridge-nf-call-arptables = # Controls the default maxmimum size of a mesage queue
kernel.msgmnb = # Controls the maximum size of a message, in bytes
kernel.msgmax = # Controls the maximum shared segment size, in bytes # Controls the maximum number of shared memory segments, in pages
kernel.shmall = # oracle-rdbms-server-12cR1-preinstall setting for fs.file-max is # oracle-rdbms-server-12cR1-preinstall setting for kernel.sem is '250 32000 100 128' # oracle-rdbms-server-12cR1-preinstall setting for kernel.shmmni is # oracle-rdbms-server-12cR1-preinstall setting for kernel.shmall is on x86_64 # oracle-rdbms-server-12cR1-preinstall setting for kernel.shmmax is on x86_64 # oracle-rdbms-server-12cR1-preinstall setting for kernel.panic_on_oops is per Orabug # oracle-rdbms-server-12cR1-preinstall setting for net.core.rmem_default is # oracle-rdbms-server-12cR1-preinstall setting for net.core.rmem_max is # oracle-rdbms-server-12cR1-preinstall setting for net.core.wmem_default is # oracle-rdbms-server-12cR1-preinstall setting for net.core.wmem_max is # oracle-rdbms-server-12cR1-preinstall setting for fs.aio-max-nr is # oracle-rdbms-server-12cR1-preinstall setting for net.ipv4.ip_local_port_range is kernel.panic =
xen.independent_wallclock = # oracle-rdbms-server-11gR2-preinstall setting for fs.file-max is
fs.file-max = # oracle-rdbms-server-11gR2-preinstall setting for kernel.sem is '250 32000 100 128'
kernel.sem = # oracle-rdbms-server-11gR2-preinstall setting for kernel.shmmni is
kernel.shmmni = # oracle-rdbms-server-11gR2-preinstall setting for kernel.shmall is on x86_64
# oracle-rdbms-server-11gR2-preinstall setting for kernel.shmall is on i386 # oracle-rdbms-server-11gR2-preinstall setting for kernel.shmmax is on x86_64
# oracle-rdbms-server-11gR2-preinstall setting for kernel.shmmax is on i386
kernel.shmmax = # oracle-rdbms-server-11gR2-preinstall setting for kernel.panic_on_oops is per Orabug
kernel.panic_on_oops = # oracle-rdbms-server-11gR2-preinstall setting for net.core.rmem_default is
net.core.rmem_default = # oracle-rdbms-server-11gR2-preinstall setting for net.core.rmem_max is
net.core.rmem_max = # oracle-rdbms-server-11gR2-preinstall setting for net.core.wmem_default is
net.core.wmem_default = # oracle-rdbms-server-11gR2-preinstall setting for net.core.wmem_max is
net.core.wmem_max = # oracle-rdbms-server-11gR2-preinstall setting for fs.aio-max-nr is
fs.aio-max-nr = # oracle-rdbms-server-11gR2-preinstall setting for net.ipv4.ip_local_port_range is
net.ipv4.ip_local_port_range = vm.nr_hugepages = net.ipv4.conf.all.accept_redirects =
net.ipv6.conf.all.accept_redirects =
net.ipv4.conf.all.send_redirects =

/etc/security/limits.conf

# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#<domain> <type> <item> <value>
#Where:
#<domain> can be:
# - a user name
# - a group name, with @group syntax
# - the wildcard *, for default entry
# - the wildcard %, can be also used with %group syntax,
# for maxlogin limit
#<type> can have the two values:
# - "soft" for enforcing the soft limits
# - "hard" for enforcing hard limits
#<item> can be one of the following:
# - core - limits the core file size (KB)
# - data - max data size (KB)
# - fsize - maximum filesize (KB)
# - memlock - max locked-in-memory address space (KB)
# - nofile - max number of open file descriptors
# - rss - max resident set size (KB)
# - stack - max stack size (KB)
# - cpu - max CPU time (MIN)
# - nproc - max number of processes
# - as - address space limit (KB)
# - maxsyslogins - max number of logins on the system
# - priority - the priority to run user process with
# - locks - max number of file locks the user can hold
# - sigpending - max number of pending signals
# - msgqueue - max memory used by POSIX message queues (bytes)
# - nice - max nice priority allowed to raise to values: [-, ]
# - rtprio - max realtime priority
#<domain> <type> <item> <value> #* soft core
#* hard rss
#@student hard nproc
#@faculty soft nproc
#@faculty hard nproc
#ftp hard nproc
# End of file # oracle-rdbms-server-11gR2-preinstall setting for nofile soft limit is
oracle soft nofile # oracle-rdbms-server-11gR2-preinstall setting for nofile hard limit is
oracle hard nofile # oracle-rdbms-server-11gR2-preinstall setting for nproc soft limit is
# refer orabug15971421 for more info.
oracle soft nproc # oracle-rdbms-server-11gR2-preinstall setting for nproc hard limit is
oracle hard nproc # oracle-rdbms-server-11gR2-preinstall setting for stack soft limit is 10240KB
oracle soft stack # oracle-rdbms-server-11gR2-preinstall setting for stack hard limit is 32768KB
oracle hard stack # oracle-rdbms-server-11gR2-preinstall setting for memlock hard limit is maximum of {128GB (x86_64) / 3GB (x86) or % of RAM}
oracle hard memlock # oracle-rdbms-server-11gR2-preinstall setting for memlock soft limit is maximum of {128GB (x86_64) / 3GB (x86) or % of RAM}
oracle soft memlock

~/.bashrc

# User specific aliases and functions
umask
ORACLE_HOME=/u01/app/oracle/product/11.2./dbhome_1; export ORACLE_HOME
OH=/u01/app/oracle/product/11.2./dbhome_1; export OH
ORACLE_UNQNAME=TESTDB; export ORACLE_UNQNAME
ORACLE_HOSTNAME=TESTDB.compute-gbsinsooft908.oraclecloud.internal; export ORACLE_HOSTNAME
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/u01/app/oracle/product/11.2./dbhome_1/bin:/u01/app/oracle/product/11.2./dbhome_1/OPatch; export PATH
LD_LIBRARY_PATH=/u01/app/oracle/product/11.2./dbhome_1/lib; export LD_LIBRARY_PATH
EMKEY_LOCATION=/u02/app/oracle/oradata/admin/TESTDB/dbs; export EMKEY_LOCATION
ORACLE_SID=TESTDB; export ORACLE_SID
TFA_HOME=/var/opt/oracle/tfa; export TFA_HOME
 
上一篇:[Android]Message,MessageQueue,Looper,Handler详解+实例


下一篇:项目中用到的SQL-总结