<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
    <channel>
        <title>鳄鱼儿随心随行</title>
        <link>https://www.125520.xyz/</link>
        <description>欢迎٩(๑^o^๑)۶</description>
        <lastBuildDate>Sat, 14 Mar 2026 08:48:44 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <language>zh-CN</language>
        <copyright>All rights reserved 2026, 我的知识小马甲</copyright>
        <item>
            <title><![CDATA[Windows后台运行程序 | 如何将exe注册为windows服务，默认开机后台自动运行]]></title>
            <link>https://www.125520.xyz/article/202403051</link>
            <guid>https://www.125520.xyz/article/202403051</guid>
            <pubDate>Tue, 05 Mar 2024 00:00:00 GMT</pubDate>
            <description><![CDATA[将exe注册为windows服务，默认后台开机自动运行]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-55615197eb794072800b6f34c0bc19c2"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-052ab2e091954570abe6bf98a6d3d19b"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="😀">😀</span></div><div class="notion-callout-text">2种方法教你，如何将exe可执行文件注册为windows服务，直接后台自动运行。</div></div><div class="notion-blank notion-block-34500e9da64947d69d7f260969864e8d"> </div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-6a4013eae38b45708abceed949dc4578" data-id="6a4013eae38b45708abceed949dc4578"><span><div id="6a4013eae38b45708abceed949dc4578" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6a4013eae38b45708abceed949dc4578" title="📝 instsrv + srvany方式"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📝 <code class="notion-inline-code"><b>instsrv</b></code><b> + </b><code class="notion-inline-code"><b>srvany</b></code><b>方式</b></span></span></h2><div class="notion-file notion-block-c3f16096bfe849f7907885de234f17ed"><a target="_blank" rel="noopener noreferrer" class="notion-file-link" href="https://file.notion.so/f/f/58af5dc2-5f6d-40fd-aa13-96c3ecc775bf/4c4f90f9-f356-4085-b628-7a9e7fbd38fb/instsrvsrvany.rar?table=block&amp;id=c3f16096-bfe8-49f7-9078-85de234f17ed&amp;spaceId=58af5dc2-5f6d-40fd-aa13-96c3ecc775bf&amp;expirationTimestamp=1773504000000&amp;signature=3SsuX-6YGYebHlVYoWzVZczhBzjTMPgnk6FoTm0sO6o"><svg class="notion-file-icon" viewBox="0 0 30 30"><path d="M22,8v12c0,3.866-3.134,7-7,7s-7-3.134-7-7V8c0-2.762,2.238-5,5-5s5,2.238,5,5v12c0,1.657-1.343,3-3,3s-3-1.343-3-3V8h-2v12c0,2.762,2.238,5,5,5s5-2.238,5-5V8c0-3.866-3.134-7-7-7S6,4.134,6,8v12c0,4.971,4.029,9,9,9s9-4.029,9-9V8H22z"></path></svg><div class="notion-file-info"><div class="notion-file-title">instsrv+srvany.rar</div><div class="notion-file-size">20.2KB</div></div></a></div><div class="notion-text notion-block-ca2ac3091a4a4ef49a140df55b1cf5b2">这种方法几乎所有exe可执行文件都可以注册为windows服务。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-909c9f36648f44f2ac65e7cab83ef552" data-id="909c9f36648f44f2ac65e7cab83ef552"><span><div id="909c9f36648f44f2ac65e7cab83ef552" class="notion-header-anchor"></div><a class="notion-hash-link" href="#909c9f36648f44f2ac65e7cab83ef552" title="instsrv+srvany"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>instsrv+srvany</b></span></span></h3><div class="notion-text notion-block-ae6d6c2362b440e580a277b51f73b422">首先介绍下 <code class="notion-inline-code">instsrv</code>和 <code class="notion-inline-code">srvany</code>是Microsoft Windows Resource Kits工具集中的两个实用工具，这两个工具配合使用可以将任何的exe应用程序作为window服务运行。</div><div class="notion-text notion-block-c50af6e449f242ceb7ded8732123fa8b"><code class="notion-inline-code">srany.exe</code>是注册程序的服务外壳，可以通过它让应用程序以system账号启动，可以使应用程序作为windows的服务随机器启动而<b>自动启动</b>，从而隐藏不必要的窗口。</div><div class="notion-blank notion-block-6e2a36ad49204bd2bc600902aa2aee43"> </div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-719caae34e184f74bf83627f4bc7b71e" data-id="719caae34e184f74bf83627f4bc7b71e"><span><div id="719caae34e184f74bf83627f4bc7b71e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#719caae34e184f74bf83627f4bc7b71e" title="安装"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">安装</span></span></h3><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-6f9f612796024b91ac233dc71cbc07fb" data-id="6f9f612796024b91ac233dc71cbc07fb"><span><div id="6f9f612796024b91ac233dc71cbc07fb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#6f9f612796024b91ac233dc71cbc07fb" title="对于Window64位系统"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">对于W<b>indow64位系统</b></span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-da04a6c084e9407a8bf78e0ff2cb4905" style="list-style-type:decimal"><li><code class="notion-inline-code">将instsrv.exe</code> 和 <code class="notion-inline-code">srvany.exe</code> 拷贝到 <code class="notion-inline-code">C:\WINDOWS\SysWOW64</code> 目录下</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-92156a6d24924d9085d365e92f51cd9a" style="list-style-type:decimal"><li>打开 cmd窗口（快捷键：win + R，键入cmd，回车）</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-5993052d60a04c28bd11b06fb5f37869" style="list-style-type:decimal"><li>运行命令：<code class="notion-inline-code">instsrv MyService C:\WINDOWS\SysWOW64\srvany.exe</code></li></ol><div class="notion-text notion-block-b6ca29a991294b3d80048798fa7fb4d0"><b>注意：</b><b><code class="notion-inline-code">MyService</code></b><b>是我们自定义的服务的名称，可以根据exe可执行文件的名称去更改，方便后续管理维护。</b></div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-d8b6466442ec4240a2c32bfd59278ec3" data-id="d8b6466442ec4240a2c32bfd59278ec3"><span><div id="d8b6466442ec4240a2c32bfd59278ec3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d8b6466442ec4240a2c32bfd59278ec3" title="对于Windows32位系统"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">对于Windows32位系统</span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-1be25a581df146358337604caae86f9c" style="list-style-type:decimal"><li>将 <code class="notion-inline-code">instsrv.exe</code> 和 <code class="notion-inline-code">srvany.exe</code> 拷贝到 <code class="notion-inline-code">C:\WINDOWS\system32</code> 目录下</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-87c48cb4d2f644efb52c97efd3600081" style="list-style-type:decimal"><li>打开cmd（快捷键：win + R，键入cmd，回车）</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-e985549b27a64c8a9a290ff940287388" style="list-style-type:decimal"><li>运行命令： <code class="notion-inline-code">instsrv MyService C:\WINDOWS\system32\srvany.exe</code></li></ol><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-fe59afbd131d4c7e829a638b90f98f7d" data-id="fe59afbd131d4c7e829a638b90f98f7d"><span><div id="fe59afbd131d4c7e829a638b90f98f7d" class="notion-header-anchor"></div><a class="notion-hash-link" href="#fe59afbd131d4c7e829a638b90f98f7d" title="配置"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>配置</b></span></span></h3><ol start="1" class="notion-list notion-list-numbered notion-block-133bc14ce6174ee28f29a0131d4d4880" style="list-style-type:decimal"><li>打开注册表：（cmd窗口中输入：<code class="notion-inline-code">regedit</code>）或（快捷键：win + R，键入 <code class="notion-inline-code">regedit</code>，回车）</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-9c42b77f8e4f46c8a1e4d4cd35279dd7" style="list-style-type:decimal"><li>ctrl+F，搜索<code class="notion-inline-code">Myservice</code>（之前自定义的服务名称）</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-abcc135ed72042f9bacdc50691b43845" style="list-style-type:decimal"><li>右击<code class="notion-inline-code">Myservice</code>新建项，名称为<code class="notion-inline-code">Parameters</code></li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-8cb909c6ef7b48edb2dbfe480cb4f80a" style="list-style-type:decimal"><li>之后在Parameters中新建几个<code class="notion-inline-code">字符串值</code> ，设置如下：</li></ol><ul class="notion-list notion-list-disc notion-block-6b23b719e3b7412b88ec438581652131"><li>名称 Application 值：你要作为服务运行的程序地址。</li></ul><ul class="notion-list notion-list-disc notion-block-e733cde40f524e18be5b825f7a59277d"><li>名称 AppDirectory 值：你要作为服务运行的程序所在文件夹路径。</li></ul><ul class="notion-list notion-list-disc notion-block-59aecd2cd44c4af898b7171f92e6bb0a"><li>名称 AppParameters 值：你要作为服务运行的程序启动所需要的参数。</li></ul><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-45874b62d1ea4747877d20b7257b1f6e"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://cdn.cdnjson.com/https://wx3.sinaimg.cn/large/006KCUaNgy1hnfx61dbvoj30lp06c3zc.jpg?spaceId=58af5dc2-5f6d-40fd-aa13-96c3ecc775bf&amp;t=45874b62-d1ea-4747-877d-20b7257b1f6e" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-c12b059e4f654df5b465617634e74628" data-id="c12b059e4f654df5b465617634e74628"><span><div id="c12b059e4f654df5b465617634e74628" class="notion-header-anchor"></div><a class="notion-hash-link" href="#c12b059e4f654df5b465617634e74628" title="启动服务"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>启动服务</b></span></span></h3><div class="notion-text notion-block-ea5b598eaa374d1fb073a37f3bdf32f2">在cmd窗口中键入<code class="notion-inline-code">net start MyService</code>，回车启动<b><code class="notion-inline-code">MyService</code></b><b>服务。</b></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-50fc1ea5011b41f8bb596e18b907fcfd" data-id="50fc1ea5011b41f8bb596e18b907fcfd"><span><div id="50fc1ea5011b41f8bb596e18b907fcfd" class="notion-header-anchor"></div><a class="notion-hash-link" href="#50fc1ea5011b41f8bb596e18b907fcfd" title="📝 命令 sc 方式"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📝 <b>命令 </b><code class="notion-inline-code"><b>sc</b></code><b> 方式</b></span></span></h2><div class="notion-text notion-block-2a6fb1286402406ca623d9b2c678f773">打开cmd，在cmd中运行下面的命令（最好使用管理员运行cmd）。</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-9f4c5590f428425ab40b99e9d1c2c506" data-id="9f4c5590f428425ab40b99e9d1c2c506"><span><div id="9f4c5590f428425ab40b99e9d1c2c506" class="notion-header-anchor"></div><a class="notion-hash-link" href="#9f4c5590f428425ab40b99e9d1c2c506" title="注册服务"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>注册服务</b></span></span></h3><div class="notion-text notion-block-6129cbd0b72744aaa455300ff08ae0af"><code class="notion-inline-code">sc create test</code><b><code class="notion-inline-code"> </code></b><code class="notion-inline-code">binpath=&quot;D:\ceshi\ceshi.exe&quot; type=own start=auto displayname=test</code></div><ul class="notion-list notion-list-disc notion-block-249af0791bbe472890d4d9d93250fa37"><li><b>test</b>：改成exe对应的名称（<b>方便后续管理维护。</b>）</li></ul><ul class="notion-list notion-list-disc notion-block-bc7e0839b0f14f13a12fc182656875f5"><li><b>binpath</b>：应用程序所在的路径(<b>使用绝对路径</b>)。</li></ul><ul class="notion-list notion-list-disc notion-block-e59c1fe096d44e1a94ef441ef46f9e86"><li><b>displayname</b>：服务显示的名称（<code class="notion-inline-code">services.msc</code>中显示的名称）。</li></ul><div class="notion-text notion-block-4167e1787b084507be40a640871ee867"><b>注意:</b>如果路径中有空格可以使用双引号</div><h4 class="notion-h notion-h3 notion-h-indent-2 notion-block-e9ed6e7a4a06431f97a102f1c7fc9f26" data-id="e9ed6e7a4a06431f97a102f1c7fc9f26"><span><div id="e9ed6e7a4a06431f97a102f1c7fc9f26" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e9ed6e7a4a06431f97a102f1c7fc9f26" title="如何判断服务是否注册成功？"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>如何判断服务是否注册成功？</b></span></span></h4><div class="notion-text notion-block-e6b96cbbfde847d8b6adaab93d3fd4c7">在cmd中输入<code class="notion-inline-code">services.msc</code>打开系统服务，查看是否出现 <code class="notion-inline-code">test</code> 名称的服务（即<code class="notion-inline-code">displayname=</code>后面的参数，我这里是test）</div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-88b7f2ad94d8407a8e6e7ee24609bd35" data-id="88b7f2ad94d8407a8e6e7ee24609bd35"><span><div id="88b7f2ad94d8407a8e6e7ee24609bd35" class="notion-header-anchor"></div><a class="notion-hash-link" href="#88b7f2ad94d8407a8e6e7ee24609bd35" title="启动服务"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>启动服务</b></span></span></h3><div class="notion-text notion-block-fe66ed87502b40b79ce79e346cea8006"><code class="notion-inline-code">net start test</code></div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-0d2070f903a34f329990042fc9e49aad" data-id="0d2070f903a34f329990042fc9e49aad"><span><div id="0d2070f903a34f329990042fc9e49aad" class="notion-header-anchor"></div><a class="notion-hash-link" href="#0d2070f903a34f329990042fc9e49aad" title="停止服务"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>停止服务</b></span></span></h3><div class="notion-text notion-block-cc530846762f4cd588d8bb78d171a7f5"><code class="notion-inline-code">net stop test</code></div><h3 class="notion-h notion-h2 notion-h-indent-1 notion-block-29a7929df8d44efc8dd31ec1090cd529" data-id="29a7929df8d44efc8dd31ec1090cd529"><span><div id="29a7929df8d44efc8dd31ec1090cd529" class="notion-header-anchor"></div><a class="notion-hash-link" href="#29a7929df8d44efc8dd31ec1090cd529" title="删除服务"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><b>删除服务</b></span></span></h3><div class="notion-text notion-block-73a54792c0c14e48958aa3d99a4385f8"><code class="notion-inline-code">sc delete &quot;test&quot;</code></div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MacBook安装MySQL]]></title>
            <link>https://www.125520.xyz/article/mac-mysql-install</link>
            <guid>https://www.125520.xyz/article/mac-mysql-install</guid>
            <pubDate>Fri, 02 Jul 2021 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-4d4e8462f27845f0a6adcff7442a5fba"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-a069d99216d242a5a532bc256ac4978c"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="😀">😀</span></div><div class="notion-callout-text">通过brew安装mysql@8.0</div></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-2f1b8e356c9a4021bb20060b401f2426" data-id="2f1b8e356c9a4021bb20060b401f2426"><span><div id="2f1b8e356c9a4021bb20060b401f2426" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2f1b8e356c9a4021bb20060b401f2426" title="📝 主旨内容"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📝 主旨内容</span></span></h2><ol start="1" class="notion-list notion-list-numbered notion-block-7a599d1de8a0441eb08a889982a5fe88" style="list-style-type:decimal"><li>brew安装</li><ol class="notion-list notion-list-numbered notion-block-7a599d1de8a0441eb08a889982a5fe88" style="list-style-type:lower-alpha"><div class="notion-text notion-block-0d61d3b5d61447c98a3d0cf695839745">安装成功会输出提示：</div><div class="notion-text notion-block-03b3b7ff9c9d4e97be07103c0dd00e48">可按照提示信息完成mysql配置。</div></ol></ol><ol start="2" class="notion-list notion-list-numbered notion-block-36cce8584ae24a1ea2a61391b6abbc1c" style="list-style-type:decimal"><li>环境配置</li><ol class="notion-list notion-list-numbered notion-block-36cce8584ae24a1ea2a61391b6abbc1c" style="list-style-type:lower-alpha"><li>查看brew安装mysql得路径</li><ol class="notion-list notion-list-numbered notion-block-159dc40dfb69408f9c0f26d38cf5952e" style="list-style-type:lower-roman"></ol><li>编辑环境变量，注意修改路径</li><ol class="notion-list notion-list-numbered notion-block-2a41c5f569c8499a9811e851d42d9844" style="list-style-type:lower-roman"></ol></ol></ol><ol start="3" class="notion-list notion-list-numbered notion-block-256e2a1b374a48e481f371cb853bbf53" style="list-style-type:decimal"><li>启动服务</li><ol class="notion-list notion-list-numbered notion-block-256e2a1b374a48e481f371cb853bbf53" style="list-style-type:lower-alpha"></ol></ol><ol start="4" class="notion-list notion-list-numbered notion-block-33b12bcb9e8d4876a23d4588788105aa" style="list-style-type:decimal"><li>安全配置</li><ol class="notion-list notion-list-numbered notion-block-33b12bcb9e8d4876a23d4588788105aa" style="list-style-type:lower-alpha"><div class="notion-text notion-block-5d49b02549934198a27b9d13c1f4ee23">配置过程信息</div></ol></ol><ol start="5" class="notion-list notion-list-numbered notion-block-8700ca4b92a04f67aa2a553c9ff94553" style="list-style-type:decimal"><li>连接mysql</li><ol class="notion-list notion-list-numbered notion-block-8700ca4b92a04f67aa2a553c9ff94553" style="list-style-type:lower-alpha"></ol></ol></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JVM系列：垃圾回收器（GC）]]></title>
            <link>https://www.125520.xyz/article/202402291</link>
            <guid>https://www.125520.xyz/article/202402291</guid>
            <pubDate>Thu, 29 Feb 2024 00:00:00 GMT</pubDate>
            <description><![CDATA[GC垃圾回收是JVM的标志性功能，无论是性能优化还是面试准备，GC都是JVM的重要内容。JVM不断对GC进行设计和优化，几乎每个Java版本都会对GC进行改进。在这里以目前使用最广泛的JDK8为例，梳理GC部分的主要内容。]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-109785415744453190b88c831a684b79"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-4b3e76ab03314bf2b861812631cfade7"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="😀">😀</span></div><div class="notion-callout-text">执行引擎将class文件加载至JVM内存中运行。在运行过程中，需要在内存中动态创建和销毁对象。在传统的C/C++语言中，需要手动进行对象销毁以避免内存泄漏。而在Java中，引入了GC垃圾回收机制。<div class="notion-text notion-block-db19dad8599441f3a3bfa76ba3a23c1d">GC垃圾回收是JVM的标志性功能，无论是性能优化还是面试准备，GC都是JVM的重要内容。JVM不断对GC进行设计和优化，几乎每个Java版本都会对GC进行改进。在这里以目前使用最广泛的JDK8为例，梳理GC部分的主要内容。</div></div></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-d833c69422f14ecc8e740d75b7356fcb" data-id="d833c69422f14ecc8e740d75b7356fcb"><span><div id="d833c69422f14ecc8e740d75b7356fcb" class="notion-header-anchor"></div><a class="notion-hash-link" href="#d833c69422f14ecc8e740d75b7356fcb" title="📝 主旨内容"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📝 主旨内容</span></span></h2><div class="notion-text notion-block-b6cc2fbc8db9452d8750e285ca2ecc5c">在文章之前，先来熟悉以下Arthas工具，这是第三方在线监控工具，由阿里开源。</div><div class="notion-text notion-block-728f2d4d35c14a0cbedccb264de30226">为什么不直接介绍垃圾回收器呢？</div><div class="notion-text notion-block-5367111ca93c40238d9e9a5ca3710771">前言中说到class文件会被加载到JVM内存中执行，这个过程不是可视的，而借助这个工具，我们可以对更可观地理解JVM底层,同时这个工具也可用于对Java进程进行性能调优，后续在JV吗M调优文章中介绍Arthas工具的具体用法。</div><div class="notion-text notion-block-71bbf5704047494dbbee12345c72fa5f">官网地址：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arthas.aliyun.com/">https://arthas.aliyun.com/</a></div><div class="notion-text notion-block-66f253361e8f45f89f4fe03a55fc7c04">我们使用一个例子来细说。</div><blockquote class="notion-quote notion-block-c4e64fe7136349eaa8f37f7f633def9f"><div>注明：1000_000 效果等于 1000000。

这是Java7引入的新特性。分割数字增强可读性。具体可以在这里阅读更多设计细节，<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html">Underscores in Numeric Literals</a>。</div></blockquote><div class="notion-blank notion-block-ac5b1f3a0ff44cecbc714dfbe1a2ae52"> </div><div class="notion-text notion-block-bc198980fe9741e890aae5a787790c4a">下载<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arthas.aliyun.com/download/latest_version?mirror=aliyun">atthas</a>后解压，在解压路径下终端运行 <code class="notion-inline-code">java -jar arthas-boot.jar</code> 启动，并根据提示选择上述例子运行的pid序号，这里序号为 <code class="notion-inline-code">3</code>。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-505a8445e1e947218220fe798a64d7b5"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F58af5dc2-5f6d-40fd-aa13-96c3ecc775bf%2Fc3d11ae4-8e47-442f-8a02-45c2c54de7f2%2FUntitled.png?table=block&amp;id=505a8445-e1e9-4721-8220-fe798a64d7b5&amp;t=505a8445-e1e9-4721-8220-fe798a64d7b5&amp;width=477.625&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-211ed0c3c1a84b46bb848709aef8075a">通过 <code class="notion-inline-code">dashboard</code> 指令就可以查看这个Java程序的实时运行状态。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-3f0abbc5c56a4473a62c68ee79a6dc1b"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F58af5dc2-5f6d-40fd-aa13-96c3ecc775bf%2Fb177fe10-3d4e-4030-aa52-407f84c2f776%2FUntitled.png?table=block&amp;id=3f0abbc5-c56a-4473-a62c-68ee79a6dc1b&amp;t=3f0abbc5-c56a-4473-a62c-68ee79a6dc1b&amp;width=477.640625&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-4e4a8d542f964d8798c3140127fe186a">在这些信息中，我们重点关注Memory部分，这部分记录了该Java程序的JVM内存使用情况。</div><div class="notion-text notion-block-11ba05053ee241aba0a1377b81fbc1cf">表中GC栏部分则展示了垃圾回收的执行情况。从这个表入手分析一个Java程序，我们就可以更方便地了解一个Java进程是如何进行管理内存的。</div><div class="notion-text notion-block-361d83d90cc240789a114b038141c408">在Memory这部分，我们还可以知道，Java进程会将其管理的内存分为heap(堆区)和nonheap(非堆区)。</div><div class="notion-text notion-block-43c0af03fb6c40e49056b3a9ddf7a0f2">非堆区包括code_cache(热点指令缓存)、metaspace(元空间)和compressed_class_space(压缩类空间)。这部分可以看作Java进程的地下室，属于较不活跃的部分。而heap堆区则类似于客厅，是Java中最关键的部分。堆区主要分为eden_space、survivor_space和old_gen三个部分，构成了JVM内存的主体。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-8f8747dd8f9b4b74bea25ac131801b7c"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F58af5dc2-5f6d-40fd-aa13-96c3ecc775bf%2Fafa3fcdc-c92d-4241-bc91-92596277df94%2FUntitled.png?table=block&amp;id=8f8747dd-8f9b-4b74-bea2-5ac131801b7c&amp;t=8f8747dd-8f9b-4b74-bea2-5ac131801b7c&amp;width=477.640625&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure><div class="notion-text notion-block-8bec198a761b42fba2ab32ce0c45674a">如上图所示，堆区是JVM中存放对象的核心内存区域。它的大小可以通过参数-Xms（初始堆内存大小）和-Xmx（最大堆内存）指令来设置。</div><div class="notion-text notion-block-0d287fe7a1b54f77be3ce035643a05ff">堆内存是可以动态扩展的，如果初始内存不足，JVM会自动扩大堆内存。然而，当内存扩展到达最大堆内存限制时仍然不足时，JVM就无法继续扩展，会导致OutOfMemory（OOM）异常。</div><div class="notion-text notion-block-b14791297d3d486c8236b20a8bdfcbe1">GC垃圾回收器的作用就是及时回收这些内存空间，使得内存可以被重复利用。</div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-124eb49df3214b818819d12025e3c538" data-id="124eb49df3214b818819d12025e3c538"><span><div id="124eb49df3214b818819d12025e3c538" class="notion-header-anchor"></div><a class="notion-hash-link" href="#124eb49df3214b818819d12025e3c538" title="📎 参考文章"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">📎 参考文章</span></span></h2><ul class="notion-list notion-list-disc notion-block-4390104314614ff68bcf20c6936819e7"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://docs.oracle.com/javase/7/docs/technotes/guides/language/underscores-literals.html">Underscores in Numeric Literals</a></li></ul><ul class="notion-list notion-list-disc notion-block-a72f4c88b59241208db185c521bb7c5e"><li><a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://arthas.aliyun.com/doc/quick-start.html">arthas文档</a></li></ul><div class="notion-blank notion-block-038138d9e91f44eeb98e9de8f3e00365"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JVM第一课：class文件结构]]></title>
            <link>https://www.125520.xyz/article/202402271</link>
            <guid>https://www.125520.xyz/article/202402271</guid>
            <pubDate>Tue, 27 Feb 2024 00:00:00 GMT</pubDate>
            <description><![CDATA[本文以 JDK8为例，讲解 Class 文件结构。]]></description>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-03d2e27e02ad4eb794817e24ffe83ae5"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-1e5e32d3657f404f8379946f32a78f23"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="😀">😀</span></div><div class="notion-callout-text">本文以 JDK8为例，讲解 Class 文件结构。</div></div><div class="notion-blank notion-block-e3edb98c16364fbb81d4949fe39d96c6"> </div><div class="notion-text notion-block-683b62cfd3fe4bb8876f65f890630f10">JDK 文档官网：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://docs.oracle.com/javase/8/">docs.oracle.com/javase/8/</a></div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-838b6c814ab645438354afa839c914cf" data-id="838b6c814ab645438354afa839c914cf"><span><div id="838b6c814ab645438354afa839c914cf" class="notion-header-anchor"></div><a class="notion-hash-link" href="#838b6c814ab645438354afa839c914cf" title="前言"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">前言</span></span></h3><div class="notion-text notion-block-c2359e9658e5476ea2a48c82a7854224">Oracle 有两个产品实现了 Java SE (Java Platform Standard Edition) 8，分别为Java SE Development Kit (JDK) 8和 Java SE Runtime Environment (JRE) 8。</div><div class="notion-text notion-block-762fbec4236947af8c94f2ce8e08be48">JDK 8是 JRE 8的超集，包含 JRE 8中的所有内容，以及开发 applet 和应用程序所需的编译器和调试器等工具。</div><div class="notion-text notion-block-eef9041e47b04c3d8ce93c0687e3cc03">而 JRE 8提供库、Java 虚拟机(JVM)和其他组件来运行用 Java 编程语言编写的 applet 和应用程序。请注意，JRE 包括 Java SE 规范不需要的组件，包括标准组件和非标准组件。</div><div class="notion-text notion-block-47394da9cf3643d5bc55a677b309cf31">简而言之，JDK 适用于开发，JRE 仅仅适用于 applet 和应用程序的部署运行，及在服务器环境下可以只使用 JRE。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-6fb26034d9fb4eefad944d01e01782a3"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/10a686554b0c4d7285b1e2590a384ab2~tplv-k3u1fbpfcp-jj-mark:0:0:0:0:q75.image?spaceId=58af5dc2-5f6d-40fd-aa13-96c3ecc775bf#?w=733&amp;h=505&amp;s=45058&amp;e=png&amp;b=fcf9f9&amp;t=6fb26034-d9fb-4eef-ad94-4d01e01782a3" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-2ad9c69cd5284adfa7eb39939592fd90" data-id="2ad9c69cd5284adfa7eb39939592fd90"><span><div id="2ad9c69cd5284adfa7eb39939592fd90" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2ad9c69cd5284adfa7eb39939592fd90" title="class 文件的产生"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">class 文件的产生</span></span></h3><ul class="notion-list notion-list-disc notion-block-0cd1376f776349b4adaa42163db0d756"><li><code class="notion-inline-code">.class</code> 文件是 <code class="notion-inline-code">.java</code> 文件编译后的形成的中间文件。下面使用一个小例子来看一下 class 文件的结构。</li></ul><div class="notion-text notion-block-ec15a70723c747daafb523dda81fcc8a">例：我们有以下的源代码文件—— <code class="notion-inline-code">Main.java</code></div><div class="notion-text notion-block-d0045139b5a54451a0d34bed6f7ac74c">编译 <code class="notion-inline-code">javac Main.java ---&gt; Main.class</code></div><div class="notion-text notion-block-77210992dd494bf2aa3935f8b98650be">补充点编译细节：Main.java -&gt; 词法分析器 -&gt; tokens 流 -&gt; 语法分析器 -&gt; 语法树/抽象语法树 -&gt; 语义分析器 -&gt; 注解抽象语法树 -&gt; 字节码生成器 -&gt; Main.class 文件。这里就不展开细说啦。</div><div class="notion-text notion-block-a19fefd2af034f948da7aefeef55c0b5">经过编译后，我们得到了 <code class="notion-inline-code">Main.class</code> 文件，如果要打开这个文件我们会看到一串一串字符乱码，这些字符是无法直接取阅读的。通过反编译后，就可以得到类似于源码的代码，如下。</div><div class="notion-text notion-block-42eee289c1c24ecc97177b09a48013ba"><b>补充：反编译工具</b></div><ol start="1" class="notion-list notion-list-numbered notion-block-82681ac7f8474e0b8ffc63d4ef0a4fa7" style="list-style-type:decimal"><li><code class="notion-inline-code">javap</code>。</li></ol><ol start="2" class="notion-list notion-list-numbered notion-block-37157dea644f4cec99ecb63875d10b9a" style="list-style-type:decimal"><li>IDE 工具：如 Idea 工具栏中 View---&#x27;show bytecode&#x27;。</li></ol><ol start="3" class="notion-list notion-list-numbered notion-block-4144746c3a3946ac8a29df3cbeab0533" style="list-style-type:decimal"><li>Idea 插件—— <code class="notion-inline-code">jclasslib Bytecode Viewer</code>，最直观展示信息。</li></ol><div class="notion-text notion-block-2cabbd0b323149f0a92df1f33fc5300e"><code class="notion-inline-code">javap</code> 是 Java 开发工具包（JDK）提供的一个命令行工具，用于反编译 Java 字节码。<code class="notion-inline-code">javap</code> 可以将 Java 类文件解析为易于阅读的文本形式，展示其中的信息以及反编译出类的结构、方法、字段、常量池等信息。通过阅读和分析这些信息，开发人员可以更好地理解 Java 类的内部实现，并进行性能调优、代码审查等操作。</div><div class="notion-text notion-block-08bfb5d9971e417e8e204406522bf929">我们可以使用 <code class="notion-inline-code">jclasslib Bytecode Viewer</code> 插件，直观的阅读 class 文件结构，包括 class 文件格式的主次版本号、常量池等信息。</div><figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-fee010e0b7334b838b922d6922229678"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column"><img style="object-fit:cover" src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/cf59d1407b3442a59d72f9f1d8f18c07~tplv-k3u1fbpfcp-jj-mark:0:0:0:0:q75.image?spaceId=58af5dc2-5f6d-40fd-aa13-96c3ecc775bf#?w=794&amp;h=389&amp;s=24051&amp;e=png&amp;b=2b2d30&amp;t=fee010e0-b733-4b83-8b92-2d6922229678" alt="notion image" loading="lazy" decoding="async"/></div></figure><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-3d819fdb6d174986828307b94a9722aa" data-id="3d819fdb6d174986828307b94a9722aa"><span><div id="3d819fdb6d174986828307b94a9722aa" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3d819fdb6d174986828307b94a9722aa" title="class 文件结构介绍"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title"><code class="notion-inline-code">class</code> 文件结构介绍</span></span></h3><div class="notion-text notion-block-3ea6aeedbf63440a8605229a83b24c42">每个 <code class="notion-inline-code">class</code> 文件包含一个类或接口的定义。</div><div class="notion-text notion-block-a5cf44a8e199484abb971c3e11f53141">类文件由字节流组成，既我们所看到的一串一串字符。所有 16 位、32 位和 64 位的变量也都是通过读入 2 个、4 个和 8 个连续的字节构建的。并且多字节数据项总是按大端模式存储，即高字节位在前。</div><div class="notion-text notion-block-0531ea125174452fb76d16e6496a618d">如下是 oracle 官方给的 <a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html">class 文件结构</a></div><div class="notion-text notion-block-7def3dd24fcb4ac1bebdaf26821b209e">案例中的数据类型表示为 <code class="notion-inline-code">u1</code>、<code class="notion-inline-code">u2</code> 和 <code class="notion-inline-code">u4</code> 类型分别代表一个、两个或四个字节的无符号量，这些类型可通过 java. Io. DataInput 接口的 readUnsignedByte、readUnsignedShort 和 readInt 等方法读取。</div><div class="notion-text notion-block-b5f790ecc57a4d54acbae1a79a4cee06">下面介绍下 class 文件结构的具体含义。</div><table class="notion-simple-table notion-block-fc8e20331df044e4ab813087b0a1b70c"><tbody><tr class="notion-simple-table-row notion-block-8efd53aa1d424a5a9f95a1d29bd6d7d2"><td class="" style="width:120px"><div class="notion-simple-table-cell">类型</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">名称</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">数量</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">说明</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-4cd25cb2868345458edbb94df6322fec"><td class="" style="width:120px"><div class="notion-simple-table-cell">u4</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">magic</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">1</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">魔数：确定一个文件是否是 Class 文件。值是固定的为  <code class="notion-inline-code">0xCAFEBABE</code></div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-77df158590a342f48625b893b8dd07b7"><td class="" style="width:120px"><div class="notion-simple-table-cell">u2</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">minor\_version</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">1</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">Class 文件的<b>次版本号</b>，与主版本号共同决定 class 文件格式的版本。如果一个类文件的主要版本号为 M，次要版本号为 m，我们就用 M.m 表示其类文件格式的版本。</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-f3e913085ac94dff8e34f86e914964cb"><td class="" style="width:120px"><div class="notion-simple-table-cell">u2</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">major\_version</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">1</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">Class 文件的<b>主版本号</b>：一个 JVM 实例只能支持特定范围内版本号的 Class 文件（可以向下兼容）。</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-4622b25f410e4bb3a750d9a94ad5c59b"><td class="" style="width:120px"><div class="notion-simple-table-cell">u2</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">constant\_pool\_count</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">1</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">常量表数量，constant\_pool\_count 项的值等于 constant\_pool 表中的条目数加1。如果一个常量大于0且小于 constant\_pool\_count 则被认为是有效的。</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-a5ee180bace84a1694982e15b5d00e41"><td class="" style="width:120px"><div class="notion-simple-table-cell">cp\_info</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">constant\_pool</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">constant\_pool\_count-1</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">常量池：可以理解为 Class 文件的资源仓库，表示在ClassFile结构及其子结构中引用的各种字符串常量、类和接口名、字段名和其他常量。后面的其他数据项可以引用常量池内容。</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-0aa2c3e970f148beafa5f310fcb17075"><td class="" style="width:120px"><div class="notion-simple-table-cell">u2</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">access\_flags</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">1</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">类的访问标志信息：用于表示这个类或者接口的访问权限及基础属性。</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-b0fc03b4c21d4ae9ba9d7a3654744797"><td class="" style="width:120px"><div class="notion-simple-table-cell">u2</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">this\_class</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">1</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">指向当前类的常量索引：用来确定这个类的的全限定名。</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-34bbf432076245c6b29804af777baeaf"><td class="" style="width:120px"><div class="notion-simple-table-cell">u2</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">super\_class</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">1</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">指向父类的常量的索引：用来确定这个类的父类的全限定名。</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-04f11439788f492ca8b90856432dc297"><td class="" style="width:120px"><div class="notion-simple-table-cell">u2</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">interfaces\_count</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">1</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">接口的数量</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-d4fc7985cd7642c98d8623ee06a1d0bb"><td class="" style="width:120px"><div class="notion-simple-table-cell">u2</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">interfaces</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">interfaces\_count</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">指向接口的常量索引：用来描述这个类实现了哪些接口。</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-d7456e7a3a7d4c3d9f6371935b246ffa"><td class="" style="width:120px"><div class="notion-simple-table-cell">u2</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">fields\_count</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">1</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">字段表数量</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-b5edd9bdc0a9489a9922b1ab0971db60"><td class="" style="width:120px"><div class="notion-simple-table-cell">field\_info</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">fields</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">fields\_count</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">字段表集合：描述当前类或接口声明的所有字段。</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-46d44e61836349b587386de3d87ee2d2"><td class="" style="width:120px"><div class="notion-simple-table-cell">u2</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">methods\_count</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">1</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">方法表数量</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-d371f22eb7cb4093bb943190d561ba91"><td class="" style="width:120px"><div class="notion-simple-table-cell">method\_info</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">methods</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">methods\_count</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">方法表集合：只描述当前类或接口中声明的方法，不包括从父类或父接口继承的方法。</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-1b90fff4b7fd4f568498c584aa0cf680"><td class="" style="width:120px"><div class="notion-simple-table-cell">u2</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">attributes\_count</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">1</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">属性表数量</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr><tr class="notion-simple-table-row notion-block-b7f8ce6438fa48f19c28fb01fc9622ed"><td class="" style="width:120px"><div class="notion-simple-table-cell">attributes\_info</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">attributes</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">attributes\_count</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">属性表集合：用于描述某些场景专有的信息，如字节码的指令信息等等。</div></td><td class="" style="width:120px"><div class="notion-simple-table-cell">ㅤ</div></td></tr></tbody></table></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[sh脚本提示没有文件或目录]]></title>
            <link>https://www.125520.xyz/article/202408071</link>
            <guid>https://www.125520.xyz/article/202408071</guid>
            <pubDate>Wed, 07 Aug 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-59059af2c2224b17b67cc6a16c9a22e0"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-aa8cd3c393c5497f94226279a7bac170"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="😀">😀</span></div><div class="notion-callout-text"></div></div><div class="notion-blank notion-block-d46c3f8eeb4844c2a71b11d75346cfb7"> </div><div class="notion-blank notion-block-deee2105559a4480804bed99ca1683e6"> </div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-b6066c788b5c488c84f5b1baf5214d4c" data-id="b6066c788b5c488c84f5b1baf5214d4c"><span><div id="b6066c788b5c488c84f5b1baf5214d4c" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b6066c788b5c488c84f5b1baf5214d4c" title="问题原因"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">问题原因</span></span></h3><div class="notion-text notion-block-0bd57a0a3fdc440192e19ef91d849a0d">因为编写sh脚本使用的操作系统是<b>windows</b>，在windows下编辑的文件，有可能存在不可见字符。具体而言，其脚本文件是DOS格式的，即每一行的行尾以 <code class="notion-inline-code">\r\n</code> 来标识, 其ASCII码分别是 <code class="notion-inline-code">0x0D, 0x0A</code></div><div class="notion-blank notion-block-0faa1ec361004269ad6a92dab85fad0f"> </div><h3 class="notion-h notion-h2 notion-h-indent-0 notion-block-1a0c889c1dcc46759ca814fdbc9a85a0" data-id="1a0c889c1dcc46759ca814fdbc9a85a0"><span><div id="1a0c889c1dcc46759ca814fdbc9a85a0" class="notion-header-anchor"></div><a class="notion-hash-link" href="#1a0c889c1dcc46759ca814fdbc9a85a0" title="解决方法"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">解决方法</span></span></h3><div class="notion-text notion-block-d42770bc2c7b48fdbccbfb49f2467afc">可以有很多种办法看这个文件是DOS格式的还是UNIX格式的, 还是MAC格式的</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-dba13e59b6994b6883c52c41ed9761a3" data-id="dba13e59b6994b6883c52c41ed9761a3"><span><div id="dba13e59b6994b6883c52c41ed9761a3" class="notion-header-anchor"></div><a class="notion-hash-link" href="#dba13e59b6994b6883c52c41ed9761a3" title="（1） vim 工具"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">（1） vim 工具</span></span></h4><div class="notion-text notion-block-1c9a24e217bb435f9cd31e9d386e4d01">然后用命令 <code class="notion-inline-code">:set ff</code></div><div class="notion-text notion-block-0b78e7cdf6a44c5facc858dfbc9938cd">可看到 <code class="notion-inline-code">dos</code> 或 <code class="notion-inline-code">unix</code> 的字样，如果的确是 <code class="notion-inline-code">dos</code> 格式的, 那么用 <code class="notion-inline-code">:set ff=unix</code> 把它强制为 <code class="notion-inline-code">unix</code> 格式的，然后使用命令 <code class="notion-inline-code">:wq</code> 存盘退出后就可运行。</div><div class="notion-blank notion-block-6297328e689c4aadaddac3e5e2c1b5da"> </div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-e3203903685b4443a8a05a49d0d16d53" data-id="e3203903685b4443a8a05a49d0d16d53"><span><div id="e3203903685b4443a8a05a49d0d16d53" class="notion-header-anchor"></div><a class="notion-hash-link" href="#e3203903685b4443a8a05a49d0d16d53" title="(2)使用工具转换"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">(2)使用工具转换</span></span></h4><div class="notion-text notion-block-184427f259f04baea4bc7fcd39267d9d">转换不同平台的文本文件格式可以用 <code class="notion-inline-code">dos2unix</code> 、 <code class="notion-inline-code">unix2dos</code> 两个小工具。</div><div class="notion-blank notion-block-8e7990b4d053474a90f79301093b9fb4"> </div></main></div>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CentOS Stream下安装 Golang（适用于1.18及以上版本）]]></title>
            <link>https://www.125520.xyz/article/centos-go-isntall</link>
            <guid>https://www.125520.xyz/article/centos-go-isntall</guid>
            <pubDate>Tue, 30 Apr 2024 00:00:00 GMT</pubDate>
            <content:encoded><![CDATA[<div id="notion-article" class="mx-auto overflow-hidden "><main class="notion light-mode notion-page notion-block-0d8772f2a64649ecb0e62f662eff7d7a"><div class="notion-viewport"></div><div class="notion-collection-page-properties"></div><div class="notion-callout notion-gray_background_co notion-block-36d3041853414ba4b08ec71f2a317b7d"><div class="notion-page-icon-inline notion-page-icon-span"><span class="notion-page-icon" role="img" aria-label="😀">😀</span></div><div class="notion-callout-text">CentOS停更了，后续更改为CentOS Stream。本文以CentOS Stream安装Golang指定版本。
<figure class="notion-asset-wrapper notion-asset-wrapper-image notion-block-419759d8e22e4407a01be887e3179247"><div style="position:relative;display:flex;justify-content:center;align-self:center;width:100%;max-width:100%;flex-direction:column;height:100%"><img style="object-fit:cover" src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F58af5dc2-5f6d-40fd-aa13-96c3ecc775bf%2F88355319-7ed7-42bc-85c1-0418bff85778%2FUntitled.png?table=block&amp;id=419759d8-e22e-4407-a01b-e887e3179247&amp;t=419759d8-e22e-4407-a01b-e887e3179247&amp;width=417.625&amp;cache=v2" alt="notion image" loading="lazy" decoding="async"/></div></figure></div></div><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-63176b8c5efb4049a6ba24b36ad8e17e" data-id="63176b8c5efb4049a6ba24b36ad8e17e"><span><div id="63176b8c5efb4049a6ba24b36ad8e17e" class="notion-header-anchor"></div><a class="notion-hash-link" href="#63176b8c5efb4049a6ba24b36ad8e17e" title="下载"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">下载</span></span></h2><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-2352c61379fa49d58c1f9e57c35919e4" data-id="2352c61379fa49d58c1f9e57c35919e4"><span><div id="2352c61379fa49d58c1f9e57c35919e4" class="notion-header-anchor"></div><a class="notion-hash-link" href="#2352c61379fa49d58c1f9e57c35919e4" title="获取Golang下载地址"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">获取Golang下载地址</span></span></h4><ul class="notion-list notion-list-disc notion-block-ff0ec42c281c4fd3bc150bebb3591194"><li>标准官网：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://go.dev/">https://go.dev/</a></li></ul><ul class="notion-list notion-list-disc notion-block-8130865b5473407e8d02e45615a16ef2"><li>国内镜像官网：<a target="_blank" rel="noopener noreferrer" class="notion-link" href="https://golang.google.cn/">https://golang.google.cn/</a></li></ul><h2 class="notion-h notion-h1 notion-h-indent-0 notion-block-4b7aeca8d3f74158ba0f4a83492fd8cf" data-id="4b7aeca8d3f74158ba0f4a83492fd8cf"><span><div id="4b7aeca8d3f74158ba0f4a83492fd8cf" class="notion-header-anchor"></div><a class="notion-hash-link" href="#4b7aeca8d3f74158ba0f4a83492fd8cf" title="安装"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">安装</span></span></h2><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-3e0b8decc1c341898e458cfd41180e6b" data-id="3e0b8decc1c341898e458cfd41180e6b"><span><div id="3e0b8decc1c341898e458cfd41180e6b" class="notion-header-anchor"></div><a class="notion-hash-link" href="#3e0b8decc1c341898e458cfd41180e6b" title="1. 进入终端，登入root"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">1. 进入终端，登入root</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-b6b4faec87f349b4a6e5d700a0c2c422" data-id="b6b4faec87f349b4a6e5d700a0c2c422"><span><div id="b6b4faec87f349b4a6e5d700a0c2c422" class="notion-header-anchor"></div><a class="notion-hash-link" href="#b6b4faec87f349b4a6e5d700a0c2c422" title="2. 来到应用安装目录"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">2. 来到应用安装目录</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-055d49a4f74044d79e8ceb5562e4da59" data-id="055d49a4f74044d79e8ceb5562e4da59"><span><div id="055d49a4f74044d79e8ceb5562e4da59" class="notion-header-anchor"></div><a class="notion-hash-link" href="#055d49a4f74044d79e8ceb5562e4da59" title="3. 使用 wget 下载"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">3. 使用 wget 下载</span></span></h4><div class="notion-text notion-block-095bc72a1cc04bfa9620f6fbd930f991">如果没有安装 wget 可通过软件包管理器安装 wget</div><div class="notion-text notion-block-6928db76c77a4260a604fad618dc3e0b">以 go1.21.5 版本下载链接演示</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-dd59047a0f55435bae9e72bbff0ebc8a" data-id="dd59047a0f55435bae9e72bbff0ebc8a"><span><div id="dd59047a0f55435bae9e72bbff0ebc8a" class="notion-header-anchor"></div><a class="notion-hash-link" href="#dd59047a0f55435bae9e72bbff0ebc8a" title="4. 解压文件"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">4. 解压文件</span></span></h4><div class="notion-text notion-block-b5be20507f4f4f7d91f68e83cbe67d73">如果之前已经安装过go的版本，先清空下go，不然可能会报错误</div><div class="notion-text notion-block-774f9d0948b94f5b99dec1701781faac">解压go包</div><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-64758640371643e2abb319db77c8e3af" data-id="64758640371643e2abb319db77c8e3af"><span><div id="64758640371643e2abb319db77c8e3af" class="notion-header-anchor"></div><a class="notion-hash-link" href="#64758640371643e2abb319db77c8e3af" title="5. 配置环境变量"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">5. 配置环境变量</span></span></h4><ol start="1" class="notion-list notion-list-numbered notion-block-ab86fad4fa50480bbd6a3fece562eaf7" style="list-style-type:decimal"><li>vim指令编辑 /etc/profile</li><ol class="notion-list notion-list-numbered notion-block-ab86fad4fa50480bbd6a3fece562eaf7" style="list-style-type:lower-alpha"></ol></ol><ol start="2" class="notion-list notion-list-numbered notion-block-a7010a22849d43a19f95562f44dfd7e2" style="list-style-type:decimal"><li>严格大小写 按顺序键入：G、o 来到文件末尾添加以下配置</li><ol class="notion-list notion-list-numbered notion-block-a7010a22849d43a19f95562f44dfd7e2" style="list-style-type:lower-alpha"><blockquote class="notion-quote notion-block-45527359033446b5b0bc417e76fe1f17"><div>go1.18 版本以后默认开启 go modules 模式，无需配置【export GO111MODULE=on】</div><div class="notion-text notion-block-41ec92a7b7eb440899327ab982c8b74c">go modules 模式下，可以不配置GOPATH，默认【/root/go】</div></blockquote></ol></ol><ol start="3" class="notion-list notion-list-numbered notion-block-c02a159e4f5844bbadc87deda77e2630" style="list-style-type:decimal"><li>按下 Esc 退出编辑模式，输入 :wq 保存并退出</li></ol><ol start="4" class="notion-list notion-list-numbered notion-block-67a97f1e27f745eda7f4f624e862b607" style="list-style-type:decimal"><li>使环境变量配置生效</li><ol class="notion-list notion-list-numbered notion-block-67a97f1e27f745eda7f4f624e862b607" style="list-style-type:lower-alpha"></ol></ol><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-a24c6e4543e3408d849084e683594fbc" data-id="a24c6e4543e3408d849084e683594fbc"><span><div id="a24c6e4543e3408d849084e683594fbc" class="notion-header-anchor"></div><a class="notion-hash-link" href="#a24c6e4543e3408d849084e683594fbc" title="6. 查看golang版本，测试是否配置成功"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">6. 查看golang版本，测试是否配置成功</span></span></h4><h4 class="notion-h notion-h3 notion-h-indent-1 notion-block-daa8ad2c5d5049f5802925565f2278c7" data-id="daa8ad2c5d5049f5802925565f2278c7"><span><div id="daa8ad2c5d5049f5802925565f2278c7" class="notion-header-anchor"></div><a class="notion-hash-link" href="#daa8ad2c5d5049f5802925565f2278c7" title="7. GO设置代理环境变量"><svg viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M7.775 3.275a.75.75 0 001.06 1.06l1.25-1.25a2 2 0 112.83 2.83l-2.5 2.5a2 2 0 01-2.83 0 .75.75 0 00-1.06 1.06 3.5 3.5 0 004.95 0l2.5-2.5a3.5 3.5 0 00-4.95-4.95l-1.25 1.25zm-4.69 9.64a2 2 0 010-2.83l2.5-2.5a2 2 0 012.83 0 .75.75 0 001.06-1.06 3.5 3.5 0 00-4.95 0l-2.5 2.5a3.5 3.5 0 004.95 4.95l1.25-1.25a.75.75 0 00-1.06-1.06l-1.25 1.25a2 2 0 01-2.83 0z"></path></svg></a><span class="notion-h-title">7. GO设置代理环境变量</span></span></h4><div class="notion-text notion-block-1ef558ff75d34930901f53c0633ac993">国内的服务器可以设置下代理环境，之后再拉去go.dev的时候就不需要科学上网了。</div><div class="notion-text notion-block-7d12301b265e48fa969c4471ca50410a"><b>注意GO1.13才开始支持direct的写法</b></div><div class="notion-text notion-block-c16f6752f8fc4ee19dbde60479e6b214">设置完后 查看Go环境变量</div></main></div>]]></content:encoded>
        </item>
    </channel>
</rss>