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 显示 ...
随机推荐
- 检测Android手机的IP地址
package com.jason.demo.androidip; import android.content.Context; import android.net.DhcpInfo; impor ...
- Excel怎么下拉框多选
打开Exlce, 确定,然后 右击查看代码,把这段代码复制到新建的文件里面 此时Excel会给出提示,选择否,,系统会提示保存,在保存的时候选择启用宏的工作簿然后保存,此时Excel下拉框多选就搞定了 ...
- jquery分页插件精选
1.最新的分页控件:Mricode.Pagination(推荐) https://github.com/mricle/Mricode.Pagination 2.Jquery Pagination Pl ...
- 时间处理:计算下一天日期,如输入"2004/12/31"(注释2014年12月31日),则输出"2005/1/1".
/* ============================================================================ Name : Exercise.c Au ...
- POJ3417 Network
一道LCA+树上差分 原题链接 显然每一条新增边都会导致环. 如果试着举些例子的话,很容易发现割掉非环上的边,则割掉其他任意一条新增边都可达成目标:若割掉的原有边是一个环上的边,那么只有割掉导致这个环 ...
- node.js 进程崩溃处理
process.on('uncaughtException', (err) => { console.error('有错误'); });
- JDK 之资源文件管理
JDK 之资源文件管理 JDK 规范目录(https://www.cnblogs.com/binarylei/p/10200503.html) 一.文件资源 user.home 用户目录,如 Linu ...
- java通过IP地址获取物理位置
import java.io.*; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern ...
- [ASP.NET]使用Oracle.ManagedDataAccess的OracleParameter参数化和OracleDataAdapter模糊查询
今天写个查询员工的信息的demo遇到了2个问题 问题1.使用Oracle.ManagedDataAccess的OracleParameter参数化 OracleParameter 的使用(参数名要以: ...
- Linux mount命令
mount 1.作用 mount命令的作用是加载文件系统,它的用权限是超级用户或/etc/fstab中允许的使用者. 2.格式 mount -a [-fv] [-t vfstype] [-n] [-r ...