设为首页 收藏本站
查看: 3274|回复: 0

[经验分享] RHEL7启动的原理和服务控制

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-8-29 10:27:36 | 显示全部楼层 |阅读模式
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 命令查看第一个启动的进程
[iyunv@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
查看默认运行级别
[iyunv@RHEL7 ~]# systemctl get-default
multi-user.target
设置默认的运行级别
[iyunv@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'
[iyunv@RHEL7 ~]#
切换运行级别
[iyunv@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表示无限期的等待,直到用户
做出选择
[iyunv@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
[iyunv@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服务,并设置为开机自动启动
[iyunv@RHEL7 ~]# yum install httpd -y
[iyunv@RHEL7 ~]# yum install httpd -y^C
[iyunv@RHEL7 ~]# systemctl enable httpd.service
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
[iyunv@RHEL7 ~]# systemctl restart httpd.service
[iyunv@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.
[iyunv@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
[iyunv@RHEL7 ~]#
启动和关闭服务
[iyunv@RHEL7 ~]# systemctl stop httpd
[iyunv@RHEL7 ~]# systemctl start httpd
列出所有服务并且检查是否开机启动
spacer.jpg
QQ截图20160829102717.png
检查资源的使用情况
[iyunv@RHEL7 ~]# systemd-cgtop
spacer.jpg
QQ截图20160829102723.png


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-264630-1-1.html 上篇帖子: linux下创建swap分区 下篇帖子: centos下新建ftp权限
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表