ORACLE 11G R2静默安装,配置

ORACLE 11G R2静默安装,配置

准备工作

1.依赖性准备

1
# yum install make gcc binutils gcc-c++ compat-libstdc++ elfutils-libelf-devel elfutils-libelf-devel-static ksh libaio libaio-devel numactl-devel sysstat unixODBC unixODBC-devel pcre-devel glibc.i686

2.用户和组准备

1
2
3
4
5

# groupadd oinstall
# groupadd dba
# useradd -g oinstall -G dba -d /home/oracle oracle
# passwd oracle //设置oracle密码

3.目录准备及权限调整

1
2
3
4
5
6
7
8
9
# mkdir -p /export/servers/oracle/11.2.0  //数据库系统安装目录
# mkdir /export/data/oradata //数据库数据安装目录
# mkdir /export/data/oradata_back //数据备份目录
# mkdir /home/oracle/inventory //清单目录
# chown -R oracle:oinstall /export/servers/oracle
# chown -R oracle:oinstall /home/oracle/inventory
# chown -R oracle:oinstall /export/data
# chomod -R 775 /export/servers/oracle
# chomod -R 775 /export/data

以上工作可通过招待 pre-install.sh 脚本完成.

4.内核参数调整

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# cat /etc/sysctl.conf
fs.aio-max-nr = 1048576
fs.file-max = 6553600
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586

# /sbin/sysctl -p //让参数生效

5.用户的限制文件修改

1
2
3
4
5
6
# cat /etc/security/limits.conf`
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240

修改/etc/pam.d/login文件,增加如下

1
2
session  required   /lib64/security/pam_limits.so  //64为系统,千万别写成/lib/security/pam_limits.so,否则导致无法登录
session required pam_limits.so
1
2
3
4
5
6
7
8
9
# cat /etc/profile
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi

6.oracle安装包准备

下载并解压安装包到 /home/oracle/database

开始安装

1.打开另外一个终端,用oracle用户登录

2.复制并修改应答文件
复制一份应答文件模板,以便改错后回滚

1
$ cp -R /home/oracle/database/response/db_install.rsp  /home/oracle/database/response/my_db_install.rsp

修改应答文件

1
2
3
4
5
6
7
8
9
10
11
12
$ cat /home/oracle/database/response/my_db_install.rsp
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=oracle11g.jd.com
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/home/oracle/inventory/
ORACLE_HOME=/export/servers/oracle/11.2.0
ORACLE_BASE=/export/servers/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=false
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
DECLINE_SECURITY_UPDATES=true

3.根据应答文件,开始安装

1
2
3
$ sudo su - oracle
$ cd /home/oracle/database/
$ ./runInstaller -silent -responseFile /home/oracle/database/response/my_db_install.rsp

4.按提示切换到root用户的终端,依次执行脚本

1
2
# /home/oracle/inventory/orainstRoot.sh
# /opt/oracle/11.2.0/root.sh

5.切换到oracle用户的终端

6.修改oracle用户环境变量

1
2
3
4
5
6
7
8
9
10
$ cat  ~/.bash_profile

# User specific environment and startup programs
export ORACLE_SID=orcl
export ORACLE_BASE=/app/server/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
PATH=$PATH:$ORACLE_HOME/bin

$ source ~/.bash_profile

安装后工作

建库

1.复制并修改建库应答文件

复制应答文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ cp -R /home/oracle/database/response/dbca.rsp  /home/oracle/database/response/my_dbca.rsp
$ cat /home/oracle/database/response/my_dbca.rsp

OPERATION_TYPE = "createDatabase"
GDBNAME = "orcl11g"
SID = "orcl"
SYSPASSWORD = "OraPwd11"
SYSTEMPASSWORD = "OraPwd11"
DATAFILEDESTINATION = /app/data/oradata
RECOVERYAREADESTINATION = /app/data/oradata_back
SYSDBAUSERNAME = "system"
SYSDBAPASSWORD = "OraPwd11"
#以上2项可选
INSTANCENAME = "orcl11g"
CHARACTERSET = "ZHS16GBK" #按需求设置,建议使用UTF-8
NATIONALCHARACTERSET= "" #可选 "UTF8" or "AL16UTF16" 建议UTF-8
TOTALMEMORY = "5120" #Oracle使用的最大内存,单位M建库

2.使用dbca静默建库

1
$ dbca -silent -responseFile /home/oracle/database/response/my_dbca.rsp

配置监听

1.使用netca静默方式创建监听

1
$ netca /silent /responsefile /vagrant/zhs16gbk/netca.rsp

执行完成会在 $ORACLE_HOME/network/admin目录下生成sqlnet.oralistener.ora两个文件。

2.注册sid

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ cat $ORACLE_HOME/network/admin/listener.ora
LISTENER =
(
DESCRIPTION_LIST =
(
DESCRIPTION =
(
ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)
)
(
ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)
)
)
)

之前添加以下内容:

1
2
3
4
5
6
7
8
9
10
11
SID_LIST_LISTENER =
(
SID_LIST =
(
SID_DESC =
(SID_NAME = orcl)
(
ORACLE_HOME = /app/server/oracle/product/11.2.0/db_1)
(PROGRAM = extproc)
)
)

3.执行$ lsnrctl reload重启监听

4.编辑 /etc/orataborcl11g:/export/servers/oracle/11.2.0:NN,改为Y,这样就可以通过dbstart启动此实例,也可以通过dbshut关闭此实例了。

测试

1.查看监听状态

1
$ lsnrctl status

类似以下返回,说明监听状态正常

1
2
3
4
5
6
Service "ORCL" has 1 instance(s).
Instance "orcl11g", status UNKNOWN, has 1 handler(s) for this service...
Service "db1" has 1 instance(s).
Instance "orcl11g", status READY, has 1 handler(s) for this service...
Service "orcl11gXDB" has 1 instance(s).
Instance "orcl11g", status READY, has 1 handler(s) for this service...

2.sqlplus连接测试

1
2
$ export $ORACLE_SID=orcl11g
$ sqlplus /as sysdba

正常登陆说明实例正常启动。

自启动脚本

加入 /etc/init.d/oracledb 文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

#!/bin/sh -e

# chkconfig: 3 56 10
# description: Oracle 11g custom start/stop script

DAEMON=oracle
ORACLE_HOME=/app/server/oracle/product/11.2.0/db_1
ORACLE_OWNER=oracle

restart() {
stop
start
}

case $1 in
'start')
su - ${ORACLE_OWNER} -c "${ORACLE_HOME}/bin/lsnrctl start"
su - ${ORACLE_OWNER} -c "${ORACLE_HOME}/bin/dbstart ${ORACLE_HOME}"
#su - ${ORACLE_OWNER} -c "${ORACLE_HOME}/bin/emctl start dbconsole"
#su - ${ORACLE_OWNER} -c "${ORACLE_HOME}/bin/isqlplusctl start"
;;
'stop')
#su - ${ORACLE_OWNER} -c "${ORACLE_HOME}/bin/isqlplusctl stop"
#su - ${ORACLE_OWNER} -c "${ORACLE_HOME}/bin/emctl stop dbconsole"
su - ${ORACLE_OWNER} -c "${ORACLE_HOME}/bin/dbshut ${ORACLE_HOME}"
su - ${ORACLE_OWNER} -c "${ORACLE_HOME}/bin/lsnrctl stop"
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop}"
exit
;;
esac

exit $?

加入自动启动:
$ sudo chkconfig --add oracledb

文档约定

#开头的命令  说明需要使用root用户执行
$开头的命令  说明需要用oracle用户执行