<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Linux - Category - MenmaTop</title><link>https://menma.top/categories/linux/</link><description>Linux - Category - MenmaTop</description><generator>Hugo -- gohugo.io</generator><language>zh-CN</language><lastBuildDate>Sat, 11 Apr 2026 18:35:48 +0800</lastBuildDate><atom:link href="https://menma.top/categories/linux/" rel="self" type="application/rss+xml"/><item><title>linux修改默认网卡名为eth0</title><link>https://menma.top/posts/linux/2026/04/linux%E4%BF%AE%E6%94%B9%E9%BB%98%E8%AE%A4%E7%BD%91%E5%8D%A1%E5%90%8D%E4%B8%BAeth0/</link><pubDate>Sat, 11 Apr 2026 18:35:48 +0800</pubDate><author>mona</author><guid>https://menma.top/posts/linux/2026/04/linux%E4%BF%AE%E6%94%B9%E9%BB%98%E8%AE%A4%E7%BD%91%E5%8D%A1%E5%90%8D%E4%B8%BAeth0/</guid><description><![CDATA[<h3 id="第一步修改内核引导参数">第一步：修改内核引导参数</h3>
<p>我们需要告诉内核禁用“一致性网络设备命名”规则。</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># 1. 备份并修改 GRUB 配置文件</span>
</span></span><span class="line"><span class="cl">sed -i <span class="s1">&#39;s/GRUB_CMDLINE_LINUX=&#34;&#34;/GRUB_CMDLINE_LINUX=&#34;net.ifnames=0 biosdevname=0&#34;/&#39;</span> /etc/default/grub
</span></span><span class="line"><span class="cl"><span class="c1"># 如果原本这一行就有内容，请手动编辑 /etc/default/grub </span>
</span></span><span class="line"><span class="cl"><span class="c1"># 将 net.ifnames=0 biosdevname=0 添加到引号内</span></span></span></code></pre></div></div>
<h3 id="第二步更新-grub-并使配置生效">第二步：更新 GRUB 并使配置生效</h3>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">update-grub</span></span></code></pre></div></div>
<h3 id="第三步修改网络接口配置文件">第三步：修改网络接口配置文件</h3>
<p>这一步至关重要，必须将配置文件里的 <code>ens17</code> 全部替换为 <code>eth0</code>，否则重启后系统找不到网卡。</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># 3. 备份原始配置文件（万一出故障可以还原）</span>
</span></span><span class="line"><span class="cl">cp /etc/network/interfaces /etc/network/interfaces.bak
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># 4. 使用 sed 批量替换 ens17 为 eth0</span>
</span></span><span class="line"><span class="cl">sed -i <span class="s1">&#39;s/ens17/eth0/g&#39;</span> /etc/network/interfaces</span></span></code></pre></div></div>
<hr>
<h3 id="第四步检查并重启">第四步：检查并重启</h3>
<p>在重启之前，请务必确认文件修改正确：</p>]]></description></item><item><title>优化VPS网络</title><link>https://menma.top/posts/linux/2026/03/%E4%BC%98%E5%8C%96vps%E7%BD%91%E7%BB%9C/</link><pubDate>Wed, 25 Mar 2026 22:59:00 +0800</pubDate><author>mona</author><guid>https://menma.top/posts/linux/2026/03/%E4%BC%98%E5%8C%96vps%E7%BD%91%E7%BB%9C/</guid><description><![CDATA[<h2 id="计算tcp最大窗口大小">计算TCP最大窗口大小</h2>
<p>依据<a href="https://blog.cloudflare.com/optimizing-tcp-for-high-throughput-and-low-latency/" target="_blank" rel="noopener noreffer ">cloudflare博客</a>计算BDP，以美西为例：带宽取1000Mbps延迟取200ms</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><pre tabindex="0"><code>BDP = 125MB/s × 0.2s = 25MB</code></pre></div>
<p>得到25MB四舍五入为32MB。</p>
<p>由于 Linux 自动调优能够正确调整 RTT 较低的会话和吞吐量较低的瓶颈链路，我们只需要调整最大值即可（其他值为默认）。</p>
<p><code>tcp_adv_win_scale</code> 使用默认的1。最大窗口大小为最大缓冲区空间的二分之一，所以需要将最大窗口大小设置为64M。</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><pre tabindex="0"><code>net.ipv4.tcp_rmem = 4096 131072 67108864
net.ipv4.tcp_wmem = 4096 16384 67108864</code></pre></div>
<hr>
<h2 id="开启bbr">开启BBR</h2>
<p>在bbr打开时，如果长连接比较多 设置<code>net.ipv4.tcp_slow_start_after_idle = 0</code>这样子空闲一段时间，之前bbr估算的拥塞窗口大小也不会从头探测</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><pre tabindex="0"><code>net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
net.ipv4.tcp_slow_start_after_idle = 0</code></pre></div>
<hr>
<h2 id="最终参数">最终参数</h2>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><pre tabindex="0"><code>net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
net.ipv4.tcp_rmem = 4096 131072 67108864
net.ipv4.tcp_wmem = 4096 16384 67108864
net.ipv4.tcp_notsent_lowat = 131072
net.ipv4.tcp_slow_start_after_idle = 0</code></pre></div>]]></description></item><item><title>Linux定时任务</title><link>https://menma.top/posts/linux/2026/03/linux%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1/</link><pubDate>Wed, 11 Mar 2026 18:34:00 +0800</pubDate><author>mona</author><guid>https://menma.top/posts/linux/2026/03/linux%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1/</guid><description><![CDATA[<p>在 Linux 系统中，设置定时任务最常用的工具是 <strong>crontab</strong>。你可以把它想象成一个自动化的“闹钟”，让系统在指定的时间执行特定的脚本或命令。</p>
<p>以下是关于 Linux 定时任务（Cron Job）的快速指南：</p>
<hr>
<h2 id="1-核心命令">1. 核心命令</h2>
<p>在终端中输入以下命令来管理你的任务列表：</p>
<ul>
<li><code>crontab -e</code>: <strong>编辑</strong>当前用户的定时任务（首次使用会让你选择编辑器，建议选 <code>nano</code> 或 <code>vim</code>）。</li>
<li><code>crontab -l</code>: <strong>查看</strong>当前所有的定时任务。</li>
<li><code>crontab -r</code>: <strong>删除</strong>当前用户的所有定时任务。</li>
</ul>
<hr>
<h2 id="2-任务格式">2. 任务格式</h2>
<p>当你进入编辑模式后，每一行代表一个任务，格式如下：</p>
<p>Bash</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><pre tabindex="0"><code># ┌───────────── 分钟 (0 - 59)
# │ ┌─────────── 小时 (0 - 23)
# │ │ ┌───────── 月份中的第几天 (1 - 31)
# │ │ │ ┌─────── 月份 (1 - 12)
# │ │ │ │ ┌───── 星期中的第几天 (0 - 6) (0是周日)
# │ │ │ │ │
# * * * * * 要执行的命令或脚本路径</code></pre></div>
<hr>
<h2 id="3-常用实例">3. 常用实例</h2>
<p>这里有一些可以直接拿来改写的例子：</p>]]></description></item><item><title>acme申请证书</title><link>https://menma.top/posts/linux/2026/01/acme%E7%94%B3%E8%AF%B7%E8%AF%81%E4%B9%A6/</link><pubDate>Sat, 24 Jan 2026 23:04:00 +0800</pubDate><author>mona</author><guid>https://menma.top/posts/linux/2026/01/acme%E7%94%B3%E8%AF%B7%E8%AF%81%E4%B9%A6/</guid><description><![CDATA[<p><strong>安装</strong></p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><pre tabindex="0"><code>curl https://get.acme.sh | sh -s email=my@example.com
source ~/.bashrc</code></pre></div>
<p><strong>申请证书</strong></p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><pre tabindex="0"><code>acme.sh --issue -d my.domain.com --nginx</code></pre></div>
<p><strong>自动重载nginx</strong></p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><pre tabindex="0"><code>acme.sh --install-cert -d my.domain.com \
--key-file       /usr/share/nginx/ssl/my.domain.com.key \
--fullchain-file /usr/share/nginx/ssl/fullchain.cer \
--reloadcmd     &#34;nginx -t &amp;&amp; systemctl reload nginx&#34;</code></pre></div>
<hr>
<p><strong>CF的方式申请泛域名证书</strong></p>]]></description></item><item><title>debian设置自动更新安全更新</title><link>https://menma.top/posts/linux/2026/01/debian%E8%AE%BE%E7%BD%AE%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0%E5%AE%89%E5%85%A8%E6%9B%B4%E6%96%B0/</link><pubDate>Mon, 19 Jan 2026 12:03:45 +0800</pubDate><author>mona</author><guid>https://menma.top/posts/linux/2026/01/debian%E8%AE%BE%E7%BD%AE%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0%E5%AE%89%E5%85%A8%E6%9B%B4%E6%96%B0/</guid><description><![CDATA[<p><strong>安装必要软件包</strong></p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-shell">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl">apt install unattended-upgrades</span></span></code></pre></div></div>
<p><strong>启用自动更新功能</strong></p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><pre tabindex="0"><code>dpkg-reconfigure -plow unattended-upgrades</code></pre></div>
<p>这步操作会在 <code>/etc/apt/apt.conf.d/20auto-upgrades</code> 自动生成配置，确保更新服务会在后台运行。</p>
<p><strong>配置更新策略</strong></p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><pre tabindex="0"><code>vi /etc/apt/apt.conf.d/50unattended-upgrades</code></pre></div>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><pre tabindex="0"><code>Unattended-Upgrade::Remove-Unused-Dependencies &#34;true&#34;;
Unattended-Upgrade::Automatic-Reboot &#34;true&#34;;
Unattended-Upgrade::Automatic-Reboot-Time &#34;04:00&#34;;</code></pre></div>]]></description></item><item><title>linux清理并保留最近两天的日志</title><link>https://menma.top/posts/linux/2025/12/linux%E6%B8%85%E7%90%86%E5%B9%B6%E4%BF%9D%E7%95%99%E6%9C%80%E8%BF%91%E4%B8%A4%E5%A4%A9%E7%9A%84%E6%97%A5%E5%BF%97/</link><pubDate>Thu, 04 Dec 2025 12:07:00 +0800</pubDate><author>mona</author><guid>https://menma.top/posts/linux/2025/12/linux%E6%B8%85%E7%90%86%E5%B9%B6%E4%BF%9D%E7%95%99%E6%9C%80%E8%BF%91%E4%B8%A4%E5%A4%A9%E7%9A%84%E6%97%A5%E5%BF%97/</guid><description><![CDATA[<h2 id="查询-systemd-日志占用空间">查询 systemd 日志占用空间</h2>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">journalctl --disk-usage</span></span></code></pre></div></div>
<p>示例输出:</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">Archived and active journals take up 180.0M in the file system.</span></span></code></pre></div></div>
<hr>
<h2 id="设置日志最大空间和只保留最近两天日志自动清理">设置日志最大空间和只保留最近两天日志（自动清理）</h2>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo nano /etc/systemd/journald.conf</span></span></code></pre></div></div>
<p>添加：</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="nv">SystemMaxUse</span><span class="o">=</span>200M
</span></span><span class="line"><span class="cl"><span class="nv">MaxRetentionSec</span><span class="o">=</span>2day</span></span></code></pre></div></div>
<p>重启服务</p>]]></description></item><item><title>debian10/11替换归档源</title><link>https://menma.top/posts/linux/2025/12/debian10_11%E6%9B%BF%E6%8D%A2%E5%BD%92%E6%A1%A3%E6%BA%90/</link><pubDate>Tue, 02 Dec 2025 23:32:59 +0800</pubDate><author>mona</author><guid>https://menma.top/posts/linux/2025/12/debian10_11%E6%9B%BF%E6%8D%A2%E5%BD%92%E6%A1%A3%E6%BA%90/</guid><description><![CDATA[<h2 id="允许过期仓库">允许过期仓库</h2>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-shell">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-shell" data-lang="shell"><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s1">&#39;Acquire::Check-Valid-Until &#34;false&#34;;&#39;</span> &gt; /etc/apt/apt.conf.d/99ignore-release-date</span></span></code></pre></div></div>
<hr>
<h3 id="修改仓库源">修改仓库源</h3>
<p><strong>debian10</strong></p>
<div class="code-block code-line-numbers" style="counter-reset: code-block 0">
    <div class="code-header language-">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><pre tabindex="0"><code>deb http://archive.debian.org/debian/ buster main contrib non-free
deb-src http://archive.debian.org/debian/ buster main contrib non-free

deb http://archive.debian.org/debian-security/ buster/updates main contrib non-free
deb-src http://archive.debian.org/debian-security/ buster/updates main contrib non-free

deb http://archive.debian.org/debian/ buster-updates main contrib non-free
deb-src http://archive.debian.org/debian/ buster-updates main contrib non-free

deb http://archive.debian.org/debian/ buster-backports main contrib non-free
deb-src http://archive.debian.org/debian/ buster-backports main contrib non-free</code></pre></div>
<p><strong>debian11</strong></p>]]></description></item><item><title>为vps添加虚拟内存</title><link>https://menma.top/posts/linux/2024/11/%E4%B8%BAvps%E6%B7%BB%E5%8A%A0%E8%99%9A%E6%8B%9F%E5%86%85%E5%AD%98/</link><pubDate>Sat, 30 Nov 2024 00:21:00 +0800</pubDate><author>mona</author><guid>https://menma.top/posts/linux/2024/11/%E4%B8%BAvps%E6%B7%BB%E5%8A%A0%E8%99%9A%E6%8B%9F%E5%86%85%E5%AD%98/</guid><description><![CDATA[<p>在运行内存不足的情况下，适当配置虚拟内存（Swap）可以缓解内存压力，提高系统稳定性。本文介绍如何在 VPS 上创建并启用 512MB 的交换空间。</p>
<h2 id="停用旧的swap文件">停用旧的swap文件</h2>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo swapoff /swapfile
</span></span><span class="line"><span class="cl">sudo rm /swapfile</span></span></code></pre></div></div>
<hr>
<h2 id="步骤-1-创建交换文件">步骤 1: 创建交换文件</h2>
<p>首先，我们需要创建一个大小为 512MB 的文件用作交换空间。可以使用以下两种方法之一：</p>
<h3 id="方法-1-使用-fallocate推荐">方法 1: 使用 <code>fallocate</code>（推荐）</h3>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo fallocate -l 512M /swapfile</span></span></code></pre></div></div>
<h3 id="方法-2-使用-dd">方法 2: 使用 <code>dd</code></h3>
<p>如果 <code>fallocate</code> 命令不可用，可以改用 <code>dd</code>：</p>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo dd <span class="k">if</span><span class="o">=</span>/dev/zero <span class="nv">of</span><span class="o">=</span>/swapfile <span class="nv">bs</span><span class="o">=</span>1M <span class="nv">count</span><span class="o">=</span><span class="m">512</span></span></span></code></pre></div></div>
<hr>
<h2 id="步骤-2-设置文件权限">步骤 2: 设置文件权限</h2>
<p>为了安全起见，确保只有 root 用户可以访问交换文件：</p>]]></description></item><item><title>Linux 文件权限管理：chown 和 chmod</title><link>https://menma.top/posts/linux/2024/11/linux-%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90%E7%AE%A1%E7%90%86chown-%E5%92%8C-chmod/</link><pubDate>Tue, 12 Nov 2024 14:43:53 +0800</pubDate><author>mona</author><guid>https://menma.top/posts/linux/2024/11/linux-%E6%96%87%E4%BB%B6%E6%9D%83%E9%99%90%E7%AE%A1%E7%90%86chown-%E5%92%8C-chmod/</guid><description><![CDATA[<p>在 Linux 系统中，文件和目录的权限管理是一个至关重要的操作。本文将介绍两条重要命令：<code>chown</code>（更改文件所有者和用户组）以及 <code>chmod</code>（更改文件权限），帮助你轻松管理文件的访问权限。</p>
<hr>
<h2 id="一chown-命令">一、<code>chown</code> 命令</h2>
<p><code>chown</code> 命令用于更改文件或目录的所有者和用户组。</p>
<h3 id="基本语法">基本语法</h3>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">chown <span class="o">[</span>选项<span class="o">]</span> 用户:用户组 文件或目录</span></span></code></pre></div></div>
<ul>
<li><strong>用户</strong>：文件的新所有者。</li>
<li><strong>用户组</strong>：文件的新用户组。</li>
</ul>
<h3 id="常用示例">常用示例</h3>
<h4 id="1-更改文件所有者">1. 更改文件所有者</h4>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">chown user1 文件名</span></span></code></pre></div></div>
<p>将文件的所有者更改为 <code>user1</code>。</p>
<h4 id="2-更改文件所有者和用户组">2. 更改文件所有者和用户组</h4>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">chown user1:group1 文件名</span></span></code></pre></div></div>
<p>将文件的所有者更改为 <code>user1</code>，用户组更改为 <code>group1</code>。</p>]]></description></item><item><title>Linux文件夹压缩与解压</title><link>https://menma.top/posts/linux/2024/11/linux%E6%96%87%E4%BB%B6%E5%A4%B9%E5%8E%8B%E7%BC%A9%E4%B8%8E%E8%A7%A3%E5%8E%8B/</link><pubDate>Tue, 12 Nov 2024 14:37:00 +0800</pubDate><author>mona</author><guid>https://menma.top/posts/linux/2024/11/linux%E6%96%87%E4%BB%B6%E5%A4%B9%E5%8E%8B%E7%BC%A9%E4%B8%8E%E8%A7%A3%E5%8E%8B/</guid><description><![CDATA[<p>在 Linux 系统中，压缩和解压文件夹是日常运维中常见的操作。本文将详细介绍如何使用 <code>zip</code> 和 <code>tar</code> 命令进行文件夹的压缩与解压，包括 <code>.zip</code>、<code>.tar.gz</code> 和 <code>.tar.bz2</code> 等格式。</p>
<h2 id="压缩文件夹">压缩文件夹</h2>
<h3 id="使用-zip-压缩文件夹">使用 <code>zip</code> 压缩文件夹</h3>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">zip -r 压缩文件名.zip 文件夹名</span></span></code></pre></div></div>
<h4 id="压缩到指定目录">压缩到指定目录</h4>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">zip -r /path/to/destination/myfolder.zip 文件夹名</span></span></code></pre></div></div>
<hr>
<h3 id="使用-tar-压缩文件夹">使用 <code>tar</code> 压缩文件夹</h3>
<p><code>tar</code> 命令可以将文件夹压缩为 <code>.tar.gz</code> 或 <code>.tar.bz2</code> 格式。</p>
<h4 id="压缩为-targz">压缩为 <code>.tar.gz</code></h4>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">tar -czvf 压缩文件名.tar.gz 文件夹名</span></span></code></pre></div></div>
<h4 id="压缩为-tarbz2">压缩为 <code>.tar.bz2</code></h4>
<div class="code-block code-line-numbers open" style="counter-reset: code-block 0">
    <div class="code-header language-bash">
        <span class="code-title"><i class="arrow fas fa-angle-right" aria-hidden="true"></i></span>
        <span class="ellipses"><i class="fas fa-ellipsis-h" aria-hidden="true"></i></span>
        <span class="copy" title="Copy to clipboard"><i class="far fa-copy" aria-hidden="true"></i></span>
    </div><div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">tar -cjvf 压缩文件名.tar.bz2 文件夹名</span></span></code></pre></div></div>
<hr>
<h2 id="解压文件夹">解压文件夹</h2>
<h3 id="解压-zip-文件">解压 <code>.zip</code> 文件</h3>
<p>使用 <code>unzip</code> 命令解压 <code>.zip</code> 文件。</p>]]></description></item></channel></rss>