<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Systemd on HiDa</title><link>https://www.0niu.cn/tags/systemd/</link><description>Recent content in Systemd on HiDa</description><generator>Hugo -- gohugo.io</generator><language>zh</language><lastBuildDate>Thu, 08 May 2025 10:16:00 +0800</lastBuildDate><atom:link href="https://www.0niu.cn/tags/systemd/index.xml" rel="self" type="application/rss+xml"/><item><title>使用 resolvectl 临时指定 DNS 服务器</title><link>https://www.0niu.cn/posts/resolvectl-temporary-dns/</link><pubDate>Thu, 08 May 2025 10:16:00 +0800</pubDate><guid>https://www.0niu.cn/posts/resolvectl-temporary-dns/</guid><description>&lt;p>在日常运维中，我们经常需要临时切换 DNS 服务器来排查域名解析问题。传统做法是修改 &lt;code>/etc/resolv.conf&lt;/code>，但在使用 systemd-resolved 的现代 Linux 发行版中，&lt;code>resolvectl&lt;/code> 提供了更优雅的解决方案。&lt;/p></description><content>&lt;p>在日常运维中，我们经常需要临时切换 DNS 服务器来排查域名解析问题。传统做法是修改 &lt;code>/etc/resolv.conf&lt;/code>，但在使用 systemd-resolved 的现代 Linux 发行版中，&lt;code>resolvectl&lt;/code> 提供了更优雅的解决方案。&lt;/p>
&lt;h2 id="为什么用-resolvectl">为什么用 resolvectl&lt;/h2>
&lt;p>传统的修改 &lt;code>/etc/resolv.conf&lt;/code> 方式有几个痛点：&lt;/p>
&lt;ul>
&lt;li>&lt;strong>systemd-resolved 管理下会被覆盖&lt;/strong>：直接编辑 &lt;code>/etc/resolv.conf&lt;/code> 可能无效，因为该文件是一个指向 &lt;code>/run/systemd/resolve/stub-resolv.conf&lt;/code> 的符号链接&lt;/li>
&lt;li>&lt;strong>需要 root 权限&lt;/strong>：编辑系统文件必须 sudo&lt;/li>
&lt;li>&lt;strong>容易忘记还原&lt;/strong>：排查完问题后忘记改回来，可能影响业务&lt;/li>
&lt;/ul>
&lt;p>而 &lt;code>resolvectl&lt;/code> 的优势：&lt;/p>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>特性&lt;/th>
&lt;th>传统方式&lt;/th>
&lt;th>resolvectl&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>修改配置文件&lt;/td>
&lt;td>✅&lt;/td>
&lt;td>❌&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>需要 root&lt;/td>
&lt;td>✅&lt;/td>
&lt;td>❌（per-link）&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>重启后恢复&lt;/td>
&lt;td>需手动还原&lt;/td>
&lt;td>✅ 自动恢复&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>影响范围&lt;/td>
&lt;td>全局&lt;/td>
&lt;td>可按网卡控制&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="查看当前-dns-状态">查看当前 DNS 状态&lt;/h2>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 查看全局 DNS 配置&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>resolvectl status
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 查看指定网卡&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>resolvectl status eth0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 查看当前生效的 DNS 服务器&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>resolvectl dns
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>输出示例：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-fallback" data-lang="fallback">&lt;span style="display:flex;">&lt;span>Global
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Resolving DNS Servers: 192.168.1.1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Fallback DNS Servers: 8.8.8.8
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Link 2 (eth0)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Current Scopes: DNS
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> Protocols: +LLMNR +mDNS -DNSOverTLS DNSSEC=no/unsupported
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Resolving DNS Servers: 192.168.1.1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> DNS Domain: lan
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="临时指定-dnsper-link">临时指定 DNS（per-link）&lt;/h2>
&lt;h3 id="指定单网卡-dns">指定单网卡 DNS&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 将 eth0 的 DNS 指定为 Google DNS&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo resolvectl dns eth0 8.8.8.8
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 指定多个 DNS（主备）&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo resolvectl dns eth0 8.8.8.8 1.1.1.1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 指定国内 DNS&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo resolvectl dns eth0 223.5.5.5 119.29.29.29
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="验证生效">验证生效&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 查看当前 DNS&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>resolvectl dns eth0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 测试解析&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>resolvectl query example.com
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 使用指定 DNS 解析&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>resolvectl query example.com --interface&lt;span style="color:#f92672">=&lt;/span>eth0
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="恢复默认-dns">恢复默认 DNS&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 恢复为空（回退到全局配置）&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo resolvectl dns eth0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 恢复为 DHCP 下发的 DNS&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo resolvectl revert eth0
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="全局临时指定-dns">全局临时指定 DNS&lt;/h2>
&lt;p>如果需要全局修改（影响所有网卡）：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 设置全局 DNS&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo resolvectl dns 8.8.8.8 1.1.1.1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 恢复全局 DNS&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo resolvectl dns
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;blockquote>
&lt;p>⚠️ 全局修改同样会在重启后恢复，但会影响所有网卡的 DNS 解析。&lt;/p>
&lt;/blockquote>
&lt;h2 id="常用国内公共-dns">常用国内公共 DNS&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>DNS 服务商&lt;/th>
&lt;th>地址&lt;/th>
&lt;th>说明&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>阿里&lt;/td>
&lt;td>223.5.5.5 / 223.6.6.6&lt;/td>
&lt;td>稳定快速&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>腾讯&lt;/td>
&lt;td>119.29.29.29&lt;/td>
&lt;td>DNSPod&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>百度&lt;/td>
&lt;td>180.76.76.76&lt;/td>
&lt;td>-&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>114 DNS&lt;/td>
&lt;td>114.114.114.114&lt;/td>
&lt;td>老牌公共 DNS&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Google&lt;/td>
&lt;td>8.8.8.8 / 8.8.4.4&lt;/td>
&lt;td>海外推荐&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>Cloudflare&lt;/td>
&lt;td>1.1.1.1 / 1.0.0.1&lt;/td>
&lt;td>海外&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="实战场景">实战场景&lt;/h2>
&lt;h3 id="场景一排查域名解析故障">场景一：排查域名解析故障&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 1. 查看当前 DNS&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>resolvectl dns
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 2. 临时切换到公共 DNS 验证&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo resolvectl dns eth0 223.5.5.5
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 3. 测试解析&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>resolvectl query api.example.com
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 4. 如果公共 DNS 正常，说明内网 DNS 有问题&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 5. 恢复原配置&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo resolvectl revert eth0
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="场景二测试-dohdot">场景二：测试 DoH/DoT&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 查看是否支持 DNS over TLS&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>resolvectl status | grep -i tls
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 开启 DNS over TLS（需要 DNS 服务器支持）&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo resolvectl dns-over-tls eth0 yes
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo resolvectl dns eth0 tls://dns.google
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="场景三多网卡环境指定-dns">场景三：多网卡环境指定 DNS&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># eth0 走内网 DNS&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo resolvectl dns eth0 192.168.1.1
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># eth1 走公共 DNS&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo resolvectl dns eth1 223.5.5.5
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 查询时指定网卡&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>resolvectl query internal.example.com --interface&lt;span style="color:#f92672">=&lt;/span>eth0
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>resolvectl query www.0niu.cn --interface&lt;span style="color:#f92672">=&lt;/span>eth1
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="注意事项">注意事项&lt;/h2>
&lt;ol>
&lt;li>&lt;strong>临时性&lt;/strong>：&lt;code>resolvectl&lt;/code> 的修改在系统重启后会自动恢复为配置文件中的默认值&lt;/li>
&lt;li>&lt;strong>与 NetworkManager 冲突&lt;/strong>：如果使用 NetworkManager 管理 DNS，可能会被 NM 覆盖，可以设置 &lt;code>NM_CONTROLLED=no&lt;/code> 或在 NM 配置中指定 DNS&lt;/li>
&lt;li>&lt;strong>systemd-resolved 必须运行&lt;/strong>：确认服务状态 &lt;code>systemctl status systemd-resolved&lt;/code>&lt;/li>
&lt;li>&lt;strong>域名搜索后缀&lt;/strong>：可以使用 &lt;code>resolvectl domain eth0 example.com&lt;/code> 临时添加搜索域&lt;/li>
&lt;/ol>
&lt;h2 id="总结">总结&lt;/h2>
&lt;p>&lt;code>resolvectl&lt;/code> 是 systemd-resolved 提供的 DNS 管理工具，用于临时切换 DNS 非常方便：&lt;/p>
&lt;ul>
&lt;li>✅ 无需修改配置文件&lt;/li>
&lt;li>✅ 重启自动恢复&lt;/li>
&lt;li>✅ 可按网卡粒度控制&lt;/li>
&lt;li>✅ 支持 DNS over TLS&lt;/li>
&lt;/ul>
&lt;p>下次排查 DNS 问题时，不妨试试 &lt;code>resolvectl&lt;/code>。&lt;/p></content></item><item><title>Prometheus 监控平台搭建</title><link>https://www.0niu.cn/posts/prometheus%E7%9B%91%E6%8E%A7%E5%B9%B3%E5%8F%B0%E6%90%AD%E5%BB%BA/</link><pubDate>Thu, 06 Mar 2025 10:43:00 +0800</pubDate><guid>https://www.0niu.cn/posts/prometheus%E7%9B%91%E6%8E%A7%E5%B9%B3%E5%8F%B0%E6%90%AD%E5%BB%BA/</guid><description>&lt;p>本文介绍如何在 Linux 系统上搭建 Prometheus 监控平台。&lt;/p>
&lt;h2 id="安装步骤">安装步骤&lt;/h2>
&lt;h3 id="1-下载并解压-prometheus">1. 下载并解压 Prometheus&lt;/h3>
&lt;p>下载预编译的 Prometheus tar 包并解压到 &lt;code>/opt/prometheus&lt;/code> 文件夹：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 下载最新版本的 Prometheus&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>wget https://github.com/prometheus/prometheus/releases/download/v*/prometheus-*.linux-amd64.tar.gz
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 解压到指定目录&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>tar xzf prometheus-*.linux-amd64.tar.gz
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>mkdir -p /opt/prometheus
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cd prometheus-*.linux-amd64
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cp prometheus promtool /opt/prometheus/
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cp -r consoles prometheus.yml /opt/prometheus/
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="2-创建系统用户和数据目录">2. 创建系统用户和数据目录&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 创建 prometheus 用户&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo useradd --no-create-home --shell /bin/false prometheus
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 创建数据目录&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo mkdir -p /app/prometheus/data
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo chown -R prometheus:prometheus /app/prometheus
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description><content>&lt;p>本文介绍如何在 Linux 系统上搭建 Prometheus 监控平台。&lt;/p>
&lt;h2 id="安装步骤">安装步骤&lt;/h2>
&lt;h3 id="1-下载并解压-prometheus">1. 下载并解压 Prometheus&lt;/h3>
&lt;p>下载预编译的 Prometheus tar 包并解压到 &lt;code>/opt/prometheus&lt;/code> 文件夹：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 下载最新版本的 Prometheus&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>wget https://github.com/prometheus/prometheus/releases/download/v*/prometheus-*.linux-amd64.tar.gz
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 解压到指定目录&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>tar xzf prometheus-*.linux-amd64.tar.gz
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>mkdir -p /opt/prometheus
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cd prometheus-*.linux-amd64
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cp prometheus promtool /opt/prometheus/
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cp -r consoles prometheus.yml /opt/prometheus/
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="2-创建系统用户和数据目录">2. 创建系统用户和数据目录&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 创建 prometheus 用户&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo useradd --no-create-home --shell /bin/false prometheus
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 创建数据目录&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo mkdir -p /app/prometheus/data
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo chown -R prometheus:prometheus /app/prometheus
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="3-编写-systemd-服务文件">3. 编写 Systemd 服务文件&lt;/h3>
&lt;p>创建服务文件 &lt;code>/etc/systemd/system/prometheus.service&lt;/code>：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-ini" data-lang="ini">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">[Unit]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">Description&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">Prometheus Monitoring&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">After&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">network-online.target&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">Wants&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">network-online.target&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">[Service]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">User&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">prometheus&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">WorkingDirectory&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">/app/prometheus&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">Restart&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">on-failure&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">RestartSec&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">5s&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">ExecStart&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">/opt/prometheus/prometheus \
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74"> --config.file=/opt/prometheus/prometheus.yml \
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#e6db74"> --storage.tsdb.path=/app/prometheus/data&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Security hardening&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">NoNewPrivileges&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">true&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">ProtectSystem&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">strict&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">ProtectHome&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">true&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">ReadWritePaths&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">/app/prometheus/data&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># Resource limits&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">MemoryMax&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">4G&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">[Install]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">WantedBy&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">multi-user.target&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="4-修改-selinux-配置">4. 修改 SELinux 配置&lt;/h3>
&lt;p>如果系统启用了 SELinux，需要调整上下文：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo restorecon -Rv /etc/systemd/system/
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo chcon -t bin_t /opt/prometheus/prometheus
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="5-启动服务">5. 启动服务&lt;/h3>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 重新加载 systemd 配置&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo systemctl daemon-reload
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 启用并启动 Prometheus&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo systemctl enable --now prometheus
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 检查服务状态&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo systemctl status prometheus
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="验证安装">验证安装&lt;/h2>
&lt;p>访问 &lt;code>http://服务器IP:9090&lt;/code> 查看 Prometheus Web 界面。&lt;/p>
&lt;h2 id="配置文件">配置文件&lt;/h2>
&lt;p>主配置文件位于 &lt;code>/opt/prometheus/prometheus.yml&lt;/code>，根据需要添加监控目标和告警规则。&lt;/p>
&lt;h2 id="参考资料">参考资料&lt;/h2>
&lt;ul>
&lt;li>&lt;a href="https://prometheus.io/docs/">Prometheus 官方文档&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/prometheus/prometheus/releases">Prometheus GitHub Releases&lt;/a>&lt;/li>
&lt;/ul></content></item><item><title>Linux 笔记本电脑合上盖子不休眠设置</title><link>https://www.0niu.cn/posts/linux-laptop-lid-close-no-suspend/</link><pubDate>Sun, 25 Nov 2018 16:13:02 +0800</pubDate><guid>https://www.0niu.cn/posts/linux-laptop-lid-close-no-suspend/</guid><description>&lt;h2 id="概述">概述&lt;/h2>
&lt;p>默认情况下，Linux 笔记本电脑在合上盖子时会进入休眠/挂起状态。但在某些场景下，我们希望合上盖子后系统继续运行，例如：&lt;/p>
&lt;ul>
&lt;li>连接外接显示器使用笔记本作为主机&lt;/li>
&lt;li>运行下载任务或服务器服务&lt;/li>
&lt;li>合盖后继续编译或渲染任务&lt;/li>
&lt;li>作为家庭服务器使用&lt;/li>
&lt;/ul>
&lt;h2 id="解决方法">解决方法&lt;/h2>
&lt;p>通过修改 &lt;code>systemd-logind&lt;/code> 配置文件即可实现合盖不休眠。&lt;/p>
&lt;h3 id="步骤">步骤&lt;/h3>
&lt;p>&lt;strong>1. 编辑配置文件&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo vi /etc/systemd/logind.conf
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>2. 修改配置项&lt;/strong>&lt;/p>
&lt;p>找到以下行：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-ini" data-lang="ini">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#HandleLidSwitch=suspend&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>取消注释并修改为：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-ini" data-lang="ini">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">HandleLidSwitch&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">ignore&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>3. 可选：同时配置其他相关选项&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-ini" data-lang="ini">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 合上盖子时忽略（不休眠）&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">HandleLidSwitch&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">ignore&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 合上盖子并连接电源时忽略&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">HandleLidSwitchExternalPower&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">ignore&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 合上盖子并仅使用电池时忽略&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">HandleLidSwitchDocked&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">ignore&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>4. 重启系统或重启 systemd-logind 服务&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 方法一：重启系统&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo reboot
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 方法二：重启 systemd-logind 服务（无需重启）&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo systemctl restart systemd-logind
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description><content>&lt;h2 id="概述">概述&lt;/h2>
&lt;p>默认情况下，Linux 笔记本电脑在合上盖子时会进入休眠/挂起状态。但在某些场景下，我们希望合上盖子后系统继续运行，例如：&lt;/p>
&lt;ul>
&lt;li>连接外接显示器使用笔记本作为主机&lt;/li>
&lt;li>运行下载任务或服务器服务&lt;/li>
&lt;li>合盖后继续编译或渲染任务&lt;/li>
&lt;li>作为家庭服务器使用&lt;/li>
&lt;/ul>
&lt;h2 id="解决方法">解决方法&lt;/h2>
&lt;p>通过修改 &lt;code>systemd-logind&lt;/code> 配置文件即可实现合盖不休眠。&lt;/p>
&lt;h3 id="步骤">步骤&lt;/h3>
&lt;p>&lt;strong>1. 编辑配置文件&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>sudo vi /etc/systemd/logind.conf
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>2. 修改配置项&lt;/strong>&lt;/p>
&lt;p>找到以下行：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-ini" data-lang="ini">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#HandleLidSwitch=suspend&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>取消注释并修改为：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-ini" data-lang="ini">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">HandleLidSwitch&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">ignore&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>3. 可选：同时配置其他相关选项&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-ini" data-lang="ini">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 合上盖子时忽略（不休眠）&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">HandleLidSwitch&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">ignore&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 合上盖子并连接电源时忽略&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">HandleLidSwitchExternalPower&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">ignore&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 合上盖子并仅使用电池时忽略&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">HandleLidSwitchDocked&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">ignore&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;strong>4. 重启系统或重启 systemd-logind 服务&lt;/strong>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 方法一：重启系统&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo reboot
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 方法二：重启 systemd-logind 服务（无需重启）&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sudo systemctl restart systemd-logind
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h2 id="验证配置">验证配置&lt;/h2>
&lt;p>修改完成后，可以使用以下命令验证配置是否生效：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 查看当前 logind 配置&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>loginctl show | grep HandleLid
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 查看配置是否已加载&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>systemctl show systemd-logind | grep HandleLid
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>预期输出应包含 &lt;code>HandleLidSwitch=ignore&lt;/code>。&lt;/p>
&lt;h2 id="恢复默认设置">恢复默认设置&lt;/h2>
&lt;p>如需恢复合盖休眠的默认行为，将配置改回：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-ini" data-lang="ini">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#a6e22e">HandleLidSwitch&lt;/span>&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">suspend&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>然后重启服务或系统即可。&lt;/p>
&lt;h2 id="注意事项">注意事项&lt;/h2>
&lt;p>⚠️ &lt;strong>重要提醒：&lt;/strong>&lt;/p>
&lt;ol>
&lt;li>&lt;strong>散热问题&lt;/strong>：合盖后继续运行可能导致散热不良，尤其是高性能任务时&lt;/li>
&lt;li>&lt;strong>电池消耗&lt;/strong>：不休眠会持续消耗电池电量&lt;/li>
&lt;li>&lt;strong>屏幕保护&lt;/strong>：合盖后屏幕会自动关闭，这是正常现象&lt;/li>
&lt;li>&lt;strong>外接显示器&lt;/strong>：如使用外接显示器，建议同时设置 &lt;code>HandleLidSwitchExternalPower=ignore&lt;/code>&lt;/li>
&lt;/ol>
&lt;h2 id="其他相关配置">其他相关配置&lt;/h2>
&lt;table>
&lt;thead>
&lt;tr>
&lt;th>配置项&lt;/th>
&lt;th>可选值&lt;/th>
&lt;th>说明&lt;/th>
&lt;/tr>
&lt;/thead>
&lt;tbody>
&lt;tr>
&lt;td>HandleLidSwitch&lt;/td>
&lt;td>ignore/suspend/hibernate/lock&lt;/td>
&lt;td>合盖时的行为&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>HandleLidSwitchExternalPower&lt;/td>
&lt;td>ignore/suspend/hibernate/lock&lt;/td>
&lt;td>连接电源时合盖的行为&lt;/td>
&lt;/tr>
&lt;tr>
&lt;td>HandleLidSwitchDocked&lt;/td>
&lt;td>ignore/suspend/hibernate/lock&lt;/td>
&lt;td>对接状态下合盖的行为&lt;/td>
&lt;/tr>
&lt;/tbody>
&lt;/table>
&lt;h2 id="故障排查">故障排查&lt;/h2>
&lt;p>如果修改后仍然休眠，检查：&lt;/p>
&lt;ol>
&lt;li>配置是否正确保存（无语法错误）&lt;/li>
&lt;li>是否重启了 &lt;code>systemd-logind&lt;/code> 服务或系统&lt;/li>
&lt;li>是否有其他电源管理工具冲突（如 TLP、powertop）&lt;/li>
&lt;li>查看系统日志：&lt;code>journalctl -u systemd-logind&lt;/code>&lt;/li>
&lt;/ol></content></item></channel></rss>