Chinaunix首页 | 论坛 | 博客
  • 博客访问: 296785
  • 博文数量: 84
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 890
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-13 16:46
文章分类

全部博文(84)

文章存档

2017年(2)

2016年(4)

2015年(78)

我的朋友

分类: LINUX

2016-10-17 16:29:46

  1. 概念

    RHEL/CentOS 7.0中一个最主要的改变,就是切换到了systemd。它用于替代红帽企业版Linux前任版本中的SysV和Upstart,对系统和服务进行管理。systemd兼容SysV和Linux标准组的启动脚本。Systemd是一个Linux操作系统下的系统和服务管理器。它被设计成向后兼容SysV启动脚本,并提供了大量的特性,如开机时平行启动系统服务,按需启动守护进程,支持系统状态快照,或者基于依赖的服务控制逻辑。先前的使用SysV初始化或Upstart的红帽企业版Linux版本中,使用位于/etc/rc.d/init.d/目录中的bash初始化脚本进行管理。而在RHEL 7/CentOS 7中,这些启动脚本被服务单元取代了。服务单元以.service文件扩展结束,提供了与初始化脚本同样的用途。要查看、启动、停止、重启、启用或者禁用系统服务,你要使用systemctl来代替旧的service命令。


    注:为了向后兼容,旧的service命令在CentOS 7中仍然可用,它会重定向所有命令到新的systemctl工具。


    对于那些支持 Systemd 的软件,安装的时候,会自动在/usr/lib/systemd/system目录添加一个配置文件。

    如果你想让该软件开机启动,就执行下面的命令(以httpd.service为例)。

    $ sudo systemctl enable httpd

    上面的命令相当于在/etc/systemd/system目录添加一个符号链接,指向/usr/lib/systemd/system里面的httpd.service文件。

    这是因为开机时,Systemd只执行/etc/systemd/system目录里面的配置文件。这也意味着,如果把修改后的配置文件放在该目录,就可以达到覆盖原始配置的效果。


(2)对比与实例

任务

旧指令

新指令

查看httpd是否为开机自启动

 

systemctl list-unit-files | grep httpd

turn the service on,for start at next boot.在下次重启后打开服务

chkconfig httpd on

systemctl enable httpd.service

turn the service off for the next reboot开机禁用

chkconfig httpd off

systemctl disable httpd.service

列出所有服务(包括启用的和禁用的)

chkconfig --list

systemctl list-unit-files --type=service

启动某服务

service httpd start

systemctl start httpd.service

停止某服务

service httpd stop

systemctl stop httpd.service

重启某服务

service httpd restart

systemctl restart httpd.service

查看服务状态

service httpd status

systemctl status httpd.service

显示启动失败的服务

 

systemctl –failed

查看某个单元(cron.serveice)是否启用

 

systemctl is-enabled crond.service

     


[root@localhost multi-user.target.wants]# systemctl disable postfix.service #开机禁用某个服务,相当于删除某个文件

rm '/etc/systemd/system/multi-user.target.wants/postfix.service'

[root@localhost multi-user.target.wants]# ll


[root@localhost system]# systemctl enable postfix.service #开机开启某个服务相当于建立了一个连接文件。

ln -s '/usr/lib/systemd/system/postfix.service' '/etc/systemd/system/multi-user.target.wants/postfix.service'

[root@localhost system]#


#systemctl get-default #列出当前使用的运行等级

multi-user.target

#systemctl isolate graphical.target #启动运行级别5,即图形模式

 

阅读(2370) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~