主要介绍systemctl的几个功能如下:

1.查看某个服务的状态

2.关闭某个服务

3.开启某个服务

4.设置某个为开机自启动

5.关闭某个服务为开机不启动

6.查看所有开启启动的服务

1.查看某个服务的状态

用法:systemctl status 需要查询的服务 例如 mariadb.service 注意Actice[root@localhost linux]# systemctl status mariadb.service
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: -- :: EDT; 19min ago
  Process:  ExecStartPost=/usr/libexec/mariadb-/SUCCESS)
  Process:  ExecStartPre=/usr/libexec/mariadb-prepare-db-/SUCCESS)
 Main PID:  (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─ /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─ /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/...

May  :: localhost.localdomain systemd[]: Starting MariaDB database server...
May  :: localhost.localdomain mysqld_safe[]:  :: mysqld_safe Logging to '/var/log...g'.
May  :: localhost.localdomain mysqld_safe[]:  :: mysqld_safe Starting mysqld daem...sql
May  :: localhost.localdomain systemd[]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost linux]# 

其实查看状态还可以用ps查询

ps aux 是查询所有进程grep是提取需要的行[root@localhost linux]# ps aux | grep mariadb
mysql         ?        Sl   :   : /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root            pts/    S+   :   : grep --color=auto mariadb
[root@localhost linux]#

2.关闭某个服务

[root@localhost linux]# systemctl stop mariadb.service
[root@localhost linux]# 再次查看其状态 可见 已经关闭完成了[root@localhost linux]# ps aux | grep -v grep | grep mariadb.service[root@localhost linux]# 

3.开启某个服务

[root@localhost linux]# systemctl start mariadb.service
[root@localhost linux]#
查看服务是否启动
[root@localhost linux]# ps aux | grep mariadb
mysql         ?        Sl   :   : /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root            pts/    S+   :   : grep --color=auto mariadb
[root@localhost linux]#
[root@localhost linux]#
[root@localhost linux]# ps aux | grep mariadb | grep -v grep
mysql         ?        Sl   :   : /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock

4.设置某个服务为开机自启动

[root@localhost linux]# systemctl is-enabled mariadb.service
enabled
[root@localhost linux]# 

5.关闭某个服务为开机不启动

[root@localhost linux]# systemctl disable mariadb.service
Removed symlink /etc/systemd/system/multi-user.target.wants/mariadb.service.
[root@localhost linux]# 

6.查看所有开启启动的服务

[root@localhost linux]# ls /etc/systemd/system/multi-user.target.wants/
abrt-ccpp.service    auditd.service      kdump.service           postfix.service   sysstat.service
abrtd.service        chronyd.service     libstoragemgmt.service  remote-fs.target  tuned.service
abrt-oops.service    crond.service       mdmonitor.service       rngd.service      vmtoolsd.service
abrt-vmcore.service  cups.path           ModemManager.service    rsyslog.service   vsftpd.service
abrt-xorg.service    cups.service        NetworkManager.service  smartd.service
atd.service          irqbalance.service  nfs-client.target       sshd.service
[root@localhost linux]# 

可见,刚刚禁止之后,这个文件中就没有了mariadb.service[root@localhost linux]# ls /etc/systemd/system/multi-user.target.wants/mariadb.servicels: cannot access /etc/systemd/system/multi-user.target.wants/mariadb.service: No such file or directory[root@localhost linux]# 

现在利用systemctl将mariadb.service设置为开机自启动[root@localhost linux]# systemctl enable mariadb.serviceCreated symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.[root@localhost linux]# 

再次写ls语句[root@localhost linux]# ls /etc/systemd/system/multi-user.target.wants/mariadb.service/etc/systemd/system/multi-user.target.wants/mariadb.service[root@localhost linux]# 

linux systemctl 常用用法简介的更多相关文章

  1. Linux find常用用法示例

    在此处只给出find的基本用法示例,都是平时我个人非常常用的搜索功能.如果有不理解的部分,则看后面的find运行机制详解对于理论的说明,也建议在看完这些基本示例后阅读一遍理论说明,它是本人翻译自fin ...

  2. linux 系统监控、诊断工具之 lsof 用法简介

    1.lsof 简介 lsof 是 Linux 下的一个非常实用的系统级的监控.诊断工具. 它的意思是 List Open Files,很容易你就记住了它是 "ls + of"的组合 ...

  3. [转帖]linux lsof 用法简介

    linux lsof 用法简介 https://www.cnblogs.com/saneri/p/5333333.html 1.简介: lsof(list open files)是一个列出当前系统打开 ...

  4. linux lsof 用法简介

    1.简介: lsof(list open files)是一个列出当前系统打开文件的工具. 只需输入 lsof 就可以生成大量的信息,因为 lsof 需要访问核心内存和各种文件,所以必须以 root 用 ...

  5. centos的vi常用用法

    centos的vi常用用法 vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何最新的文本编辑器,这里只是简单地介绍一下它的用法和一小部分指令.由于对Unix及Linux系统的 ...

  6. Linux 内核引导选项简介

    Linux 内核引导选项简介 作者:金步国 连接地址:http://www.jinbuguo.com/kernel/boot_parameters.html 参考参数:https://www.cnbl ...

  7. 转 Linux中常用操作命令

    http://blog.csdn.net/ljianhui/article/details/11100625 初窥Linux 之 我最常用的20条命令 玩过Linux的人都会知道,Linux中的命令的 ...

  8. 【转载】Linux中常用操作命令

    说明:开始学习linux系统,为了方便查看,特转载一篇Linux中常用操作命令,转载地址:http://www.cnblogs.com/laov/p/3541414.html 正文: Linux简介及 ...

  9. LINUX下常用SHELL指令

    Linux Shell常用shell命令 一.文件.目录操作命令 1.ls命令 功能:显示文件和目录的信息 ls 以默认方式显示当前目录文件列表 ls -a 显示所有文件包括隐藏文件 ls -l 显示 ...

随机推荐

  1. 移动端meta行大全

    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable= ...

  2. grep与正则表达式的使用

    正则表达式以及grep的使用 grep是一种文本过滤工具(模式:pattern)基本使用用法如下: grep [option] PATTERN FILE grep [OPTIONS] [-e PATT ...

  3. c# mac地址 和http://xx.xx.xx/ 正则表达式匹配

    Mac  :^([0-9a-fA-F]{2})(([/\s:][0-9a-fA-F]{2}){5})$ C# 书写方式 一下是允许mac中间间隔符是“:”或者“-”两种输入方式 并且我把上边的正则表达 ...

  4. 解决 win 7 64 位 vs2010 调试silverlight项目无法加载,提示更新developer ,跟新报 消息 ID: 1517 已安装了 Silverlight 的 64 位版本

    出现上面的问题是我们安装的silverlight的版本和系统给的silverlight下载的版本冲突, 解决的方法是,首先卸载Silverlight runtime(也就是默认的silverlight ...

  5. linux利用crontab设置定时任务运行jar包

    参考链接: 1.http://blog.csdn.net/javadhh/article/details/42779505 2.http://blog.csdn.net/cctv_liu/articl ...

  6. spring自动注解Autowired配置

    1.spring注解:http://blog.csdn.net/xyh820/article/details/7303330/ 2.最简ssm配置:http://blog.csdn.net/qq_18 ...

  7. jqgrid子表格

    .前台 <%-- builed by manage.aspx.cmt [ver:] at // :: --%> <%@ Page Language="C#" Au ...

  8. ASP.NET 在OnClientClick中js方法直接调用Eval绑定字段的数据

    最近有一项目中使用到了asp.net的GridView控件.需要在前端被点击某一行数据时,前端获取到改行后台绑定的数据序列号.遍用<%# Bind("ID) %>.<%# ...

  9. css字符串转换为类map对象及反转

    存储对象为啥是类map(即:{key:val,...}格式),因为Map对象的val为字符时,无法存储 '('.')' 左右括号,我也很无奈╮(╯▽╰)╭ 解析脚本: <!DOCTYPE htm ...

  10. Ubuntu下Tomcat绑定80端口(zz)

    Ubuntu下Tomcat绑定80端口 来源:本站转载 作者:佚名 时间:2011-02-22 TAG: 工作环境迁移到了Ubuntu,很多东西发生了变化,比如原先配置tomcat端口.只需要配置se ...