<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>2018 on Ricky</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/</link><description>Recent content in 2018 on Ricky</description><generator>Hugo -- gohugo.io</generator><language>zh-tw</language><lastBuildDate>Mon, 24 Dec 2018 13:22:33 +0800</lastBuildDate><atom:link href="https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/index.xml" rel="self" type="application/rss+xml"/><item><title>阿瓦隆(The Resistance：Avalon)</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20181224-avalon/</link><pubDate>Mon, 24 Dec 2018 13:22:33 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20181224-avalon/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://mj9981168.pixnet.net/blog/posts/8196168065" target="_blank" rel="noopener">阿瓦隆(The Resistance：Avalon)&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>Linux CentOS 7 安裝字體庫 &amp; 中文本體</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20181218-fonts/</link><pubDate>Tue, 18 Dec 2018 22:13:40 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20181218-fonts/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://hk.saowen.com/a/8e1349c5e25aaca06614d56d65fcd43156684d591da80b5a886806ceac06e199" target="_blank" rel="noopener">Linux CentOS 7 安裝字體庫 &amp;amp; 中文本體&lt;/a>&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>yum -y install fontconfig
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>這時在 /usr/shared 目錄就可以看到 fonts 和 fontconfig 目錄了（之前是沒有的）&lt;/p>
&lt;p>在這之前我們還需要新建目錄，首先在 /usr/shared/fonts 目錄下新建一個目錄 chinese&lt;/p>
&lt;p>&lt;code>mkdir /usr/shared/fonts/chinese&lt;/code>&lt;/p>
&lt;p>只需要將我們需要的字體拷貝出來並上傳至 linux 服務器 /usr/shared/fonts/chinese 目錄下即可，在這裏我選擇宋體和黑體（報表中用到了這兩種字體），可以看到是兩個後綴名為 ttf 和 ttc 的文檔&lt;/p>
&lt;p>&lt;code>chmod -R 755 /usr/share/fonts/chinese&lt;/code>&lt;/p>
&lt;p>接下來需要安裝 ttmkfdir 來搜索目錄中所有的字體信息，並彙總生成 fonts.scale 文檔&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>yum -y install ttmkfdir
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>vi /etc/fonts/fonts.conf
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&amp;lt;dir&amp;gt;/usr/shared/fonts/chinese&amp;lt;dir&amp;gt;
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>刷新內存中的字體緩存&lt;/p>
&lt;p>&lt;code>fc-cache&lt;/code>&lt;/p></description></item><item><title>auth.log 中 sshd 這行的 SHA256 是什麼？</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20181217-what-is-the-sha256-that-comes-on-the-sshd-entry-in-auth-log/</link><pubDate>Mon, 17 Dec 2018 16:11:43 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20181217-what-is-the-sha256-that-comes-on-the-sshd-entry-in-auth-log/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://serverfault.com/questions/888281/what-is-the-sha256-that-comes-on-the-sshd-entry-in-auth-log" target="_blank" rel="noopener">auth.log 中 sshd 這行的 SHA256 是什麼？&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>&lt;code>ssh-keygen -lf .ssh/id_rsa.pub&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>cat .ssh/id_rsa.pub |
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> awk &lt;span style="color:#e6db74">&amp;#39;{ print $2 }&amp;#39;&lt;/span> | &lt;span style="color:#75715e"># 只取實際的 key 資料，不含前綴或註解&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> base64 -d | &lt;span style="color:#75715e"># 以 base64 解碼&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> sha256sum | &lt;span style="color:#75715e"># SHA256 雜湊（回傳十六進位）&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> awk &lt;span style="color:#e6db74">&amp;#39;{ print $1 }&amp;#39;&lt;/span> | &lt;span style="color:#75715e"># 只取十六進位資料&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> xxd -r -p | &lt;span style="color:#75715e"># 十六進位轉位元組&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> base64 &lt;span style="color:#75715e"># 以 base64 編碼&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Shell 中 `&lt; &lt;(command args)` 是什麼意思？</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20181117-what-does-command-args-mean-in-the-shell/</link><pubDate>Sat, 17 Nov 2018 22:29:23 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20181117-what-does-command-args-mean-in-the-shell/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://stackoverflow.com/questions/2443085/what-does-command-args-mean-in-the-shell" target="_blank" rel="noopener">Shell 中 &lt;code>&amp;lt; &amp;lt;(command args)&lt;/code> 是什麼意思？&lt;/a>&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">while&lt;/span> IFS&lt;span style="color:#f92672">=&lt;/span> read -r -d &lt;span style="color:#e6db74">$&amp;#39;\0&amp;#39;&lt;/span> file; &lt;span style="color:#66d9ef">do&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> dosomethingwith &lt;span style="color:#e6db74">&amp;#34;&lt;/span>$file&lt;span style="color:#e6db74">&amp;#34;&lt;/span> &lt;span style="color:#75715e"># 對每個檔案進行處理&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">done&lt;/span> &amp;lt; &amp;lt;&lt;span style="color:#f92672">(&lt;/span>find /bar -name *foo* -print0&lt;span style="color:#f92672">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>&lt;code>&amp;lt;()&lt;/code> 在手冊中稱為 &lt;a href="http://www.gnu.org/software/bash/manual/html_node/Process-Substitution.html#Process-Substitution" target="_blank" rel="noopener">&lt;strong>process substitution&lt;/strong>&lt;/a>，它類似於管線，但會傳遞 &lt;code>/dev/fd/63&lt;/code> 這種形式的參數，而不是使用 stdin。&lt;/p>
&lt;p>&lt;code>&amp;lt;&lt;/code> 會從命令列指定的檔案讀取輸入。&lt;/p>
&lt;p>這兩個運算子合起來的作用與管線完全相同，因此可以改寫為：&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>find /bar -name *foo* -print0 | &lt;span style="color:#66d9ef">while&lt;/span> read line; &lt;span style="color:#66d9ef">do&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> ...
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">done&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Netcat（Linux nc 指令）網路管理者工具實用範例</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20181109-linux-utility-netcat-examples/</link><pubDate>Fri, 09 Nov 2018 00:17:47 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20181109-linux-utility-netcat-examples/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://blog.gtwang.org/linux/linux-utility-netcat-examples/" target="_blank" rel="noopener">Netcat（Linux nc 指令）網路管理者工具實用範例&lt;/a>&lt;/li>
&lt;/ul>
&lt;h4 id="傳送測試用的-udp-封包到遠端伺服器">傳送測試用的 UDP 封包到遠端伺服器&lt;/h4>
&lt;p>下面這行指令會傳送 UDP 的測試封包到指定的機器與連接埠，&lt;code>-w1&lt;/code> 參數是指定 timeout 的時間為 1 秒。&lt;/p>
&lt;p>&lt;code>echo -n &amp;quot;foo&amp;quot; | nc -u -w1 192.168.1.8 5000&lt;/code>&lt;/p>
&lt;h4 id="開啟-udp-連接埠接收資料">開啟 UDP 連接埠接收資料&lt;/h4>
&lt;p>&lt;code>nc -lu localhost 5000&lt;/code>&lt;/p>
&lt;h4 id="遠端機器的連接埠掃描port-scanning">遠端機器的連接埠掃描（Port Scanning）&lt;/h4>
&lt;p>這行指令會掃描指定機器 1 ~ 1000 與 2000 ~ 3000 這兩個範圍的 TCP 連接埠，看看哪些埠號有開啟。&lt;/p>
&lt;p>&lt;code>nc -vnz -w 1 192.168.233.208 1-1000 2000-3000&lt;/code>&lt;/p>
&lt;p>這行則是掃描 UDP 的連接埠&lt;/p>
&lt;p>&lt;code>nc -vnzu 192.168.1.8 1-65535&lt;/code>&lt;/p>
&lt;h4 id="在兩台主機之間複製檔案">在兩台主機之間複製檔案&lt;/h4>
&lt;p>假設現在有兩台主機，分別為 A 主機與 B 主機，若要將一個檔案從 A 主機複製到 B 主機，可以先在 B 主機（檔案接收者）上執行：&lt;/p>
&lt;p>&lt;code>nc -l 5000 &amp;gt; my.jpg&lt;/code>&lt;/p></description></item><item><title>vimrc設定教學</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20181103-vimrc/</link><pubDate>Sat, 03 Nov 2018 23:30:52 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20181103-vimrc/</guid><description>&lt;ul>
&lt;li>
&lt;p>&lt;a href="https://wiki.csie.ncku.edu.tw/vim/vimrc" target="_blank" rel="noopener">vimrc 設定教學&lt;/a>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>:set nu&lt;/p>
&lt;ul>
&lt;li>顯示行號：對於 debug 相當有幫助!&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>:set ai&lt;/p>
&lt;ul>
&lt;li>自動對齊縮排：如果上一行有兩個 tab 的寬度，按 enter 繼續編輯下一行時會自動保留兩個 tab 鍵的寬度。&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>:set cursorline&lt;/p>
&lt;ul>
&lt;li>光標底線：光標所在的那一行會有底線，幫助尋找光標位置&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>:set bg=light&lt;/p>
&lt;ul>
&lt;li>上色模式-針對亮背景上色&lt;/li>
&lt;li>預設為亮背景(白色等)上色，但是終端機的初始背景色為深紫色，會出現文字失蹤 ( 例如註解為深藍色 ) 的情況。將這一行換成 :set bg=dark 即可。&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>:set tabstop=4&lt;/p>
&lt;ul>
&lt;li>縮排間隔數 ( 預設為 8 個空白對齊 )&lt;/li>
&lt;li>也就是說按一次 tab 鍵，游標會自動跳 4 格空白字元的寬度。雖有多個空格但實際上只有一個 tab 字元。&lt;/li>
&lt;li>注意：也就是說，在其他環境下，看到 tab 字元，依舊是 8 個空白寬&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>
&lt;p>:set shiftwidth=4&lt;/p>
&lt;ul>
&lt;li>自動縮排對齊間隔數：向右或向左一個縮排的寬度&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;p>以下可以斟酌使用&lt;/p>
&lt;ul>
&lt;li>:set mouse=a
&lt;ul>
&lt;li>啟用游標選取：游標可以直接選取文字，滾輪可以直接滑動頁面 ( 非移動游標 )。&lt;/li>
&lt;li>可以取代用 v 選取字元的功能，配合 ctrl+insert ( 複製 ) 及 shift+inset ( 貼上 )，相當方便&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>:set mouse=&amp;quot;&amp;quot;
&lt;ul>
&lt;li>停用游標選取：游標無法選取文字，滾輪只會移動光標的位置。&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>:set ruler
&lt;ul>
&lt;li>( 預設就有 ) 顯示右下角的 行,列 目前在文件的位置 % 的資訊&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>:set backspace=2
&lt;ul>
&lt;li>( 預設就有 ) 在 insert 模式啟用 backspace 鍵&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>:set formatoptions+=r
&lt;ul>
&lt;li>自動註解(注意：若要貼上的文件某一行有註解，會因為此項設定而讓其以下每一行都變成註解)&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>:set history=100
&lt;ul>
&lt;li>保留 100 個使用過的指令&lt;/li>
&lt;/ul>
&lt;/li>
&lt;li>:set incsearch
&lt;ul>
&lt;li>在關鍵字尚未完全輸入完畢前就顯示結果&lt;/li>
&lt;li>如果覺得這功能太過熱心的話，可以使用 ctrl+n 來達成自動補完的功能&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul></description></item><item><title>為什麼瀏覽器 user-agent string 總是包含 Mozilla/5.0 ?</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20181017-mozilla5-0-always-user-agent-string/</link><pubDate>Wed, 17 Oct 2018 12:03:04 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20181017-mozilla5-0-always-user-agent-string/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://yulun.me/2013/mozilla5-0-always-user-agent-string/" target="_blank" rel="noopener">為什麼瀏覽器 user-agent string 總是包含 Mozilla/5.0 ?&lt;/a>&lt;/li>
&lt;li>&lt;a href="http://stackoverflow.com/questions/12288452/what-does-mozilla-5-0-in-user-agent-string-signify" target="_blank" rel="noopener">What does &amp;ldquo;Mozilla/5.0&amp;rdquo; in user agent string signify?&lt;/a>&lt;/li>
&lt;li>&lt;a href="http://webaim.org/blog/user-agent-string-history/" target="_blank" rel="noopener">History of the browser user-agent string&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>快速結論&lt;/p>
&lt;p>因為網站開發者可能會因為你是某瀏覽器(這裡是 Mozilla)，所以輸出一些特殊功能的程式碼(這裡指好的特殊功能)，所以當其他瀏覽器也支援這種好功能時，就試圖去模仿 Mozilla 瀏覽器讓網站輸出跟 Mozilla 一樣的內容，而不是輸出被閹割功能的程式碼。&lt;/p></description></item><item><title>使用 TC 和 Netem 模拟网络异常</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180915-simulate-network-anomalies-using-tc-and-netem/</link><pubDate>Sat, 15 Sep 2018 16:17:26 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180915-simulate-network-anomalies-using-tc-and-netem/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://www.hi-linux.com/posts/35699.html" target="_blank" rel="noopener">使用 TC 和 Netem 模拟网络异常&lt;/a>&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>Netem 与 TC 简要说明&lt;/p>
&lt;p>Netem 是 Linux 2.6 及以上内核版本提供的一个网络模拟功能模块。该功能模块可以用来在性能良好的局域网中，模拟出复杂的互联网传输性能。例如:低带宽、传输延迟、丢包等等情况。使用 Linux 2.6 (或以上) 版本内核的很多 Linux 发行版都默认开启了该内核模块，比如：Fedora、Ubuntu、Redhat、OpenSuse、CentOS、Debian 等等。&lt;/p>
&lt;p>TC 是 Linux 系统中的一个用户态工具，全名为 Traffic Control (流量控制)。TC 可以用来控制 Netem 模块的工作模式，也就是说如果想使用 Netem 需要至少两个条件，一是内核中的 Netem 模块被启用，另一个是要有对应的用户态工具 TC 。&lt;/p>&lt;/blockquote>
&lt;ol>
&lt;li>所有的报文延迟 100ms 发送: &lt;code>$ tc qdisc add dev enp0s5 root netem delay 100ms&lt;/code>&lt;/li>
&lt;li>模拟丢包率: &lt;code>$ tc qdisc change dev enp0s5 root netem loss 50%&lt;/code>&lt;/li>
&lt;li>模拟包重复: &lt;code>$ tc qdisc change dev enp0s5 root netem duplicate 50%&lt;/code>&lt;/li>
&lt;li>模拟包损坏: &lt;code>tc qdisc change dev enp0s5 root netem corrupt 2%&lt;/code>&lt;/li>
&lt;li>模拟包乱序(每 5 个报文（第 5、10、15…报文）会正常发送，其他的报文延迟 100ms): &lt;code>tc qdisc change dev enp0s5 root netem reorder 50% gap 3 delay 100ms&lt;/code>&lt;/li>
&lt;/ol>
&lt;h5 id="查看并显示-enp0s5-网卡的相关传输配置">查看并显示 enp0s5 网卡的相关传输配置&lt;/h5>
&lt;p>&lt;code>$ tc qdisc show dev enp0s5&lt;/code>&lt;/p></description></item><item><title>Quagga Routing - 安裝、設定與建置 BGP</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180814-quagga-routing--install-configure-and-setup-bgp/</link><pubDate>Tue, 14 Aug 2018 22:13:12 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180814-quagga-routing--install-configure-and-setup-bgp/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://www.psychz.net/client/kb/en/quagga-routing--install-configure-and-setup-bgp.html" target="_blank" rel="noopener">Quagga Routing - 安裝、設定與建置 BGP&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>Systemd 入门教程：实战篇</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180809-systemd-tutorial-part-two/</link><pubDate>Thu, 09 Aug 2018 13:53:32 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180809-systemd-tutorial-part-two/</guid><description>&lt;ul>
&lt;li>&lt;a href="http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html" target="_blank" rel="noopener">Systemd 入门教程：实战篇&lt;/a>&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>$ systemctl cat sshd.service
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">[&lt;/span>Unit&lt;span style="color:#f92672">]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Description&lt;span style="color:#f92672">=&lt;/span>OpenSSH server daemon
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Documentation&lt;span style="color:#f92672">=&lt;/span>man:sshd&lt;span style="color:#f92672">(&lt;/span>8&lt;span style="color:#f92672">)&lt;/span> man:sshd_config&lt;span style="color:#f92672">(&lt;/span>5&lt;span style="color:#f92672">)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>After&lt;span style="color:#f92672">=&lt;/span>network.target sshd-keygen.service
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Wants&lt;span style="color:#f92672">=&lt;/span>sshd-keygen.service
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">[&lt;/span>Service&lt;span style="color:#f92672">]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>EnvironmentFile&lt;span style="color:#f92672">=&lt;/span>/etc/sysconfig/sshd
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ExecStart&lt;span style="color:#f92672">=&lt;/span>/usr/sbin/sshd -D $OPTIONS
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>ExecReload&lt;span style="color:#f92672">=&lt;/span>/bin/kill -HUP $MAINPID
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Type&lt;span style="color:#f92672">=&lt;/span>simple
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>KillMode&lt;span style="color:#f92672">=&lt;/span>process
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>Restart&lt;span style="color:#f92672">=&lt;/span>on-failure
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>RestartSec&lt;span style="color:#f92672">=&lt;/span>42s
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">[&lt;/span>Install&lt;span style="color:#f92672">]&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>WantedBy&lt;span style="color:#f92672">=&lt;/span>multi-user.target
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h4 id="unit-区块启动顺序与依赖关系">[Unit] 区块：启动顺序与依赖关系&lt;/h4>
&lt;p>&lt;code>After&lt;/code> 字段：表示如果 &lt;code>network.target&lt;/code> 或 &lt;code>sshd-keygen.service&lt;/code> 需要启动，那么 &lt;code>sshd.service&lt;/code> 应该在它们之后启动。&lt;/p>
&lt;p>相应地，还有一个 &lt;code>Before&lt;/code> 字段，定义 &lt;code>sshd.service&lt;/code> 应该在哪些服务之前启动。&lt;/p>
&lt;p>注意，After 和 Before 字段只涉及启动顺序，不涉及依赖关系。&lt;/p>
&lt;p>设置依赖关系，需要使用 Wants 字段和 Requires 字段&lt;/p>
&lt;p>&lt;code>Wants&lt;/code> 字段：表示 &lt;code>sshd.service&lt;/code> 与 &lt;code>sshd-keygen.service&lt;/code> 之间存在&amp;quot;弱依赖&amp;quot;关系，即如果&amp;quot;sshd-keygen.service&amp;quot;启动失败或停止运行，不影响 &lt;code>sshd.service&lt;/code> 继续执行。&lt;/p>
&lt;p>&lt;code>Requires&lt;/code> 字段则表示&amp;quot;强依赖&amp;quot;关系，即如果该服务启动失败或异常退出，那么 &lt;code>sshd.service&lt;/code> 也必须退出。&lt;/p>
&lt;p>注意，Wants 字段与 Requires 字段只涉及依赖关系，与启动顺序无关，默认情况下是同时启动的。&lt;/p></description></item><item><title>Raid10 徹底崩壞 ,壞就壞在同組作Mirror硬碟一起故障。</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180801-raid/</link><pubDate>Wed, 01 Aug 2018 18:21:20 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180801-raid/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://jerry2yang.wordpress.com/2013/01/09/raid10-%E5%BE%B9%E5%BA%95%E5%B4%A9%E5%A3%9E-%E5%A3%9E%E5%B0%B1%E5%A3%9E%E5%9C%A8%E5%90%8C%E7%B5%84%E4%BD%9Cmirror%E7%A1%AC%E7%A2%9F%E4%B8%80%E8%B5%B7%E6%95%85%E9%9A%9C%E3%80%82/" target="_blank" rel="noopener">Raid10 徹底崩壞 ,壞就壞在同組作 Mirror 硬碟一起故障。&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://zh.wikipedia.org/wiki/RAID" target="_blank" rel="noopener">RAID&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>CDN 相关 https 证书的申请</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180724-dehydrated/</link><pubDate>Tue, 24 Jul 2018 18:35:39 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180724-dehydrated/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://github.com/lukas2511/dehydrated" target="_blank" rel="noopener">dehydrated&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/kappataumu/letsencrypt-cloudflare-hook" target="_blank" rel="noopener">letsencrypt-cloudflare-hook&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>由于我们不能上传文件到 CDN 服务器，所以我们不能采用文件验证方式来申请 https 证书。所幸 Let&amp;rsquo;s Encrypt 支持 dns-01 challenge 通过 DNS 验证方式来申请 https 证书。我们使用 Dehydrated 配合 CloudFlare hook 来申请 https 证书。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-shell" data-lang="shell">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 首先 clone dehydrated 这个仓库&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>git clone https://github.com/lukas2511/dehydrated
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 在 clone 出来的 dehydrated 目录下创建 config 文件，内容参考 config 文件(https://github.com/dehydrated-io/dehydrated/blob/master/docs/examples/config)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 在 config 文件的末尾加上 Cloudflare 相关的信息&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>echo &lt;span style="color:#e6db74">&amp;#34;export CF_EMAIL=user@example.com&amp;#34;&lt;/span> &amp;gt;&amp;gt; config
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>echo &lt;span style="color:#e6db74">&amp;#34;export CF_KEY=K9uX2HyUjeWg5AhAb&amp;#34;&lt;/span> &amp;gt;&amp;gt; config
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># clone Cloudflare hook&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>mkdir hooks
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>git clone https://github.com/kappataumu/letsencrypt-cloudflare-hook hooks/cloudflare
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 安装依赖&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>pip install -r hooks/cloudflare/requirements-python-2.txt
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 创建 domains.txt 文件，每行一个域名&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">[&lt;/span>root@db-slave01 dehydrated&lt;span style="color:#f92672">]&lt;/span>&lt;span style="color:#75715e"># cat domains.txt&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>apk.kosungames.com
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sp-res.kosungames.com
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>cpweb.kosungames.com
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 申请 https 证书&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>./dehydrated -c -k hooks/cloudflare/hook.py
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e"># 使用 Python 脚本上传证书。脚本需在 dehydrated 目录下&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-python" data-lang="python">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">#!/usr/bin/env python&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">from&lt;/span> aliyunsdkcore &lt;span style="color:#f92672">import&lt;/span> client
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">from&lt;/span> aliyunsdkcdn.request.v20141111 &lt;span style="color:#f92672">import&lt;/span> SetDomainServerCertificateRequest
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">import&lt;/span> uuid
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">def&lt;/span> &lt;span style="color:#a6e22e">upload&lt;/span>(domain):
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> cli &lt;span style="color:#f92672">=&lt;/span> client&lt;span style="color:#f92672">.&lt;/span>AcsClient(&lt;span style="color:#e6db74">&amp;#34;LTAI7zSXga2D&amp;#34;&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;ed03Mt9xcNkRgmadx0XtpyDje&amp;#34;&lt;/span>, &lt;span style="color:#e6db74">&amp;#34;cn-hongkong&amp;#34;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> request &lt;span style="color:#f92672">=&lt;/span> SetDomainServerCertificateRequest&lt;span style="color:#f92672">.&lt;/span>SetDomainServerCertificateRequest()
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> request&lt;span style="color:#f92672">.&lt;/span>set_accept_format(&lt;span style="color:#e6db74">&amp;#34;json&amp;#34;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> request&lt;span style="color:#f92672">.&lt;/span>set_DomainName(domain)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> request&lt;span style="color:#f92672">.&lt;/span>set_CertName(domain &lt;span style="color:#f92672">+&lt;/span> str(uuid&lt;span style="color:#f92672">.&lt;/span>uuid1()))
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e">#request.set_CertName(domain)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#75715e">#certificate = open(&amp;#34;certs/&amp;#34; + domain + &amp;#34;/fullchain.pem&amp;#34;).read()&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> certificate &lt;span style="color:#f92672">=&lt;/span> open(&lt;span style="color:#e6db74">&amp;#34;certs/&amp;#34;&lt;/span> &lt;span style="color:#f92672">+&lt;/span> domain &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#e6db74">&amp;#34;/cert.pem&amp;#34;&lt;/span>)&lt;span style="color:#f92672">.&lt;/span>read()
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">with&lt;/span> open(&lt;span style="color:#e6db74">&amp;#34;certs/&amp;#34;&lt;/span> &lt;span style="color:#f92672">+&lt;/span> domain &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#e6db74">&amp;#34;/chain.pem&amp;#34;&lt;/span>) &lt;span style="color:#66d9ef">as&lt;/span> f:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> f&lt;span style="color:#f92672">.&lt;/span>readline()
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> f&lt;span style="color:#f92672">.&lt;/span>readline()
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> chain &lt;span style="color:#f92672">=&lt;/span> f&lt;span style="color:#f92672">.&lt;/span>read()
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> certificate &lt;span style="color:#f92672">+=&lt;/span> chain
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> key &lt;span style="color:#f92672">=&lt;/span> open(&lt;span style="color:#e6db74">&amp;#34;certs/&amp;#34;&lt;/span> &lt;span style="color:#f92672">+&lt;/span> domain &lt;span style="color:#f92672">+&lt;/span> &lt;span style="color:#e6db74">&amp;#34;/privkey.pem&amp;#34;&lt;/span>)&lt;span style="color:#f92672">.&lt;/span>read()
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> request&lt;span style="color:#f92672">.&lt;/span>set_ServerCertificateStatus(&lt;span style="color:#e6db74">&amp;#39;on&amp;#39;&lt;/span>)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> request&lt;span style="color:#f92672">.&lt;/span>set_ServerCertificate(certificate)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> request&lt;span style="color:#f92672">.&lt;/span>set_PrivateKey(key)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> result &lt;span style="color:#f92672">=&lt;/span> cli&lt;span style="color:#f92672">.&lt;/span>do_action_with_exception(request)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>domain_file&lt;span style="color:#f92672">=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;domains.txt&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">with&lt;/span> open(domain_file) &lt;span style="color:#66d9ef">as&lt;/span> f:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">for&lt;/span> line &lt;span style="color:#f92672">in&lt;/span> f:
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> domain &lt;span style="color:#f92672">=&lt;/span> line&lt;span style="color:#f92672">.&lt;/span>split()[&lt;span style="color:#ae81ff">0&lt;/span>]
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> upload(domain)
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>Nginx 访问日志中记录毫秒级别的时间精度</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180724-milliseconds-server-time/</link><pubDate>Tue, 24 Jul 2018 18:31:42 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180724-milliseconds-server-time/</guid><description>&lt;p>Nginx 的 access log 可以记录毫秒级的时间戳，但是是以 &lt;code>EPOCH&lt;/code> 开始的毫秒数，比如 &lt;code>1503544071.865&lt;/code>, 另一个变量 &lt;code>$time_local&lt;/code> 记录的是秒级别的时间格式，比如 &lt;code>24/Aug/2017:11:07:51 +0800&lt;/code>，在业务量大的时候，我们需要记录毫秒精度的时间格式，比如 &lt;code>24/Aug/2017:11:07:51.865 +0800&lt;/code>, 这个可以通过 Lua 实现。&lt;/p>
&lt;p>首先需要在 nginx.conf 中定义一个变量，叫做 &lt;code>time_millis&lt;/code>，并初始化为空。类似于使用 &lt;code>auto-ssl&lt;/code> 获取证书的时候需要指定一个 fallback 的自签证书。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-nginx" data-lang="nginx">&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">map&lt;/span> $host $time_millis {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">default&lt;/span> &lt;span style="color:#e6db74">&amp;#39;&amp;#39;&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>如果不定义这个变量，在 &lt;code>log_format&lt;/code> 中引用的时候会报错。&lt;/p>
&lt;p>使用 Lua 获取毫秒数，并追加到 &lt;code>$time_local&lt;/code> 的末尾。&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-nginx" data-lang="nginx">&lt;span style="display:flex;">&lt;span> &lt;span style="color:#66d9ef">log_by_lua_block&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">millis&lt;/span> = &lt;span style="color:#e6db74">string.gsub(ngx.var.msec,&lt;/span> &lt;span style="color:#e6db74">&amp;#34;(%d+).(%d+)&amp;#34;,&lt;/span> &lt;span style="color:#e6db74">&amp;#34;%2&amp;#34;)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e6db74">ngx.var.time_millis&lt;/span> = &lt;span style="color:#e6db74">string.gsub(ngx.var.time_local,&lt;/span> &lt;span style="color:#e6db74">&amp;#34;(.+)&lt;/span> &lt;span style="color:#e6db74">(.+)&amp;#34;,&lt;/span> &lt;span style="color:#e6db74">&amp;#34;%1.&amp;#34;&lt;/span> &lt;span style="color:#e6db74">..&lt;/span> &lt;span style="color:#e6db74">millis&lt;/span> &lt;span style="color:#e6db74">..&lt;/span> &lt;span style="color:#e6db74">&amp;#34;&lt;/span> &lt;span style="color:#e6db74">%2&amp;#34;)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#960050;background-color:#1e0010">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>在 &lt;code>log_format&lt;/code> 中将 &lt;code>$time_local&lt;/code> 改为 &lt;code>$time_millis&lt;/code>&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-nginx" data-lang="nginx">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">http&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">map&lt;/span> $host $time_millis {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">default&lt;/span> &lt;span style="color:#e6db74">&amp;#39;&amp;#39;&lt;/span>;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> }
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">log_by_lua_block&lt;/span> {
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">millis&lt;/span> = &lt;span style="color:#e6db74">string.gsub(ngx.var.msec,&lt;/span> &lt;span style="color:#e6db74">&amp;#34;(%d+).(%d+)&amp;#34;,&lt;/span> &lt;span style="color:#e6db74">&amp;#34;%2&amp;#34;)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e6db74">ngx.var.time_millis&lt;/span> = &lt;span style="color:#e6db74">string.gsub(ngx.var.time_local,&lt;/span> &lt;span style="color:#e6db74">&amp;#34;(.+)&lt;/span> &lt;span style="color:#e6db74">(.+)&amp;#34;,&lt;/span> &lt;span style="color:#e6db74">&amp;#34;%1.&amp;#34;&lt;/span> &lt;span style="color:#e6db74">..&lt;/span> &lt;span style="color:#e6db74">millis&lt;/span> &lt;span style="color:#e6db74">..&lt;/span> &lt;span style="color:#e6db74">&amp;#34;&lt;/span> &lt;span style="color:#e6db74">%2&amp;#34;)&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#960050;background-color:#1e0010">}&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e6db74">log_format&lt;/span> &lt;span style="color:#e6db74">main&lt;/span> &lt;span style="color:#e6db74">&amp;#39;&lt;/span>$remote_addr &lt;span style="color:#e6db74">-&lt;/span> $remote_user &lt;span style="color:#e6db74">[&lt;/span>$time_millis] &lt;span style="color:#e6db74">&amp;#34;&lt;/span>$request&amp;#34; &lt;span style="color:#e6db74">&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e6db74">&amp;#39;&lt;/span>$status $body_bytes_sent &lt;span style="color:#e6db74">&amp;#34;&lt;/span>$http_referer&amp;#34; &lt;span style="color:#e6db74">&amp;#39;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#e6db74">&amp;#39;&amp;#34;&lt;/span>$http_user_agent&amp;#34; $msec &lt;span style="color:#e6db74">&amp;#34;&lt;/span>$http_x_forwarded_for&amp;#34; $host $request_time $upstream_response_time $scheme &lt;span style="color:#e6db74">&amp;#34;&lt;/span>$request_body&amp;#34;&amp;#39;;
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div></description></item><item><title>HA command</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180721-ha/</link><pubDate>Sat, 21 Jul 2018 14:45:29 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180721-ha/</guid><description>&lt;pre tabindex="0">&lt;code>load merge relative terminal
# 全新設備上面沒啟用過HA 必須先定義Cluster ID
# ClustartID 必須獨立，不可以與其他SRX重複，因為HA會建立一組Virtual MAC Address ，而這個ID數值會對其產生影響，重複有可能導致MAC address 重複而出現不可預期的錯誤
#
request system zeroize
# 以下command 必須在 &amp;gt; 模式使用
set chassis cluster cluster-id &amp;lt;ID範圍 0~ 255&amp;gt; node 0 # 這個是在 node 0 的設備下的
set chassis cluster cluster-id &amp;lt;ID範圍 0~ 255&amp;gt; node 1 # 這個是在 node 1 的設備下的
在secondary node 下 這個command
request chassis cluster configuration-synchronize
# 等待機器重開機後，會出現Hold 或stanby 字樣 ，看到Cluster 是否有起來
show chassis cluster status
# 這個是RETH interface 建立好才會出現，必須先做config才會有
show chassis cluster interfaces
# 以下command 則是在 Config mode 下使用 ，先把設定檔建起來
---
# 這邊需要 backup-router 是給 HA裡面的Standby Device 的管理介面 (fxp) 一筆routing 可以回應，預設Standby 不會啟用routing engine，所以需要這筆設定
set groups node0 system host-name SRX-node0
set groups node0 system backup-router 10.10.0.254
set groups node0 system backup-router destination 0.0.0.0/0
set groups node0 interfaces fxp0 unit 0 family inet address 10.10.0.2/24
set groups node1 system host-name SRX-node1
set groups node1 system backup-router 10.10.0.254
set groups node1 system backup-router destination 0.0.0.0/0
set groups node1 interfaces fxp0 unit 0 family inet address 10.10.0.3/24
set apply-groups &amp;#34;${node}&amp;#34;
set system time-zone Asia/Taipei
set chassis cluster control-link-recovery
set chassis cluster reth-count 10
set chassis cluster heartbeat-interval 2000
# 另外建議在建置期間先將IPv6 打開，可以使用以下指令，因為日後開啟IPv6功能則必須要將設備重開機
set security forwarding-options family inet6 mode flow-based
# 這邊的interface 號碼要看每一台Chassis 的型號不同而會有所不同
# 最簡單的識別方式是看那台設備的Slot 有幾個，像SRX550HM 是 0~ 8都有擴充可以使用，所以預設HA會在 9開始 ，所以會是 ge-9/x/x
set chassis cluster redundancy-group 0 node 0 priority 150
set chassis cluster redundancy-group 0 node 1 priority 100
set chassis cluster redundancy-group 0 interface-monitor ge-0/0/3 weight 150
set chassis cluster redundancy-group 0 interface-monitor ge-0/0/5 weight 150
set chassis cluster redundancy-group 0 interface-monitor ge-9/0/3 weight 100
set chassis cluster redundancy-group 0 interface-monitor ge-9/0/5 weight 100
set chassis cluster redundancy-group 1 node 0 priority 150
set chassis cluster redundancy-group 1 node 1 priority 100
set chassis cluster redundancy-group 1 interface-monitor ge-0/0/3 weight 150
set chassis cluster redundancy-group 1 interface-monitor ge-0/0/5 weight 150
set chassis cluster redundancy-group 1 interface-monitor ge-9/0/3 weight 100
set chassis cluster redundancy-group 1 interface-monitor ge-9/0/5 weight 100
# 這裡是作為Redundancy group: 1 的 Data sync 設定 ，請務必設定上去才會啟用ge-0/0/2 的 heartbeat link
set interfaces fab0 fabric-options member-interfaces ge-0/0/2
set interfaces fab1 fabric-options member-interfaces ge-9/0/2
# 設定interface 加入reth Group
set interfaces ge-0/0/3 gigether-options redundant-parent reth0
set interfaces ge-0/0/4 gigether-options redundant-parent reth0
set interfaces ge-9/0/3 gigether-options redundant-parent reth0
set interfaces ge-9/0/4 gigether-options redundant-parent reth0
set interfaces ge-0/0/5 gigether-options redundant-parent reth1
set interfaces ge-9/0/5 gigether-options redundant-parent reth1
set interfaces reth0 vlan-tagging
# 務必要將RETH 加入 data sync Group 裡面，不然不會動
set interfaces reth0 redundant-ether-options redundancy-group 1
# 特別注意，在SRX雖然是LACP Passive mode ，在Switch 請務必使用LACP Activate mode
set interfaces reth0 redundant-ether-options lacp passive
set interfaces reth0 redundant-ether-options lacp periodic slow
set interfaces reth1 redundant-ether-options redundancy-group 1
set interfaces reth1 unit 0 family inet address 202.99.240.100/26
&lt;/code>&lt;/pre></description></item><item><title>與 DDoS 奮戰：nginx, iptables 與 fail2ban</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180720-defend-against-ddos-with-nginx-iptable-and-fail2ban/</link><pubDate>Fri, 20 Jul 2018 18:47:42 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180720-defend-against-ddos-with-nginx-iptable-and-fail2ban/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://blog.techbridge.cc/2016/08/12/defend-against-ddos-with-nginx-iptable-and-fail2ban/" target="_blank" rel="noopener">與 DDoS 奮戰：nginx, iptables 與 fail2ban&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>[Juniper Firewall] command</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180627-juniper/</link><pubDate>Wed, 27 Jun 2018 00:58:01 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180627-juniper/</guid><description>&lt;p>下列操作命令在操作模式下使用，或在配置模式下 run show…&lt;/p>
&lt;p>查看當前防火牆 session 數&lt;/p>
&lt;pre tabindex="0">&lt;code>show security flow session | match 10.22.12.104
show security flow session source-prefix 10.22.12.104
&lt;/code>&lt;/pre>&lt;p>清除當前 session&lt;/p>
&lt;pre tabindex="0">&lt;code>clear security flow session all
&lt;/code>&lt;/pre>&lt;p>查 OID&lt;/p>
&lt;pre tabindex="0">&lt;code>show snmp mib walk decimal 1.3.6.1.2.1.2.2.1.2
&lt;/code>&lt;/pre>&lt;p>查看當前軟體版本號&lt;/p>
&lt;pre tabindex="0">&lt;code>show system software
&lt;/code>&lt;/pre>&lt;p>查看系統啟動時間&lt;/p>
&lt;pre tabindex="0">&lt;code>show system uptime
&lt;/code>&lt;/pre>&lt;p>查看硬體板卡及序列號&lt;/p>
&lt;pre tabindex="0">&lt;code>show chassis haredware
&lt;/code>&lt;/pre>&lt;p>查看硬體板卡當前狀態&lt;/p>
&lt;pre tabindex="0">&lt;code>show chassis environment
&lt;/code>&lt;/pre>&lt;p>查看路由表&lt;/p>
&lt;pre tabindex="0">&lt;code>show route
&lt;/code>&lt;/pre>&lt;p>設備商的 Administrative distance / Route preference 預設值比較&lt;/p>
&lt;p>查看 ARP 表&lt;/p>
&lt;pre tabindex="0">&lt;code>show arp
&lt;/code>&lt;/pre>&lt;p>查看系統 log&lt;/p>
&lt;pre tabindex="0">&lt;code>show log messages
&lt;/code>&lt;/pre>&lt;p>查看所有介面運行狀態&lt;/p>
&lt;pre tabindex="0">&lt;code>show interface terse
&lt;/code>&lt;/pre>&lt;p>查看介面運行細節資訊&lt;/p>
&lt;pre tabindex="0">&lt;code>show interface ge-x/y/z detail
&lt;/code>&lt;/pre>&lt;p>動態統計介面資料包轉發資訊&lt;/p>
&lt;pre tabindex="0">&lt;code>monitor interface ge-x/y/z
&lt;/code>&lt;/pre>&lt;p>檢查 ALG 開啟情況&lt;/p></description></item><item><title>Switch版本更新</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180614-cisco-firmware-version-update/</link><pubDate>Thu, 14 Jun 2018 12:28:29 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180614-cisco-firmware-version-update/</guid><description>&lt;h4 id="事前準備">事前準備:&lt;/h4>
&lt;p>插 console&lt;/p>
&lt;p>將更新檔丟到 usb 裡&lt;/p>
&lt;p>&lt;strong>&lt;em>使用前可先使用 &lt;code>show version&lt;/code> 查看當前版本&lt;/em>&lt;/strong>&lt;/p>
&lt;h4 id="更新-sop">更新 SOP:&lt;/h4>
&lt;ol>
&lt;li>將裝有更新檔的 usb 插入要更新版本的 Switch 上，此時畫面會顯示偵測到 device name&lt;/li>
&lt;li>將 usb 裡的更新檔複製到 switch 的 flash 裡面: &lt;code>copy usbflash0(device name):更新檔 flash:&lt;/code>
&lt;ol>
&lt;li>此時按 enter 後他會問你檔名是否要用這個，再按一次 enter 即可，看到一堆 ccccccccc 就代表有在複製&lt;/li>
&lt;/ol>
&lt;/li>
&lt;li>複製完後，&lt;code>dir flash&lt;/code> 查看底下有沒有剛剛複製過去的更新檔&lt;/li>
&lt;li>&lt;code>conf t&lt;/code> 進入編輯模式，&lt;code>boot system flash:更新檔&lt;/code> ，指定 Switch 使用新版的 IOS 來開機&lt;/li>
&lt;li>&lt;code>exit&lt;/code> 離開編輯模式，&lt;code>show boot&lt;/code>，確定是否使用新版的 IOS 來開機&lt;/li>
&lt;li>&lt;code>write memory&lt;/code>，套用設定至 Running-Config&lt;/li>
&lt;li>reload&lt;/li>
&lt;li>大概會跑 15~20 分鐘左右，等他跑完就可以查看版本是否升級成功&lt;/li>
&lt;/ol>
&lt;pre tabindex="0">&lt;code>copy usbflash0:cat.bin flash:
copy usbflash0:cat.bin flash0-2:
software install file flash:cat.bin switch 1-2
software clean
&lt;/code>&lt;/pre></description></item><item><title>防火牆更新</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180612-juniper-firmware-version-update/</link><pubDate>Tue, 12 Jun 2018 07:48:48 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180612-juniper-firmware-version-update/</guid><description>&lt;h4 id="事前準備">事前準備:&lt;/h4>
&lt;p>插 console&lt;/p>
&lt;p>將更新檔丟到 usb 裡&lt;/p>
&lt;p>&lt;strong>&lt;em>使用前可先使用 &lt;code>show version&lt;/code> 查看當前版本&lt;/em>&lt;/strong>&lt;/p>
&lt;h4 id="更新-sop">更新 SOP:&lt;/h4>
&lt;ol>
&lt;li>&lt;code>start shell&lt;/code>&lt;/li>
&lt;li>&lt;code>su成root身分&lt;/code>&lt;/li>
&lt;li>&lt;code>建資料夾mkdir /var/tmp/usb(名字可自取)&lt;/code>&lt;/li>
&lt;li>插入 USB，這邊要注意 da 後面的數字，目前是 da1&lt;/li>
&lt;li>掛載 &lt;code>mount -t msdos /dev/da1s1 /var/tmp/usb&lt;/code> (如果是 da0，就要變成 da0s1，以此類推)&lt;/li>
&lt;li>跑完後 &lt;code>cd /cf/var/tmp/usb/da2s1/&lt;/code> (usb)
&lt;ol>
&lt;li>&lt;code>ls&lt;/code> (junos-srxsme-15.1X49-D120.3-domestic.tgz)&lt;/li>
&lt;/ol>
&lt;/li>
&lt;li>cli 切換成 operational mode
&lt;ol>
&lt;li>&lt;code>request system software add /var/tmp/usb/da2s1/junos-srxsme-15.1X49-D120.3-domestic.tgz&lt;/code>&lt;/li>
&lt;/ol>
&lt;/li>
&lt;li>&lt;code>request system reboot&lt;/code>&lt;/li>
&lt;li>&lt;code>show version&lt;/code>&lt;/li>
&lt;/ol></description></item><item><title>最好用的 V2Ray 一鍵安裝腳本 &amp; 管理腳本</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180208-v2ray/</link><pubDate>Thu, 08 Feb 2018 10:56:54 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180208-v2ray/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://233blog.com/post/16/" target="_blank" rel="noopener">最好用的 V2Ray 一鍵安裝腳本 &amp;amp; 管理腳本&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://github.com/233boy/v2ray" target="_blank" rel="noopener">v2ray&lt;/a>&lt;/li>
&lt;/ul></description></item><item><title>如何在 Switch 上啟用 snmp 設定</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180204-switchsnmp/</link><pubDate>Sun, 04 Feb 2018 14:48:12 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180204-switchsnmp/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://itlocation.blogspot.com/2013/10/switchsnmp.html" target="_blank" rel="noopener">如何在 Switch 上啟用 snmp 設定&lt;/a>&lt;/li>
&lt;/ul>
&lt;p>以 snmp-server 為主要指令&lt;/p>
&lt;p>&lt;code>C3750(Config)#snmp-server community RO&lt;/code>&lt;/p>
&lt;p>指的是 SNMP 協定時互相溝通的密碼
RO 指的是 Read Only (SNMP 工具不允許修改設定)
RW 指的是 Read and Write (SNMP 工具可以修改設定)&lt;/p>
&lt;p>&lt;code>C3750(config)#snmp-server group SNMP_ROA v3 priv match exact&lt;/code>&lt;/p>
&lt;ol>
&lt;li>設定 SNMP Group 名： SNMP_ROA&lt;/li>
&lt;li>Version ： V3&lt;/li>
&lt;li>最高的 priv&lt;/li>
&lt;/ol>
&lt;p>&lt;code>C3750(config)#snmp-server user cater SNMP_ROA v3 auth MD5 cisco12345 priv des56 test12345&lt;/code>&lt;/p>
&lt;p>這行設定跟 PRTG 設定有關聯，一定要記清楚&lt;/p>
&lt;ol>
&lt;li>使用者 ：cater&lt;/li>
&lt;li>隸屬 Group 為：SNMP_ROA&lt;/li>
&lt;li>驗證模式 ：MD5&lt;/li>
&lt;li>密碼(MD5) ：cisco12345 (PRTG 要求要 8 碼以上)&lt;/li>
&lt;li>Priv 驗證密碼 ：test12345 (PRTG 要求要 8 碼以上)&lt;/li>
&lt;/ol>
&lt;p>&lt;code>C3750(config)#snmp-server host 192.168.3.100 version 3 priv cater&lt;/code>&lt;/p></description></item><item><title>A10</title><link>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180110-a10/</link><pubDate>Wed, 10 Jan 2018 03:44:14 +0800</pubDate><guid>https://9855cc0f.linzeyan.pages.dev/zh-tw/posts/2018/20180110-a10/</guid><description>&lt;ul>
&lt;li>&lt;a href="https://jal.tw/a10:l2:link-aggregation" target="_blank" rel="noopener">A10 Link Aggregation&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jal.tw/a10:slb:healthmonitor:tcl" target="_blank" rel="noopener">Health Monitor use TCL&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jal.tw/a10:slb:ssl-cipher" target="_blank" rel="noopener">A10 SSL Offload Cipher Suite Support List&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jal.tw/a10:slb:compression" target="_blank" rel="noopener">Compression&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jal.tw/a10:slb:ramcache" target="_blank" rel="noopener">A10 RAM Cache 加速&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jal.tw/a10:nat" target="_blank" rel="noopener">A10 NAT&lt;/a>&lt;/li>
&lt;li>&lt;a href="https://jal.tw/a10:basic:config" target="_blank" rel="noopener">A10 configuration template&lt;/a>&lt;/li>
&lt;/ul>
&lt;h4 id="a10-link-aggregation">A10 Link Aggregation&lt;/h4>
&lt;h5 id="8023ad-lacp">802.3ad LACP&lt;/h5>
&lt;blockquote>
&lt;p>A10 trunk can config a maximnm of 16 LACP trunks per device.&lt;/p>&lt;/blockquote>
&lt;pre tabindex="0">&lt;code>interface ethernet 1
lacp trunk 1 mode active
lacp timeout long
!
interface ethernet 2
lacp trunk 1 mode active
lacp timeout long
&lt;/code>&lt;/pre>&lt;h5 id="static-link-aggregation">Static Link Aggregation&lt;/h5>
&lt;blockquote>
&lt;p>None LACP.&lt;/p>
&lt;p>Up to 8 static trunks.&lt;/p></description></item></channel></rss>