{"slug":"alist-for-aliyun","title":"利用阿里云云函数 FC 搭建AList后端，每月仅需5毛！","description":"阿里云云函数 FC是一个弹性的计算平台，可托管多种服务。搭配AList的前后端分离部署，实现比VPS更低的价格，得到更好的体验","coverImage":"https://b.acofork.com/img/alist-for-aliyun-47518d4403328a0fcb716f0e06fc7f608e6c65b7.webp","coverWidth":744,"coverHeight":380,"date":"2025-01-12","tags":["服务器"],"pinned":false,"wordCount":1273,"html":"<h2 id=\"还是建议购买一个便宜的云服务器来部署或者用家里云-这种方法很灵车\">还是建议购买一个便宜的云服务器来部署或者用家里云，这种方法很灵车</h2><p>推荐Akile：<a href=\"https://akile.io/register?aff_code=503fe5ea-e7c5-4d68-ae05-6de99513680e\" target=\"_blank\" rel=\"noopener noreferrer\">https://akile.io/register?aff_code=503fe5ea-e7c5-4d68-ae05-6de99513680e</a></p>\n<hr />\n<h2 id=\"原理\">原理</h2><ol>\n<li>AList前端有一个专门的项目：<a href=\"https://github.com/AlistGo/alist-web\" target=\"_blank\" rel=\"noopener noreferrer\">https://github.com/AlistGo/alist-web</a> 。可前往<a href=\"/posts/alist-web/\">AList-Web部署教程</a>。教程使用了Cloudflare Page进行前端部署，我们更建议你使用 <a href=\"https://vercel.com\" target=\"_blank\" rel=\"noopener noreferrer\">https://vercel.com</a> 来进行前端部署，因为更快。这些都完全免费</li>\n<li>部署完毕前端后，我们就需要一个后端，它需要能够执行AList的二进制文件，并且能开放端口（默认为5244）来让前端可以和后端相互通信。在传统情况下我们会选择购买一台云服务器，或者用自己的电脑/家里云+Cloudflare Tunnel又或者是Serv00这种免费的托管。本篇我们使用阿里云FC函数计算，它虽然可以运行二进制文件，但是和传统架构大相径庭，我们要深入了解。</li>\n<li>FC函数是一个实例性服务。用户可以创建函数部署服务，当一定条件被触发（比如HTTP触发器）则创建新的实例开始运行用户的服务。也就是说这个实例是无状态的，如果直接拿来部署AList就会导致第一次配置完毕后过一段时间再访问就会变为初始状态。就算你一开始就使用一个全量包来部署，在部署后也无法对其进行更改，所以我们需要绑定一个NAS文件系统，用于数据持久化。但是NAS文件系统并不能直接绑定到代码的运行时 /code/xxx 目录，我们可以使用AList的指定配置文件参数，将NAS绑定到 /mnt/AList 然后指定配置文件到 /mnt/AList 。也就是通过 <strong>./alist server --data /mnt/AList</strong> 命令来启动，这样就做到了数据持久化。</li>\n</ol>\n<h2 id=\"关于计费\">关于计费</h2><ol>\n<li>FC函数通过CU数来收费</li>\n<li>NAS通过存储空间来收费</li>\n</ol>\n<h2 id=\"实操\">实操</h2><ol>\n<li>我们假设你已经部署完毕了前端。前端和后端的通信地址在根目录的 env.production 文件定义</li>\n<li>我们目前并不知道这个后端URL如何填写，因为这个URL是由阿里云在FC函数创建完毕的时候才会展示，所以我们暂且搁置到一遍</li>\n<li>接下来我们前往阿里云-函数计算FC官网 <a href=\"https://fcnext.console.aliyun.com/overview\" target=\"_blank\" rel=\"noopener noreferrer\">https://fcnext.console.aliyun.com/overview</a> </li>\n<li>依次点击 左侧边栏的 函数 -&gt; 创建函数 -&gt; Web函数。进入到创建Web函数的页面</li>\n<li>函数名称填写AList，运行环境选择Debian 10或Debian 11，代码上传方式选择从文件夹上传代码，启动命令填写：<strong>./alist server --data /mnt/AList</strong>，监听端口填写5244</li>\n<li>我们需要上传代码到函数，也就是AList的二进制文件，我们前往 <a href=\"https://github.com/AlistGo/alist/releases/latest\" target=\"_blank\" rel=\"noopener noreferrer\">https://github.com/AlistGo/alist/releases/latest</a> 下载最新的Linux AMD64架构的二进制文件，也就是 <strong>alist-linux-amd64.tar.gz</strong>。将其解压，你会得到一个名为 <strong>alist</strong>的二进制文件，创建一个空文件夹将其放进去，然后上传这个文件夹到函数</li>\n</ol>\n<p><img src=\"https://b.acofork.com/img/alist-for-aliyun-QmdajYeRyt1u3BSmRdGx8uUHKamGDkwoRe4TmEFZsJsaqS.webp\" alt=\"image\" width=\"1920\" height=\"1032\" loading=\"eager\" decoding=\"async\" /></p>\n<ol>\n<li><p>然后点击左下角的创建</p>\n</li>\n<li><p>然后你会进入到函数的控制面板，依次点击 配置 -&gt; 网络 -&gt; 网络 编辑 -&gt; 允许访问VPC:是 -&gt; 自动配置。依次点击 配置 -&gt; 存储 -&gt; NAS文件存储 编辑 -&gt; 挂载 NAS 文件系统:启用 -&gt; 自动配置。依次点击 日志 -&gt; 开通日志服务</p>\n</li>\n<li><p>现在回到 代码 界面，点击部署代码。稍等片刻会提示部署成功，然后点击 函数详情内的 HTTP触发器 ，复制公网访问地址。这个就是我们前文提到的要写到前端根目录的 env.production 文件的URL，将其填写进去，例如</p>\n<div class=\"markdown-code\" data-language=\"shell\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M12 19h8\"></path><path d=\"m4 17 6-6-6-6\"></path></svg><span>shell</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-shell\">VITE_API_URL = <span class=\"hljs-string\">\"https://aliyun-fc-alist.run\"</span></code></pre></div></li>\n<li><p>提交你的新更改，前端会自动重新构建</p>\n</li>\n<li><p>尝试直接访问你的AList前端URL，它应该会顺利进入到AList的登录页面</p>\n</li>\n<li><p>此时查看控制面板的 实例 是否有一条新的实例正在工作，如果有，再前往日志查看该实例日志，你会看到AList初始化时生成的管理员密码，拿这个密码到前端URL登录AList，然后就可以正常使用了</p>\n</li>\n</ol>\n<hr />\n<h2 id=\"疑难解答\">疑难解答</h2><ol>\n<li>如果出现正在加载储存：\n<img src=\"https://b.acofork.com/img/alist-for-aliyun-QmZVewYnKwCJzcShnkGTTVZJiTSUUSQi9u6pZ5rXRDK3rK.webp\" alt=\"9aa460cd2dc84e1debe43e9df2d342fc\" width=\"391\" height=\"148\" loading=\"lazy\" decoding=\"async\" />\n查看你的日志，是否有存储加载失败，如果有可以尝试：<ol>\n<li>反复重新部署，直到能进后台然后删除那些加载失败的存储</li>\n<li><a href=\"https://github.com/AlistGo/alist/discussions/3976\" target=\"_blank\" rel=\"noopener noreferrer\">https://github.com/AlistGo/alist/discussions/3976</a></li>\n</ol>\n</li>\n</ol>\n","toc":[{"id":"还是建议购买一个便宜的云服务器来部署或者用家里云-这种方法很灵车","text":"还是建议购买一个便宜的云服务器来部署或者用家里云，这种方法很灵车","depth":2},{"id":"原理","text":"原理","depth":2},{"id":"关于计费","text":"关于计费","depth":2},{"id":"实操","text":"实操","depth":2},{"id":"疑难解答","text":"疑难解答","depth":2}]}