systemctl/systemd 常用命令
01.检查systemd是否正在运行。
# ps -eaf | grep [s]ystemd
root 1 0 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd --switched-root --system --deserialize 23
root 444 1 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd-journald
root 469 1 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd-udevd
root 555 1 0 16:27 ? 00:00:00 /usr/lib/systemd/systemd-logind
dbus 556 1 0 16:27 ? 00:00:00 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
注意:systemd作为父守护进程运行(PID = 1)。 在上面的命令ps中使用(-e)选择所有进程,( - a)选择除会话前导之外的所有进程和(-f)选择完整格式列表(即-eaf)。
02.列出所有可用的单位
# systemctl list-unit-files
UNIT FILE STATE
proc-sys-fs-binfmt_misc.automount static
dev-hugepages.mount static
dev-mqueue.mount static
proc-sys-fs-binfmt_misc.mount static
sys-fs-fuse-connections.mount static
sys-kernel-config.mount static
sys-kernel-debug.mount static
tmp.mount disabled
brandbot.path disabled
.....
03、检查单元(cron.service)是否启用?
# systemctl is-enabled crond.service
enabled
04.检查单元或服务是否正在运行?
systemctl status firewalld.service
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)
Active: active (running) since Tue 2018-04-28 16:27:55 IST; 34min ago
Main PID: 549 (firewalld)
CGroup: /system.slice/firewalld.service
└─549 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
Apr 28 16:27:51 tecmint systemd[1]: Starting firewalld - dynamic firewall daemon...
Apr 28 16:27:55 tecmint systemd[1]: Started firewalld - dynamic firewall daemon.
05.列出所有服务(包括启用和禁用)
# systemctl list-unit-files --type=service
UNIT FILE STATE
arp-ethers.service disabled
auditd.service enabled
autovt@.service disabled
blk-availability.service disabled
brandbot.service static
collectd.service disabled
console-getty.service disabled
console-shell.service disabled
cpupower.service disabled
crond.service enabled
dbus-org.fedoraproject.FirewallD1.service enabled
06.如何在Linux中启动,重新启动,停止,重新加载和检查服务(httpd.service)的状态
# systemctl start httpd.service
# systemctl restart httpd.service
# systemctl stop httpd.service
# systemctl reload httpd.service
# systemctl status httpd.service
httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: active (running) since Tue 2018-04-28 17:21:30 IST; 6s ago
Process: 2876 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
Main PID: 2881 (httpd)
Status: "Processing requests..."
CGroup: /system.slice/httpd.service
├─2881 /usr/sbin/httpd -DFOREGROUND
├─2884 /usr/sbin/httpd -DFOREGROUND
├─2885 /usr/sbin/httpd -DFOREGROUND
├─2886 /usr/sbin/httpd -DFOREGROUND
├─2887 /usr/sbin/httpd -DFOREGROUND
└─2888 /usr/sbin/httpd -DFOREGROUND
Apr 28 17:21:30 tecmint systemd[1]: Starting The Apache HTTP Server...
Apr 28 17:21:30 tecmint httpd[2881]: AH00558: httpd: Could not reliably determine the server's fully q...ssage
Apr 28 17:21:30 tecmint systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.
注意:当我们使用systemctl等启动,重启,停止和重载等命令时,我们将不会在终端上获得任何输出,只有status命令会打印输出。
07.如何在引导时激活服务并启用或禁用服务(系统引导时自动启动服务)
# systemctl is-active httpd.service
# systemctl enable httpd.service
# systemctl disable httpd.service
实战
创建一个systemd服务
cd /etc/systemd/system
sudo nano ss2.service
ss2.service内容如下
[Unit]
Description=ss2 service
After=network.target
[Service]
Type=simple
ExecStart=/bin/bash /home/hl/sh/ss2.sh[Install]
WantedBy=multi-user.target
systemctl enable ss2
systemctl start ss2
小贴士:
Service types
There are several different start-up types to consider when writing a custom service file. This is set with the Type=
parameter in the [Service]
section:
Type=simple
(default): systemd considers the service to be started up immediately. The process must not fork. Do not use this type if other services need to be ordered on this service, unless it is socket activated.Type=forking
: systemd considers the service started up once the process forks and the parent has exited. For classic daemons use this type unless you know that it is not necessary. You should specifyPIDFile=
as well so systemd can keep track of the main process.Type=oneshot
: this is useful for scripts that do a single job and then exit. You may want to setRemainAfterExit=yes
as well so that systemd still considers the service as active after the process has exited.Type=notify
: identical toType=simple
, but with the stipulation that the daemon will send a signal to systemd when it is ready. The reference implementation for this notification is provided by libsystemd-daemon.so.Type=dbus
: the service is considered ready when the specifiedBusName
appears on DBus's system bus.Type=idle
: systemd will delay execution of the service binary until all jobs are dispatched. Other than that behavior is very similar toType=simple
.
See the systemd.service(5) § OPTIONS man page for a more detailed explanation of the Type
values.
systemctl/systemd 常用命令相关推荐
- systemctl的常用命令和使用说明
一.管理服务器 #重启: systemctl reboot #挂起: systemctl suspend #关机 systemctl halt.systemctl poweroff #休眠: syst ...
- Linux下netstat常用,Linux netstat常用命令
1.统计80端口连接数 netstat -nat|grep -i "80"|wc -l 2.统计httpd协议连接数(查看Apache的并发请求数及其TCP连接状态) ps -ef ...
- Linux 系统服务管理器(初始化系统/init system) -- systemd 及命令 systemctl 的详细介绍
文章目录 一.系统服务管理器 systemd (一)systemd 的特性 (二)systemd 与 传统 init 系统的区别 (三)systemd 的目录和文件 (四)systemd 的 Unit ...
- Linux中systemctl详细理解及常用命令
一.systemctl理解 Linux 服务管理两种方式service和systemctl systemd是Linux系统最新的初始化系统(init),作用是提高系统的启动速度,尽可能启动较少的进程, ...
- systemctl重新加载_linux中systemctl详细理解及常用命令
一.systemctl理解 Linux 服务管理两种方式service和systemctl systemd是Linux系统最新的初始化系统(init),作用是提高系统的启动速度,尽可能启动较少的进程, ...
- Docker(二)安装及常用命令
1.安装 1.安装虚拟机VMWare 链接:https://pan.baidu.com/s/1Xl7ENUm2gapPOFs-iXHpRQ 提取码:eubm 2.下载centos,我下的是这个版本的 ...
- haproxy服务启动命令_HaProxy安装和常用命令
安装haproxy 对于 haproxy 安装,网上有大量的资源可以参考,最常见的是使用 yum 和 编译安装两种方式. yum 安装 haproxy CentOS自带了haproxy,但可能版本比较 ...
- checksum linux 命令_linux常用命令总结
一.find命令 作用:查找文件 [root@server ~]# find / -name elasticsearch /var/log/elasticsearch /var/run/elastic ...
- Linux常用命令,超强万字总结!
来自:JAVA小咖秀 链接:https://juejin.im/post/5ee444ea6fb9a047ca10f796 ls 最高使用频率的命令之一. 命令格式: ls [OPTION]... ...
- kubernetes常用命令整理
一.维护类: master节点: [root@k8s-master01 -]# for I in etcd kube-apiserver kube-controller-manager kube-sc ...
最新文章
- python搭建可视化管理平台_搭建可视化数据平台 superset
- 学python好不好-学历低可以学python吗?好不好就业?
- linux diff(differential) 命令
- 使用gPXE网络启动引导ISO和安装ESXi5
- win10系统预览体验计划错误代码0x800bfa19怎么办
- html背景图适应div_CSS实现背景图片屏幕自适应
- java swing 删除事件_java swing清除事件队列
- [读书笔记]机器学习:实用案例解析(4)
- 数学图形(1.41)super spiral超级螺线
- 第八届蓝桥杯省赛C/C++本科B组真题解析
- 六石管理学:培训重点应该是工作技能
- C# 使用Microsoft.Reporting打印票据
- 运算放大器权威指南(第3版) (op amps for everyone)_OP高质量,ED多版本,有钱的动物狂想曲就是能为所欲为...
- 最新oss对象储存防红直连 防红代码html静态页面
- html中的em的使用方法,css布局的em的使用方法
- ACE库中ACE_Msg_Log日志对象浅论
- DS1042C数字示波器的波形截图流程
- 操作系统第三次实验——线程基础总结
- 数据库having的用法详细介绍
- 解决导出Excel报COM类工厂错误的办法--修改版
热门文章
- 终于理解你的软件 搞那么多年了 (通用权限管理系统组件源码完善了7-8年)
- Scott Mitchell 的ASP.NET 2.0数据操作教程之九:跨页面的主/从报表
- js基础-13-常见DOM操作
- Eclipse使用Git上传新项目到GitHub
- oracle 关系 表 视图_在Oracle数据库中,表和视图的区别与联系
- odp.net连接oracle9i 出错解决_架构师成长之路:Kafka连接器深度解读之错误处理和死信队列...
- Introduction to Computer Networking学习笔记(十一):flow control 滑动窗口详解
- c语言i=5.6a=(int)i,(PSIM仿真)从零开始设计BOOST数字控制器
- C# fmpeg加虹软的人脸识别demo
- 微信客服系统开发SDK使用教程-给好友发消息任务