您好,登錄后才能下訂單哦!
這篇文章主要講解了“怎么實(shí)現(xiàn)Oracle集群自啟動(dòng)”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“怎么實(shí)現(xiàn)Oracle集群自啟動(dòng)”吧!
我們先看如下部分:
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版本中,系統(tǒng)啟動(dòng)時(shí)由init進(jìn)程根據(jù)/etc/inittab配置文件來(lái)派生出集群的高可用守護(hù)進(jìn)程,在Oracle 11g中,init僅派生出init.ohasd,然后由init.ohasd啟動(dòng)ohasd.bin實(shí)現(xiàn)集群的自啟動(dòng)。
另外,由于RedHat Linux 6.x棄用了inittab文件,目前配置init.ohasd進(jìn)程的文件由/etc/inittab變?yōu)?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腳本配置又一次發(fā)生變化,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
大部分資料在介紹集群自啟動(dòng)時(shí),均是按照以上方式來(lái)介紹的,但這種描述方式并不準(zhǔn)確,實(shí)際上Oracle集群自啟動(dòng)是由init.ohasd和ohasd兩個(gè)腳本相互配合來(lái)完成集群的自啟動(dòng),這兩個(gè)腳本均位于/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
通過(guò)對(duì)init.ohasd腳本的分析,該腳本主要有兩個(gè)作用,第一個(gè)作用為創(chuàng)建名為npohasd的命名管道文件,并在init.ohasd運(yùn)行過(guò)程中始終read該命名管道文件,以此作為標(biāo)記,該作用為init.ohasd最重要的作用,因?yàn)楫?dāng)命名管道文件未被read標(biāo)記時(shí)集群無(wú)法啟動(dòng)),第二個(gè)作用,init.ohasd作為ohasd.bin的高可用守護(hù)進(jìn)程而存在,當(dāng)ohasd.bin進(jìn)程異常終止時(shí),由init.ohasd再次啟動(dòng)ohasd.bin,來(lái)實(shí)現(xiàn)ohasd.bin進(jìn)程的高可用,而ohasd.bin進(jìn)程是集群的高可用進(jìn)程,當(dāng)集群資源意外終止時(shí)由ohasd.bin所屬的agent進(jìn)程負(fù)責(zé)重新啟動(dòng)相應(yīng)資源,同時(shí)ohasd.bin也是負(fù)責(zé)整個(gè)集群?jiǎn)?dòng)的進(jìn)程。(集群并非由init.ohasd腳本啟動(dòng),init.ohasd做集群?jiǎn)?dòng)時(shí)的前期準(zhǔn)備工作)
ohasd
ohasd腳本是在系統(tǒng)啟動(dòng)時(shí),真正啟動(dòng)集群的腳本,集群安裝完畢后,ohasd腳本被軟連接到/etc/rc.d下面的相關(guān)啟動(dòng)級(jí)別目錄中(/etc/rc.d/rc[0-6].d/*),系統(tǒng)啟動(dòng)時(shí),執(zhí)行不同級(jí)別的腳本程序,啟動(dòng)級(jí)別為3時(shí)/etc/rc.d/rc3.d/S96ohasd被執(zhí)行,此時(shí)ohasd腳本調(diào)用$ORACLE_HOME/bin/crsctl腳本來(lái)啟動(dòng)集群。
ohasd腳本在執(zhí)行時(shí)會(huì)判斷/var/tmp/.oracle目錄是否存在,如果/var/tmp/.oracle不存在,將會(huì)創(chuàng)建/var/tmp/.oracle目錄,并將.oracle目錄權(quán)限置為01777 ,/var/tmp/.oracle目錄中存放著集群?jiǎn)?dòng)及正常運(yùn)行時(shí)所產(chǎn)生的套接字以及命名管道文件。
如下為/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何時(shí)被調(diào)用
1)開機(jī)BIOS自檢,且根據(jù)BIOS中配置的啟動(dòng)設(shè)備讀取MBR并加載Bootloader程序。
2)加載并執(zhí)行引導(dǎo)程序GRUB。
3)GRUB根據(jù)配置加載內(nèi)核映像。
4)內(nèi)核啟動(dòng)(根文件系統(tǒng)掛載,內(nèi)核執(zhí)行/sbin/init)。
5)Init依據(jù)/etc/inittab中配置運(yùn)行級(jí)別進(jìn)行系統(tǒng)的初始化(初始化腳本: /etc/rc.d/rc.sysinit)。/etc/init/*內(nèi)配置文件生效是在該步進(jìn)行
6)根據(jù)不同的運(yùn)行級(jí)別,啟動(dòng)相應(yīng)服務(wù) (服務(wù)程序腳本位于/etc/rc.d/rc[0-6].d中)。
Linux系統(tǒng)在啟動(dòng)時(shí)大概可以分為6步,init.ohasd和ohash是在第5步和第6步來(lái)被調(diào)用啟動(dòng)集群。
當(dāng)系統(tǒng)啟動(dòng)到第5步的時(shí)候,init進(jìn)程會(huì)掃描/etc/init/下面的所有配置文件,關(guān)于Oracle集群,init進(jìn)程會(huì)根據(jù)/etc/init/oracle-ohasd.conf中的內(nèi)容派生init.ohasd進(jìn)程(由init.ohasd發(fā)出read命名管道文件npohasd的命令)。
系統(tǒng)啟動(dòng)到第6步時(shí),根據(jù)系統(tǒng)的不同啟動(dòng)級(jí)別,/etc/rc.d/rc[0-6].d/*中的腳本程序被執(zhí)行,此時(shí)ohasd調(diào)用$ORACLE_HOME/bin/crsctl腳本,由crsctl負(fù)責(zé)集群的啟動(dòng)。
在/etc/oracle/scls_scr/[SID]/root/目錄中有一個(gè)配置文件ohasdstr,當(dāng)ohasd腳本被調(diào)用時(shí)會(huì)讀取ohasdstr文件,根據(jù)ohasdstr文件中記錄的enable/disable來(lái)判斷集群是否隨系統(tǒng)啟動(dòng)而自啟動(dòng)。
如何避免集群隨系統(tǒng)啟動(dòng)而自啟動(dòng)?正確的做法是通過(guò)"crsctl disable/enable crs"的方式來(lái)控制集群是否隨系統(tǒng)啟動(dòng)而自啟動(dòng),"crsctl disable/enable crs"實(shí)際上就是修改配置文件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] #
當(dāng)然,我們也可以直接手工修改ohasdstr文件。
另外,也有些資料在介紹禁止集群自啟動(dòng)時(shí),采用注釋掉oracle-ohasd.conf中派生init.ohasd部分,此時(shí)系統(tǒng)啟動(dòng)時(shí)init進(jìn)程無(wú)法派生init.ohash腳本,但這種方式為取巧方式,直接將init.ohasd的運(yùn)行進(jìn)行禁止,這種方式并不建議,如果init.ohasd腳本未啟動(dòng),npohasd命名管道文件不會(huì)被創(chuàng)建,并且不會(huì)被read,當(dāng)需要使用’crsctl start crs’手工啟動(dòng)集群時(shí),由于命名管道為被read,此時(shí)集群無(wú)法啟動(dòng),這種情況下我們可以手工執(zhí)行"exec /etc/init.d/init.ohasd run",然后再使用’crsctl start crs’命令來(lái)啟動(dòng)集群。
順便說(shuō)一下,在/etc/oracle/scls_scr/[SID]/root/目錄中還有一個(gè)ohasdrun配置文件,該文件是控制init.ohasd是否實(shí)現(xiàn)ohasd.bin高可用的配置文件,上面我們說(shuō)過(guò)init.ohasd腳本其中一個(gè)作用是實(shí)現(xiàn)ohasd.bin進(jìn)程的高可用,init.ohasd就是通過(guò)ohasdrun這個(gè)配置文件來(lái)判斷當(dāng)ohasd.bin進(jìn)程異常終止時(shí),是否啟動(dòng)ohasd.bin進(jìn)程。
init.ohasd/ohasd丟失后如何處理
init.ohasd/ohasd兩個(gè)腳本是在集群安裝配置時(shí)執(zhí)行root.sh過(guò)程中,由$GRID_HOME/crs/init/目錄中復(fù)制而來(lái),當(dāng)腳本init.ohasd/ohasd丟失后可以從$GRID_HOME/crs/init中重新復(fù)制,并將/etc/init.d中的init.ohasd/ohasd權(quán)限置為755即可。
感謝各位的閱讀,以上就是“怎么實(shí)現(xiàn)Oracle集群自啟動(dòng)”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)怎么實(shí)現(xiàn)Oracle集群自啟動(dòng)這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。