17092601_CentOS7(64)下Oracle11g設定開機自啟動
1. 環境準備
1.1 系統
作業系統:CentOS 7(64位)
1.2 工具/軟體
已安裝完成的Oracle11g(64位);
建立資料庫例項,本文中資料庫例項名:test;$ORACLE_SID:testsid
2. 方法/步驟
2.1 配置/etc/oratab
以root身份登入到linux系統,編輯/etc/oratab檔案,找到
testsid:/data/oracle/product/11.2.0/db_1:N
,改為
testsid:/data/oracle/product/11.2.0/db_1:Y
注意:/data/oracle/product/11.2.0/db_1為安裝的$ORACLE_HOME,根據情況自行修改路徑。
[[email protected] ~]$ su #切換到root
Password: #輸入root密碼
[[email protected] oracle]# vim /etc/oratab
[[email protected] oracle]# cat /etc/oratab
#
tsid:/data/oracle/product/11.2.0/db_1:N
# 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.
#
#
testsid:/data/oracle/product/11.2.0/db_1:Y
[[email protected] oracle]#
2.2 配置/etc/rc.d/rc.local
新增如下行:
su oracle -lc “/data/oracle/product/11.2.0/db_1/bin/lsnrctl start”
su oracle -lc /data/oracle/product/11.2.0/db_1/bin/dbstart
其中第一行因為lsnrctl之後有空格,需要引號,第二行加不加引號都可以。修改完儲存退出即可。
程式碼如下:
[[email protected] /]# vim /etc/rc.d/rc.local
[[email protected] /]# cat /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
su oracle -lc "/data/oracle/product/11.2.0/db_1/bin/lsnrctl start"
su oracle -lc /data/oracle/product/11.2.0/db_1/bin/dbstart
touch /var/lock/subsys/local
# mount -a
[[email protected] /]#
如果是在以前的centos版本中,這樣就可以了。但是centos7 的/etc/rc.local不會開機執行,認真檢視/etc/rc.local檔案的內容就發現問題的原因了
[[email protected] /]# cat /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
翻譯一下:
這個檔案是為了相容性的問題而新增的。
強烈建議建立自己的systemd服務或udev規則來在開機時執行指令碼而不是使用這個檔案。
與以前的版本引導時的並行執行相比較,這個指令碼將不會在其他所有的服務後執行。
請記住,你必須執行“chmod +x /etc/rc.d/rc.local”來確保確保這個指令碼在引導時執行。
檢視一下/etc/rc.d/rc.local的許可權
[root@zm-centos7 /]# ll /etc/rc.d/rc.local
-rw-r--r-- 1 root root 484 Oct 11 17:17 /etc/rc.d/rc.local
發現沒有執行許可權,按照說明的內容執行命令:
[root@zm-centos7 bin]# chmod +x /etc/rc.d/rc.local
[root@zm-centos7 bin]# reboot #重啟機器,確認結果
2.3 重啟機器,確認自啟動結果
以oracle使用者,開啟一個終端:
[[email protected] ~]$ lsnrctl status # 檢視監聽狀態
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 11-OCT-2017 23:05:06
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 11-OCT-2017 23:02:22
Uptime 0 days 0 hr. 2 min. 45 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /data/oracle/product/11.2.0/db_1/network/admin/listener.ora
Listener Log File /data/oracle/diag/tnslsnr/zm-centos7/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
Services Summary...
Service "test" has 1 instance(s).
Instance "testsid", status READY, has 1 handler(s) for this service...
Service "testsidXDB" has 1 instance(s).
Instance "testsid", status READY, has 1 handler(s) for this service...
The command completed successfully
檢視oracle服務狀態
[[email protected] ~]$ ps -ef |grep ora
oracle 3053 1 0 23:02 ? 00:00:00 /data/oracle/product/11.2.0/db_1/bin/tnslsnr LISTENER -inherit
oracle 3283 1 0 23:03 ? 00:00:00 ora_pmon_testsid
oracle 3285 1 0 23:03 ? 00:00:00 ora_vktm_testsid
oracle 3289 1 0 23:03 ? 00:00:00 ora_gen0_testsid
oracle 3291 1 0 23:03 ? 00:00:00 ora_diag_testsid
oracle 3293 1 0 23:03 ? 00:00:00 ora_dbrm_testsid
oracle 3295 1 0 23:03 ? 00:00:00 ora_psp0_testsid
oracle 3297 1 0 23:03 ? 00:00:00 ora_dia0_testsid
oracle 3299 1 0 23:03 ? 00:00:00 ora_mman_testsid
oracle 3301 1 0 23:03 ? 00:00:00 ora_dbw0_testsid
oracle 3303 1 0 23:03 ? 00:00:00 ora_lgwr_testsid
oracle 3305 1 0 23:03 ? 00:00:00 ora_ckpt_testsid
oracle 3307 1 0 23:03 ? 00:00:00 ora_smon_testsid
oracle 3309 1 0 23:03 ? 00:00:00 ora_reco_testsid
oracle 3311 1 0 23:03 ? 00:00:00 ora_mmon_testsid
oracle 3313 1 0 23:03 ? 00:00:00 ora_mmnl_testsid
oracle 3315 1 0 23:03 ? 00:00:00 ora_d000_testsid
oracle 3317 1 0 23:03 ? 00:00:00 ora_s000_testsid
oracle 3364 1 0 23:03 ? 00:00:00 ora_p000_testsid
oracle 3366 1 0 23:03 ? 00:00:00 ora_p001_testsid
oracle 3368 1 0 23:03 ? 00:00:00 ora_qmnc_testsid
oracle 3563 1 0 23:03 ? 00:00:00 ora_cjq0_testsid
oracle 3577 1 0 23:03 ? 00:00:00 ora_q000_testsid
oracle 3579 1 0 23:03 ? 00:00:00 ora_q001_testsid
oracle 3633 1 0 23:03 ? 00:00:00 ora_vkrm_testsid
root 3792 1241 0 23:04 ? 00:00:00 sshd: oracle [priv]
oracle 3801 3792 0 23:04 ? 00:00:00 sshd: [email protected]/0
oracle 3806 3801 0 23:04 pts/0 00:00:00 -bash
oracle 3914 1 0 23:06 ? 00:00:00 ora_j000_testsid
oracle 3916 1 0 23:06 ? 00:00:00 ora_j001_testsid
oracle 3926 3806 0 23:07 pts/0 00:00:00 ps -ef
oracle 3927 3806 0 23:07 pts/0 00:00:00 grep --color=auto ora
[[email protected] ~]$
確認自啟動成功。另外再說一下,雖然此方法實現了自啟動,但在學習的過程中,還看到了其他的方法實現自啟動,本人也將在之後的博文中進行實踐和總結。謝謝!