數據庫和監聽器開機自啟動
編輯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 ~]$ dbstart ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener Usage: /u01/app/oracle/product/11.2.0/db_1/bin/dbstart ORACLE_HOME Processing 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=$1 ORACLE_HOME_LISTNER=$ORACLE_HOME
同上修改dbshut文件。
dbstart驗證:
[oracle@ocptest bin]$ dbstart Processing Database instance "orcl": log file /u01/app/oracle/product/11.2.0/db_1/startup.log [oracle@ocptest bin]$ ps -ef|grep smon oracle 4125 1 0 23:46 ? 00:00:00 ora_smon_orcl oracle 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 LISTENER Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production Start Date 21-APR-2019 23:46:20 Uptime 0 days 0 hr. 0 min. 51 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora Listener Log File /u01/app/oracle/diag/tnslsnr/ocptest/listener/alert/log.xml Listening 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]$ dbshut Processing Database instance "orcl": log file /u01/app/oracle/product/11.2.0/db_1/shutdown.log [oracle@ocptest bin]$ ps -ef|grep smon oracle 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 listener TNS-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/local su 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/bash source /u01/app/oracle/product/11.2.0/db_1 lsnrctl start; sqlplus / as sysdba <<EOF startup EOF
vi oracle.stop
[oracle@ocptest ~]$ vi oracle.stop #!/bin/bash source /u01/app/oracle/product/11.2.0/db_1 sqlplus / as sysdba <<EOF startup EOF lsnrctl 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 2 esac
chkconfig oracle on
然后重啟服務器測試下,我這里測試都沒問題。
驗證端口:
[oracle@ocptest ~]$ netstat -an|grep :1521 tcp 0 0 192.168.181.2:62747 192.168.181.2:1521 ESTABLISHED tcp 0 0 :::1521 :::* LISTEN tcp 0 0 ::ffff:192.168.181.2:1521 ::ffff:192.168.181.2:62747 ESTABLISHED