linux centos7 服务管理命令:systemctl和service和chkconfig区别

引用:https://blog.csdn.net/wangganggelian/article/details/49848225

            https://blog.csdn.net/cds86333774/article/details/51165361

linux centos7 服务管理命令:systemctl和service和chkconfig区别

1 service

service命令用于对系统服务进行管理,比如启动(start)、停止(stop)、重启(restart)、重新加载配置(reload)、查看状态(status)等。

2 chkconfig

老版本的使用说明:管理自启动

chkconfig

提供了一个维护/etc/rc[0~6] d 文件夹的命令行工具,它减轻了系统直接管理这些文件夹中的符号连接的负担。chkconfig主要包括5个原始功能:为系统管理增加新的服务、为系统管理移除服务、列出单签服务的启动信息、改变服务的启动信息和检查特殊服务的启动状态。当单独运行chkconfig命令而不加任何参数时,他将显示服务的使用信息。

必要参数
–add 开启指定的服务程序
–del 关闭指定的服务程序
–list 列出chkconfig所知道的所有服务

选择参数
–level<代号> 设置服务程序的等级代号,它是一串0~7的数字,如“-level35”代表指定运行等级3和5
–help 显示帮助信息
–version 显示版本信息

3 systemctl

我们可以把systemctl理解为systemd的一个工具。也可以认为systemctl命令将service和chkconfig命令结合在了一起。总之,需要的时候会用就行。下面我们来看一些常见用法。

列出所有可用单元

# systemctl list-unit-files

列出所有运行中单元

# systemctl list-units

列出所有失败的单元

[root@master ~]# systemctl --failed
0 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
[root@master ~]# 

检查某个单元是否启用

[root@master ~]# systemctl is-enabled mysqld.service
disabled
[root@master ~]# 

查看某个服务(单元)的状态

这里写图片描述

[root@master ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

*启动、重启、停止、重载服务

# systemctl start httpd.service
# systemctl restart httpd.service
# systemctl stop httpd.service
# systemctl reload httpd.service
# systemctl status httpd.service

*激活/禁止自动启动

# systemctl enable httpd.service
# systemctl disable httpd.service

*杀死服务

# systemctl kill httpd

使用Systemctl控制并管理挂载点:

systemctl list-unit-files --type=mount

# systemctl start tmp.mount
# systemctl stop tmp.mount
# systemctl restart tmp.mount
# systemctl reload tmp.mount
# systemctl status tmp.mount

# systemctl is-active tmp.mount
# systemctl enable tmp.mount
# systemctl disable tmp.mount

# systemctl mask tmp.mount

使用Systemctl控制并管理套接口

# systemctl list-unit-files --type=socket

# systemctl start cups.socket
# systemctl restart cups.socket
# systemctl stop cups.socket
# systemctl reload cups.socket
# systemctl status cups.socket

# systemctl is-active cups.socket
# systemctl enable cups.socket
# systemctl disable cups.socket

# systemctl mask cups.socket

使用Systemctl管理服务的CPU利用率

# systemctl show -p CPUShares httpd.service

# systemctl set-property httpd.service CPUShares=2000
# systemctl show -p CPUShares httpd.service

# systemctl show httpd

其他

# systemd-analyze critical-chain httpd.service

# systemctl list-dependencies httpd.service

# systemd-cgls
# systemd-cgtop

# systemctl emergency

# systemctl reboot
# systemctl halt
# systemctl suspend
# systemctl hibernate
# systemctl hybrid-sleep

启动防火墙——systemctl start firewalld.service

 

停止防火墙——systemctl stop firewalld.service

查看firewalld防火墙状态——firewall-cmd --state

禁止防火墙开机启动——systemctl disable firewalld.service

列出正在运行的服务状态——systemctl

启动一个服务——systemctl start postfix.service

关闭一个服务——systemctl stop postfix.service

重启一个服务:——systemctl restart postfix.service

显示一个服务的状态——systemctl status postfix.service

在开机时启用一个服务——systemctl enable postfix.service

在开机时禁用一个服务——systemctl disable postfix.service

查看服务是否开机启动——systemctl is-enabled postfix.service

查看已启动的服务列表——systemctl list-unit-files|grep enabled



  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值