如何查看通过 systemctl 命令启动的服务的日志
发表于|更新于|编程文摘
|浏览量:
systemctl 是 Linux 系统服务管理工具,它可以用来启动、停止、重启、启用或禁用系统服务。当我们启动一个服务时,systemctl 会记录服务的启动日志,我们可以通过查看这些日志来排查服务启动时的问题。
查看 systemctl 服务日志的步骤如下:
找到服务的完整名称。系统服务的名称通常以 .service 结尾,例如 httpd.service、mysql.service 等。
使用
journalctl命令查看服务的日志。命令格式为:
1 | journalctl -u <服务名称> |
将 <服务名称> 替换为服务的完整名称。例如,要查看 httpd 服务的日志,运行:
1 | journalctl -u httpd.service |
journalctl会输出服务的启动日志、运行日志和停止日志。
(END)
文章作者: Johnson Lin
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 Johnson Lin!
相关推荐
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-14
Troubleshooting "chattr: Operation not permitted while setting flags"
I’m trying to set an immutable attribute on some files in my home directory, but I keep encountering issues: chattr: Operation not permitted while setting flags on /data/ops/app.conf.12$ chattr +i /data/ops/app.confchattr: Operation not permitted while setting flags on /data/ops/app.confFrom the chattr man page: A file with the ‘i’ attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file, most of the file’s metadata can not be modified, and the file ...
2023-04-26
Ubuntu 20.04 apt upgrade Error: Could not read response to hello message from hook
当我运行 sudo apt upgrade 命令以更新 Ubuntu 子系统(WSL)中的软件包时,出现了以下错误: 123456789101112131415161718$ sudo apt upgradeReading package lists... DoneBuilding dependency treeReading state information... DoneCalculating upgrade... DoneThe following packages were automatically installed and are no longer required: ant ant-optional gdisk gir1.2-packagekitglib-1.0 jruby-openssl junit4 libappstream4 libasm-java libatasmart4 libbcpkix-java libbcprov-java libblockdev-crypto2 libblockdev-fs2 libblockdev-loop2 libbl...
2022-06-27
【Linux常用命令】查看主机名
主机名(英语:hostname),也称计算机名,是指分配给计算机的一串唯一标识码,用于在网络上唯一识别该计算机。通常由字母、数字组成,也可以包含一些特殊字符,如英文连字符(-)、英文句点(.)和下划线(_)。典型的主机名最多包含 253 个字符。 在大多数 Linux 发行版中,主机名通常存储在 /etc/hostname 文件中。默认情况下,通过 ssh 命令在终端成功连接到目标服务器时,也可以看到目标服务器的主机名。如以下命令可以看到目标服务器的主机名为 kafka-eagle。 123456$ ssh hadoop@10.10.18.8Last login: Fri May 13 20:50:56 2022 from 10.10.18.215Welcome to Alibaba Cloud Elastic Compute Service ![hadoop@kafka-eagle ~]$ 介绍完主机名的概念,接下来,我们一起了解在 Linux 操作系统中其他各种查找主机名的命令。 使用 hostname 命令hostname 命令用于显示 Linux 系统的 DNS 名称和主...
2023-04-27
Ubuntu 20.04 安装 Python3.7
对于 Ubuntu 用户来说,安装 Python 3.7 的最简单方法是使用 deadsnakes PPA。它提供了对 Python 的最新更新和任何其他所需软件包的访问。 安装 Python3.7添加 PPA 源: 1sudo add-apt-repository ppa:deadsnakes/ppa -y 添加完 PPA 源后,需要运行 apt 更新: 1sudo apt update 安装 Python3.7: 1sudo apt install python3.7 验证 Python 版本: 1python3.7 --version 至此,就已经成功安装了 Python 3.7。 如果还想为 Python 3.7 安装额外的工具,例如调试模块、开发者模块、虚拟环境模块、Distutils 模块、lib2to3 工具模块、DBM.GNU 模块和 Tkinter 模块,可以运行以下命令: 1sudo apt install python3.7-dbg python3.7-dev python3.7-venv python3.7-distutils python3.7-lib2...

2024-06-05
Finding the Hostname in Linux: A Guide to Common Methods
Finding the hostname in Linux can be done in a few different ways, depending on your specific needs and the Linux distribution you’re using. Here are a few common methods: 1. Using the hostname CommandThe simplest way to find the hostname of your Linux system is to use the hostname command in your terminal. Simply open a terminal window and type:1hostnameThis command will display the hostname of your system.For example:12$ hostnamepresto-node-10 2. Using the uname CommandWhile the uname comma...
