本文介绍CentOS6.9下Oracle 11gr2的静默安装。
环境要求
- 内存:1G,推荐2G。
- Swap空间:内存的1至1.5倍。
- 磁盘空间:
/tmp
至少1G,软件空间4.7G,数据空间1.7G。
本文CentOS6.9采用最小化(Minimal)的方式安装,2个物理CPU,每个2线程,2G内存,60G硬盘,2G的Swap,30G的/
目录,28G的/home
目录
软件包安装
配置Yum源,可以参考Linux进阶09:CentOS的Yum库设置。
安装软件包。1
2
3$ sudo yum install binutils compat-libcap1 compat-libstdc++-33 \
gcc gcc-c++ glibc glibc glibc-devel glibc-devel ksh libgcc \
libstdc++ libstdc++-devel libaio libaio-devel make sysstat unzip -y
新建用户和组
新建组oinstall
和dba
,以及oracle
用户。1
2
3
4$ sudo groupadd oinstall
$ sudo groupadd dba
$ sudo useradd -g oinstall -G dba oracle
$ sudo passwd oracle
修改内核参数
/etc/sysctl.conf
最后一行添加如下内容。1
2
3
4
5
6
7kernel.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 = 1048576
执行sudo sysctl -p
使内核参数生效。
调整会话限制
/etc/pam.d/login
最后一行添加如下内容。1
session required pam_limits.so
限制设置
/etc/security/limits.conf
最后一行添加如下内容。1
2
3
4oracle soft nproc 8192
oracle hard nproc 16384
oracle soft nofile 32768
oracle hard nofile 65536
添加IP地址到host
在/etc/hosts
中明确添加域名与本机IP地址的映射。1
2
3
4# hostname
CentOS6
# vi /etc/hosts
192.168.80.6 CentOS6
新建文件
1 | $ sudo vi /etc/oraInst.loc |
安装准备
切换到oracle
用户,本步骤后所有操作均为oracle
用户。
新建oracle文件夹,作为软件安装目录。1
2$ su - oracle
$ mkdir oracle
修改环境变量,并生效。1
2
3
4
5
6$ vi ~/.bash_profile
export PATH=$PATH:/home/oracle/oracle/product/11gr2/dbhome_1/bin
export ORACLE_HOME=/home/oracle/oracle/product/11gr2/dbhome_1
export ORACLE_SID=higoge
export ORACLE_UNQNAME=$ORACLE_SID
$ source ~/.bash_profile
安装
下载linux.x64_11gR2_database_1of2.zip以及linux.x64_11gR2_database_2of2.zip,并进行解压和安装(将下载地址复制到迅雷后即可下载,无需登录,下载后改名即可)。本文解压到/home/oracle/backup
目录下。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17$ cd ~/backup
$ unzip linux.x64_11gR2_database_1of2.zip
$ unzip linux.x64_11gR2_database_2of2.zip
$ cd database
$ ./runInstaller -silent -debug -force -ignorePrereq \
DECLINE_SECURITY_UPDATES=true \
oracle.install.option=INSTALL_DB_SWONLY \
UNIX_GROUP_NAME=oinstall \
INVENTORY_LOCATION=/home/oracle/oracle/oraInventory \
ORACLE_HOME=/home/oracle/oracle/product/11gr2/dbhome_1 \
ORACLE_BASE=/home/oracle/oracle \
oracle.install.db.InstallEdition=EE \
oracle.install.db.EEOptionsSelection=true \
oracle.install.db.optionalComponents=oracle.rdbms.partitioning:11.2.0.3.0,oracle.oraolap:11.2.0.3.0,oracle.rdbms.dm:11.2.0.3.0,oracle.rdbms.lbac:11.2.0.3.0,oracle.rdbms.rat:11.2.0.3.0 \
oracle.install.db.DBA_GROUP=dba \
oracle.install.db.OPER_GROUP=dba \
oracle.install.db.isRACOneInstall=false
执行到[OUISetupDriver.JobExecutorThread] [ 2018-05-08 01:32:36.271 CST ] [UnixSystem.getCSSConfigType:2387] configType=null
会出现假死状态,请继续等待,建议新起一个窗口使用top
命令监控下。
出现以下信息表示成功。1
2
3
4
5
6
7
8
9
10
11
12The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root scripts to run
/home/oracle/oracle/product/11gr2/dbhome_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
用户执行如下脚本,或直接使用sudo
执行。1
$ sudo /home/oracle/oracle/product/11gr2/dbhome_1/root.sh
启动监听
1 | $ netca /silent /responsefile /home/oracle/backup/database/response/netca.rsp |
报错,Listener start failed.
以及The exit code is 1
。
此时会生成listener.ora
,对此文件进行编辑,修改为本机IP地址。1
2$ vi /home/oracle/oracle/product/11gr2/dbhome_1/network/admin/listener.ora
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.80.6)(PORT = 1521))
再次运行,成功。1
$ netca /silent /responsefile /home/oracle/backup/database/response/netca.rsp
会有Oracle Net Services configuration successful. The exit code is 0
字样。
启动服务,并查看状态。1
2$ lsnrctl start
$ lsnrctl status
启动端口是1521
。
配置数据库
1 | $ cp ~/backup/database/response/dbca.rsp ~ |
静默安装数据库。1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24$ dbca -silent -responseFile ~/dbca.rsp
Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/home/oracle/oracle/cfgtoollogs/dbca/higoge/higoge.log" for further details.
创建用户
1 | $ sqlplus /nolog |
说明:创建用户jeremy
,密码learnit
,默认表空间USERS
,临时表空间TEMP
,概要文件DEFAULT
。角色权限为connect
和resource
。系统权限为create any procedure
,create any view
,debug connect session
,unlimited tablespace
。
远程登录
使用PL/SQL,登录数据库为(description=(address=(protocol=tcp)(host=192.168.80.6)(port=1521))(connect_data=(sid=higoge)))
,连接为Normal
。
使用Navicat Premium,登录SID为higoge
,其他信息输入即可。
自启动服务
每次服务器重启后,都需要手动执行lsnrctl start
以及使用sqlplus
连接数据库后,执行startup
,可以编写自启动脚本,加入到系统service
中。/etc/oratab
中,higoge:/home/oracle/oracle/product/11gr2/dbhome_1:N
改为higoge:/home/oracle/oracle/product/11gr2/dbhome_1:Y
。/home/oracle/oracle/product/11gr2/dbhome_1/bin/
下的dbstart
和dbshut
中,ORACLE_HOME_LISTNER=$1
改为$ORACLE_HOME
。1
2#ORACLE_HOME_LISTNER=$1
ORACLE_HOME_LISTNER=$ORACLE_HOME
root
用户新建/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
40
41
42
43
44
45
46
47
48
#
# chkconfig: 345 10 90
# description: Oracle auto start-stop script. Edit by higoge.
# /etc/init.d/oracledb
#
export ORACLE_HOME=/home/oracle/oracle/product/11gr2/dbhome_1/
export ORACLE_SID=higoge
export ORACLE_UNQNAME=$ORACLE_SID
export PATH=$PATH:$ORACLE_HOME/bin
ORA_OWNR=oracle
# if the executables do not exist -- display error
if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi
# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display
case "$1" in
start)
# Oracle listener and instance startup
echo -n "Starting Oracle: "
su $ORA_OWNR -c "$ORACLE_HOME/bin/dbstart"
su $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl start"
touch /var/lock/oracle
su $ORA_OWNR -c $ORACLE_HOME/bin/emctl start dbconsole
echo "OK"
;;
stop)
# Oracle listener and instance shutdown
echo -n "Shutdown Oracle: "
su $ORA_OWNR -c "$ORACLE_HOME/bin/lsnrctl stop"
su $ORA_OWNR -c $ORACLE_HOME/bin/dbshut
rm -f /var/lock/oracle
su $ORA_OWNR -c $ORACLE_HOME/bin/emctl stop dbconsole
echo "OK"
;;
reload|restart)
$0 stop
$0 start
;;
****)
echo "Usage: service oracledb start|stop|restart|reload"
exit 1
esac
exit 0
配置权限1
2$ sudo chmod 755 /etc/init.d/oracledb
$ sudo chkconfig oracledb on
重启服务器验证即可。
如果本文对你有所帮助,请小额赞助。
~~ EOF ~~