mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-15 16:51:37 +00:00
88 lines
32 KiB
HTML
88 lines
32 KiB
HTML
<!DOCTYPE html><html lang="zh-CN" data-default-color-scheme=""auto""><head><meta charset="UTF-8"><link rel="apple-touch-icon" sizes="76x76" href="/images/img/apple-touch-icon.webp"><link rel="icon" type="image/png" href="/images/img/favicon.webp"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no,shrink-to-fit=no"><meta http-equiv="x-ua-compatible" content="ie=edge"><meta name="theme-color" content="#9DC8C8"><meta name="description" content=""><meta name="author" content="Defectink"><meta name="keywords" content=""><title>写作与协作 - 🍭Defectink</title><link rel="stylesheet" href="https://cdn.defectink.com/static/twitter-bootstrap/4.5.3/css/bootstrap.min.css"><link rel="stylesheet" href="https://cdn.defectink.com/static/github-markdown-css/4.0.0/github-markdown.min.css"><link rel="stylesheet" href="/lib/hint/hint.min.css"><link rel="stylesheet" href="https://cdn.defectink.com/static/highlight.js/10.0.0/styles/github-gist.min.css"><link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css"><link rel="stylesheet" href="https://cdn.defectink.com/static/t/font_1736178_kmeydafke9r.css"><link rel="stylesheet" href="/css/main.css"><link rel="stylesheet" href="/css/xfy.css"><script src="/js/utils.js"></script><script src="/js/color-schema.js"></script><meta name="generator" content="Hexo 5.2.0"><link rel="alternate" href="/xml/atom.xml" title="🍭Defectink" type="application/atom+xml"><link rel="alternate" href="/xml/rss.xml" title="🍭Defectink" type="application/rss+xml"></head><body><header style="height:75vh"><nav id="navbar" class="navbar fixed-top navbar-expand-lg navbar-dark scrolling-navbar"><div class="container"><a class="navbar-brand" href="/"> <strong>🍭Defectink</strong> </a> <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"><div class="animated-icon"><span></span><span></span><span></span></div></button><div class="collapse navbar-collapse" id="navbarSupportedContent"><ul class="navbar-nav ml-auto text-center"><li class="nav-item"><a class="nav-link" href="/">🏠 首页</a></li><li class="nav-item dropdown"><a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">📕 索引</a><div class="dropdown-menu" aria-labelledby="navbarDropdown"><a class="dropdown-item" href="/categories/">🎁 分类</a> <a class="dropdown-item" href="/tags/">🎐 标签</a></div></li><li class="nav-item"><a class="nav-link" href="/archives/">📂 归档</a></li><li class="nav-item"><a class="nav-link" href="/about/">🎃 关于</a></li><li class="nav-item"><a class="nav-link" href="/links/">🙆♀️ 小伙伴</a></li><li class="nav-item"><a class="nav-link" href="/pgp/">🔐 PGP</a></li><li class="nav-item" id="search-btn"><a class="nav-link" data-toggle="modal" data-target="#modalSearch"> <i class="iconfont icon-search"></i> </a></li><li class="nav-item" id="color-toggle-btn"><a class="nav-link" href="javascript:"> <i class="iconfont icon-dark" id="color-toggle-icon"></i> </a></li></ul></div></div></nav><div class="banner intro-2" id="background" parallax="true" style="background:url(/images/img/post.webp) no-repeat center center;background-size:cover"><div class="full-bg-img"><div class="mask flex-center" style="background-color:rgba(0,0,0,.3)"><div class="container page-header text-center fade-in-up"><span class="h2" id="subtitle"></span><div class="mt-3"><span class="post-meta mr-2"><i class="iconfont icon-author" aria-hidden="true"></i> Defectink</span><span class="post-meta"><i class="iconfont icon-date-fill" aria-hidden="true"></i> <time datetime="2020-06-29 12:12" pubdate>2020年6月29日 中午</time></span></div><div class="mt-1"><span class="post-meta mr-2"><i class="iconfont icon-chart"></i> 3.6k 字</span><span class="post-meta mr-2"><i class="iconfont icon-clock-fill"></i> 42 分钟</span></div></div></div></div></div></header><main><div class="container-fluid"><div class="row"><div class="d-none d-lg-block col-lg-2"></div><div class="col-lg-8 nopadding-md"><div class="container nopadding-md" id="board-ctn"><div class="py-5" id="board"><article class="post-content mx-auto" id="post"><h1 style="display:none">写作与协作</h1><p class="note note-info">本文最后水于:2020年11月2日 凌晨</p><div class="markdown-body" id="post-body"><p>出于对速度无理的追求,最终还是放弃了使用动态内容。转战静态blog。以前也稍微尝试过hexo,所以决定还是主要为hexo为主了。</p><p>在之前试过的typecho、wordpress之中,越是臃肿复杂的程序,1M的带宽越是不够。再详细的折腾了hexo之后,发现了最佳的解决方案。</p><p>在早期的一些常识之后,我也学会了很多。在刚入坑hexo的时候是盯上了阿里云的ECS+OSS和CDN的。虽然部署还是比较麻烦,但起码已经有了一套比较完善的流程了。</p><h2 id="从前的写作流程✍"><a href="#从前的写作流程✍" class="headerlink" title="从前的写作流程✍"></a>从前的写作流程✍</h2><p>Typora + OneDrive + VScode</p><p>以前买过软软的365,于是就用Onedrive来同步写的东西了。Onedrive对windows用起来还好,虽然有时会出些莫名其的问题,但基本上的备份与同步都是正常的。</p><p>但对于这套流程的问题不只是Onedrive它卡,这三个软件的契合度并不是很高。写一段代码要切到VScode,写完了再切回来复制到Typora。Onedrive在后台的实时同步还占用一定的性能。</p><p>相比较而下,我的部署流程就更为复杂了。因为我的Markdown文件都是放在Onedrive里的,而Hxeo因为<code>node_modules</code>的原因并不在Onedrive里,我需要写完了之后再将图片和MD放到Hexo的目录。之后再手动执行生成文章的命令。随后再将生成好的文章手动上传到ECS里挂载的OSS目录。</p><p>为什么要通过ECS再传到OSS呢?因为ECS和OSS再同一个区域是不会产生流量费用的。😅</p><p>Hexo –> ECS –> OSS</p><h2 id="现在的流程"><a href="#现在的流程" class="headerlink" title="现在的流程"></a>现在的流程</h2><p>VScode + git</p><p>将步骤的简化带来的不只是效率,从之前的两个编辑器来回切换到现在的只需要一个编辑器,在文字多的情况下也能保证一定的性能。此外,整体流程的步骤也更加契合,写完了之后可以直接在VScode里打开Terminal进行push。</p><p>配上CI持续集成,只需要写完push,之后就可以等着全新的文章上线。</p><p>Hexo –> CI –> COS</p><p>Hexo的仓库直接push,之后CI持续集成就会按照预设好的步骤来进行部署,除了可以部署到几个仓库的Pages外,还可以直接部署到云存储。</p><h3 id="VS-Code-不只是代码"><a href="#VS-Code-不只是代码" class="headerlink" title="VS Code - 不只是代码"></a>VS Code - 不只是代码</h3><p>软软的Visual Studio Code是一款很棒的编辑器。很早之前我就用它来尝试写一些东西,但只是用作于编辑器,主要功能就是代码补全和着色。</p><p>在早期的时候我比较喜欢用Typora来写作,它的风格我很喜欢,还能换主题,整体看上去很漂亮。但最近发现了一些比较难以容忍的毛病;就是当它的一篇文章字符超过10K的时候,性能略差一点的电脑就会很卡,打字都不出来的那种。我猜想可能和它是electron写的有关系。</p><p>就在我还没放弃它的时候,我无意中找到了VScode的Markdown插件。反正装插件也不是很麻烦是事情,于是就是尝试了一下。</p><p>没想到一时间我便爱上了它,虽然整体界面没有以前那么整洁、那么清新脱俗。但整体给人给感觉没有非常杂乱,反而看上去倒有点像剪辑软件?</p><p>除了外观从清新脱俗到繁重了一点,余下就只剩方便了。对于我这种才转到hexo的写作半吊子,一直很想找个与hexo契合度高的写作姿势。之前需要在Typora中写完,然后再将文章和单独的图片文件夹复制到hexo的<code>souce/_post</code>目录。像我这种半年产出一篇文章的还好,要是天天写,那样会被麻烦死。况且,如果有某一篇文章出了点小差错需要改。那就要同时动两个md文件和两组图片文件夹,对着资源管理翻来覆去的找,极为麻烦!🌚</p><p><img src="../images/%E5%86%99%E4%BD%9C%E4%B8%8E%E5%8D%8F%E4%BD%9C/vscode.webp" srcset="/images/img/loading.gif" alt="vscode"></p><h4 id="粘贴图片🖼"><a href="#粘贴图片🖼" class="headerlink" title="粘贴图片🖼"></a>粘贴图片🖼</h4><p>之前在使用Typora写作的时候,最为方便的莫非是粘贴图片了。目前Windows上的Typora也支持将粘贴的图片复制到指定的路径或者是云存储。我的图片存放路径都是相对于文章的目录下的<code>images</code>目录:</p><pre><code class="hljs bash">../images/postName/</code></pre><p>Typora可以设置将图片复制到指定文件夹,还能创建文件夹。不过好在在VScode里也有插件能够实现同样的操作。使得插图剩下了一大笔麻烦的操作。</p><p>我用的是开源的<a target="_blank" rel="noopener" href="https://marketplace.visualstudio.com/items?itemName=mushan.vscode-paste-image">Paste Images</a>。</p><p>只需要将插件稍微改下设置,将path修改下就能达到想要的效果。</p><pre><code class="hljs bash">../images/<span class="hljs-variable">${currentFileNameWithoutExt}</span>/</code></pre><h4 id="一些小设置"><a href="#一些小设置" class="headerlink" title="一些小设置"></a>一些小设置</h4><p><strong>Quick Suggestions</strong></p><p>Editor > Suggest: Snippets Prevent Quick Suggestions</p><p>在代码段中依然显示建议。</p><p><strong>自定义Suggestions</strong></p><pre><code class="hljs js">{
|
||
<span class="hljs-comment">// Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and </span>
|
||
<span class="hljs-comment">// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:</span>
|
||
<span class="hljs-comment">// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the </span>
|
||
<span class="hljs-comment">// same ids are connected.</span>
|
||
<span class="hljs-comment">// Example:</span>
|
||
<span class="hljs-string">"Print to console"</span>: {
|
||
<span class="hljs-string">"prefix"</span>: <span class="hljs-string">"cl"</span>,
|
||
<span class="hljs-string">"body"</span>: [
|
||
<span class="hljs-string">"console.log($1);"</span>,
|
||
],
|
||
<span class="hljs-string">"description"</span>: <span class="hljs-string">"Log output to console"</span>
|
||
}
|
||
}</code></pre><h3 id="Coding-持续构建⏰"><a href="#Coding-持续构建⏰" class="headerlink" title="Coding - 持续构建⏰"></a>Coding - 持续构建⏰</h3><p>之前最大的问题还是手动部署hexo的繁琐操作,每新增一篇文章都是几个重复的机械性操作。对于我这种半年才写一篇文章的咸鱼来说都感觉到烦了。</p><p>使用CI持续部署的好处就是,可以完全专心与创作,而不用再去管部署之类的问题。只需要第一次写好流程,剩下的就全部交给自动化吧。</p><p><img src="../images/%E5%86%99%E4%BD%9C%E4%B8%8E%E5%8D%8F%E4%BD%9C/2020-08-07-09-30-54.webp" srcset="/images/img/loading.gif" alt="coding"></p><p>之前的我从来没有用过Coding,对CI/CD也没有什么了解,从来没考虑过自动化部署这类操作。后来在研究静态化网站时发现了新大陆,完全可以将复杂重复的工作交给机器。并且随着后面文章的增加,渲染markdown文件肯定会越来越慢,于其手动繁琐的操作,不如完全交给CI。</p><h3 id="Github-Action"><a href="#Github-Action" class="headerlink" title="Github Action"></a>Github Action</h3><p>在我研究CI姿势的这段时间里,Github也推出了自己的CI(钞能力)。无论是谁家的CI,除了部署步骤不一样,其结果肯定是相同的。Github action也是能达到同样的效果,对于各个厂家的云存储,action也有同样的解决方法,甚至是比coding的jenkins还要灵活一点。</p><p><img src="../images/%E5%86%99%E4%BD%9C%E4%B8%8E%E5%8D%8F%E4%BD%9C/2020-08-27-16-32-48.webp" srcset="/images/img/loading.gif"></p><h2 id="Hexo插件📥"><a href="#Hexo插件📥" class="headerlink" title="Hexo插件📥"></a>Hexo插件📥</h2><h3 id="压缩"><a href="#压缩" class="headerlink" title="压缩"></a>压缩</h3><p>我用的是<a target="_blank" rel="noopener" href="https://github.com/chenzhutian/hexo-all-minifier">Hexo-all-minifier</a>,可以静态文件以及图片。还可以分别设置压缩等级来权衡质量与大小。</p><pre><code class="hljs bash">npm install hexo-all-minifier --save
|
||
```
|
||
|
||
不过它使用到了已经编译好的二进制包gifsicle等,在安装时需要走个脚本编译一下,在网络不好的情况下大概率会安装失败。为此我还特地水过一次:[Can<span class="hljs-string">'t install gifsicle](https://www.defectink.com/defect/cant-install-gifsicle.html)</span>
|
||
<span class="hljs-string"></span>
|
||
<span class="hljs-string">Hexo-all-minifier用到的也是gulp和一些图片压缩的工具,相对于gulp来说,它的配置更简单,更适合像我这种比较懒的咸鱼。</span>
|
||
<span class="hljs-string"></span>
|
||
<span class="hljs-string">只需要在站点配置文件添加一段聚合好的配置文件就好了,像这样:</span>
|
||
<span class="hljs-string"></span>
|
||
<span class="hljs-string">```yml</span>
|
||
<span class="hljs-string"># minifier</span>
|
||
<span class="hljs-string">all_minifier: ture</span>
|
||
<span class="hljs-string"></span>
|
||
<span class="hljs-string">html_minifier:</span>
|
||
<span class="hljs-string"> enable: true</span>
|
||
<span class="hljs-string"> ignore_error: false</span>
|
||
<span class="hljs-string"> silent: false</span>
|
||
<span class="hljs-string"> exclude:</span>
|
||
<span class="hljs-string"></span>
|
||
<span class="hljs-string">css_minifier:</span>
|
||
<span class="hljs-string"> enable: true</span>
|
||
<span class="hljs-string"> silent: false</span>
|
||
<span class="hljs-string"> exclude: </span>
|
||
<span class="hljs-string"> - '</span>*.min.css<span class="hljs-string">'</span>
|
||
<span class="hljs-string"></span>
|
||
<span class="hljs-string">js_minifier:</span>
|
||
<span class="hljs-string"> enable: true</span>
|
||
<span class="hljs-string"> mangle: true</span>
|
||
<span class="hljs-string"> silent: false</span>
|
||
<span class="hljs-string"> output:</span>
|
||
<span class="hljs-string"> compress:</span>
|
||
<span class="hljs-string"> exclude: </span>
|
||
<span class="hljs-string"> - '</span>*.min.js<span class="hljs-string">'</span>
|
||
<span class="hljs-string"></span>
|
||
<span class="hljs-string">image_minifier:</span>
|
||
<span class="hljs-string"> enable: true</span>
|
||
<span class="hljs-string"> interlaced: false</span>
|
||
<span class="hljs-string"> multipass: false</span>
|
||
<span class="hljs-string"> optimizationLevel: 2</span>
|
||
<span class="hljs-string"> webpquant: false</span>
|
||
<span class="hljs-string"> progressive: false</span>
|
||
<span class="hljs-string"> silent: false</span></code></pre><h3 id="Sitemap与RSS"><a href="#Sitemap与RSS" class="headerlink" title="Sitemap与RSS"></a>Sitemap与RSS</h3><p>两个小功能吧,虽然也不会有人来订阅我的小破站🤣。</p><pre><code class="hljs bash">npm install hexo-generator-sitemap --save
|
||
npm install hexo-generator-feed --save</code></pre><p>和压缩插件一样,都是在站点的<code>_config.yml</code>里添上相应的配置文件就好了。</p><pre><code class="hljs yml"><span class="hljs-comment"># feed</span>
|
||
<span class="hljs-attr">feed:</span>
|
||
<span class="hljs-attr">type:</span>
|
||
<span class="hljs-bullet">-</span> <span class="hljs-string">atom</span>
|
||
<span class="hljs-bullet">-</span> <span class="hljs-string">rss2</span>
|
||
<span class="hljs-attr">path:</span>
|
||
<span class="hljs-bullet">-</span> <span class="hljs-string">/xml/atom.xml</span>
|
||
<span class="hljs-bullet">-</span> <span class="hljs-string">/xml/rss.xml</span>
|
||
<span class="hljs-attr">limit:</span> <span class="hljs-number">20</span>
|
||
<span class="hljs-attr">hub:</span>
|
||
<span class="hljs-attr">content:</span>
|
||
<span class="hljs-attr">content_limit:</span> <span class="hljs-number">140</span>
|
||
<span class="hljs-attr">content_limit_delim:</span> <span class="hljs-string">' '</span>
|
||
<span class="hljs-attr">order_by:</span> <span class="hljs-string">-date</span>
|
||
<span class="hljs-attr">icon:</span> <span class="hljs-string">icon.webp</span>
|
||
<span class="hljs-attr">autodiscovery:</span> <span class="hljs-literal">true</span>
|
||
<span class="hljs-attr">template:</span>
|
||
|
||
<span class="hljs-comment"># sitemap</span>
|
||
<span class="hljs-attr">sitemap:</span>
|
||
<span class="hljs-attr">path:</span> <span class="hljs-string">/xml/sitemap.xml</span>
|
||
<span class="hljs-attr">template:</span> <span class="hljs-string">./source/_data/sitemap_template.xml</span>
|
||
<span class="hljs-attr">rel:</span> <span class="hljs-literal">false</span>
|
||
<span class="hljs-attr">tags:</span> <span class="hljs-literal">true</span>
|
||
<span class="hljs-attr">categories:</span> <span class="hljs-literal">true</span></code></pre><p>另外,可以来试一下:</p><ul><li><a href="/xml/atom.xml">Atom</a></li><li><a href="/xml/rss.xml">RSS</a></li><li><a href="/xml/sitemap.xml">Sitemap</a></li></ul><h2 id="Git加速"><a href="#Git加速" class="headerlink" title="Git加速"></a>Git加速</h2><p>使用Linux主机或者在Windows中使用git bash时,修改(新建)在用户目录下的<code>~/.ssh/config</code>文件,新加如下内容。</p><pre><code class="hljs bash">host github.com
|
||
HostName github.com
|
||
PreferredAuthentications publickey
|
||
IdentityFile ~/.ssh/id_rsa
|
||
ProxyCommand connect -S 127.0.0.1:1080 %h %p</code></pre><p>macos的connect可以用brew安装,而windows的git bash中已有:</p><pre><code class="hljs bash">brew install connect</code></pre><p>对于Ubuntu:</p><pre><code class="hljs bash">apt-get install connect-proxy</code></pre><p>某些发行版可能没有connect软件包,这个地址下载源码编译一下就好了。</p><pre><code class="hljs awk">https:<span class="hljs-regexp">//</span>bitbucket.org<span class="hljs-regexp">/gotoh/</span>connect<span class="hljs-regexp">/src/</span>default/</code></pre><p>对于http:</p><pre><code class="hljs bash">git config --global http.proxy <span class="hljs-string">"socks5://127.0.0.1:1080"</span>
|
||
git config --global https.proxy <span class="hljs-string">"socks5://127.0.0.1:1080"</span></code></pre><p>node的淘宝源</p><pre><code class="hljs bash">npm config <span class="hljs-built_in">set</span> registry https://registry.npm.taobao.org</code></pre><pre><code class="hljs bash">npm config <span class="hljs-built_in">set</span> registry https://registry.npmjs.org</code></pre><h2 id="早期计划"><a href="#早期计划" class="headerlink" title="早期计划"></a>早期计划</h2><h3 id="内容分发网络"><a href="#内容分发网络" class="headerlink" title="内容分发网络"></a>内容分发网络</h3><p>之前就有在使用cdn来加速图片的访问,效果也还是不错的。但是整体blog的内容还都是有1M服务器上的php生成的。所以就算异地图片加载速度再快,终端也需要连接到身在华南的服务器。无论是人多还是人少,速度总是不理想。</p><p>最后打算使用纯静态的blog,直接部署到cdn上,速度肯定是无可比拟的。但是还是有一点弊端的,例如cdn节点可能更新不及时等问题。</p><h3 id="解决方案"><a href="#解决方案" class="headerlink" title="解决方案"></a>解决方案</h3><p>正好手头有个1M出口的ECS,嫌它太慢。而它的真正作用在于和阿里云的oss进行通信,因为走的是阿里云的内网,所以通过ECS上传文件到oss是不需要收流量费用的。而ECS仅仅只是出口1M而已,入口是不限速的。如果需要最大化节约的上传文件到oss,可以通过ECS传。</p><p>阿里云的oss在linux上有个可以连接oss的软件,但是那个操作并不是我想需要的。好在阿里云还有一款<a target="_blank" rel="noopener" href="https://help.aliyun.com/document_detail/32196.html?spm=a2c4g.11186623.6.749.72b73adfsKCqTT">ossfs</a>软件。它可以将对象存储OSS的存储空间(Bucket)挂载到本地文件系统中,能够像操作本地文件一样操作OSS的对象(Object),实现数据的共享。</p><p>这对于写静态blog来说实在是太方便了,只需要将Bucket挂载到本地文件夹,就像挂载磁盘那样操作。随后就可以不用流量的将静态文件上传到oss。</p><p>开启OSS的静态网站托管,将hexo生成的静态blog都放到挂载的目录下即可。非常的方便,文章内的图片也可以使用相对路径,而不需要一张一张的插入外链那么麻烦了。</p><p>需要注意一点的是:使用OSS默认域名访问时,Response Header中会自动加上 <code>Content-Disposition:'attachment=filename;'</code>。即从浏览器访问网页类型文件时,不会显示文件内容,而是以附件形式进行下载。也就是说需要绑定自己的域名才能静态托管。</p><h3 id="多重备份"><a href="#多重备份" class="headerlink" title="多重备份"></a>多重备份</h3><p>这种方案解决的好处就是,可以在多个地方实现多重的数据备份。且不需要在备份数据库了。</p><ul><li>Github一份备份</li><li>CDN一份备份</li><li>ECS一份备份</li><li>自己的电脑还可以有多份备份</li></ul><p>一步直接实现异地多备份。</p><h3 id="OSSFS"><a href="#OSSFS" class="headerlink" title="OSSFS"></a>OSSFS</h3><p>目前有多个发行版的安装包:</p><table><thead><tr><th align="left">Linux发行版</th><th align="left">下载</th></tr></thead><tbody><tr><td align="left">Ubuntu 18.04 (x64)</td><td align="left"><a target="_blank" rel="noopener" href="http://gosspublic.alicdn.com/ossfs/ossfs_1.80.6_ubuntu18.04_amd64.deb">ossfs_1.80.6_ubuntu18.04_amd64.deb</a></td></tr><tr><td align="left">Ubuntu 16.04 (x64)</td><td align="left"><a target="_blank" rel="noopener" href="http://gosspublic.alicdn.com/ossfs/ossfs_1.80.6_ubuntu16.04_amd64.deb">ossfs_1.80.6_ubuntu16.04_amd64.deb</a></td></tr><tr><td align="left">Ubuntu 14.04 (x64)</td><td align="left"><a target="_blank" rel="noopener" href="http://gosspublic.alicdn.com/ossfs/ossfs_1.80.6_ubuntu14.04_amd64.deb">ossfs_1.80.6_ubuntu14.04_amd64.deb</a></td></tr><tr><td align="left">CentOS 7.0 (x64)</td><td align="left"><a target="_blank" rel="noopener" href="http://gosspublic.alicdn.com/ossfs/ossfs_1.80.6_centos7.0_x86_64.rpm">ossfs_1.80.6_centos7.0_x86_64.rpm</a></td></tr><tr><td align="left">CentOS 6.5 (x64)</td><td align="left"><a target="_blank" rel="noopener" href="http://gosspublic.alicdn.com/ossfs/ossfs_1.80.6_centos6.5_x86_64.rpm">ossfs_1.80.6_centos6.5_x86_64.rpm</a></td></tr></tbody></table><p>下载到主机内后,根据不同的发行版进行安装就好了。而对于Ubuntu需要使用gdebi:</p><pre><code class="hljs bash">sudo apt-get update
|
||
sudo apt-get install gdebi-core
|
||
sudo gdebi your_ossfs_package</code></pre><h4 id="配置账号信息"><a href="#配置账号信息" class="headerlink" title="配置账号信息"></a>配置账号信息</h4><p>成功了安装了之后就可以配置oss的账号信息来登陆。使用AccessKeyId/AccessKeySecret来代替账号密码进行访问。如果担心安全问题还可以使用阿里云的子账号只赋予oss的访问权限,来最大程度的保护账户资产。在阿里云的<a target="_blank" rel="noopener" href="https://ram.console.aliyun.com/overview">RAM访问控制</a>中可以进行添加子账户并赋予特定的权限。</p><p><img src="../images/%E5%86%99%E4%BD%9C%E4%B8%8E%E5%8D%8F%E4%BD%9C/image-20200229104812836.webp" srcset="/images/img/loading.gif" alt="image-20200229104812836"></p><p>AccessKeyId/AccessKeySecret信息存放在<code>/etc/passwd-ossfs</code>文件中。并且文件的权限必须正确设置,建议设为640。</p><p>格式为:<code>bucket名:AccessKeyId:AccessKeySecret</code></p><pre><code class="hljs bash"><span class="hljs-built_in">echo</span> my-bucket:my-access-key-id:my-access-key-secret > /etc/passwd-ossfs
|
||
chmod 640 /etc/passwd-ossfs</code></pre><p>如果需要配置多个账号或者多个bucket,可以直接将账号信息写在后面,ossfs会根据挂载的存储空间名称匹配到正确的账号上。</p><pre><code class="hljs bash"><span class="hljs-built_in">echo</span> my-second-bucket:my-access-key-id:my-access-key-secret >> /etc/passwd-ossfs</code></pre><h4 id="挂载到指定目录"><a href="#挂载到指定目录" class="headerlink" title="挂载到指定目录"></a>挂载到指定目录</h4><p>账号信息填写的非常简单,写到指定文件里就可以了。填完之后就可以将oss挂载到本地的指定目录上。</p><p>格式为:<code>ossfs bucket名 本地挂载点 -ourl=oss url</code></p><pre><code class="hljs applescript">ossfs <span class="hljs-keyword">my</span>-bucket <span class="hljs-keyword">my</span>-mount-point -ourl=<span class="hljs-keyword">my</span>-oss-endpoint</code></pre><p>如果正好使用的是阿里云的ECS机器,可以走oss的内网,在上传文件时就不会产生多余的流量费用。通常oss的内网域名包含internal。例如:</p><pre><code class="hljs css"><span class="hljs-selector-tag">oss-cn-beijing-internal</span><span class="hljs-selector-class">.aliyuncs</span><span class="hljs-selector-class">.com</span></code></pre><p>只需要将近4条左右的命令就可以将oss成功挂载到本地上,就如同一个文件夹。</p><h4 id="开机自动挂载"><a href="#开机自动挂载" class="headerlink" title="开机自动挂载"></a>开机自动挂载</h4><p>和开机自动挂载分区一样,Ubuntu需要在<code>/etc/fstab</code>中进行操作。</p><pre><code class="hljs bash">ossfs<span class="hljs-comment">#bucket_name mount_point fuse _netdev,url=url,allow_other 0 0</span></code></pre><p>对应的填入了信息之后,可以使用<code>mount -a</code>进行测试。如果没有任何报错,即代表成功。</p><h3 id="阿里云子目录"><a href="#阿里云子目录" class="headerlink" title="阿里云子目录"></a>阿里云子目录</h3><p>阿里云oss的默认配置是不会去访问子目录下的首页的,子目录下的<code>index.html</code>必须访问全部的静态链接。否则会跳转回主页的<code>index.html</code>。</p><p>网上的大多数解决办法就是修改hexo的配置,把所有的子目录的绝对路径都生成出来。这是一种解决办法,但不能从根源上解决所有问题。</p><p>并且阿里云也早就支持了子目录首页了。只需要简单开一下就能解决这个问题。</p><p><img src="../images/%E5%86%99%E4%BD%9C%E4%B8%8E%E5%8D%8F%E4%BD%9C/image-20200401100940056.webp" srcset="/images/img/loading.gif" alt="image-20200401100940056"></p></div><hr><div><div class="post-metas mb-3"><div class="post-meta mr-3"><i class="iconfont icon-category"></i> <a class="hover-with-bg" href="/categories/%E5%AE%9E%E8%B7%B5/">实践</a></div><div class="post-meta"><i class="iconfont icon-tags"></i> <a class="hover-with-bg" href="/tags/Tools/">Tools</a></div></div><p class="note note-warning"><a target="_blank" href="https://zh.wikipedia.org/wiki/Wikipedia:CC_BY-SA_3.0%E5%8D%8F%E8%AE%AE%E6%96%87%E6%9C%AC" rel="nofollow noopener noopener">CC BY-SA 3.0❤</a></p><div class="post-prevnext row"><article class="post-prev col-6"><a href="/defect/javascript-scope-and-chain.html"><i class="iconfont icon-arrowleft"></i> <span class="hidden-mobile">JavaScript的作用域与链</span> <span class="visible-mobile">上一篇</span></a></article><article class="post-next col-6"><a href="/defect/javascript-notes-reference-type.html"><span class="hidden-mobile">JavaScript笔记-引用类型</span> <span class="visible-mobile">下一篇</span><i class="iconfont icon-arrowright"></i></a></article></div></div><article class="comments" id="comments"><div id="vcomments"></div><script type="text/javascript">function loadValine(){addScript("https://cdn.defectink.com/static/valine/1.4.14/Valine.min.js",function(){new Valine({el:"#vcomments",app_id:"dD9t7mcIBVzJWag5ez6GPy2v-MdYXbMMI",app_key:"bWG6pmKsEscrH4JjrpNNAAy6",placeholder:"嘤嘤嘤???",path:window.location.pathname,avatar:"retro",meta:["nick","mail","link"],pageSize:"10",lang:"zh-CN",highlight:!0,recordIP:!1,serverURLs:""})})}waitElementVisible("vcomments",loadValine)</script><noscript>Please enable JavaScript to view the <a target="_blank" href="https://valine.js.org" rel="nofollow noopener noopener">comments powered by Valine.</a></noscript></article></article></div></div></div><div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn"><div id="toc"><p class="toc-header"><i class="iconfont icon-list"></i> 目录</p><div id="tocbot"></div></div></div></div></div></main><a id="scroll-top-button" href="#" role="button"><i class="iconfont icon-arrowup" aria-hidden="true"></i></a><div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true"><div class="modal-dialog modal-dialog-scrollable modal-lg" role="document"><div class="modal-content"><div class="modal-header text-center"><h4 class="modal-title w-100 font-weight-bold">搜索</h4><button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button></div><div class="modal-body mx-3"><div class="md-form mb-5"><input type="text" id="local-search-input" class="form-control validate"> <label data-error="x" data-success="v" for="local-search-input">关键词</label></div><div class="list-group" id="local-search-result"></div></div></div></div></div><footer class="text-center mt-5 py-3"><div class="footer-content"><a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a><i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a></div><div class="beian"><a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">皖ICP备17017808号</a></div></footer><script src="https://cdn.defectink.com/static/jquery/3.4.1/jquery.min.js"></script><script src="https://cdn.defectink.com/static/twitter-bootstrap/4.5.3/js/bootstrap.min.js"></script><script src="/js/debouncer.js"></script><script src="/js/main.js"></script><script src="/js/lazyload.js"></script><script defer="defer" src="https://cdn.defectink.com/static/clipboard.js/2.0.6/clipboard.min.js"></script><script src="/js/clipboard-use.js"></script><script src="/js/xfy.js"></script><script src="https://cdn.defectink.com/static/tocbot/4.11.1/tocbot.min.js"></script><script>$(document).ready(function(){var t=$("#board-ctn").offset().top;tocbot.init({tocSelector:"#tocbot",contentSelector:"#post-body",headingSelector:"h1,h2,h3,h4,h5,h6",linkClass:"tocbot-link",activeLinkClass:"tocbot-active-link",listClass:"tocbot-list",isCollapsedClass:"tocbot-is-collapsed",collapsibleClass:"tocbot-is-collapsible",collapseDepth:3,scrollSmooth:!0,headingsOffset:-t}),0<$(".toc-list-item").length&&$("#toc").css("visibility","visible")})</script><script src="https://cdn.defectink.com/static/typed.js/2.0.11/typed.min.js"></script><script>var typed=new Typed("#subtitle",{strings:[" ","写作与协作 "],cursorChar:"❤",typeSpeed:70,loop:!1});typed.stop(),$(document).ready(function(){$(".typed-cursor").addClass("h2"),typed.start()})</script><script src="/js/local-search.js"></script><script>var path="/xml/local-search.xml",inputArea=document.querySelector("#local-search-input");inputArea.onclick=function(){searchFunc(path,"local-search-input","local-search-result"),this.onclick=null}</script><script src="https://cdn.defectink.com/static/fancybox/3.5.7/jquery.fancybox.min.js"></script><link rel="stylesheet" href="https://cdn.defectink.com/static/fancybox/3.5.7/jquery.fancybox.min.css"><script>$("#post img:not(.no-zoom img, img[no-zoom]), img[zoom]").each(function(){var t=document.createElement("a");$(t).attr("data-fancybox","images"),$(t).attr("href",$(this).attr("src")),$(this).wrap(t)})</script><script src="https://cdn.defectink.com/static/mermaid/8.5.0/mermaid.min.js"></script><script>window.mermaid&&mermaid.initialize({theme:"default"})</script></body></html> |