linux systemctl 常用用法简介
主要介绍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 常用用法简介的更多相关文章
- Linux find常用用法示例
在此处只给出find的基本用法示例,都是平时我个人非常常用的搜索功能.如果有不理解的部分,则看后面的find运行机制详解对于理论的说明,也建议在看完这些基本示例后阅读一遍理论说明,它是本人翻译自fin ...
- linux 系统监控、诊断工具之 lsof 用法简介
1.lsof 简介 lsof 是 Linux 下的一个非常实用的系统级的监控.诊断工具. 它的意思是 List Open Files,很容易你就记住了它是 "ls + of"的组合 ...
- [转帖]linux lsof 用法简介
linux lsof 用法简介 https://www.cnblogs.com/saneri/p/5333333.html 1.简介: lsof(list open files)是一个列出当前系统打开 ...
- linux lsof 用法简介
1.简介: lsof(list open files)是一个列出当前系统打开文件的工具. 只需输入 lsof 就可以生成大量的信息,因为 lsof 需要访问核心内存和各种文件,所以必须以 root 用 ...
- centos的vi常用用法
centos的vi常用用法 vi编辑器是所有Unix及Linux系统下标准的编辑器,它的强大不逊色于任何最新的文本编辑器,这里只是简单地介绍一下它的用法和一小部分指令.由于对Unix及Linux系统的 ...
- Linux 内核引导选项简介
Linux 内核引导选项简介 作者:金步国 连接地址:http://www.jinbuguo.com/kernel/boot_parameters.html 参考参数:https://www.cnbl ...
- 转 Linux中常用操作命令
http://blog.csdn.net/ljianhui/article/details/11100625 初窥Linux 之 我最常用的20条命令 玩过Linux的人都会知道,Linux中的命令的 ...
- 【转载】Linux中常用操作命令
说明:开始学习linux系统,为了方便查看,特转载一篇Linux中常用操作命令,转载地址:http://www.cnblogs.com/laov/p/3541414.html 正文: Linux简介及 ...
- LINUX下常用SHELL指令
Linux Shell常用shell命令 一.文件.目录操作命令 1.ls命令 功能:显示文件和目录的信息 ls 以默认方式显示当前目录文件列表 ls -a 显示所有文件包括隐藏文件 ls -l 显示 ...
随机推荐
- 理解Linux中的shutdown、poweroff、halt和reboot命令
原文 http://os.51cto.com/art/201706/541525.htm 在本篇中,我们会向你解释 shutdown.poweroff.halt 以及 reboot 命令.我们会 ...
- zh-cn 与 zh-hans 是什么关系、有什么区别
回答一: 作者:知乎用户 链接:https://www.zhihu.com/question/21980689/answer/19923726 来源:知乎 著作权归作者所有.商业转载请联系作者获得授权 ...
- Linux_(1)基本命令(上)
一.基本命令1.我是谁 whoami --who am i2.谁在线 who w3.显示当前路径(定位) pwd4.切换目录 cd ~返回主目录 cd ..返回上一级目录5.查看某个目录中的子目录和文 ...
- Activity2.java
package com.hanqi.text3; import android.app.Activity; import android.os.Bundle; import android.os.Pe ...
- 常用的TCP Option
当前,TCP常用的Option如下所示———— Kind (Type) Length Name Reference 描述 & 用途 0 1 EOL RFC 793 选项列表结束 1 1 NOP ...
- What is MaxiSys Pro MS908P Software Advantage
The Autel Maxisys Pro Diagnostic Platform is an evolutionary smart solution for specialized automoti ...
- BZOJ 1874 取石子游戏 - SG函数
Description $N$堆石子, $M$种取石子的方式, 最后取石子的人赢, 问先手是否必胜 $A_i <= 1000$,$ B_i <= 10$ Solution 由于数据很小, ...
- Tinyos学习笔记(三)
读取Telosb内部传感器数据,并在计算机上显示. senseC.nc代码如下: #include "Timer.h" #include "sense.h" # ...
- 使用hMailServer搭建邮件服务器
本文没有什么高深的技术内容,只是使用hMailServer,介绍搭建邮件服务器的全过程,供参考. 一.安装邮件服务器组件 打开软件,点下一步 选择存储数据的数据库,这里有两种选择, 一种是使用嵌入型数 ...
- zookeeper和keepalived的区别
zookeeper主要就是为了保持数据的一致性来的,举个栗子,通俗点就是 本来是存储在各个服务器上的配置文件,现在我不存储在各个服务器上了,我就把全部配置文件都存储在zookeeper服务器上,应用服 ...