联系:QQ(5163721)
标题:Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列–6-开机自动启动或者禁用服务
作者:Lunar©版权所有[文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.]
测试目的:研究一下Linux7中,如何设置服务的开机自动启动或者不自动启动
当前的OS版本:
[root@lunar1 ~]# cat /etc/centos-release CentOS Linux release 7.2.1511 (Core) [root@lunar1 ~]# [root@lunar1 ~]# cat /etc/centos-release-upstream Derived from Red Hat Enterprise Linux 7.2 (Source) [root@lunar1 ~]# [root@lunar1 ~]# cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7" [root@lunar1 ~]# [root@lunar1 ~]# cat /etc/system-release-cpe cpe:/o:centos:centos:7 [root@lunar1 ~]#
CRS版本:
[root@lunar1 ~]# crsctl query crs activeversion -f Oracle Clusterware active version on the cluster is [12.1.0.2.0]. The cluster upgrade state is [NORMAL]. The cluster active patch level is [0]. [root@lunar1 ~]#
Linux7使用systemd替换了SysV,Systemd目的是要取代Unix时代以来一直在使用的init系统,兼容SysV和LSB的启动脚本,而且够在进程启动过程并行加载必要的服务。
支持并行化任务
同时采用socket式与D-Bus总线式激活服务;
按需启动守护进程(daemon);
利用 Linux 的 cgroups 监视进程;
支持快照和系统恢复;
维护挂载点和自动挂载点;
各服务间基于依赖关系进行精密控制
.
systemd可以创建不同的状态,状态提供了灵活的机制来设置启动时的配置项。
这些状态是由多个unit文件组成的,状态又叫做启动目标(target),unit文件可以控制服务、设备、套接字和挂载点。
systemd配置文件被称为unit单元,使用man systemd可以查看这些unit(单元)的具体定义。
根据类型不同,unit以不同的扩展名结尾。
.service系统服务;
.target一组系统服务;
.automount自动挂载点;
.device能被内核识别的设备;
.mount挂载点;
.path文件系统的文件或者目录;
.scope外部创建的进程;
.slice一组分层次管理的系统进程;
.snapshot系统服务状态管理;
.socket进程间通讯套接字;
.swap定义swap文件或者设备;
.timer定义定时器。
.
所有可用的unit(单元文件)存放在下面的两个目录下:
/etc/systemd/system/ —–优先级更高(这个目录中的内容很少,一般只有十几个)
例如:
[root@localhost ~]# ll /usr/lib/systemd/system/|grep journald -rw-r--r--. 1 root root 1145 11月 20 12:49 systemd-journald.service -rw-r--r--. 1 root root 833 11月 20 12:49 systemd-journald.socket [root@localhost ~]#
/usr/lib/systemd/system/ —这个目录是一些Unit的socket,targt等等
例如:
[root@localhost ~]# ll /usr/lib/systemd/system/|grep runlevel lrwxrwxrwx. 1 root root 15 1月 20 09:57 runlevel0.target -> poweroff.target lrwxrwxrwx. 1 root root 13 1月 20 09:57 runlevel1.target -> rescue.target drwxr-xr-x. 2 root root 49 1月 20 09:57 runlevel1.target.wants lrwxrwxrwx. 1 root root 17 1月 20 09:57 runlevel2.target -> multi-user.target drwxr-xr-x. 2 root root 49 1月 20 09:57 runlevel2.target.wants lrwxrwxrwx. 1 root root 17 1月 20 09:57 runlevel3.target -> multi-user.target drwxr-xr-x. 2 root root 49 1月 20 09:57 runlevel3.target.wants lrwxrwxrwx. 1 root root 17 1月 20 09:57 runlevel4.target -> multi-user.target drwxr-xr-x. 2 root root 49 1月 20 09:57 runlevel4.target.wants lrwxrwxrwx. 1 root root 16 1月 20 09:57 runlevel5.target -> graphical.target drwxr-xr-x. 2 root root 49 1月 20 09:57 runlevel5.target.wants lrwxrwxrwx. 1 root root 13 1月 20 09:57 runlevel6.target -> reboot.target -rw-r--r--. 1 root root 761 11月 20 12:49 systemd-update-utmp-runlevel.service [root@localhost ~]#
当前系统已经安装了Oracle 12.1 GI,查看当前开机自动启动的服务:
[root@lunar1 ~]# ls -lrt /etc/systemd/system/multi-user.target.wants/|grep oracle lrwxrwxrwx 1 root root 38 Jan 19 17:16 oracle-tfa.service -> /etc/systemd/system/oracle-tfa.service lrwxrwxrwx 1 root root 40 Jan 19 17:18 oracle-ohasd.service -> /etc/systemd/system/oracle-ohasd.service [root@lunar1 ~]# [root@lunar1 ~]# ls /etc/systemd/system/multi-user.target.wants/|wc -l 35 [root@lunar1 ~]# [root@lunar1 ~]# ls /etc/systemd/system/multi-user.target.wants/ abrt-ccpp.service atd.service irqbalance.service libvirtd.service oracle-ohasd.service rsyslog.service vboxadd-x11.service abrtd.service chronyd.service kdump.service mdmonitor.service oracle-tfa.service sshd.service vmtoolsd.service abrt-oops.service crond.service ksm.service ModemManager.service postfix.service sysstat.service vncserver@:1.service abrt-vmcore.service hypervkvpd.service ksmtuned.service NetworkManager.service remote-fs.target vboxadd.service vncserver@:2.service abrt-xorg.service hypervvssd.service libstoragemgmt.service nfs-client.target rngd.service vboxadd-service.service vncserver@:3.service [root@lunar1 ~]#
OEL 7.2和CentOS 7.2中,如果选择了GUI服务器,添加开发包和兼容库后,一般来说,没有安装Oracle时,只需要32个自动启动的服务:
[root@localhost ~]# ls /etc/systemd/system/multi-user.target.wants/|wc -l 32 [root@localhost ~]# ls /etc/systemd/system/multi-user.target.wants/ abrt-ccpp.service abrt-xorg.service chronyd.service hypervkvpd.service ksmtuned.service ModemManager.service remote-fs.target sshd.service abrtd.service atd.service crond.service hypervvssd.service libstoragemgmt.service NetworkManager.service rngd.service sysstat.service abrt-oops.service auditd.service cups.path irqbalance.service libvirtd.service nfs-client.target rsyslog.service tuned.service abrt-vmcore.service avahi-daemon.service cups.service ksm.service mdmonitor.service postfix.service smartd.service vmtoolsd.service [root@localhost ~]#
以irqbalance.service为例,该服务的作用大致是用于优化中断分配,它会自动收集系统数据以分析使用模式
并依据系统负载状况将工作状态置于 Performance mode 或 Power-save mode.
处于 Performance mode 时,irqbalance 会将中断尽可能均匀地分发给各个 CPU core,以充分利用 CPU 多核,提升性能.
处于 Power-save mode 时,irqbalance 会将中断集中分配给第一个 CPU,以保证其它空闲 CPU 的睡眠时间,降低能耗.
(详见:http://www.irqbalance.org/documentation.php)
IRP的github项目地址:https://github.com/Irqbalance/irqbalance
.
Oracle官方文档中建议:
When Should Not To Use
In most of time, irqbalance service is enabled and should be used unless:
Manually pinning apps/IRQ’s to specific cores for a very good reason (low latency, realtime requirements, etc.)Virtual Guests.
It does not really make sense because unless you are pinning the guest to specific CPUs and IRQs and dedicated net/storage hardware, you will likely not see the benefits you would on bare metal.
.
在Exadata的低版本中,需要禁用该服务,否则容易出现系统问题,参见:
Exadata 11.2.3.2.1 release and patch (14522699) for Exadata 11.1.3.3, 11.2.1.2.x, 11.2.2.2.x, 11.2.2.3.x, 11.2.2.4.x, 11.2.3.1.x, 11.2.3.2.x (Doc ID 1485475.1)
Stop and disable irqbalance service on Exadata V2 database and storage servers (X4275) to prevent unexpected reboots caused by Linux bug 15835941
相关bug:
BUG:15835941 – V2 EXADATA REBOOTED FREQUENTLY AFTER UPGRADE: NO IRQ HANDLER FOR VECTOR
BUG:17165350 – BL460 G6 NIC’S GO OFFLINE “DO_IRQ: 10.136 NO IRQ HANDLER FOR VECTOR (IRQ -1)”
.
现在,查看一下该服务当前的状态:
[root@lunar1 system]# systemctl status irqbalance.service ● irqbalance.service - irqbalance daemon Loaded: loaded (/usr/lib/systemd/system/irqbalance.service; enabled; vendor preset: enabled) Active: active (running) since Wed 2016-01-20 07:58:38 CST; 1h 0min ago Main PID: 743 (irqbalance) CGroup: /system.slice/irqbalance.service └─743 /usr/sbin/irqbalance --foreground Jan 20 07:58:38 lunar1.oracle.com systemd[1]: Started irqbalance daemon. Jan 20 07:58:38 lunar1.oracle.com systemd[1]: Starting irqbalance daemon... [root@lunar1 system]#
我们看到当前irqbalance服务runing的状态,它加载的配置文件是/usr/lib/systemd/system/irqbalance.service
启动日期是:Wed 2016-01-20 07:58:38 CST; 1h 0min ago
进程号是743
现在我们停止这个服务:
[root@lunar1 system]# systemctl stop irqbalance.service [root@lunar1 system]# systemctl status irqbalance.service ● irqbalance.service - irqbalance daemon Loaded: loaded (/usr/lib/systemd/system/irqbalance.service; enabled; vendor preset: enabled) Active: inactive (dead) since Wed 2016-01-20 09:00:07 CST; 5s ago Process: 743 ExecStart=/usr/sbin/irqbalance --foreground $IRQBALANCE_ARGS (code=exited, status=0/SUCCESS) Main PID: 743 (code=exited, status=0/SUCCESS) Jan 20 07:58:38 lunar1.oracle.com systemd[1]: Started irqbalance daemon. Jan 20 07:58:38 lunar1.oracle.com systemd[1]: Starting irqbalance daemon... Jan 20 09:00:07 lunar1.oracle.com systemd[1]: Stopping irqbalance daemon... Jan 20 09:00:07 lunar1.oracle.com systemd[1]: Stopped irqbalance daemon. [root@lunar1 system]#
根据上面的信息,我们知道该服务是开机自动启动的服务,当前的状态是没有启动的(Active: inactive (dead) )
查看一下该服务的定义:
[root@localhost ~]# cat /usr/lib/systemd/system/irqbalance.service [Unit] Description=irqbalance daemon After=syslog.target [Service] EnvironmentFile=/etc/sysconfig/irqbalance ExecStart=/usr/sbin/irqbalance --foreground $IRQBALANCE_ARGS [Install] WantedBy=multi-user.target [root@localhost ~]#
这里我们看到该服务是在After=syslog.target之后启动的服务,也就是它依赖于syslog这个服务。
然后我们设置禁止irqbalance.service开机自动启动:
[root@lunar1 system]# systemctl disable irqbalance.service Removed symlink /etc/systemd/system/multi-user.target.wants/irqbalance.service. [root@lunar1 system]#
这里我们看到,禁止开机自动启动的本质就是:
Removed symlink /etc/systemd/system/multi-user.target.wants/irqbalance.service.
也就是我们前面说的,开机自动启动的实质是删除了/etc/systemd/system/下的link文件:
[root@lunar1 system]# ll /etc/systemd/system/multi-user.target.wants/irqbalance.service ls: cannot access /etc/systemd/system/multi-user.target.wants/irqbalance.service: No such file or directory [root@lunar1 system]#
具体删除那个target下的link文件呢?
由于该服务定义文件中的[Install]部分写明了“WantedBy=multi-user.target”
因此就需要删除/etc/systemd/system/multi-user.target.wants/irqbalance.service文件。
.
再次查看,irqbalance.service服务已经是开机不自动重启了“/irqbalance.service; disabled;”:
[root@lunar1 system]# systemctl status irqbalance.service ● irqbalance.service - irqbalance daemon Loaded: loaded (/usr/lib/systemd/system/irqbalance.service; disabled; vendor preset: enabled) Active: inactive (dead) Jan 20 07:58:38 lunar1.oracle.com systemd[1]: Started irqbalance daemon. Jan 20 07:58:38 lunar1.oracle.com systemd[1]: Starting irqbalance daemon... Jan 20 09:00:07 lunar1.oracle.com systemd[1]: Stopping irqbalance daemon... Jan 20 09:00:07 lunar1.oracle.com systemd[1]: Stopped irqbalance daemon. [root@lunar1 system]#
再来看一下开机自动启动的服务在Linux7中如何实现的:
[root@lunar1 system]# systemctl enable irqbalance.service Created symlink from /etc/systemd/system/multi-user.target.wants/irqbalance.service to /usr/lib/systemd/system/irqbalance.service. [root@lunar1 system]# ll /etc/systemd/system/multi-user.target.wants/irqbalance.service lrwxrwxrwx 1 root root 42 Jan 20 09:08 /etc/systemd/system/multi-user.target.wants/irqbalance.service -> /usr/lib/systemd/system/irqbalance.service [root@lunar1 system]#
这里我们看到,设置开机自动重启的本质就是在/etc/systemd/system/multi-user.target.wants/下面创建一个指向/usr/lib/systemd/system/同名service定义的软link
为什么在/etc/systemd/system/的multi-user.target.wants目录下创建呢?
还记得定义文件中的[Install]部分怎么写的么:
WantedBy=multi-user.target
因此,就是创建在multi-user.target.wants目录下了。
.
如果使用service命令是什么效果:
[root@localhost ~]# systemctl status irqbalance.service ● irqbalance.service - irqbalance daemon Loaded: loaded (/usr/lib/systemd/system/irqbalance.service; enabled; vendor preset: enabled) Active: active (running) since 三 2016-01-20 10:49:37 CST; 2h 32min ago Main PID: 630 (irqbalance) CGroup: /system.slice/irqbalance.service └─630 /usr/sbin/irqbalance --foreground 1月 20 10:49:37 localhost.localdomain systemd[1]: Started irqbalance daemon. 1月 20 10:49:37 localhost.localdomain systemd[1]: Starting irqbalance daemon... [root@localhost ~]# [root@localhost ~]#
重启服务:
[root@localhost ~]# service irqbalance restart Redirecting to /bin/systemctl restart irqbalance.service [root@localhost ~]#
这里看到,如果使用service启动服务,本质是重定向到了systemctl命令:/bin/systemctl restart irqbalance.service
再次查看状态:
[root@localhost ~]# systemctl status irqbalance.service ● irqbalance.service - irqbalance daemon Loaded: loaded (/usr/lib/systemd/system/irqbalance.service; enabled; vendor preset: enabled) Active: active (running) since 三 2016-01-20 13:22:36 CST; 11s ago Main PID: 14954 (irqbalance) CGroup: /system.slice/irqbalance.service └─14954 /usr/sbin/irqbalance --foreground 1月 20 13:22:36 localhost.localdomain systemd[1]: Started irqbalance daemon. 1月 20 13:22:36 localhost.localdomain systemd[1]: Starting irqbalance daemon... [root@localhost ~]#
注意服务启动时间从“ 三 2016-01-20 10:49:37 CST; 2h 32min ago”改变为“ 三 2016-01-20 10:49:37 CST; 2h 32min ago”了。
证明service确实可以重启服务,不过我感觉这个是systemd为了向下兼容的。
.
再来看一下Oracle的GIohasd.service服务:
[root@lunar1 ~]# ps -ef|grep ohasd root 1462 1 0 12:45 ? 00:00:00 /bin/sh /etc/init.d/init.ohasd run >/dev/null 2>&1 </dev/null root 12192 27423 0 15:31 pts/1 00:00:00 grep --color=auto ohasd root 27770 1 1 15:02 ? 00:00:18 /u01/app/12.1.0.2/grid/bin/ohasd.bin reboot [root@lunar1 ~]# [root@lunar1 ~]# systemctl status ohasd.service ● ohasd.service - Oracle High Availability Services Loaded: loaded (/etc/systemd/system/ohasd.service; enabled; vendor preset: disabled) Active: inactive (dead) [root@lunar1 ~]#
从上面的输出可以看到,已经安装了ohasd.service服务,并且启动进程正在运行
从systemctl status的输出可以看到,目前系统已经加载了/etc/systemd/system/ohasd.service文件,并且设置为开机自动启动的模式了。
但是后面的Active: inactive (dead),不知道是为什么,怀疑是12.1 GI的bug。
注意:
Linux 7.2上Oracle 12.1和12.2beta版本的GI软件有bug,执行root.sh的时候没有正确安装该服务。
现在看到的这个ohasd.service服务是我自己手工安装的。
[root@lunar1 ~]# crsctl query crs autostart 'Autostart delay': 0 'Autostart servercount': 1 [root@lunar1 ~]#
CRS状态:
[root@lunar1 ~]# crsctl status res -t -------------------------------------------------------------------------------- Name Target State Server State details -------------------------------------------------------------------------------- Local Resources -------------------------------------------------------------------------------- ora.CRSDG.dg ONLINE ONLINE lunar1 STABLE ONLINE ONLINE lunar2 STABLE ora.DATADG1.dg ONLINE ONLINE lunar1 STABLE ONLINE ONLINE lunar2 STABLE ora.LISTENER.lsnr ONLINE ONLINE lunar1 STABLE ONLINE ONLINE lunar2 STABLE ora.asm ONLINE ONLINE lunar1 Started,STABLE ONLINE ONLINE lunar2 Started,STABLE ora.net1.network ONLINE ONLINE lunar1 STABLE ONLINE ONLINE lunar2 STABLE ora.ons ONLINE ONLINE lunar1 STABLE ONLINE ONLINE lunar2 STABLE -------------------------------------------------------------------------------- Cluster Resources -------------------------------------------------------------------------------- ora.LISTENER_SCAN1.lsnr 1 ONLINE ONLINE lunar1 STABLE ora.MGMTLSNR 1 ONLINE ONLINE lunar1 169.254.128.253,STAB LE ora.cvu 1 ONLINE ONLINE lunar1 STABLE ora.lunar1.vip 1 ONLINE ONLINE lunar1 STABLE ora.lunar2.vip 1 ONLINE ONLINE lunar2 STABLE ora.lunardb.db 1 ONLINE ONLINE lunar1 Open,STABLE 2 ONLINE ONLINE lunar2 Open,STABLE ora.mgmtdb 1 OFFLINE OFFLINE STABLE ora.oc4j 1 ONLINE ONLINE lunar1 STABLE ora.scan1.vip 1 ONLINE ONLINE lunar1 STABLE -------------------------------------------------------------------------------- [root@lunar1 ~]#
这里看到MGMTDB没有启动,这个是有玄机的,后面慢慢说,O(∩_∩)O哈哈~
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列–1-简介
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-2-修改主机名和hostnamectl工具的使用
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列–3-systemd(d.bin和ohasd守护进程)
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列–4-target(图形界面和字符界面)
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列–5-防火墙
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列–6-开机自动启动或者禁用服务
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-7-网络管理之添加网
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-7-网络管理之修改IP地址
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-7-网络管理之修改网络接口名
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-8-在Linux7上安装11.2 RAC和12.1 RAC需要禁用哪些服务
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-9-Linux 7.2上的virbr0设备
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-10-ABRT-系统启动后自动检查和报告错误
Linux7(CentOS,RHEL,OEL)和Oracle RAC环境系列-11-配置VNC和常见问题处理