# mount /dev/cdrom /mediaapache
/dev/mapper/rhel_rh7-root xfs 50G 4.8G 46G 10% /bash
说明:rhel_rh7-root的组成是rhel_主机名-分区标签app
RHEL7版本开始对系统服务启动脚本的管理再也不放到/etc/init.d/目录下,这里只有少数几个启动脚本,例如:less
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:offoop
提示:传统的放到/etc/init.d目录下的启动脚本仍是能够用的,须要调用的/etc/init.d/functions启动脚本函数库文件还在。spa
#! /bin/bashrest
# chkconfig: 2345 10 90
# description: Activates/Deactivates all network interfaces configured to start at boot time.
# Source function library.
. /etc/init.d/functions
……code
RHEL7开始大部分启动脚本的管理都必须使用 systemctl 这个命令
LinuxSystemctl是一个系统管理守护进程、工具和库的集合,用于取代System V、service和chkconfig命令,初始进程主要负责控制systemd系统和服务管理器。经过Systemctl –help能够看到该命令主要分为:查询或发送控制命令给systemd服务,管理单元服务的命令,服务文件的相关命令,任务、环境、快照相关命令,systemd服务的配置重载,系统开机关机相关的命令。
1)查看已经安装软件的是否开机自动启动或禁止 systemctl list-unit-files (也可使用这个命令查看启动服务的名称是怎么写的)
举例:列出全部可用的服务名称,及其开机自动启动状态
# systemctl list-unit-files --type=service
UNIT FILE STATE
abrt-ccpp.service enabled
abrt-oops.service enabled
abrt-pstoreoops.service disabled
abrt-vmcore.service enabled
2)启动|中止|重启|从新加载 systemctl start|stop|restart|reload foobar.service
2)中止某个服务启动
# systemctl stop firewalld.service
3)设置开机容许|禁止启动 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.
4)进入援救模式或紧急模式
启动救援模式
# systemctl rescue
进入紧急模式
# systemctl emergency
重启
# systemctl reboot
关闭电源关机
# systemctl poweroff
使用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
对比RHEL6与RHEL7对服务的管理命令
显示全部服务 | chkconfig --list | systemctl list-unit-files --type=service | ||
显示全部已启动的服务 | chkconfig --list|grep on | systemctl list-units --type=service | ||
使某服务开机自动启动 | chkconfig --level 3 httpd on | systemctl enable httpd.service | ||
使某服务开机禁止启动 | chkconfig --level 3 httpd off | systemctl disable httpd.service | ||
检查服务状态 | service httpd status | systemctl status httpd.service (服务详细信息) systemctl is-active httpd.service (仅显示是否 Active) | ||
启动某服务 | service httpd start | systemctl start httpd.service | ||
中止某服务 | service httpd stop | systemctl stop httpd.service | ||
重启某服务 | service httpd restart | systemctl restart httpd.service |