本节所讲内容:
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 命令查看第一个启动的进程
[[email protected] ~]# 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
查看默认运行级别
[[email protected] ~]# systemctl get-default
multi-user.target
设置默认的运行级别
[[email protected] ~]# 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‘
[[email protected] ~]#
切换运行级别
[[email protected] ~]# 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表示无限期的等待,直到用户
做出选择
[[email protected] ~]# 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
[[email protected] ~]# 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服务,并设置为开机自动启动
[[email protected] ~]# yum install httpd -y
[[email protected] ~]# yum install httpd -y^C
[[email protected] ~]# systemctl enable httpd.service
ln -s ‘/usr/lib/systemd/system/httpd.service‘ ‘/etc/systemd/system/multi-user.target.wants/httpd.service‘
[[email protected] ~]# systemctl restart httpd.service
[[email protected] ~]# 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.
[[email protected] ~]# 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
[[email protected] ~]#
启动和关闭服务
[[email protected] ~]# systemctl stop httpd
[[email protected] ~]# systemctl start httpd
列出所有服务并且检查是否开机启动
检查资源的使用情况
[[email protected] ~]# systemd-cgtop