共計 5575 個字符,預計需要花費 14 分鐘才能閱讀完成。
這篇文章主要講解了“怎么實現 Oracle 集群自啟動”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著丸趣 TV 小編的思路慢慢深入,一起來研究和學習“怎么實現 Oracle 集群自啟動”吧!
我們先看如下部分:
Oracle 10G:
cat /etc/inittab
h2:35:respawn:/etc/init.d/init.evmd run /dev/null 2 1 /dev/null
h3:35:respawn:/etc/init.d/init.cssd fatal /dev/null 2 1 /dev/null
h4:35:respawn:/etc/init.d/init.crsd run /dev/null 2 1 /dev/null
Oracle 11G:
cat /etc/inittab
h2:35:respawn:/etc/init.d/init.ohasd run /dev/null 2 1 /dev/null
在 Oracle10g 版本中,系統啟動時由 init 進程根據 /etc/inittab 配置文件來派生出集群的高可用守護進程,在 Oracle 11g 中,init 僅派生出 init.ohasd,然后由 init.ohasd 啟動 ohasd.bin 實現集群的自啟動。
另外,由于 RedHat Linux 6.x 棄用了 inittab 文件,目前配置 init.ohasd 進程的文件由 /etc/inittab 變為 /etc/init/oracle-ohasd.conf。
[root@rac1 init]# cat /etc/rc.d/init.d/oracle-ohasd.conf
# Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
#
# Oracle OHASD startup
start on runlevel [35]
stop on runlevel [!35]
respawn
exec /etc/init.d/init.ohasd run /dev/null 2 1 /dev/null
[root@rac1 ]#
在 Red Hat 7.* 以上版本中,init.ohasd 腳本配置又一次發生變化,init.ohasd 以 service 形式配置在 /etc/systemd/system 下。
Red Hat Linux 7.*
#cat /etc/systemd/system/oracle-ohasd.service
# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
# Oracle OHASD startup
[Unit]
Description=Oracle High Availability Services
After=syslog.target network-online.target remote-fs.target
[Service]
ExecStart=/etc/init.d/init.ohasd run /dev/null 2 1 /dev/null
ExecStop=/etc/init.d/init.ohasd stop /dev/null 2 1 /dev/null
TimeoutStopSec=60min
Type=simple
Restart=always
# Do not kill any processes except init.ohasd after ExecStop, unless the
# stop command times out.
KillMode=process
SendSIGKILL=yes
[Install]
WantedBy=multi-user.target graphical.target
大部分資料在介紹集群自啟動時,均是按照以上方式來介紹的,但這種描述方式并不準確,實際上 Oracle 集群自啟動是由 init.ohasd 和 ohasd 兩個腳本相互配合來完成集群的自啟動,這兩個腳本均位于 /etc/rc.d/init.d 目錄下。
如下:
Red Hat Linux 7.*
#cat /etc/systemd/system/oracle-ohasd.service
# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
# Oracle OHASD startup
[root@rac1 init.d]# pwd
/etc/rc.d/init.d
[root@rac1 init.d]# ls -ltr *ohasd*
-rwxr-xr-x. 1 root root 6835 Aug 29 09:57 ohasd
-rwxr-xr-x. 1 root root 9076 Aug 29 10:40 init.ohasd
[root@rac1 init.d]#
init.ohasd
通過對 init.ohasd 腳本的分析,該腳本主要有兩個作用,第一個作用為創建名為 npohasd 的命名管道文件,并在 init.ohasd 運行過程中始終 read 該命名管道文件,以此作為標記,該作用為 init.ohasd 最重要的作用,因為當命名管道文件未被 read 標記時集群無法啟動),第二個作用,init.ohasd 作為 ohasd.bin 的高可用守護進程而存在,當 ohasd.bin 進程異常終止時,由 init.ohasd 再次啟動 ohasd.bin,來實現 ohasd.bin 進程的高可用,而 ohasd.bin 進程是集群的高可用進程,當集群資源意外終止時由 ohasd.bin 所屬的 agent 進程負責重新啟動相應資源,同時 ohasd.bin 也是負責整個集群啟動的進程。(集群并非由 init.ohasd 腳本啟動,init.ohasd 做集群啟動時的前期準備工作)
ohasd
ohasd 腳本是在系統啟動時,真正啟動集群的腳本,集群安裝完畢后,ohasd 腳本被軟連接到 /etc/rc.d 下面的相關啟動級別目錄中 (/etc/rc.d/rc[0-6].d/*),系統啟動時,執行不同級別的腳本程序,啟動級別為 3 時 /etc/rc.d/rc3.d/S96ohasd 被執行,此時 ohasd 腳本調用 $ORACLE_HOME/bin/crsctl 腳本來啟動集群。
ohasd 腳本在執行時會判斷 /var/tmp/.oracle 目錄是否存在,如果 /var/tmp/.oracle 不存在,將會創建 /var/tmp/.oracle 目錄,并將.oracle 目錄權限置為 01777,/var/tmp/.oracle 目錄中存放著集群啟動及正常運行時所產生的套接字以及命名管道文件。
如下為 /etc/rc.d/rc[0-6]/* 中 ohasd 腳本的軟連接情況:
[root@rac1 ~]# ls -ltr /etc/rc.d/rc[0-6].d/*ohasd*
lrwxrwxrwx. 1 root root 17 Feb 21 2018 /etc/rc.d/rc5.d/S96ohasd - /etc/init.d/ohasd
lrwxrwxrwx. 1 root root 17 Feb 21 2018 /etc/rc.d/rc6.d/K15ohasd - /etc/init.d/ohasd
lrwxrwxrwx. 1 root root 17 Feb 21 2018 /etc/rc.d/rc4.d/K15ohasd - /etc/init.d/ohasd
lrwxrwxrwx. 1 root root 17 Feb 21 2018 /etc/rc.d/rc2.d/K15ohasd - /etc/init.d/ohasd
lrwxrwxrwx. 1 root root 17 Feb 21 2018 /etc/rc.d/rc1.d/K15ohasd - /etc/init.d/ohasd
lrwxrwxrwx. 1 root root 17 Feb 21 2018 /etc/rc.d/rc0.d/K15ohasd - /etc/init.d/ohasd
lrwxrwxrwx. 1 root root 17 Mar 26 01:40 /etc/rc.d/rc3.d/S96ohasd - /etc/init.d/ohasd
[root@rac1 ~]#
init.ohasd/ohasd 何時被調用
1)開機 BIOS 自檢, 且根據 BIOS 中配置的啟動設備讀取 MBR 并加載 Bootloader 程序。
2)加載并執行引導程序 GRUB。
3)GRUB 根據配置加載內核映像。
4)內核啟動 (根文件系統掛載, 內核執行 /sbin/init)。
5)Init 依據 /etc/inittab 中配置運行級別進行系統的初始化 (初始化腳本: /etc/rc.d/rc.sysinit)。/etc/init/* 內配置文件生效是在該步進行
6)根據不同的運行級別, 啟動相應服務 (服務程序腳本位于 /etc/rc.d/rc[0-6].d 中 )。
Linux 系統在啟動時大概可以分為 6 步,init.ohasd 和 ohash 是在第 5 步和第 6 步來被調用啟動集群。
當系統啟動到第 5 步的時候,init 進程會掃描 /etc/init/ 下面的所有配置文件,關于 Oracle 集群,init 進程會根據 /etc/init/oracle-ohasd.conf 中的內容派生 init.ohasd 進程 (由 init.ohasd 發出 read 命名管道文件 npohasd 的命令)。
系統啟動到第 6 步時,根據系統的不同啟動級別,/etc/rc.d/rc[0-6].d/* 中的腳本程序被執行,此時 ohasd 調用 $ORACLE_HOME/bin/crsctl 腳本,由 crsctl 負責集群的啟動。
| 禁用集群自啟動 ohasdstr
在 /etc/oracle/scls_scr/[SID]/root/ 目錄中有一個配置文件 ohasdstr,當 ohasd 腳本被調用時會讀取 ohasdstr 文件,根據 ohasdstr 文件中記錄的 enable/disable 來判斷集群是否隨系統啟動而自啟動。
如何避免集群隨系統啟動而自啟動?正確的做法是通過 crsctl disable/enable crs 的方式來控制集群是否隨系統啟動而自啟動,crsctl disable/enable crs 實際上就是修改配置文件 ohasdstr。
如下:
#cat /etc/oracle/scls_scr/qdata1/root/ohasdstr
enable
[root@qdata1 /root]
#crsctl disable crs
CRS-4621: Oracle High Availability Services autostart is disabled.
[root@qdata1 /root]
#cat /etc/oracle/scls_scr/qdata1/root/ohasdstr
disable
[root@qdata1 /root]
#crsctl enable crs
CRS-4622: Oracle High Availability Services autostart is enabled.
[root@qdata1 /root]
#cat /etc/oracle/scls_scr/qdata1/root/ohasdstr
enable
[root@qdata1 /root]
#
當然,我們也可以直接手工修改 ohasdstr 文件。
另外,也有些資料在介紹禁止集群自啟動時,采用注釋掉 oracle-ohasd.conf 中派生 init.ohasd 部分,此時系統啟動時 init 進程無法派生 init.ohash 腳本,但這種方式為取巧方式,直接將 init.ohasd 的運行進行禁止,這種方式并不建議,如果 init.ohasd 腳本未啟動,npohasd 命名管道文件不會被創建,并且不會被 read,當需要使用’crsctl start crs’手工啟動集群時,由于命名管道為被 read,此時集群無法啟動,這種情況下我們可以手工執行 exec /etc/init.d/init.ohasd run,然后再使用’crsctl start crs’命令來啟動集群。
順便說一下,在 /etc/oracle/scls_scr/[SID]/root/ 目錄中還有一個 ohasdrun 配置文件,該文件是控制 init.ohasd 是否實現 ohasd.bin 高可用的配置文件,上面我們說過 init.ohasd 腳本其中一個作用是實現 ohasd.bin 進程的高可用,init.ohasd 就是通過 ohasdrun 這個配置文件來判斷當 ohasd.bin 進程異常終止時,是否啟動 ohasd.bin 進程。
init.ohasd/ohasd 丟失后如何處理
init.ohasd/ohasd 兩個腳本是在集群安裝配置時執行 root.sh 過程中,由 $GRID_HOME/crs/init/ 目錄中復制而來,當腳本 init.ohasd/ohasd 丟失后可以從 $GRID_HOME/crs/init 中重新復制,并將 /etc/init.d 中的 init.ohasd/ohasd 權限置為 755 即可。
感謝各位的閱讀,以上就是“怎么實現 Oracle 集群自啟動”的內容了,經過本文的學習后,相信大家對怎么實現 Oracle 集群自啟動這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是丸趣 TV,丸趣 TV 小編將為大家推送更多相關知識點的文章,歡迎關注!