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,如需转载请自行联系原作者

相关文章
|
机器人 BI vr&ar
伙伴客户案例|阿里云RPA助力制造零售企业降本增效 ——财务场景篇
RPA全称机器人流程自动化(Robotic Process Automation),是一种新兴的“数字劳动力”,可以替代或辅助人完成规则明确的重复性劳动,大幅提升业务流程效率,实现企业业务流程的自动化和智能化,从而降本增效。目前,RPA解决方案的应用场景几乎涵盖了所有行业,包括银行、保险、制造、零售、医疗、物流、电子商务甚至政府和公共机构。
2904 3
伙伴客户案例|阿里云RPA助力制造零售企业降本增效 ——财务场景篇
|
Linux Android开发
开源免费版RPA:详细指南[2.0版]
和市面上任何软件一样,全世界都在一起努力创建开源软件。那么RPA有开源的吗?答案是肯定的。但开源RPA生态系统目前尚不成熟。51RPA小编预测,这种情况不会在不久的将来发生变化,因为我们还没有看到支持无代码RPA的主要营利实体。
|
存储 Ubuntu Shell
OpenZFS安装和使用
在Ubuntu 22.04.3 LTS上,本文介绍了OpenZFS的容错功能,如RAID-Z(类似RAID 5)、Mirror(类似RAID 1)、RAID-Z2和RAID-Z3,以及Hot Spare和Scrubbing。推荐使用RAID-Z1以平衡容量和预算。主要步骤包括安装zfsutils-linux,创建RAID-Z1存储池和ZFS文件系统,以及管理文件系统。此外,还提到了使用nfs共享ZFS文件系统的命令。
766 0
|
机器学习/深度学习 Ubuntu 算法
操作系统原理实验2:进程调度(在Ubuntu虚拟机gcc编译环境下
操作系统原理实验2:进程调度(在Ubuntu虚拟机gcc编译环境下
339 0
|
网络协议 安全 网络安全
华为-DSVPN 案例配置及原理分析
华为-DSVPN 案例配置及原理分析
1019 0
华为-DSVPN 案例配置及原理分析
|
开发工具 git
git 报错 RPC failed; curl 18 transfer closed with outstanding read data remaining
这个错误是因为项目太久,tag资源文件太大 找了很久网上都说这样: 配置如下: $ git  config --global http.
10795 0
|
Swift 数据安全/隐私保护 iOS开发
iOS开发 - swift通过Alamofire实现https通信
iOS开发 - swift通过Alamofire实现https通信
547 0
iOS开发 - swift通过Alamofire实现https通信
|
JavaScript 前端开发
electron 10行核心代码定制自己的浏览器
electron 10行核心代码定制自己的浏览器
921 0
electron 10行核心代码定制自己的浏览器
|
运维 架构师 Cloud Native
软件工程:为数十亿用户设计架构
在过去,我们已经分享过了支付宝伴随着双十一大促一路走来的技术演进,今天,我们邀请到了支付宝全局架构师曹刚,请他给大家分享一下,给 12 亿用户设计架构是什么体验。
软件工程:为数十亿用户设计架构