RHEL7启动的原理和服务控制

简介:

RHEL7启动的原理和服务控制

本节所讲内容:

1-1-    RHEL7的启动原理

1-2-    1-2-RHEL7的服务管理

1-3-    1-3-网络模型与IP地址的概述

BIOS自检-> MBR启动GRUB 加载内核 systemd的init进程

systemd的初始化进程

作用:加载所需的服务和用户空间工具,挂载文件系统/etc/fstab

systemd是Linux内核启动的第一个进程,取代了sysvinit程序(即init)

负责协调引导过程的其余部分并配置为用户的环境

systemd 相比 init 的优点

1.    启动速度快各服务平行运行(SSD会加快)

2.    提供系统服务的快照

3.    挂载及自动挂载的管理

4.    服务自动实时更新,重新启动与暂停或停止.

5.    使用Linux核心cgroup 功能进行管理

rhel7 使用systemd 进程初始化

初始化的进程一般是pid为 1

使用pstree 命令查看第一个启动的进程

[root@RHEL7 ~]# pstree

systemd─┬─ModemManager───2*[{ModemManager}]

        ├─NetworkManager─┬─2*[dhclient]

        │                └─3*[{NetworkManager}]

        ├─2*[abrt-watch-log]

        ├─abrtd

        ├─accounts-daemon───2*[{accounts-daemon}]

        ├─alsactl

        ├─at-spi-bus-laun─┬─dbus-daemon───{dbus-daemon}

        │                 └─3*[{at-spi-bus-laun}]

        ├─at-spi2-registr───{at-spi2-registr}

        ├─atd

        ├─auditd─┬─audispd─┬─sedispatch

        │        │         └─{audispd}

        │        └─{auditd}

RHEL7设置运行级别

systemctl 使用目标取代了运行级别的概念

6     7

init        systemd

init0    systemctl poweroff   关机

init1    systemctl  isolate rescue.target  单用户

init3    systemctl  isolate  multi-user.target   字符界面

init5    systemctl  isolate graphical.target       图形化

init6    systemctl  reboot  重启

打开/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

当使用systemd ,inittab不再使用

添加配置将在您的系统上没有影响。

ctrl - alt - delete是由/usr/lib/systemd/system/ctrl-alt-del.target处理

systemd使用“target”而不是运行级。默认情况下,有两个主要target:

multi-user.target:类似于运行级别3

graphical.target:类似于运行级5

查看当前默认目标,运行:

systemctl get-default

设置一个默认目标,运行:

systemctl set-default TARGET.target

查看默认运行级别

[root@RHEL7 ~]# systemctl get-default

multi-user.target

设置默认的运行级别

[root@RHEL7 ~]# systemctl set-default multi-user.target

rm '/etc/systemd/system/default.target'

ln -s '/usr/lib/systemd/system/multi-user.target' '/etc/systemd/system/default.target'

[root@RHEL7 ~]#

切换运行级别

[root@RHEL7 ~]# systemctl isolate multi-user.target

RHEL7 中grub引导配置

主要配置文件

/boot/grub2/grub.cfg  直接修改,换一个内核,之前的配置失效

/etc/default/grub  默认修改

GRUB_TIMEOUT=5

GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"

GRUB_DEFAULT=saved

GRUB_DISABLE_SUBMENU=true

GRUB_TERMINAL_OUTPUT="console"

GRUB_CMDLINE_LINUX="rd.lvm.lv=rhel/root crashkernel=auto  rd.lvm.lv=rhel/swap vconsole.font=latarcyrheb-sun16 vconsole.keymap=us rhgb quiet"

GRUB_DISABLE_RECOVERY="true"

然后使用grub2-mkconfig 命令生效。

GRUB_TIMEOUT="5" ->设置进入默认启动项的等候时间,默认值5秒,按自己需要修改

选择菜单的显示时间,默认是5,值是0表示不显示菜单选项,值是-1表示无限期的等待,直到用户

做出选择

[root@RHEL7 ~]# vim /boot/grub2/grub.cfg

if [ x$feature_timeout_style = xy ] ; then

  set timeout_style=menu

  set timeout=5

# Fallback normal timeout code in case the timeout_style feature is

# unavailable.

else

  set timeout=5

fi

[root@RHEL7 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg

Generating grub configuration file ...

Found linux image: /boot/vmlinuz-3.10.0-123.el7.x86_64

Found initrd image: /boot/initramfs-3.10.0-123.el7.x86_64.img

Found linux image: /boot/vmlinuz-0-rescue-9f99183cd7dd46d791c1f23005d01176

Found initrd image: /boot/initramfs-0-rescue-9f99183cd7dd46d791c1f23005d01176.img

done

RHEL7服务启动配置

systemd 的主要的命令行工具是systemctl

大多数Linux系统的管理员应该后已经熟练service chkconfig 的使用, systemd 可以同样的完成

注意:service  和 chkconfig 在systemd 照常可以使用

systemctl 的语法格式

systemctl start [服务名称]  启动 

systemctl restart [服务名称]   重新启动

systemctl stop [服务名称]   停止

systemctl status [服务名称]   状态查询

systemctl enable  [服务名称]  开机自启

systemctl disable  [服务名称]   开机自动关闭

例:安装httpd服务,并设置为开机自动启动

[root@RHEL7 ~]# yum install httpd -y

[root@RHEL7 ~]# yum install httpd -y^C

[root@RHEL7 ~]# systemctl enable httpd.service

ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'

[root@RHEL7 ~]# systemctl restart httpd.service

[root@RHEL7 ~]# systemctl status httpd.service

httpd.service - The Apache HTTP Server

   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)

   Active: active (running) since Fri 2016-08-26 21:00:08 CST; 11s ago

 Main PID: 6065 (httpd)

   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"

   CGroup: /system.slice/httpd.service

           ├─6065 /usr/sbin/httpd -DFOREGROUND

           ├─6078 /usr/sbin/httpd -DFOREGROUND

           ├─6079 /usr/sbin/httpd -DFOREGROUND

           ├─6080 /usr/sbin/httpd -DFOREGROUND

           ├─6081 /usr/sbin/httpd -DFOREGROUND

           └─6082 /usr/sbin/httpd -DFOREGROUND

Aug 26 20:59:48 RHEL7.2 httpd[6065]: AH00557: httpd: apr_sockaddr_info_get() failed fo...7.2

Aug 26 20:59:48 RHEL7.2 httpd[6065]: AH00558: httpd: Could not reliably determine the ...age

Aug 26 21:00:08 RHEL7.2 systemd[1]: Started The Apache HTTP Server.

Hint: Some lines were ellipsized, use -l to show in full.

[root@RHEL7 ~]# ls /etc/systemd/system/multi-user.target.wants/

abrt-ccpp.service     crond.service       libstoragemgmt.service     rhsmcertd.service

abrtd.service         cups.path           libvirtd.service           rngd.service

abrt-oops.service     httpd.service       mdmonitor.service          rpcbind.service

abrt-vmcore.service   hypervkvpd.service  ModemManager.service       rsyslog.service

abrt-xorg.service     hypervvssd.service  netcf-transaction.service  smartd.service

atd.service           irqbalance.service  NetworkManager.service     sshd.service

auditd.service        kdump.service       nfs.target                 sysstat.service

avahi-daemon.service  ksm.service         postfix.service            tuned.service

chronyd.service       ksmtuned.service    remote-fs.target           vmtoolsd.service

[root@RHEL7 ~]#

启动和关闭服务

[root@RHEL7 ~]# systemctl stop httpd

[root@RHEL7 ~]# systemctl start httpd

列出所有服务并且检查是否开机启动

spacer.gif

wKiom1fAQPyALr7xAAG10IzJeiw992.png-wh_50

检查资源的使用情况

[root@RHEL7 ~]# systemd-cgtop

spacer.gif

wKioL1fAQP7iaTMcAAFk19xu42w833.png-wh_50




本文转自 OpenStack2015 51CTO博客,原文链接:http://blog.51cto.com/andyliu/1843106,如需转载请自行联系原作者

相关文章
|
7月前
|
安全 Linux Shell
16.5.3 【Linux】SELinux 三种模式的启动、关闭与观察
16.5.3 【Linux】SELinux 三种模式的启动、关闭与观察
116 0
|
11月前
|
网络协议 Linux 网络安全
CentOS 8防火墙常规设置命令记录
CentOS 8防火墙常规设置命令记录
127 0
|
Unix Linux
RHEL系统状态检测命令
1.ifconfig命令 2.uname命令 3.uptime命令 4.free命令 5.who命令 6.last命令 7.ping命令 8.traceoath命令 9.netstat命令 10.history命令 11.sosreport命令
172 0
RHEL系统状态检测命令
|
Linux
RHEL系统初始化进程
systemd、开机默认进入 多用户的文本界面
86 0
RHEL系统初始化进程
CentOS8的阿里云源停止维护后的更新配置方法 2022-2-17
CentOS8的生命周期停止,阿里云源repo也不再维护了,旧的yum/dnf更新报错失效,官方的配置方法也失效无人维护,只好自己经过一段时间研究终于解决了使dnf/yum可以正常更新使用的方法。
|
安全 Linux Shell
RHEL7 运行级别简介及切换操作
init是Linux系统操作中不可缺少的程序之一。
RHEL7 运行级别简介及切换操作