# mount /dev/cdrom /media
/dev/mapper/rhel_rh7-root xfs 50G 4.8G 46G 10% /
说明:rhel_rh7-root的组成是rhel_主机名-分区标签
RHEL7版本开始对系统服务启动脚本的管理不再放到/etc/init.d/目录下,这里只有少数几个启动脚本,例如:
netconsole network rhnsd
说明:上面的启动脚本还是可以使用传统的chkconfig --list 来查看启动级别的,而大部分启动脚本用这个命令是看不到的
# chkconfig --list
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
rhnsd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
提示:传统的放到/etc/init.d目录下的启动脚本还是可以用的,需要调用的/etc/init.d/functions启动脚本函数库文件还在。
#! /bin/bash
# chkconfig: 2345 10 90
# description: Activates/Deactivates all network interfaces configured to start at boot time.
# Source function library.
. /etc/init.d/functions
……
RHEL7开始大部分启动脚本的管理都必须使用 systemctl 这个命令
启动|停止|重启|重新加载 systemctl start|stop|restart|reload foobar.service
查看已经安装软件的启动级别 systemctl list-unit-files (也可以使用这个命令查看启动服务的名称是怎么写的)
例如:查看防火墙启动脚本的名称,并关闭
# systemctl list-unit-files|more
firewalld.service enabled
fprintd.service static
fstrim.service static
# systemctl stop firewalld.service
设置开机允许|禁止启动 systemctl enable|disable foobar.service
例如:设置开机禁止防火墙服务启动
# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
例如:设置开机自动启动防火墙服务
# systemctl enable firewalld.service
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/basic.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
使用systemctl 命令管理的原理:
(1)真实的启动Daemon都保存在/usr/lib/systemd/system目录下,例如:httpd.service
(2)systemctl根据启动级别会在/etc/systemd/system目录下创建一些子目录
sysinit.target.wants(lvm2-monitor.service) multi-user.target.wants(多用户可以启动的脚本,大部分都放这里) basic.target.wants(firewalld.service和microcode.service)
(3)如果设置成开机自动启动的启动Daemon都会在/etc/systemd/system/不同级别子目录下/创建一个软连接,来源就是从/usr/lib/systemd/system目录下创建的。
例如:
# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
# ls -l /etc/systemd/system/multi-user.target.wants|grep httpd
lrwxrwxrwx. 1 root root 37 Apr 18 05:57 httpd.service -> /usr/lib/systemd/system/httpd.service
(4)如果禁止开机自动启动,就把软连接删除
(5)真实的启动Daemon脚本文件内容如下所示,用httpd.service举例
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd 加载环境变量文件
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND 执行start命令时真正执行的命令和参数
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful 执行reload命令时真正执行的命令和参数
ExecStop=/bin/kill -WINCH ${MAINPID} 执行stop命令时真正执行的命令和参数
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
~