[size=small]oracle数据库实现自动启动:
1)使用自带的dbstart命令实现自启动
1.环境变量检查:
[oracle@oratest ~]$ echo $ORACLE_HOME
/u01/oracle
如果没有设置或设置与实际不符,到oracle家目录下的.bash_profile中添加
export ORACLE_BASE=/u01
export ORACLE_HOME=/u01/oracle
export SID=tinadb
export PATH=$ORACLE_HOME/bin:$PATH:$HOME/bin
export LD_LIBRARY_PATH=$ORALCE_HOME/lib:/usr/lib
2.命令dbstart所在位置
[oracle@oratest bin]$ cd /u01/oracle/bin
[oracle@oratest bin]$ ll |grep dbs
-rwxr-x---. 1 oracle oinstall 6030 Jan 1 2000 dbshut
-rwxr-x---. 1 oracle oinstall 13797 Jan 1 2000 dbstart
[oracle@oratest bin]$ dbstart
ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
Usage: /u01/oracle/bin/dbstart ORACLE_HOME
Processing Database instance "tinadb": log file /u01/oracle/startup.log
3.修改文件/etc/oratab内容
su - oracle
vi /etc/oratab
修改这些句话的最后的字母N为Y。
tinadb:/u01/oracle:N
改成 tinadb:/u01/oracle:Y
4.修改文件/etc/rc.d/rc.local内容
su - root
vi /etc/rc.d/rc.local
添加:
su - oracle -c '$ORACLE_HOME/bin/lsnrctl start tinadb'
sleep 2s
su - oracle -c '$ORACLE_HOME/bin/dbstart'
---这里不带tinadb就会默认启动LISTENER的监听名,dbstart有启动监听的命令,这行可以不要
5.修改dbstart
vi /u01/oracle/bin/dbstart
ORACLE_HOME_LISTNER=$1
改成下面的:
ORACLE_HOME_LISTNER=$ORACLE_HOME
$ORACLE_HOME_LISTNER/bin/lsnrctl start>> $LOG 2>&1 &
改成自己的监听名:
$ORACLE_HOME_LISTNER/bin/lsnrctl start tinadb>> $LOG 2>&1 & --相应修改
6.手动执行试试能否成功
[oracle@oratest bin]$ dbstart ---已经改成既可以启动监听,也可以启动库
Processing Database instance "tinadb": log file /u01/oracle/startup.log
[oracle@oratest bin]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-DEC-2015 10:55:29
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias tinadb
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 15-DEC-2015 10:54:52
Uptime 0 days 0 hr. 0 min. 36 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/oracle/network/admin/listener.ora
Listener Log File /u01/diag/tnslsnr/oratest/tinadb/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.12.253)(PORT=1521)))
Services Summary...
Service "tinadb" has 2 instance(s).
Instance "tinadb", status UNKNOWN, has 1 handler(s) for this service...
Instance "tinadb", status READY, has 1 handler(s) for this service...
Service "tinadbXDB" has 1 instance(s).
Instance "tinadb", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@oratest bin]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Tue Dec 15 10:55:37 2015
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.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
---------------- ------------
tinadb OPEN
ok!!
7.关闭主机,看db和监听是否都正常自动启动
# reboot
启动后:
# su - oracle
[oracle@oratest ~]$ lsnrctl status --监听正常
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-DEC-2015 11:19:04
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias tinadb
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 15-DEC-2015 11:18:07
Uptime 0 days 0 hr. 0 min. 57 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/oracle/network/admin/listener.ora
Listener Log File /u01/diag/tnslsnr/oratest/tinadb/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.12.253)(PORT=1521)))
Services Summary...
Service "tinadb" has 2 instance(s).
Instance "tinadb", status UNKNOWN, has 1 handler(s) for this service...
Instance "tinadb", status READY, has 1 handler(s) for this service...
Service "tinadbXDB" has 1 instance(s).
Instance "tinadb", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@oratest ~]$ sqlplus / as sysdba --数据库正常
SQL*Plus: Release 11.2.0.3.0 Production on Tue Dec 15 11:19:22 2015
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.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
---------------- ------------
tinadb OPEN
db和监听运行正常的状态下,手动执行dbstart也不会报错。会重启一次
2)使用自制脚本实现自启动
注意dbshut也要去修改ORACLE_HOME_LISTNER=$1--->$ORACLE_HOME
1.脚本要存放在/etc/init.d/目录下,命名可以自定义
# cd /etc/init.d
# vi oracle11g ---还是用oracle命名比较方便!
#!/bin/bash
#chkconfig: - 20 80
#description: Oracle auto start-stop script.
export ORACLE_HOME=/u01/oracle
export ORACLE_BASE=/u01/
export ORACLE_SID=tinadb
export PATH=$PATH:$ORACLE_HOME/bin
ORA_OWNER=oracle
LOGFILE=/var/log/oracle11g.log
echo "#################################" >>${LOGFILE}
date +"%Y-%m-%d %H:%M:%S: Run Oracle" >>${LOGFILE}
if [ ! -f ${ORACLE_HOME}/bin/dbstart ] || [ ! -f ${ORACLE_HOME}/bin/dbshut ]; then
echo "Error: Missing the script file ${ORACLE_HOME}/bin/dbstart or ${ORACLE_HOME}/bin/dbshut!" >>${LOGFILE}
exit
fi
start(){
# Start the Oracle databases:
su - $ORA_OWNER -c '$ORACLE_HOME/bin/dbstart'
su - $ORA_OWNER -c '$ORACLE_HOME/bin/lsnrctl start tinadb'
}
stop(){
# Stop the Oracle databases:
su - $ORA_OWNER -c '$ORACLE_HOME/bin/lsnrctl stop'
su - $ORA_OWNER -c '$ORACLE_HOME/bin/dbshut'
}
case "$1" in
'start')
start >> ${LOGFILE}
;;
'stop')
stop >> ${LOGFILE}
;;
'restart')
stop >> ${LOGFILE}
start >> ${LOGFILE}
esac
date +"%Y-%m-%d %H:%M:%S: Finished." >>${LOGFILE}
echo "#################################" >>${LOGFILE}
2.赋予执行权限
chmod a+x /etc/init.d/oracle11g
3.手动执行命令
/etc/init.d/oracle start #启动oracle(包括数据库实例、监听器、EM)
/etc/init.d/oracle stop #关闭oracle
/etc/init.d/oracle restart #重启oracle
---生成的日志内容如下:
#################################
2015-12-15 14:20:26: Run Oracle
Processing Database instance "tinadb": log file /u01/oracle/startup.log
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-DEC-2015 14:20:35
Copyright (c) 1991, 2011, Oracle. All rights reserved.
TNS-01106: Listener using listener name tinadb has already been started
2015-12-15 14:20:35: Finished.
#################################
#################################
2015-12-15 14:21:39: Run Oracle
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-DEC-2015 14:21:39
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
The command completed successfully
Processing Database instance "tinadb": log file /u01/oracle/shutdown.log
2015-12-15 14:21:47: Finished.
#################################
4.将 oracle 添加到 chkconfig中:
报错:
# chkconfig --add oracle
service oracle does not support chkconfig
补充说明1:
vi /etc/init.d/oracle11g
# chkconfig: 2345 10 90
# description: ....
其中2345是默认启动级别,级别有0-6共7个级别。
等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动
10是启动优先级,90是停止优先级,优先级范围是0-100,数字越大,优先级越低。
补充说明2:可使用如下命令查看和设置oracle服务的开机启动级别:
chkconfig | grep oracle11g #查看oracle服务的开机启动级别
chkconfig --level 24 oracle11g off #修改oracle服务的开机启动级别
chkconfig --level 35 oracle11g on
5.至此可使用如下命令对oracle的启动或关闭进行管理
service oracle11g start #启动
service oracle11g stop #关闭
service oracle11g restart #重启
6.建立连接:
ln -s /etc/init.d/oracle11g /etc/rc0.d/K80oracle11g #关机执行
ln -s /etc/init.d/oracle11g /etc/rc6.d/K80oracle11g #重启执行
去目录下发现已经有这两个软链接存在:
lrwxrwxrwx. 1 root root 19 Dec 15 14:30 K80oracle11g -> ../init.d/oracle11g
lrwxrwxrwx. 1 root root 19 Dec 15 14:30 K80oracle11g -> ../init.d/oracle11g
以后就可以使用service来启动oracle数据库了~~~
[/size]
1)使用自带的dbstart命令实现自启动
1.环境变量检查:
[oracle@oratest ~]$ echo $ORACLE_HOME
/u01/oracle
如果没有设置或设置与实际不符,到oracle家目录下的.bash_profile中添加
export ORACLE_BASE=/u01
export ORACLE_HOME=/u01/oracle
export SID=tinadb
export PATH=$ORACLE_HOME/bin:$PATH:$HOME/bin
export LD_LIBRARY_PATH=$ORALCE_HOME/lib:/usr/lib
2.命令dbstart所在位置
[oracle@oratest bin]$ cd /u01/oracle/bin
[oracle@oratest bin]$ ll |grep dbs
-rwxr-x---. 1 oracle oinstall 6030 Jan 1 2000 dbshut
-rwxr-x---. 1 oracle oinstall 13797 Jan 1 2000 dbstart
[oracle@oratest bin]$ dbstart
ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener
Usage: /u01/oracle/bin/dbstart ORACLE_HOME
Processing Database instance "tinadb": log file /u01/oracle/startup.log
3.修改文件/etc/oratab内容
su - oracle
vi /etc/oratab
修改这些句话的最后的字母N为Y。
tinadb:/u01/oracle:N
改成 tinadb:/u01/oracle:Y
4.修改文件/etc/rc.d/rc.local内容
su - root
vi /etc/rc.d/rc.local
添加:
su - oracle -c '$ORACLE_HOME/bin/lsnrctl start tinadb'
sleep 2s
su - oracle -c '$ORACLE_HOME/bin/dbstart'
---这里不带tinadb就会默认启动LISTENER的监听名,dbstart有启动监听的命令,这行可以不要
5.修改dbstart
vi /u01/oracle/bin/dbstart
ORACLE_HOME_LISTNER=$1
改成下面的:
ORACLE_HOME_LISTNER=$ORACLE_HOME
$ORACLE_HOME_LISTNER/bin/lsnrctl start>> $LOG 2>&1 &
改成自己的监听名:
$ORACLE_HOME_LISTNER/bin/lsnrctl start tinadb>> $LOG 2>&1 & --相应修改
6.手动执行试试能否成功
[oracle@oratest bin]$ dbstart ---已经改成既可以启动监听,也可以启动库
Processing Database instance "tinadb": log file /u01/oracle/startup.log
[oracle@oratest bin]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-DEC-2015 10:55:29
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias tinadb
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 15-DEC-2015 10:54:52
Uptime 0 days 0 hr. 0 min. 36 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/oracle/network/admin/listener.ora
Listener Log File /u01/diag/tnslsnr/oratest/tinadb/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.12.253)(PORT=1521)))
Services Summary...
Service "tinadb" has 2 instance(s).
Instance "tinadb", status UNKNOWN, has 1 handler(s) for this service...
Instance "tinadb", status READY, has 1 handler(s) for this service...
Service "tinadbXDB" has 1 instance(s).
Instance "tinadb", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@oratest bin]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.3.0 Production on Tue Dec 15 10:55:37 2015
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.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
---------------- ------------
tinadb OPEN
ok!!
7.关闭主机,看db和监听是否都正常自动启动
# reboot
启动后:
# su - oracle
[oracle@oratest ~]$ lsnrctl status --监听正常
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-DEC-2015 11:19:04
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
STATUS of the LISTENER
------------------------
Alias tinadb
Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production
Start Date 15-DEC-2015 11:18:07
Uptime 0 days 0 hr. 0 min. 57 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/oracle/network/admin/listener.ora
Listener Log File /u01/diag/tnslsnr/oratest/tinadb/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.12.253)(PORT=1521)))
Services Summary...
Service "tinadb" has 2 instance(s).
Instance "tinadb", status UNKNOWN, has 1 handler(s) for this service...
Instance "tinadb", status READY, has 1 handler(s) for this service...
Service "tinadbXDB" has 1 instance(s).
Instance "tinadb", status READY, has 1 handler(s) for this service...
The command completed successfully
[oracle@oratest ~]$ sqlplus / as sysdba --数据库正常
SQL*Plus: Release 11.2.0.3.0 Production on Tue Dec 15 11:19:22 2015
Copyright (c) 1982, 2011, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.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
---------------- ------------
tinadb OPEN
db和监听运行正常的状态下,手动执行dbstart也不会报错。会重启一次
2)使用自制脚本实现自启动
注意dbshut也要去修改ORACLE_HOME_LISTNER=$1--->$ORACLE_HOME
1.脚本要存放在/etc/init.d/目录下,命名可以自定义
# cd /etc/init.d
# vi oracle11g ---还是用oracle命名比较方便!
#!/bin/bash
#chkconfig: - 20 80
#description: Oracle auto start-stop script.
export ORACLE_HOME=/u01/oracle
export ORACLE_BASE=/u01/
export ORACLE_SID=tinadb
export PATH=$PATH:$ORACLE_HOME/bin
ORA_OWNER=oracle
LOGFILE=/var/log/oracle11g.log
echo "#################################" >>${LOGFILE}
date +"%Y-%m-%d %H:%M:%S: Run Oracle" >>${LOGFILE}
if [ ! -f ${ORACLE_HOME}/bin/dbstart ] || [ ! -f ${ORACLE_HOME}/bin/dbshut ]; then
echo "Error: Missing the script file ${ORACLE_HOME}/bin/dbstart or ${ORACLE_HOME}/bin/dbshut!" >>${LOGFILE}
exit
fi
start(){
# Start the Oracle databases:
su - $ORA_OWNER -c '$ORACLE_HOME/bin/dbstart'
su - $ORA_OWNER -c '$ORACLE_HOME/bin/lsnrctl start tinadb'
}
stop(){
# Stop the Oracle databases:
su - $ORA_OWNER -c '$ORACLE_HOME/bin/lsnrctl stop'
su - $ORA_OWNER -c '$ORACLE_HOME/bin/dbshut'
}
case "$1" in
'start')
start >> ${LOGFILE}
;;
'stop')
stop >> ${LOGFILE}
;;
'restart')
stop >> ${LOGFILE}
start >> ${LOGFILE}
esac
date +"%Y-%m-%d %H:%M:%S: Finished." >>${LOGFILE}
echo "#################################" >>${LOGFILE}
2.赋予执行权限
chmod a+x /etc/init.d/oracle11g
3.手动执行命令
/etc/init.d/oracle start #启动oracle(包括数据库实例、监听器、EM)
/etc/init.d/oracle stop #关闭oracle
/etc/init.d/oracle restart #重启oracle
---生成的日志内容如下:
#################################
2015-12-15 14:20:26: Run Oracle
Processing Database instance "tinadb": log file /u01/oracle/startup.log
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-DEC-2015 14:20:35
Copyright (c) 1991, 2011, Oracle. All rights reserved.
TNS-01106: Listener using listener name tinadb has already been started
2015-12-15 14:20:35: Finished.
#################################
#################################
2015-12-15 14:21:39: Run Oracle
LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 15-DEC-2015 14:21:39
Copyright (c) 1991, 2011, Oracle. All rights reserved.
Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))
The command completed successfully
Processing Database instance "tinadb": log file /u01/oracle/shutdown.log
2015-12-15 14:21:47: Finished.
#################################
4.将 oracle 添加到 chkconfig中:
报错:
# chkconfig --add oracle
service oracle does not support chkconfig
补充说明1:
vi /etc/init.d/oracle11g
# chkconfig: 2345 10 90
# description: ....
其中2345是默认启动级别,级别有0-6共7个级别。
等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动
10是启动优先级,90是停止优先级,优先级范围是0-100,数字越大,优先级越低。
补充说明2:可使用如下命令查看和设置oracle服务的开机启动级别:
chkconfig | grep oracle11g #查看oracle服务的开机启动级别
chkconfig --level 24 oracle11g off #修改oracle服务的开机启动级别
chkconfig --level 35 oracle11g on
5.至此可使用如下命令对oracle的启动或关闭进行管理
service oracle11g start #启动
service oracle11g stop #关闭
service oracle11g restart #重启
6.建立连接:
ln -s /etc/init.d/oracle11g /etc/rc0.d/K80oracle11g #关机执行
ln -s /etc/init.d/oracle11g /etc/rc6.d/K80oracle11g #重启执行
去目录下发现已经有这两个软链接存在:
lrwxrwxrwx. 1 root root 19 Dec 15 14:30 K80oracle11g -> ../init.d/oracle11g
lrwxrwxrwx. 1 root root 19 Dec 15 14:30 K80oracle11g -> ../init.d/oracle11g
以后就可以使用service来启动oracle数据库了~~~
[/size]