<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="/feed.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2025-12-22T03:21:02+00:00</updated><id>/feed.xml</id><title type="html">chaosky</title><subtitle></subtitle><entry><title type="html">Spring Prometheus</title><link href="/2023/10/17/spring-prometheus.html" rel="alternate" type="text/html" title="Spring Prometheus" /><published>2023-10-17T00:00:00+00:00</published><updated>2023-10-17T00:00:00+00:00</updated><id>/2023/10/17/spring-prometheus</id><content type="html" xml:base="/2023/10/17/spring-prometheus.html"><![CDATA[<!-- omit from toc -->
<h1 id="gathering-metrics-from-spring-boot-with-prometheus-and-grafana">Gathering Metrics from Spring Boot with Prometheus and Grafana</h1>

<ul>
  <li><a href="#使用-docker-compose-部署和配置环境">使用 docker-compose 部署和配置环境</a>
    <ul>
      <li><a href="#grafana">grafana</a></li>
    </ul>
  </li>
  <li><a href="#使用指南">使用指南</a>
    <ul>
      <li><a href="#prometheus">Prometheus</a></li>
      <li><a href="#业务层">业务层</a></li>
      <li><a href="#grafana-1">grafana</a></li>
    </ul>
  </li>
  <li><a href="#参考资料">参考资料</a>
    <ul>
      <li><a href="#主要">主要</a></li>
      <li><a href="#promql-和-grafana-查询">promql 和 grafana 查询</a></li>
      <li><a href="#次要">次要</a></li>
      <li><a href="#promql-查询">promql 查询</a></li>
    </ul>
  </li>
</ul>

<h1 id="使用-docker-compose-部署和配置环境">使用 docker-compose 部署和配置环境</h1>

<h2 id="grafana">grafana</h2>

<h1 id="使用指南">使用指南</h1>

<h2 id="prometheus">Prometheus</h2>

<h3 id="数据模型">数据模型</h3>
<p>Prometheus 具有多维分析的能力，数据模型有如下几部分组成。</p>

<p>Metric Name(指标名称) + Labels(标签) + Timestamp(时间戳) + Value/Sample(监控值/样品)</p>
<ul>
  <li>Metric Name(指标名称)：监控对象的含义（例如，http_request_total - 表示当前系统接收到的HTTP请求总量）。</li>
  <li>标签(label)：表示当前样本的特征维度，是一个K/V结构，通过这些维度 Prometheus 可以对样本数据进行过滤，聚合等。</li>
  <li>时间戳(timestamp)：一个精确到毫秒的时间戳。</li>
  <li>样本值(value)：一个float64的浮点型数据表示当前样本的值。</li>
</ul>

<p>参考资料</p>

<ul>
  <li><a href="https://prometheus.io/docs/concepts/data_model/">DATA MODEL</a></li>
  <li><a href="https://prometheus.io/docs/practices/naming/">Metric/Label 命名最佳实践</a></li>
</ul>

<h2 id="业务层">业务层</h2>

<p><a href="https://prometheus.io/docs/practices/instrumentation">如何检测/测量系统</a></p>

<h3 id="spring-boot">spring boot</h3>

<p>spring-boot-actuator 的包 org.springframework.boot.actuate.metrics</p>
<ul>
  <li>org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter</li>
</ul>

<p>参考资料</p>
<ul>
  <li><a href="https://docs.spring.io/spring-boot/docs/2.2.7.RELEASE/reference/html/production-ready-features.html">Spring Boot Actuator: Production-ready Features 2.2.7.RELEASE</a></li>
</ul>

<h3 id="micrometer">micrometer</h3>

<p>io.micrometer#micrometer-core 的包 io.micrometer.core.instrument.binder</p>
<ul>
  <li>io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics</li>
  <li>io.micrometer.core.instrument.binder.jvm.JvmGcMetrics</li>
</ul>

<h4 id="异常处理">异常处理</h4>

<p>log/2023/11/error-2023-11-06_0.log.gz:2023-11-06 22:14:13.498 [] [uof-ticket-11-1] ERROR c.i.s.t.c.s.u.RollbackBetSettlementHandler( 266) - Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter name d ‘ilot_sport_ticket_rollback_tickets_total’ containing tag keys [application, bet_from, currency, game_rb_ret, game_winrb_ret, payo ut_type, rbpayout, rbstake, region, stack]. The meter you are attempting to register has keys [application, region, stack]. 
log/2023/11/error-2023-11-06_0.log.gz:java.lang.IllegalArgumentException: Prometheus requires that all meters with the same name hav e the same set of tag keys. There is already an existing meter named ‘ilot_sport_ticket_rollback_tickets_total’ containing tag keys [application, bet_from, currency, game_rb_ret, game_winrb_ret, payout_type, rbpayout, rbstake, region, stack]. The meter you are att empting to register has keys [application, region, stack].</p>

<p>2023-11-09 03:59:03.093 [] [uof-ticket-13-1] ERROR c.i.s.t.c.s.u.BetSettlementHandler(251) - Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter named ‘ilot_sport_ticket_rollback_tickets_total’ containing tag keys [application, region, stack]. The meter you are attempting to register has keys [application, bet_from, currency, game_rb_ret, game_winrb_ret, payout_type, rbpayout, rbstake, region, stack].java.lang.IllegalArgumentException: Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter named ‘ilot_sport_ticket_rollback_tickets_total’ containing tag keys [application, region, stack]. The meter you are attempting to register has keys [application, bet_from, currency, game_rb_ret, game_winrb_ret, payout_type, rbpayout, rbstake, region, stack].</p>

<h2 id="grafana-1">grafana</h2>

<h1 id="参考资料">参考资料</h1>

<h2 id="主要">主要</h2>

<h2 id="promql-和-grafana-查询">promql 和 grafana 查询</h2>

<h3 id="查询日志增量示例">查询日志增量示例</h3>

<p>时间戳 1697773320 -&gt; 2023-10-20T03:42:00.000Z</p>

<p>promql</p>

<pre><code class="language-promql">increase(logback_events_total{application="xxx-service",level="debug",stack='dev'}[1m] @ 1697773320)
# 124.8
rate(logback_events_total{application="xxx-service",level="debug",stack='dev'}[1m] @ 1697773320)
# 2.08
logback_events_total{application="xxx-service",level="debug", stack='dev'}[1m] @ 1697773320
# 16916 @1697773263.216
# 16918 @1697773273.216
# 16920 @1697773283.216
# 16930 @1697773293.216
# 16984 @1697773303.216
# 17020 @1697773313.216
</code></pre>

<p>官方文档描述 increase 是 rate 的封装的语法糖。所以上面的 increase 可以转换为</p>

<pre><code class="language-promql">rate(logback_events_total{application="xxx-service",level="debug",stack='dev'}[1m] @ 1697773320) * 60s
# 124.8
</code></pre>

<h3 id="spring">Spring</h3>
<ul>
  <li><a href="https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html">Spring Boot Actuator: Production-ready features</a></li>
  <li><a href="https://docs.spring.io/spring-boot/docs/3.1.4/actuator-api/htmlsingle/">Spring Boot Actuator Web API Documentation</a></li>
</ul>

<h3 id="micrometer-1">Micrometer</h3>
<ul>
  <li><a href="https://micrometer.io/docs/registry/prometheus">Micrometer Prometheus</a></li>
  <li><a href="https://micrometer.io/docs/concepts">Micrometer Concepts</a></li>
</ul>

<h3 id="prometheus-1">Prometheus</h3>
<ul>
  <li><a href="https://prometheus.io/docs/prometheus/latest/configuration/configuration/">Prometheus CONFIGURATION</a></li>
</ul>

<h3 id="grafana-2">Grafana</h3>
<ul>
  <li><a href="https://grafana.com/docs/grafana/latest/setup-grafana/configure-docker/">Configure a Grafana Docker image</a></li>
</ul>

<h2 id="次要">次要</h2>
<ul>
  <li><a href="https://cloud.tencent.com/document/product/1416/56027">自定义监控</a></li>
  <li><a href="https://medium.com/simform-engineering/revolutionize-monitoring-empowering-spring-boot-applications-with-prometheus-and-grafana-e99c5c7248cf">Monitoring Made Simple: Empowering Spring Boot Applications with Prometheus and Grafana</a></li>
  <li><a href="https://tanzu.vmware.com/developer/guides/spring-prometheus/">Gathering Metrics from Spring Boot on Kubernetes with Prometheus and Grafana</a></li>
  <li><a href="https://hezhiqiang.gitbook.io/prometheus/">Prometheus监控</a></li>
</ul>

<h2 id="promql-查询">promql 查询</h2>
<ul>
  <li><a href="https://stackoverflow.com/questions/75933096/how-to-calculate-average-over-last-week-for-the-same-time-in-prometheus">How to calculate average over last week for the same time in prometheus?</a></li>
  <li><a href="https://stackoverflow.com/questions/55073399/prometheus-getting-cumulative-kwh-from-milliwatt-samples">Prometheus: getting cumulative KwH from milliwatt samples</a></li>
  <li></li>
</ul>]]></content><author><name></name></author><summary type="html"><![CDATA[Gathering Metrics from Spring Boot with Prometheus and Grafana]]></summary></entry><entry><title type="html">通过 ssh x11 转发远程主机上 dingtalk 的 docker 容器到本机</title><link href="/2022/12/19/Forwarding-dingtalk-using-ssh-x11.html" rel="alternate" type="text/html" title="通过 ssh x11 转发远程主机上 dingtalk 的 docker 容器到本机" /><published>2022-12-19T06:00:00+00:00</published><updated>2022-12-19T06:00:00+00:00</updated><id>/2022/12/19/Forwarding-dingtalk-using-ssh-x11</id><content type="html" xml:base="/2022/12/19/Forwarding-dingtalk-using-ssh-x11.html"><![CDATA[<p>使用 docker 在远程服务器上运行钉钉(dingtalk)，然后使用 ssh X11 转发到本机。</p>

<h2 id="先决条件">先决条件</h2>

<ul>
  <li>安装有 docker，docker-compose 的 linux 服务器，这里选择 centos 7</li>
  <li>安装有 linux 发行版的本机，这里选择 fedora 36</li>
</ul>

<h2 id="二次加工创建自己的镜像">二次加工，创建自己的镜像</h2>

<p>使用的基础镜像 <a href="https://github.com/fitme96/dingtalk-image">fitme96/dingtalk:1.3.0.20214</a></p>

<p>docker run –name dingtalk_fitme96_temp -it fitme96/dingtalk:1.3.0.20214 bash</p>

<p>docker exec -it dingtalk_fitme96_temp bash</p>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#容器中执行</span>
apt update
apt <span class="nb">install</span> <span class="nt">-y</span> vim ssh x11-apps
<span class="c"># 设置 sshd</span>
vim /etc/ssh/sshd_config 
/etc/init.d/ssh start
vim ~/.bashrc
<span class="c"># 退出容器</span>
</code></pre></div></div>

<p>/etc/ssh/sshd_config</p>

<pre><code class="language-sshd_config"># Run X application in a Docker container reliably on a server connected via SSH without "--net host" https://stackoverflow.com/questions/48235040/run-x-application-in-a-docker-container-reliably-on-a-server-connected-via-ssh-w/48235281#48235281
X11Forwarding yes
X11UseLocalhost no
#AcceptEnv LANG LC_*
</code></pre>

<p>.bashrc</p>

<pre><code class="language-.bashrc">export XMODIFIERS='@im=fcitx'
export QT_IM_MODULE=fcitx
export GTK_IM_MODULE=fcitx
</code></pre>

<p>退出容器, 保存镜像</p>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>docker ps <span class="nt">-a</span> <span class="c">#查看容器id</span>
docker commit 容器id
docker images
docker tag 镜像id 镜像tag
</code></pre></div></div>

<h2 id="测试镜像">测试镜像</h2>

<p>docker 宿主机安装 docker-compose</p>

<p>docker-compose.yml:</p>

<div class="language-yml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="na">version</span><span class="pi">:</span> <span class="s2">"</span><span class="s">3.3"</span>
<span class="na">services</span><span class="pi">:</span>
  <span class="na">dd</span><span class="pi">:</span>
    <span class="na">image</span><span class="pi">:</span> <span class="s2">"</span><span class="s">"</span>
    <span class="na">environment</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="s">DISPLAY=本机$DISPLAY:0</span>
      <span class="c1"># https://github.com/fitme96/dingtalk-image/issues/1</span>
      <span class="pi">-</span> <span class="s">XMODIFIERS='@im=fcitx'</span>
      <span class="pi">-</span> <span class="s">QT_IM_MODULE=fcitx</span>
      <span class="pi">-</span> <span class="s">GTK_IM_MODULE=fcitx</span>
    <span class="na">volumes</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="s">/data/docker/dt_yml:/root</span>
    <span class="na">ports</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="s2">"</span><span class="s">8023:22"</span>
    <span class="na">stdin_open</span><span class="pi">:</span> <span class="no">true</span>
    <span class="na">tty</span><span class="pi">:</span> <span class="no">true</span>
    <span class="na">command</span><span class="pi">:</span> <span class="s">bash</span>
    <span class="na">ulimits</span><span class="pi">:</span>
      <span class="na">core</span><span class="pi">:</span>
        <span class="na">hard</span><span class="pi">:</span> <span class="m">0</span>
        <span class="na">soft</span><span class="pi">:</span> <span class="m">0</span>
</code></pre></div></div>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># 启动容器</span>
docker-compose up
<span class="c"># 进入容器</span>
docker <span class="nb">exec</span> <span class="nt">-it</span> 容器id bash

<span class="c"># 容器中运行</span>
/etc/init.d/ssh start
</code></pre></div></div>

<p>本机执行 ssh -v -X $user@ip -p 8023 xeyes</p>

<h2 id="运行-dingtalk">运行 dingtalk</h2>

<div class="language-shell highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ssh <span class="nt">-v</span> <span class="nt">-X</span> user@ip <span class="nt">-p</span> 8023 <span class="s2">"/bin/sh /opt/apps/com.alibabainc.dingtalk/files/Elevator.sh"</span>
</code></pre></div></div>
<h1 id="总结">总结</h1>

<p>通过 docker-compose 在远程服务器上运行钉钉(dingtalk)，然后使用 ssh X11 转发到本机，避免使用本机资源运行 dingtalk，节省内存。</p>

<p>直接使用官方提供的 deb 包，也避免了特定 linux 发行版无法安装 dingtalk deb 包的问题。</p>

<h1 id="参考">参考</h1>

<ul>
  <li><a href="https://github.com/fitme96/dingtalk-image">fitme96/dingtalk-image</a></li>
  <li><a href="https://stackoverflow.com/questions/48235040/run-x-application-in-a-docker-container-reliably-on-a-server-connected-via-ssh-w">Run X application in a Docker container reliably on a server connected via SSH without “–net host”</a></li>
  <li>
    <p><a href="https://github.com/fitme96/dingtalk-image/issues/1">新的1.4版本需要配置环境变量，使得输入法可以使用 #1</a></p>
  </li>
  <li><a href="https://dzone.com/articles/docker-x11-client-via-ssh">Docker X11 Client Via SSH</a></li>
  <li><a href="https://stackoverflow.com/questions/44429394/x11-forwarding-of-a-gui-app-running-in-docker">X11 forwarding of a GUI app running in docker</a></li>
  <li><a href="https://stackoverflow.com/questions/28392949/running-chromium-inside-docker-gtk-cannot-open-display-0">Running Chromium inside Docker - Gtk: cannot open display: :0</a></li>
  <li><a href="https://stackoverflow.com/questions/38249629/inside-a-docker-container-error-cannot-open-display-localhost11-0">Inside a Docker Container: “Error: cannot open display: localhost:11.0”</a></li>
  <li><a href="https://superuser.com/questions/310197/how-do-i-fix-a-cannot-open-display-error-when-opening-an-x-program-after-sshi">How do I fix a “cannot open display” error when opening an X program after ssh’ing with X11 forwarding enabled?</a></li>
</ul>]]></content><author><name></name></author><category term="docker" /><category term="ssh" /><category term="x11" /><category term="dingtalk" /><summary type="html"><![CDATA[使用 docker 在远程服务器上运行钉钉(dingtalk)，然后使用 ssh X11 转发到本机。]]></summary></entry><entry><title type="html">在 Ubuntu 18.04 上安装 Unity3D</title><link href="/2020/04/27/install-unity3d-on-ubuntu.html" rel="alternate" type="text/html" title="在 Ubuntu 18.04 上安装 Unity3D" /><published>2020-04-27T00:00:00+00:00</published><updated>2020-04-27T00:00:00+00:00</updated><id>/2020/04/27/install-unity3d-on-ubuntu</id><content type="html" xml:base="/2020/04/27/install-unity3d-on-ubuntu.html"><![CDATA[<p>本文包括在 Ubuntu 上安装 Unity3D 的过程，遇到的问题及解决办法。先安装 UnityHub，再安装 Unity，就可以使用 Unity 了。把官方教学项目 FPS Microgame 构建为 WebGL 平台程序后，可以直接在浏览器中试玩游戏。</p>

<h1 id="安装-unityhub">安装 UnityHub</h1>

<p>下载最新版本 UnityHub：</p>

<p>https://public-cdn.cloud.unity3d.com/hub/prod/UnityHub.AppImage</p>

<p>国内地址：<a href="https://public-cdn.cloud.unitychina.cn/hub/prod/UnityHub.AppImage">https://public-cdn.cloud.unitychina.cn/hub/prod/UnityHub.AppImage</a></p>

<p>下载完毕后，赋予执行权限</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nb">chmod</span> +x UnityHub.AppImage
</code></pre></div></div>

<p>然后就可以直接执行此程序</p>

<p>参考 ：<a href="https://www.linuxdeveloper.space/install-unity-linux/">Install Unity3D on Linux</a></p>

<h1 id="安装-unity">安装 Unity</h1>

<p>当前在 Ubuntu 下，无法脱离 UnityHub 单独运行 Unity，需要 UnityHub 激活和管理许可证（License）后才能正常使用 Unity。</p>

<p>有几种安装方式可以选择</p>

<h2 id="方式1使用-unityhub-安装">方式1：使用 UnityHub 安装</h2>

<p>直接使用 UnityHub 安装相应版本的 Unity，这种方式安装只有有限的几个版本可以选择，如果想要安装其他版本，需要进行手动安装，然后添加到 UnityHub 中。</p>

<p>由于需要下载的文件巨大（几个GB），国内网络环境下可能会频繁遇到下载中断、下载速度慢的问题，可以在执行 UnityHub 时挂上代理，加快下载速度。</p>

<h2 id="方式2手动安装">方式2：手动安装</h2>

<p>也可以使用 UnitySetup 手动安装 Unity。按着官方论坛 <a href="https://forum.unity.com/threads/unity-on-linux-release-notes-and-known-issues.350256">Unity on Linux: Release Notes and Known Issues</a> 的说明，下载最新版本的 UnitySetup-x.x.x 后，运行 UnitySetup 进行安装。下载 UnitySetup 时可能也需要挂上代理。</p>

<h3 id="下载其他版本的-unitysetup">下载其他版本的 UnitySetup</h3>

<p>如果论坛中没有你需要的版本，可以通过替换下载链接中的参数来下载其他版本。论坛中官方人员给出的下载地址，有一定的规律。以 <strong>2019.1.0f2</strong> 版本为例，下载地址为：</p>

<p>http://beta.unity3d.com/download/<strong>292b93d75a2c</strong>/UnitySetup-<strong>2019.1.0f2</strong></p>

<p>国内地址：<a href="https://download.unitychina.cn/download_unity/292b93d75a2c/UnitySetup-2019.1.0f2">https://download.unitychina.cn/download_unity/292b93d75a2c/UnitySetup-2019.1.0f2</a></p>

<p>只需要替换链接中的 Hash 和版本号就可以下载相应的版本。</p>

<p>假如我们想下载 <strong>Unity 2019.3.11</strong>，根据官方<a href="https://unity3d.com/get-unity/download/archive">下载存档列表</a>找到相应版本，Chrome浏览器在 <strong>Unity Hub</strong> 链接（按钮）上鼠标右键<strong>审查</strong>（Firefox 鼠标右键‘检查元素’），得到版本 UnityHub 安装链接为 <strong>unityhub://2019.3.11f1/ceef2d848e70</strong>，链接中 <strong>2019.3.11f1</strong> 和 <strong>ceef2d848e70</strong> 就是我们需要的参数，替换参数后的链接为：</p>

<p>http://beta.unity3d.com/download/<strong>ceef2d848e70</strong>/UnitySetup-<strong>2019.3.11f1</strong></p>

<p>国内地址：<a href="https://download.unitychina.cn/download_unity/ceef2d848e70/UnitySetup-2019.3.11f1">https://download.unitychina.cn/download_unity/ceef2d848e70/UnitySetup-2019.3.11f1</a></p>

<p>就可以下载到<strong>2019.3.11f1</strong>版本的 UnitySetup。</p>

<p>官方下载存档列表备份：</p>
<ul>
  <li>备份1：<a href="https://gitlab.com/gableroux/unity3d/-/blob/master/ci-generator/unity_versions.old.yml">旧版本</a> ， <a href="https://gitlab.com/gableroux/unity3d/-/blob/master/ci-generator/unity_versions.yml">当前版本</a></li>
  <li><a href="https://github.com/neogeek/get-unity/blob/master/data/editor-installers.json">备份2</a></li>
</ul>

<h3 id="解决-unitysetup-下载问题">解决 UnitySetup 下载问题</h3>

<p>运行 UnitySetup 下载相关安装包时，可能会遇到中断和下载太慢的问题。UnitySetup 会顺序下载已经选定的组件，如果想对下载进行加速，可以在外部先下载好相关安装包，再运行 UnitySetup，此时会跳过下载步骤，直接开始安装 Unity。</p>

<p>根据 UnitySetup 启动时请求的配置文件，我们可以<strong>按上一步</strong>的方式，替换参数获得对应版本的组件配置文件，自己下载。以 <strong>2019.1.0f2</strong> 版本为例，UnitySetup 启动时会请求以下链接获取配置文件，进行后续下载和安装过程：</p>

<p>https://netstorage.unity3d.com/unity/<strong>292b93d75a2c</strong>/unity-<strong>2019.1.0f2</strong>-linux.ini</p>

<p>国内地址：<a href="https://netstorage.unitychina.cn/unity/292b93d75a2c/unity-2019.1.0f2-linux.ini">https://netstorage.unitychina.cn/unity/292b93d75a2c/unity-2019.1.0f2-linux.ini</a></p>

<p>我们把其中的参数替换为 <strong>2019.3.11f1</strong> 的后，就可以得到对应版本的组件配置信息：</p>

<p>https://netstorage.unity3d.com/unity/<strong>ceef2d848e70</strong>/unity-<strong>2019.3.11f1</strong>-linux.ini</p>

<p>国内地址：<a href="https://netstorage.unitychina.cn/unity/ceef2d848e70/unity-2019.3.11f1-linux.ini">https://netstorage.unitychina.cn/unity/ceef2d848e70/unity-2019.3.11f1-linux.ini</a></p>

<p>然后进行多线程下载：</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># 下载配置文件</span>
curl <span class="nt">-L</span> https://netstorage.unity3d.com/unity/ceef2d848e70/unity-2019.3.11f1-linux.ini <span class="nt">-o</span> unity-2019.3.11f1-linux.ini
<span class="c"># 通过代理下载配置文件</span>
<span class="c">#proxychains curl -L https://netstorage.unity3d.com/unity/ceef2d848e70/unity-2019.3.11f1-linux.ini -o unity-2019.3.11f1-linux.ini</span>
<span class="c"># 把 unity-2019.3.11f1-linux.ini 需要下载的组件写入下载列表文件中, 同样需要参数替换</span>
<span class="nb">echo</span> <span class="s1">'
https://netstorage.unity3d.com/unity/ceef2d848e70/LinuxEditorInstaller/Unity.tar.xz
https://netstorage.unity3d.com/unity/ceef2d848e70/MacEditorTargetInstaller/UnitySetup-Android-Support-for-Editor-2019.3.11f1.pkg
https://netstorage.unity3d.com/unity/ceef2d848e70/LinuxEditorTargetInstaller/UnitySetup-Linux-IL2CPP-Support-for-Editor-2019.3.11f1.tar.xz
https://netstorage.unity3d.com/unity/ceef2d848e70/MacEditorTargetInstaller/UnitySetup-Windows-Mono-Support-for-Editor-2019.3.11f1.pkg
https://netstorage.unity3d.com/unity/ceef2d848e70/LinuxEditorTargetInstaller/UnitySetup-WebGL-Support-for-Editor-2019.3.11f1.tar.xz
'</span> <span class="o">&gt;</span> list.txt
<span class="c"># 使用 aria2c 进行多线程下载</span>
aria2c <span class="nt">--auto-file-renaming</span> <span class="nb">false</span> <span class="nt">-m</span> 0 <span class="nt">-i</span> list.txt
<span class="c"># 下载完毕后，运行 UnitySetup，下载目录指向当前已经下载好的组件目录，就可以直接跳过下载进行安装了   </span>
</code></pre></div></div>

<p>国内链接版本</p>

<div class="language-sh highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># 下载配置文件</span>
curl <span class="nt">-L</span> https://netstorage.unitychina.cn/unity/ceef2d848e70/unity-2019.3.11f1-linux.ini <span class="nt">-o</span> unity-2019.3.11f1-linux.ini
<span class="c"># 把 unity-2019.3.11f1-linux.ini 需要下载的组件写入下载列表文件中, 同样需要参数替换</span>
<span class="nb">echo</span> <span class="s1">'
https://netstorage.unitychina.cn/unity/ceef2d848e70/LinuxEditorInstaller/Unity.tar.xz
https://netstorage.unitychina.cn/unity/ceef2d848e70/MacEditorTargetInstaller/UnitySetup-Android-Support-for-Editor-2019.3.11f1.pkg
https://netstorage.unitychina.cn/unity/ceef2d848e70/LinuxEditorTargetInstaller/UnitySetup-Linux-IL2CPP-Support-for-Editor-2019.3.11f1.tar.xz
https://netstorage.unitychina.cn/unity/ceef2d848e70/MacEditorTargetInstaller/UnitySetup-Windows-Mono-Support-for-Editor-2019.3.11f1.pkg
https://netstorage.unitychina.cn/unity/ceef2d848e70/LinuxEditorTargetInstaller/UnitySetup-WebGL-Support-for-Editor-2019.3.11f1.tar.xz
'</span> <span class="o">&gt;</span> list.txt
<span class="c"># 使用 aria2c 进行多线程下载</span>
aria2c <span class="nt">--auto-file-renaming</span> <span class="nb">false</span> <span class="nt">-m</span> 0 <span class="nt">-i</span> list.txt
<span class="c"># 下载完毕后，运行 UnitySetup，下载目录指向当前已经下载好的组件目录，就可以直接跳过下载进行安装了   </span>
</code></pre></div></div>

<h1 id="测试安装效果">测试安装效果</h1>

<p>Unity 安装完毕后，运行 UnityHub，在 Learn - Project 下选择一个教学项目进行测试，这里下载了 FPS Microgame（此项目需要安装 WebGL Build Support 组件）。下载完毕后，在 UnityHub 中创建一个新的 3D 项目，然后将 FPS Microgame 导入到新项目中（可能在 /tmp/fps-microgame.unitypackage 或者 ~/.local/share/unity3d/Asset Store-5.x/Unity Technologies/Project/fps-microgame.unitypackage）。</p>

<p>先点击菜单栏中的 Play 按钮，测试游戏能否正常运行。可以运行后，再点击菜单栏中 File -&gt; Build Settings 设置目标平台为 WebGL，然后构建并运行游戏，就可以在<strong>浏览器</strong>中玩游戏了。也可以切换构建平台到 PC, Mac &amp; Linux，然后选择 Linux，构建本地应用。</p>

<h2 id="新手教程">新手教程</h2>

<p>如果是刚开始学习 Unity，可以在菜单栏中 Tutorials -&gt; Show Tutorials 打开内置教程，一步一步学习如何使用 Unity。</p>

<h1 id="遇到的问题">遇到的问题</h1>

<h2 id="网络网络网络">网络，网络，网络</h2>

<p>从 unity.com 上下载时，大部分资源的 CDN 都在国外，国内下载过程中随时可能会遇到中断或者速度慢的情况，这时最好中断下载，挂上代理再下载。也可以使用国内链接来下载。</p>

<h2 id="帐号注册和登录">帐号注册和登录</h2>

<p>运行 Unity 时可能会遇到需要登录 Unity Id 的情况，这时可以挂代理在 unity.com 上申请帐号，不挂代理的话会根据 ip 分配到 unity.cn 上申请。</p>

<h1 id="参考资料">参考资料</h1>

<ul>
  <li><a href="https://forum.unity.com/threads/unity-on-linux-release-notes-and-known-issues.350256">Unity on Linux: Release Notes and Known Issues</a></li>
  <li><a href="https://askubuntu.com/questions/1077816/how-to-install-unity3d-on-ubuntu-18-04">How to install Unity3D on Ubuntu 18.04?</a></li>
  <li><a href="https://www.linuxdeveloper.space/install-unity-linux/">Install Unity3D on Linux</a></li>
  <li><a href="https://unity3d.com/get-unity/download/archive">Unity download archive</a></li>
  <li><a href="https://github.com/neogeek/get-unity/blob/master/data/editor-installers.json">unity3d editor-installers.json - github</a></li>
  <li><a href="https://gitlab.com/gableroux/unity3d/-/blob/master/ci-generator/unity_versions.yml">unity_versions.yml - gitlab</a></li>
  <li><a href="https://gitlab.com/gableroux/unity3d/-/blob/master/ci-generator/unity_versions.old.yml">unity_versions.old.yml - gitlab</a></li>
  <li><a href="https://unity.cn/releases">https://unity.cn/releases</a></li>
</ul>]]></content><author><name></name></author><category term="game" /><category term="unity3d" /><category term="linux" /><category term="ubuntu" /><summary type="html"><![CDATA[本文包括在 Ubuntu 上安装 Unity3D 的过程，遇到的问题及解决办法。先安装 UnityHub，再安装 Unity，就可以使用 Unity 了。把官方教学项目 FPS Microgame 构建为 WebGL 平台程序后，可以直接在浏览器中试玩游戏。]]></summary></entry></feed>