如何查看通过 systemctl 命令启动的服务的日志
Created|Updated|编程文摘
|Post Views:
systemctl 是 Linux 系统服务管理工具,它可以用来启动、停止、重启、启用或禁用系统服务。当我们启动一个服务时,systemctl 会记录服务的启动日志,我们可以通过查看这些日志来排查服务启动时的问题。
查看 systemctl 服务日志的步骤如下:
找到服务的完整名称。系统服务的名称通常以 .service 结尾,例如 httpd.service、mysql.service 等。
使用
journalctl命令查看服务的日志。命令格式为:
1 | journalctl -u <服务名称> |
将 <服务名称> 替换为服务的完整名称。例如,要查看 httpd 服务的日志,运行:
1 | journalctl -u httpd.service |
journalctl会输出服务的启动日志、运行日志和停止日志。
(END)
Author: Johnson Lin
Copyright Notice: All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.
Related Articles
2023-04-21
Ubuntu 20.04 systemctl 错误:System has not been booted with systemd as init system (PID 1). Can't operate.
在 Ubuntu 20.04 系统中,使用 systemctl 命令启动 logstash,出现以下错误: 123$ systemctl start logstashSystem has not been booted with systemd as init system (PID 1). Can't operate.Failed to connect to bus: Host is down 这是因为 systemctl 不是 Ubuntu 系统自带的命令,可以通过 apt 命令进行安装: 1sudo apt install systemctl 安装过程中,会提示你输入 Yes, do as I say! 以继续安装。 (END)
2024-08-16
A Deep Dive into the apt Command: Linux Package Management Simplified
The apt command is a powerful tool used for managing packages on Debian-based Linux distributions such as Ubuntu. It simplifies the process of installing, updating, and removing software packages. Whether you’re a beginner or an experienced user, mastering the apt command can greatly enhance your Linux experience. In this guide, we’ll explore some of the most commonly used apt commands with practical examples. Syntax1apt [options] [command] [package ...] Options: Optional settings, such as -...
2023-04-24
Ubuntu 20.04 上安装 pip3.7 错误:ModuleNotFoundError: No module named 'distutils.cmd'
我在 Ubuntu 20.04 系统上已经安装好 python3.7,然后手动安装 pip: 首先,下载 get-pip.py 文件: 1wget https://bootstrap.pypa.io/get-pip.py 然后等该文件下载完后,使用以下命令安装 pip: 1python3.7 get-pip.py 结果出现以下错误信息: 1234567891011121314151617181920$ python3.7 get-pip.pyTraceback (most recent call last): File "get-pip.py", line 32321, in <module> main() File "get-pip.py", line 135, in main bootstrap(tmpdir=tmpdir) File "get-pip.py", line 111, in bootstrap monkeypatch_for_cert(tmpdir) File ...
2023-04-03
Linux 常用命令 | pwgen 详解
pwgen 是一个生成密码的小工具,可以通过参数生成满足各种条件的密码,如生成的密码至少要包含一个特殊字符,或生成的密码不要包含数字,或生成长度为 16 的密码等。 安装在 Ubuntu 操作系统,可以直接通过 apt-get 方式安装: 1apt-get install pwgen 在 CentOS 操作系统,需要先安装 epel-release 软件包后才能使用 yum 方式安装 pwgen。 安装 epel-release: 1yum install -y epel-release 安装 pwgen: 1yum install -y pwgen 用法1pwgen [ 选项 ] [ 密码长度 ] [ 密码数量 ] 例如,生成 4 个长度为 8 的密码: 1pwgen 8 4 结果如下: 12$ pwgen 8 4Hah8eeth ies6Yuxu iemoo1Ko aeB7shu4 pwgen 支持的选项 选项 说明 -c 或 —capitalize 在密码中至少包含一个大写字母 -A 或 —no-capitalize 不在密码中包含大写字母 -n 或 ...
2024-08-15
Understanding the "chattr: Inappropriate ioctl for device while reading flags" Error
If you’ve encountered the error message chattr: Inappropriate ioctl for device while reading flags on /etc/nginx/conf.d/test.conf, you’re not alone. This error can be confusing, especially if you’re not familiar with the chattr command and its uses. Let’s break down what this error means and how to resolve it. What is the chattr Command?The chattr (change attribute) command in Linux is used to change file attributes on files and directories. These attributes can control various aspects of fil...
2023-03-22
Linux 常用命令 | head 详解
Linux 命令行工具提供了足够丰富的命令用于管理服务器上的文件和目录。其中最常用的命令之一是 head,它允许我们只查看文件的前几行内容,这在查看超大文件(文件大小为几个 GB 以上)时尤其有用。在这篇博文中,我们将详细讨论该命令的使用说明、注意事项、技巧窍门等,以充分利用该命令。 使用说明head 命令用于显示一个文件的前几行。要使用该命令,只需输入 head 和你想查看的文件名即可。例如,要查看一个名为 example.log 的文件的前10行,你可以输入以下命令: 1head -n 10 example.log 其中,-n 选项用于指定要查看的行数。如果不指定数字,它将默认为 10 行。还可以使用 - 号来表示除了文件最后多少行外输出所有行内容。例如,要查看文件的所有行,但不包括最后的 11 行,可以输入以下命令: 1head -n -11 example.log 注意事项在使用 head 命令时,有两个地方需要注意: 首先,注意不要使用 > 操作符意外覆盖原来的文件。例如,执行以下命令会导致 example.log 文件被其前 10 行的内容覆盖,相当于 exam...