linux下静默方式安装oracle 11g

安装前准备工作

一、安装相关依赖包

1
yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel elfutils-libelf-devel-static gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers kernel-headers ksh libaio libaio-devel libgcc libgomp libstdc++ libstdc++-devel make sysstat unixODBC unixODBC-devel

二、修改内核参数

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
(root身份,没有的自行添加)
vi /etc/sysctl.conf
kernel.shmall = 2097152 //表示系统一次可以使用的共享内存总量(以页为单位)。缺省值就是2097152,通常不需要修改
kernel.shmmax = 2147483648 //定义了共享内存段的最大尺寸(以字节为单位)。缺省为32M,对于oracle来说,该缺省值太低了,通常将其设置为2G=2147483648/1024/1024/1024
kernel.shmmni = 4096 //用于设置系统范围内共享内存段的最大数量。该参数的默认值是4096 。通常不需要更改
kernel.sem = 250 32000 100 128 //表示设置的信号量
fs.file-max = 65536 //表示文件句柄的最大数量。文件句柄表示在Linux系统中可以打 开的文件数量。其实是由"fs.file-max = 512 * PROCESSES"得到的,我们指定PROCESSES的值为128,即为"fs.file-max =512 *128"
fs.aio-max-nr = 1048576 //同时可以拥有的的异步IO请求数目。
net.ipv4.ip_local_port_range = 1024 65000 //应用程序可使用的Ipv4端口范围。
net.core.rmem_default = 262144 //默认的接收窗口大小
net.core.rmem_max = 4194304 //接收窗口的最大大小
net.core.wmem_default = 262144 //默认的发送窗口大小
net.core.wmem_max = 1048586 //发送窗口的最大大小

实例:
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 536870912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586

使修改生效

1
sysctl -p   //使修改立即生效

sysctl -p报错处理

1
2
3
4
5
6
error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key  
error: "net.bridge.bridge-nf-call-iptables" is an unknown key
error: "net.bridge.bridge-nf-call-arptables" is an unknown key

modprobe bridge
lsmod | grep bridge

为oracle用户设置shell限制

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#vi /etc/security/limits.conf   添加以下内容
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536

#vi /etc/pam.d/login 添加以下内容
session required pam_limits.so

关闭selinux
#vi /etc/selinux/config 修改为disabled
SELINUX=disabled

临时关闭命令
setenforce 0

编辑/etc/profile,添加如下内容

1
2
3
4
5
6
7
8
9
#vi /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

编辑/etc/csh.login,添加如下内容

1
2
3
4
5
#vi /etc/csh.login
if ( $USER == "oracle" ) then
limit maxproc 16384
limit descriptors 65536
endif

注:内核参数并非必须修改,可以根据自己实际情况而定。 以上为安装oracle的前置工作

安装oracle

创建需要的目录

1
2
3
4
5
6
7
groupadd oinstall
groupadd oradba
useradd -g oinstall -G oradba oracle
id oracle //查看账户是否建立完成
mkdir -p /opt/oracle
mkdir /opt/oracle/11g
chown -R oracle:oinstall /opt/oracle

添加oracle环境变量

1
2
3
4
5
6
7
#vi /etc/profile
export ORACLE_BASE=/opt/oracle
export ORACLE_HOME=/opt/oracle/11g
export ORACLE_SID=orcl11g
export PATH=$PATH:$ORACLE_HOME/bin

#source /etc/profile

设置db_install.rsp安装文件

编辑oracle应答文件db_install.rsp,文件存在解压目录的response目录下(最好将文件解压到oracle家目录/home/oracle下)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#vi db_install.rsp
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=localhost
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/opt/oracle/oraInventory
SELECTED\_LANGUAGES=en,zh_CN
ORACLE_HOME=/opt/oracle/11g
ORACLE_BASE=/opt/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=oradba
oracle.install.db.OPER_GROUP=oradba
DECLINE_SECURITY_UPDATES=true

#su oracle
$./runInstaller -silent -responseFile /home/oracle/database/response/db_install.rsp -ignorePrereq

当出现下面提示时,脚本执行正常完成

1
2
3
4
5
6
7
8
9
10
11
12
13
The following configuration scripts need to be executed as the "root" user. 
#!/bin/sh
#Root scripts to run

/opt/oracle/oraInventory/orainstRoot.sh
/opt/oracle/11g/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.

系统初始化

1
2
3
su root
$ORACLE_BASE/oraInventory/orainstRoot.sh
$ORACLE_HOME/root.sh

安装网络监听器

1
2
3
4
5
6
7
8
9
10
su oracle
$ORACLE_HOME/bin/netca /silent /responseFile /home/oracle/database/response/netca.rsp
查看监听器状态
$ORACLE_HOME/bin/lsnrctl status



su oracle
vi $ORACLE_HOME/bin/dbstart
将ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle(或者是ORACLE_HOME_LISTNER=$1)修改成ORACLE_HOME_LISTNER=$ORACLE_HOME

安装数据库实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
编辑response目录下的dbca.rsp文件
#vi dbca.rsp
GDBNAME = "orcl11g" //全局数据库的名字=SID+主机域名
SID = "orcl11g" //对应的实例名字
TEMPLATENAME = "General_Purpose.dbc" //建库用的模板文件
SYSPASSWORD = 9xxxx //SYS用户初始密码
SYSTEMPASSWORD = 9xxxxx //SYSTEM用户初始密码
DATAFILEDESTINATION = /opt/oracle/oradata //数据文件存放目录
RECOVERYAREADESTINATION = /opt/oracle/oradata_back //恢复数据文件存放目录
CHARACTERSET = "ZHS16GBK"
TOTALMEMORY = "2048"

保存完毕后切换到oracle身份
su oracle
$ORACLE_HOME/bin/dbca -silent -responseFile /home/oracle/database/response/dbca.rsp

修改oracle启动配置文件/etc/oratab
su oracle
vi /etc/oratab

orcl11g:/usr/local/oracle/11g:N
修改为
orcl11g:/usr/local/oracle/11g:Y

ORACLE的启动和关闭

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
su oracle

监听器的启动
$ORACLE_HOME/bin/lsnrctl start
监听器的状态查看
$ORACLE_HOME/bin/lsnrctl status

启动oracle实例
sqlplus sys as sysdba
输入密码后进入
SQL>startup //启动数据库命令
或者使用命令启动
$ORACLE_HOME/bin/dbstart

关闭数据库实例
SQL>shutdown immediate
或者使用命令关闭
$ORACLE_HOME/bin/dbstart

关闭监听
$lsnrctl stop

将oracle作为服务

在root登录下

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
vi /etc/init.d/oracle  复制以下文本后保存

#!/bin/sh

# chkconfig: 35 80 10
# description: Oracle auto start-stop script.

#
# Set ORACLE\_HOME to be equivalent to the $ORACLE\_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORACLE_OWNER to the user id of the owner of the
# Oracle database in ORACLE_HOME.
ORACLE_HOME=/opt/oracle/11g
ORACLE_OWNER=oracle
if [ ! -f $ORACLE_HOME/bin/dbstart ]
then
echo "Oracle startup: cannot start"
exit
fi
case "$1" in
'start')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbstart" >>/var/log/oracle
echo "Done"

# Start the Listener:
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl start" >>/var/log/oracle
echo "Done."
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;

'stop')
# Stop the Oracle Listener:
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop" >>/var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle

# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
;;

'restart')
$0 stop
$0 start
;;
esac





chmod +x /etc/init.d/oracle
chkconfig --level 35 oracle on

错误解决

启动oracle时提示找不到pflie文件错误解决
1.启动时指定pfile文件

1
SQL> startup pfile=/oradata/oracle/admin/orcl/pfile/init.ora.3102012232637

2.启动后,重新创建spfile文件

1
2
SQL> create spfile from pfile='/oradata/oracle/admin/orcl/pfile/init.ora.3102012232637';
File created.

3.关闭数据库

1
SQL> shutdown immediate

4.此时启动就不需要指定pfile文件了,默认以spfile文件启动

1
SQL> startup
  1. 修改用户

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    sqlplus /nolog
    SQL> conn /as sysdba
    已连接。
    SQL> alter user system identified by password;

    用户已更改。

    SQL> alter user sys identified by password;

    用户已更改。

    SQL> alter user system identified by manger;

    解锁方法
    alter user system account unlock;
  2. Oracle开启远程连接
    listener.ora文件

    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
    # 修改前
    LISTENER =
    (DESCRIPTION_LIST =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
    )
    )

    ADR_BASE_LISTENER = /opt/oracle

    # 修改后

    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (GLOBAL_DBNAME = orcl11g)
    (ORACLE_HOME = /opt/oracle/11g)
    (SID_NAME = orcl11g)
    )
    )
    LISTENER =
    (DESCRIPTION_LIST =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.90.57)(PORT = 1521))
    )
    )

    ADR_BASE_LISTENER = /opt/oracle


tnsnames.ora文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 修改前
ORCL11G =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.90.57)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl11g)
)
)
# 修改后
ORCL11G =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.16.90.57)(PORT = 1521))
)
(CONNECT_DATA =
(SID = orcl11g)
)
)

重启oracle监听服务

1
2
lsnrctl stop
lsnrctl start