oracle 11.2和12c RAC的ohasd守護進程對比

來源:互聯網
上載者:User

前面我們已經講解過11.2 RAC的啟動過程,可以注意到,RAC的根守護進程是/etc/init.d/init.ohasd,那麼不同版本的Linux中/etc/init.d/init.ohasd是如何啟動的呢?
注意:12.1的非Flex Cluster啟動過程跟11.2 RAC一致。但是從12.2beta版 RAC的測試結果來看,從12.2開始OUI安裝很可能只有Flex Cluster了,沒有了11.2的那種普通RAC了。
.
Linux4和Linux5中,在完成核內引導(核心被載入記憶體並運行,初始化所有的裝置驅動程式和資料結構等)之後,就通過啟動一個使用者級程式/sbin/init的方式來啟動其他使用者級的進程或服務。
所以,init始終是第一個進程,其PID始終為1(ps -aux | less),它是系統所有進程的父進程.
[root@lunarnew1 grid]# ps -ef|grep init|grep -v grep
root         1     0  0 Jan14 ?        00:00:00 init [5]                                                                
root      2987     1  0 Jan14 ?        00:00:00 /bin/sh /etc/init.d/init.ohasd run
[root@lunarnew1 grid]#
[root@lunarnew1 grid]# which init
/sbin/init
[root@lunarnew1 grid]#
接下來/sbin/init會讀取/etc/inittab的內容,/etc/inittab中包含了很多啟動其他使用者進程和服務的指令:
其格式如下:
 identifier :  run_level  :  action  :  process
因此,開機自動啟動/etc/init.d/init.ohasd的指令碼也配置在/etc/inittab中。
我的環境是Linux5.10,看一下ohasd的啟動指令碼的具體資訊:
[root@lunarnew1 grid]# cat /etc/issue
Oracle Linux Server release 5.10
Kernel \r on an \m
 
[root@lunarnew1 grid]#
[root@lunarnew1 grid]# ll /etc/inittab.orig
ls: /etc/inittab.orig: No such file or directory
[root@lunarnew1 grid]# ll /etc/inittab*
-rw-r--r-- 1 root root 1671 Mar 21  2015 /etc/inittab.no_crs
-rw-r--r-- 1 root root 1740 Mar 21  2015 /etc/inittab.crs
-rw-r--r-- 1 root root 1740 Mar 21  2015 /etc/inittab
[root@lunarnew1 grid]#
我們看一下這三個檔案哪裡不同:
[root@lunarnew1 grid]# diff /etc/inittab.crs /etc/inittab
[root@lunarnew1 grid]# diff /etc/inittab.no_crs /etc/inittab
58a59,60
>
> h1:35:respawn:/etc/init.d/init.ohasd run >/dev/null 2>&1 </dev/null
[root@lunarnew1 grid]#
可以看出,/etc/inittab.no_crs的內容就是在沒安裝GI以前的/etc/inittab備份檔案,而/etc/inittab.crs的內容就是安裝GI以後/etc/inittab 備份檔案
也就是說,在Linux 5中,安裝完RAC(10.2或者11.2)後,該指令碼就會增加上面一行啟動ohasd守護進程的指令碼,如果要在系統啟動時啟動crs,那麼就需要讓/etc/inittab中包含下面的一行啟動命令:
h1:35:respawn:/etc/init.d/init.ohasd run >/dev/null 2>&1 如果要讓系統啟動時不啟動crs,那麼就不能包含上述行。當然這個方法是Oracle不支援的,Oracle建議使用crsctl disable has來禁止開機啟動HAS。
(注意,如果rac環境,使用crsctl disable crs命令)
/etc/inittab的全部內容如下(注意,只有Linux 5 和Linux5以下的版本是這樣的):
[root@lunarnew1 grid]# cat  /etc/inittab
#
# inittab       This file describes how the INIT process should set up
#               the system in a certain run-level.
#
# Author:       Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>
#               Modified for RHS Linux by Marc Ewing and Donnie Barnes
#
 
# Default runlevel. The runlevels used by RHS are:
#   0 – halt (Do NOT set initdefault to this)
#   1 – Single user mode
#   2 – Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 – Full multiuser mode
#   4 – unused
#   5 – X11
#   6 – reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
 
# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit
 
l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6
 
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
 
# When our UPS tells us power has failed, assume we have a few minutes
# of power left.  Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly. 
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"
 
# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
 
 
# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6
 
# Run xdm in runlevel 5
x:3:respawn:/etc/X11/prefdm -nodaemon
 
 
h1:35:respawn:/etc/init.d/init.ohasd run >/dev/null 2>&1 </dev/null
[root@lunarnew1 grid]#
到了Linux 6中,init只負責讀取設定檔,處理各種服務和應用程式的依賴關係,根據事件來啟動這些功能和服務,並動態進行管理。
而事件在Linux 6中是由“Upstart 事件管理器”來管理的,並且這些事件使用initctl工具來控制,initctl的作用類似於Linux5中的chkconfig工具。
我這裡的一套在Linux 6.6環境安裝的11.2.0.4 單機ASM環境(Standalone),可以看到其中並沒有Linux 5中那樣/etc/inittab.orig檔案:
[root@lunarlib rootwork]# ll /etc/inittab.orig
ls: cannot access /etc/inittab.orig: No such file or directory
[root@lunarlib rootwork]#
也就是說,到了Linux 6版本,Oracle不再將/etc/init.d/init.ohasd的啟動不再寫入/etc/inittab檔案(不由/sbin/init進程根據inittab來啟動ohasd的指令碼):
[root@lunarlib rootwork]# ll /etc/inittab*
-rw-r-----. 1 root root 884 Apr  6  2015 /etc/inittab
[root@lunarlib rootwork]#
[root@lunarlib rootwork]# tail /etc/inittab
# Default runlevel. The runlevels used are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault:
[root@lunarlib rootwork]#
那麼在Linux 6中Oracle RAC的這個守護進程如何啟動的呢?
因為從Linux 6開始系統採用upstart事件引導機制(好像是Linux 6特有的),根據/etc/init/目錄下的事件管理設定檔來決定系統在啟動時運行哪些服務:
[root@lunarlib init.d]# cat /etc/init/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@lunarlib init.d]#
因此,Oracle也採用了這種方式。安裝GI時,oracle會為/etc/init.d/init.ohasd引導進程配置一個相應的設定檔,也就是/etc/init/oracle-ohasd.conf設定檔。
也就是說,在Linux 6中使用/etc/init目錄下的oracle-ohasd.conf設定檔的啟動方式,取代了Linux5中的配置使用/etc/inittab啟動的方式。
這個就是Oracle順應Linux的發展,根據系統啟動時的引導和啟動服務的機制在Linux中不同版本的變化而變化。
[root@lunarlib rootwork]# ll /etc/init
total 72
-rw-r--r--. 1 root root  412 Jul 22  2014 control-alt-delete.conf
-rw-r--r--. 1 root root  130 Mar 12  2014 init-system-dbus.conf
-rw-r--r--. 1 root root  463 Jul 22  2014 kexec-disable.conf
-rw-r--r--  1 root root  220 Oct 11 01:30 oracle-ohasd.conf
-rw-r--r--. 1 root root  560 Jul 22  2014 plymouth-shutdown.conf
-rw-r--r--. 1 root root  357 Jul 22  2014 prefdm.conf
-rw-r--r--. 1 root root  505 Jul 22  2014 quit-plymouth.conf
-rw-r--r--. 1 root root  417 Jul 22  2014 rc.conf
-rw-r--r--. 1 root root 1046 Jul 22  2014 rcS.conf
-rw-r--r--. 1 root root  430 Jul 22  2014 rcS-emergency.conf
-rw-r--r--. 1 root root  725 Jul 22  2014 rcS-sulogin.conf
-rw-r--r--. 1 root root 2915 Nov 21  2013 readahead-collector.conf
-rw-r--r--. 1 root root 1559 Nov 21  2013 readahead.conf
-rw-r--r--. 1 root root  726 Nov 21  2013 readahead-disable-services.conf
-rw-r--r--. 1 root root 1302 Jul 22  2014 serial.conf
-rw-r--r--. 1 root root  791 Jul 22  2014 splash-manager.conf
-rw-r--r--. 1 root root  473 Jul 22  2014 start-ttys.conf
-rw-r--r--. 1 root root  335 Jul 22  2014 tty.conf
[root@lunarlib rootwork]#
[root@lunarlib rootwork]# ls -l /etc/init/oracle-ohasd.conf
-rw-r--r-- 1 root root 220 Oct 11 01:30 /etc/init/oracle-ohasd.conf
[root@lunarlib rootwork]#
在Linux 6中,可以使用/sbin/initctl工具(類似於Linux5的chkconfig工具)來管理/etc/init.d/init.ohasd的啟動。
(注意,Linux5中不能使用chkconfig管理/etc/init.d/init.ohasd進程)
[root@lunarlib rootwork]# initctl list
rc stop/waiting
tty (/dev/tty3) start/running, process 4353
tty (/dev/tty2) start/running, process 4349
tty (/dev/tty1) start/running, process 4347
tty (/dev/tty6) start/running, process 4365
tty (/dev/tty5) start/running, process 4361
tty (/dev/tty4) start/running, process 4359
plymouth-shutdown stop/waiting
control-alt-delete stop/waiting
rcS-emergency stop/waiting
readahead-collector stop/waiting
kexec-disable stop/waiting
quit-plymouth stop/waiting
rcS stop/waiting
prefdm stop/waiting
init-system-dbus stop/waiting
readahead stop/waiting
splash-manager stop/waiting
start-ttys stop/waiting
readahead-disable-services stop/waiting
rcS-sulogin stop/waiting
serial stop/waiting
oracle-ohasd start/running, process 12661
[root@lunarlib rootwork]#
查看oracle-ohasd服務的資訊:
[root@lunarlib rootwork]# /sbin/initctl list |grep oracle-ohasd
oracle-ohasd start/running, process 2897
[root@lunarlib rootwork]#
[root@lunarlib rootwork]# ps -ef|grep ohasd
root      2897     1  0 06:05 ?        00:00:01 /bin/sh /etc/init.d/init.ohasd run
root      6651  6336  0 07:52 pts/0    00:00:00 grep ohasd
[root@lunarlib rootwork]#
到了Linux 7,由於系統的引導方式又變化了,系統採用systemd機制,使用 socket 和 D-Bus 來並行啟動服務的模式,提供基於守護進程的按需啟動策略,已經沒有運行層級的概念(但是完全相容sysvinit)。
哪些需要啟動的服務的設定檔放在 /lib/systemd/system/ 目錄下,以 *.service命名,類似如下:
在Linux7中,系統啟動載入Oracle RAC使用的ohasd單元需要如下配置(安裝時,執行root.sh就會配置ohasd服務單元,如果沒有配置好,自己手工配置就可以了):
[root@lunar system]# ll /etc/systemd/system/|grep ohasd
-rw-r--r--  1 root root  361 Oct  9 12:29 oracle-ohasd.service
[root@lunar system]#
[root@lunar system]# systemctl list-units -t service|grep ohasd
ohasd.service                      loaded active exited  ohasd.service
oracle-ohasd.service               loaded active running Oracle High Availability Services
[root@lunar system]#
事實上,在Linux 7(當前的版本只有Linux 7.1和7.2)上安裝,Oracle 11.2.0.4(在11.2的版本中,只有11.2.0.4支援Linux 7,其餘11.2支援Linux 7以下的版本)和12c(當前的是12.1和12.2beta版本)RAC時,有bug,該檔案是不能被root.sh建立的,需要自己手工建立。
具體看下服務定義檔的格式:
[root@lunar system]# cat /etc/systemd/system/oracle-ohasd.service
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
#
# Oracle OHASD startup
 
[Unit]
Description=Oracle High Availability Services
After=syslog.target network.target remote-fs.target
 
[Service]
ExecStart=/etc/init.d/init.ohasd run >/dev/null 2>&1 </dev/null
Type=simple
Restart=always
 
[Install]
WantedBy=multi-user.target graphical.target
[root@lunar system]#
systemd的單元定義中,如果指定了“After=”,那麼就表示這個服務依賴於After指定的服務。如果沒有After,就表示這個服務可以跟其他的並行啟動。
這裡定義了oracle-ohasd.service在syslog.target network.target remote-fs.target這三個單元啟動後開始啟動
執行命令為:/etc/init.d/init.ohasd run >/dev/null 2>&1 啟動類型為:simple
最後,我們查看系統當前載入的所有單元:
[root@lunar system]# ll /etc/systemd/system/
total 16
drwxr-xr-x. 2 root root   30 Oct  8 07:17 basic.target.wants
drwxr-xr-x. 2 root root   30 Oct  7 23:08 bluetooth.target.wants
lrwxrwxrwx. 1 root root   41 Oct  7 23:08 dbus-org.bluez.service -> /usr/lib/systemd/system/bluetooth.service
lrwxrwxrwx. 1 root root   44 Oct  7 23:10 dbus-org.freedesktop.ModemManager1.service -> /usr/lib/systemd/system/ModemManager.service
lrwxrwxrwx. 1 root root   46 Oct  7 23:04 dbus-org.freedesktop.NetworkManager.service -> /usr/lib/systemd/system/NetworkManager.service
lrwxrwxrwx. 1 root root   57 Oct  7 23:04 dbus-org.freedesktop.nm-dispatcher.service -> /usr/lib/systemd/system/NetworkManager-dispatcher.service
lrwxrwxrwx  1 root root   41 Oct  8 16:51 default.target -> /usr/lib/systemd/system/multi-user.target
drwxr-xr-x. 2 root root   85 Oct  7 23:02 default.target.wants
lrwxrwxrwx. 1 root root   35 Oct  7 23:08 display-manager.service -> /usr/lib/systemd/system/gdm.service
drwxr-xr-x. 2 root root   31 Oct  7 23:02 getty.target.wants
drwxr-xr-x. 2 root root   90 Oct  9 12:29 graphical.target.wants
drwxr-xr-x. 2 root root 4096 Oct  9 12:29 multi-user.target.wants
lrwxrwxrwx. 1 root root   38 Oct  7 23:04 mysql.service -> /usr/lib/systemd/system/mysqld.service
-rw-r--r--  1 root root  361 Oct  9 12:29 oracle-ohasd.service
drwxr-xr-x. 2 root root   25 Oct  7 23:05 printer.target.wants
drwxr-xr-x. 2 root root 4096 Oct  8 07:32 sockets.target.wants
drwxr-xr-x. 2 root root   35 Oct  7 23:10 spice-vdagentd.target.wants
drwxr-xr-x. 2 root root 4096 Oct  8 22:19 sysinit.target.wants
drwxr-xr-x. 2 root root   83 Oct  7 23:05 system-update.target.wants
[root@lunar system]#
[root@lunar system]# ps -ef|grep ohasd
root      1132     1  0 04:26 ?        00:00:00 /bin/sh /etc/init.d/init.ohasd run >/dev/null 2>&1 </dev/null
grid      4017     1  0 04:27 ?        00:00:59 /u01/app/12.1.0.2/grid/bin/ohasd.bin reboot
root     11362  8874  0 09:50 pts/1    00:00:00 grep --color=auto ohasd
[root@lunar system]#

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.