数据库和监听器开机自启动 编辑oratab文件: 修改:orcl:/u01/app/oracle/product/11.2.0/db_1:N orcl:/u01/app/oracle/product/11.2.0/db_1:Y
[oracle@ocptest bin]$ vi /etc/oratab# # This file is used by ORACLE utilities. It is created by root.sh# and updated by the Database Configuration Assistant when creating# a database. # A colon, ‘:‘, is used as the field terminator. A new line terminates# the entry. Lines beginning with a pound sign, ‘#‘, are comments.## Entries are of the form:# $ORACLE_SID:$ORACLE_HOME:<N|Y>:## The first and second fields are the system identifier and home# directory of the database respectively. The third filed indicates# to the dbstart utility that the database should , "Y", or should not,# "N", be brought up at system boot time.## Multiple entries with the same $ORACLE_SID are not allowed.##orcl:/u01/app/oracle/product/11.2.0/db_1:Y
执行dbstart和dbshut(数据库启动而监听器没有自启动)
[oracle@ocptest ~]$ dbstartORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net ListenerUsage: /u01/app/oracle/product/11.2.0/db_1/bin/dbstart ORACLE_HOMEProcessing Database instance "orcl": log file /u01/app/oracle/product/11.2.0/db_1/startup.log
修改dbstart和dbshut文件:
[oracle@ocptest ~]$ cd $ORACLE_HOME/bin[oracle@ocptest bin]$ vi dbstart
找到这行修改为:
ORACLE_HOME_LISTNER=$1ORACLE_HOME_LISTNER=$ORACLE_HOME
同上修改dbshut文件。 dbstart验证:
[oracle@ocptest bin]$ dbstartProcessing Database instance "orcl": log file /u01/app/oracle/product/11.2.0/db_1/startup.log[oracle@ocptest bin]$ ps -ef|grep smonoracle 4125 1 0 23:46 ? 00:00:00 ora_smon_orcloracle 4241 3254 0 23:46 pts/0 00:00:00 grep smon[oracle@ocptest bin]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-APR-2019 23:47:11 Copyright (c) 1991, 2009, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ocptest)(PORT=1521)))STATUS of the LISTENER------------------------Alias LISTENERVersion TNSLSNR for Linux: Version 11.2.0.1.0 - ProductionStart Date 21-APR-2019 23:46:20Uptime 0 days 0 hr. 0 min. 51 secTrace Level offSecurity ON: Local OS AuthenticationSNMP OFFListener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.oraListener Log File /u01/app/oracle/diag/tnslsnr/ocptest/listener/alert/log.xmlListening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=ocptest)(PORT=1521)))Services Summary...Service "orcl" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service...Service "orclXDB" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service...
dbshut验证:
[oracle@ocptest bin]$ dbshutProcessing Database instance "orcl": log file /u01/app/oracle/product/11.2.0/db_1/shutdown.log[oracle@ocptest bin]$ ps -ef|grep smonoracle 4369 3254 0 23:48 pts/0 00:00:00 grep smon[oracle@ocptest bin]$ lsnrctl status LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 21-APR-2019 23:48:32 Copyright (c) 1991, 2009, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ocptest)(PORT=1521)))TNS-12541: TNS:no listenerTNS-12560: TNS:protocol adapter error TNS-00511: No listener Linux Error: 111: Connection refused
添加开机自启动: 编辑/etc/rc.d/rc.local添加su oracle -lc /u01/app/oracle/product/11.2.0/db_1/bin/dbstart 到最后一行
[oracle@ocptest ~]$ vi /etc/rc.d/rc.local#!/bin/sh## This script will be executed *after* all the other init scripts.# You can put your own initialization stuff in here if you don‘t# want to do the full Sys V style init stuff. touch /var/lock/subsys/localsu oracle -lc /u01/app/oracle/product/11.2.0/db_1/bin/dbstart
如果上面没有编辑dbstart和dbshut文件添加侦听器参数: 则还需添加 su oracle -lc "/u01/oracle/bin/lsnrctl start"到/etc/rc.d/rc.local文件中; 第二种方法: 在oracle家目录创建两个文件: oracle.start oracle.stop 编辑: vi oracle.start
[oracle@ocptest ~]$ vi oracle.start#!/bin/bashsource /u01/app/oracle/product/11.2.0/db_1lsnrctl start;sqlplus / as sysdba <<EOFstartupEOF
vi oracle.stop
[oracle@ocptest ~]$ vi oracle.stop#!/bin/bashsource /u01/app/oracle/product/11.2.0/db_1sqlplus / as sysdba <<EOFstartupEOFlsnrctl stop;
权限: chmod +x /etc/init.d/oracle chmod a+x oracle.start oracle.stop 单独执行这两个脚本进行验证; 通过copy一个network模板
cp /etc/init.d/network /etc/init.d/oracle[root@ocptest ~]# vi /etc/init.d/oracle#! /bin/bash## oracle Bring up/down oracle## chkconfig: 2345 90 1# description: Activates/Deactivates all oracle configured to # start at boot time.## Source function library.. /etc/init.d/functions # See how we were called.case "$1" in start) su - oracle -c "/home/oracle/oracle.start" ;; stop) su - oracle -c "/home/oracle/oracle.stop" ;; *) echo $"Usage: $0 {start|stop}" exit 2esac
chkconfig oracle on 然后重启服务器测试下,我这里测试都没问题。 验证端口:
[oracle@ocptest ~]$ netstat -an|grep :1521tcp 0 0 192.168.181.2:62747 192.168.181.2:1521 ESTABLISHEDtcp 0 0 :::1521 :::* LISTENtcp 0 0 ::ffff:192.168.181.2:1521 ::ffff:192.168.181.2:62747 ESTABLISHED