You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

753 lines
22 KiB

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!doctype html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Lednerb">
<meta name="description" content="Bilberry Premium Theme for Hugo.">
<meta name="keywords" content="blog,personal,responsive,search,font awesome,pages,posts,multilingual,highlight.js,syntax highlighting,premium,shortcuts">
<meta name="generator" content="Hugo 0.50" />
<title> [BLOG] 新增 Vultr Storage VPS 提供 iscsi 給wordpress 主機使用 | My cool new Blog</title>
<meta name="description" content="[BLOG] 新增 Vultr Storage VPS 提供 iscsi 給wordpress 主機使用 - Bilberry Premium Theme for Hugo.">
<meta itemprop="name" content="[BLOG] 新增 Vultr Storage VPS 提供 iscsi 給wordpress 主機使用">
<meta itemprop="description" content="[BLOG] 新增 Vultr Storage VPS 提供 iscsi 給wordpress 主機使用 - Bilberry Premium Theme for Hugo.">
<meta property="og:title" content="[BLOG] 新增 Vultr Storage VPS 提供 iscsi 給wordpress 主機使用">
<meta property="og:description" content="[BLOG] 新增 Vultr Storage VPS 提供 iscsi 給wordpress 主機使用 - Bilberry Premium Theme for Hugo.">
<meta property="og:image" content="https://www.gravatar.com/avatar/88188b6cc451928eba90e8400bc68086?size=200">
<meta property="og:url" content="https://h.cowbay.org/article/blog-e6-96-b0-e5-a2-9e-vultr-storage-vps-e6-8f-90-e4-be-9b-iscsi-e7-b5-a6wordpress-e4-b8-bb-e6-a9-9f-e4-bd-bf-e7-94-a8/">
<meta property="og:site_name" content="My cool new Blog">
<meta property="og:type" content="article">
<link rel="icon" type="image/png" href="https://h.cowbay.org/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="https://h.cowbay.org/favicon-16x16.png" sizes="16x16">
<link rel="stylesheet" href="https://h.cowbay.org/sass/combined.min.717098cb5503581e75f12e486a847ca410bf8367d4d8713f4c37affc868c5a1d.css">
</head>
<body class="bilberry-hugo-theme">
<nav>
<div class="container">
<ul class="topnav">
<li><a href="/page/about-bilberry/">About Bilberry</a></li>
<li><a href="https://github.com/Lednerb/bilberry-hugo-theme" target="_blank">Github</a></li>
</ul>
<div id="search-box" class="search">
<i class="fa fa-search"></i>
<input id="search" type="text" placeholder="Search ...">
</div>
</div>
</nav>
<header>
<div class="container">
<div class="logo">
<a href="/" class="logo">
<img src="https://www.gravatar.com/avatar/88188b6cc451928eba90e8400bc68086?d=mm&size=200" alt="">
<span class="overlay"><i class="fa fa-home"></i></span>
</a>
</div>
<div class="titles">
<h3 class="title"><a href="/">My cool new Blog</a></h3>
<span class="subtitle">Hello World! This is the most epic subtitle ever.</span>
</div>
<div class="languages">
<a href="/en" class="active">en</a>
<a href="/de">de</a>
</div>
<div class="toggler">
<i class="fa fa-bars" aria-hidden="true"></i>
</div>
</div>
</header>
<div class="main container">
<div class="article-wrapper u-cf single">
<a class="bubble" href="/article/blog-e6-96-b0-e5-a2-9e-vultr-storage-vps-e6-8f-90-e4-be-9b-iscsi-e7-b5-a6wordpress-e4-b8-bb-e6-a9-9f-e4-bd-bf-e7-94-a8/">
<i class="fa fa-fw fa-pencil"></i>
</a>
<article class="default article">
<div class="content">
<h3><a href="/article/blog-e6-96-b0-e5-a2-9e-vultr-storage-vps-e6-8f-90-e4-be-9b-iscsi-e7-b5-a6wordpress-e4-b8-bb-e6-a9-9f-e4-bd-bf-e7-94-a8/">[BLOG] 新增 Vultr Storage VPS 提供 iscsi 給wordpress 主機使用</a></h3>
<div class="meta">
<span class="date moment">2016-03-10</span>
<span class="categories">
<a href="/categories/blog">BLOG</a>
</span>
</div>
<h2 id="新增-vultr-storage-vps-提供-iscsi-給wordpress-主機使用"><strong>新增 Vultr Storage VPS 提供 iscsi 給wordpress 主機使用</strong></h2>
<p>前幾天因為DO的WP主機速度不理想就連拿來當作上PTT的跳板都會頓爹</p>
<p>所以把主機換到了vultr 的東京機房光是ping值就從 14x ms 下降到了 4x ms整個大改善啊</p>
<p>而且方案從原本的 10USD 換成了 5USD (1 cpu / 768M/15G) 裝好FreeBSD拿來跑 WP算是綽綽有餘</p>
<p>不過因為這台還當作 pydio 主機來用, 15G的空間實在不夠用</p>
<p>發TICKET詢問客服能不能增加硬碟空間客服表示只能upgrade plan</p>
<p>但是再往上一級的10 USD方案也只有 20G多了 5 USD 只有多5G空間(好啦 還有流量也增加,問題是我用不到流量啊&hellip;)</p>
<p>算一算,實在不是很划算</p>
<p>就在這個摸門特,發現了 vultr 有 Storage Instance !</p>
<p>只要 5USD 就有一台虛擬主機 (1 cpu / 512M/125G SATA HD)</p>
<p>怎麼算都比upgrade 到 10USD的方案划算而且價格一樣</p>
<p>二話不說馬上申請一台一樣跑FreeBSD 10.2,打算拿來當作儲存空間用</p>
<p>至於要用 sshfs / curlftpfs  / nfs /iscsi 則是還沒決定,且戰且走</p>
<p>&nbsp;</p>
<hr />
<p>&nbsp;</p>
<p></p>
<p>系統開起來之後,先到管理介面替兩台主機都新增一個 private IP然後兩台主機都需要重新開機</p>
<p><a href="http://wp.cowbay.org/wp-content/uploads/2016/03/firefox_2016-03-10_11-36-04.png"><img src="http://wp.cowbay.org/wp-content/uploads/2016/03/firefox_2016-03-10_11-36-04-1024x722.png" alt="firefox_2016-03-10_11-36-04" /></a></p>
<p>&nbsp;</p>
<p>重新開機後,必須要手動到系統內去新增虛擬 IP</p>
<p>就分別ssh 到這兩台機器然後用bsdconfig 去設定 Network Management</p>
<p>(By the way , Storage Instance 的效能真的差滿多的,兩台一起設定,就能比較出來)</p>
<p>設定完之後兩台ping 一下,應該要能通
&gt; root@wpstorage:/etc # ping 10.99.0.11
&gt;
&gt; PING 10.99.0.11 (10.99.0.11): 56 data bytes
&gt;
&gt; 64 bytes from 10.99.0.11: icmp_seq=0 ttl=64 time=0.469 ms
&gt;
&gt; 64 bytes from 10.99.0.11: icmp_seq=1 ttl=64 time=0.715 ms
&gt;
&gt; 64 bytes from 10.99.0.11: icmp_seq=2 ttl=64 time=0.511 ms
&gt;
&gt; 64 bytes from 10.99.0.11: icmp_seq=3 ttl=64 time=0.755 ms
&gt;
&gt; ^C
&gt;
&gt; &mdash; 10.99.0.11 ping statistics &mdash;
&gt;
&gt; 4 packets transmitted, 4 packets received, 0.0% packet loss
&gt;
&gt; round-trip min/avg/max/stddev = 0.<sup>469</sup>&frasl;<sub>0</sub>.<sup>612</sup>&frasl;<sub>0</sub>.<sup>755</sup>&frasl;<sub>0</sub>.124 ms
接下來就來測試怎麼把Storage Instance的空間掛來 WP 使用</p>
<p>先測試比較簡單的 sshfs</p>
<p>在WP主機上先載入fuse.ko
&gt; kldload fuse.ko
然後 sshfs root@10.99.0.11 /mnt</p>
<p>輸入密碼之後就把Storage主機的硬碟掛載 /mnt 底下了</p>
<p>測試一下速度</p>
<p>root@wp:/iscsi # dd if=/dev/zero of=testfile bs=1k count=100000
100000+0 records in
100000+0 records out
102400000 bytes transferred in 17.661407 secs (1056241 bytes/sec)</p>
<p>WHAT !!!!!?????</p>
<p>這效能是怎麼回事???糟糕到一個不行啊!!!換算起來才  1mb 不到!?</p>
<p>有沒有那麼糟糕啊??看來用 sshfs 行不通!</p>
<p>馬上 umount</p>
<p>既然用fuse 去掛載進來的效能這麼糟糕,那 curlftpfs 應該也不用測試了,跳過,改用 iscsi 好了</p>
<p>翻了一下 google ,好像 FreeBSD 10.2的 iscsi 改用 ctl 來處理</p>
<p>於是參考這篇文章  <a href="http://jxtm.jzu.cn/?p=3238">用FreeBSD10搭建基于ZFS的iSCSI服务 </a>跳過 ZFS 的部分來建立iscsi target</p>
<hr />
<p>&nbsp;</p>
<p>以下這段在 storage 主機操作</p>
<p>首先修改 /etc/rc.conf 加入
&gt; <pre class="brush:java;">ctld_enable=&ldquo;YES&rdquo;
&gt;
&gt;
&gt; </pre>
&nbsp;</p>
<p>接著編輯 ctld 的設定檔</p>
<p>vim /etc/ctld.conf
&gt; <pre class="brush:java;">portal-group san {
&gt;
&gt; discovery-auth-group no-authentication
&gt;
&gt; listen 10.99.0.10 #改成自己的 IP
&gt;
&gt; }
&gt;
&gt;
&gt; target iqn.2014-05.com.example:target0 { #target name 可改可不改,就先保留,不要動吧
&gt;
&gt; auth-group no-authentication
&gt;
&gt; portal-group san
&gt;
&gt; lun 0 {
&gt;
&gt; path /mnt/iscsifile #指定 iscsi file 的位置
&gt;
&gt; blocksize 4096
&gt;
&gt; size 100G #指定大小
&gt;
&gt; }
&gt;
&gt; }</pre>
建立一個 target(iqn.2014-05.com.example:target0 )、一個 portal-group (san) 不需要認證 (反正這個LAN只有我自己的主機能存取)</p>
<p>再來修改ctld.conf 的權限
&gt; <pre class="brush:java;">chmod 600 /etc/ctl.conf</pre>
啟動 ctld 服務
&gt; <pre class="brush:java;">service ctld start</pre>
檢查 /var/log/messages 看看有沒有啥錯誤,正常來說應該不會有啥問題。</p>
<hr />
<p>&nbsp;</p>
<p>iscsi target 到這邊設定OK接著來去WP主機建立 iscsi initiator</p>
<p>先載入 iscsi_initiator.ko
&gt; kldload -v iscsi_initiator.ko
如果以後開機要自動載入的話</p>
<p>vim /boot/loader.conf
新增底下這一行
&gt; iscsi_initiator_load=”YES”
存檔後離開,修改檔案權限
&gt; chmod 755  /boot/loader.conf
再來,搜尋一下 iscsi target
&gt; iscontrol -v -d targetaddress=10.99.0.10 initiatorname=iqn
&gt;
&gt;
&gt; #targetaddress 要改成 storage主機的 IP
如果一切沒問題,應該會出現這樣的訊息
&gt; adding &lsquo;targetaddress=10.99.0.10&rsquo;
&gt;
&gt; I-: cmd=0x3 len=265
&gt;
&gt; SessionType=Discovery
&gt;
&gt; InitiatorName=nxl
&gt;
&gt; MaxBurstLength=131072
&gt;
&gt; HeaderDigest=None,CRC32C
&gt;
&gt; DataDigest=None,CRC32C
&gt;
&gt; MaxRecvDataSegmentLength=65536
&gt;
&gt; ErrorRecoveryLevel=0
&gt;
&gt; DefaultTime2Wait=0
&gt;
&gt; DefaultTime2Retain=0
&gt;
&gt; DataPDUInOrder=Yes
&gt;
&gt; DataSequenceInOrder=Yes
&gt;
&gt; MaxOutstandingR2T=1
&gt;
&gt; T-: cmd=0x23 len=212
&gt;
&gt; MaxBurstLength=131072
&gt;
&gt; HeaderDigest=None
&gt;
&gt; DataDigest=None
&gt;
&gt; MaxRecvDataSegmentLength=131072
&gt;
&gt; ErrorRecoveryLevel=0
&gt;
&gt; DefaultTime2Wait=0
&gt;
&gt; DefaultTime2Retain=0
&gt;
&gt; DataPDUInOrder=Yes
&gt;
&gt; DataSequenceInOrder=Yes
&gt;
&gt; MaxOutstandingR2T=1
&gt;
&gt; I-: cmd=0x4 len=16
&gt;
&gt; SendTargets=All
&gt;
&gt; T-: cmd=0x24 len=75
&gt;
&gt; TargetName=iqn.2014-05.com.example:target0
&gt;
&gt; TargetAddress=10.99.0.10:3260,2
&gt;
&gt; TargetName=iqn.2014-05.com.example:target0
&gt;
&gt; TargetAddress=10.99.0.10:3260,2
&gt;
&gt; I-: cmd=0x6 len=0
&gt;
&gt; T-: cmd=0x26 len=0
雖然很多看不懂,但是看樣子似乎是有找到,把 targetName / TargetAddress 抄下來</p>
<p>接著設定 iscsi initiator的設定檔</p>
<p>vim /etc/iscsi.conf
&gt; wpiscsi {
&gt;
&gt; authmethod      = CHAP
&gt;
&gt; chapIName       = YOUR-ISCSI-USERNAME #認證名稱 沒用到
&gt;
&gt; chapSecret      = YOUR-ISCSI-PASSWORD #認證密碼 沒用到
&gt;
&gt; initiatorname   = iqn
&gt;
&gt; TargetName      = iqn.2014-05.com.example:target0 #改成剛剛搜尋回傳的結果
&gt;
&gt; TargetAddress   = 10.99.0.10:3260,2 # 改成剛剛搜尋回傳的結果
&gt;
&gt; }
存檔離開、設定權限
&gt; chmod 755 /etc/iscsi.conf
測試連線
&gt; iscontrol -c /etc/iscsi.conf -n wpiscsi
正常的話,會出現類似這樣的訊息
&gt; <span style="font-family: Consolas,Monaco,Menlo,Courier,Verdana,sans-serif;"><span style="color: #111111;">iscontrol[8146]: running</span></span>
dmesg 看一下,最底下應該會出現找到新磁碟的訊息
&gt; da0 at iscsi0 bus 0 scbus2 target 0 lun 0
&gt;
&gt; da0: &lt;FREEBSD CTLDISK 0001&gt; Fixed Direct Access SPC-4 SCSI device
&gt;
&gt; da0: Serial Number MYSERIAL   0
&gt;
&gt; da0: 102400MB (26214400 4096 byte sectors: 255H 63S/T 1631C)
BINGO !抓到了!</p>
<p>再來就是去bsdconfig 分割,然後掛載
&gt; root@wp:/iscsi # mount
&gt;
&gt; /dev/vtbd0p2 on / (ufs, local, soft-updates)
&gt;
&gt; devfs on /dev (devfs, local, multilabel)
&gt;
&gt; /dev/da0s1a on /iscsi (ufs, local, journaled soft-updates)
&gt;
&gt; root@wp:/iscsi #
馬上來測試一下速度看看!可以發現磁碟寫入速度有大幅度的增加!!
&gt; root@wp:/iscsi # dd if=/dev/zero of=testfile bs=1k count=1000
&gt;
&gt; 1000+0 records in
&gt;
&gt; 1000+0 records out
&gt;
&gt; 1024000 bytes transferred in 0.005329 secs (192151364 bytes/sec)
&gt;
&gt; root@wp:/iscsi # dd if=/dev/zero of=testfile bs=1k count=10000
&gt;
&gt; 10000+0 records in
&gt;
&gt; 10000+0 records out
&gt;
&gt; 10240000 bytes transferred in 0.196187 secs (52195094 bytes/sec)
&gt;
&gt; root@wp:/iscsi # dd if=/dev/zero of=testfile bs=1k count=100000
&gt;
&gt; 100000+0 records in
&gt;
&gt; 100000+0 records out
&gt;
&gt; 102400000 bytes transferred in 17.661407 secs (5797953 bytes/sec)
&gt;
&gt; root@wp:/iscsi # dd if=/dev/zero of=testfile bs=1k count=100000
&gt;
&gt; 100000+0 records in
&gt;
&gt; 100000+0 records out
&gt;
&gt; 102400000 bytes transferred in 9.815858 secs (10432099 bytes/sec)
&nbsp;</p>
<p>接著編輯 /root/iscsi.sh 重開機就去執行這個指令把iscsi 掛進來
&gt; #!/bin/sh
&gt;
&gt; iscontrol -c /etc/iscsi.conf -n wpiscsi
&gt;
&gt; sleep 60
&gt;
&gt; mount /dev/da0s1d /iscsi
chmod u+rwx /root/iscsi.sh</p>
<p>大功告成!</p>
<p>日後重開機的話,手動執行 iscsi.sh ,就可以了!</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
<div class="footer">
<div class="tags">
<i class="fa fa-tags"></i>
<div class="links">
<a href="/tags/iscsi">iscsi</a>
<a href="/tags/storage">storage</a>
<a href="/tags/vps">vps</a>
<a href="/tags/vultr">Vultr</a>
<a href="/tags/wordpress">wordpress</a>
</div>
</div>
</div>
</article>
</div>
<div id="disqus_thread"></div>
<script type="application/javascript">
var disqus_config = function () {
};
(function() {
if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
return;
}
var d = document, s = d.createElement('script'); s.async = true;
s.src = '//' + "bilberry-hugo-theme" + '.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
<footer>
<div class="container">
<div class="recent-posts">
<strong>Latest posts</strong>
<ul>
<li>
<a href="/article/google-550-5-7-1-sloution/">寄信給google被退信 錯誤 550-5.7.1的解法</a>
</li>
<li>
<a href="/article/netdata-linux-system-performance-monitor-dashboard/">Netdata Linux System Performance Monitor Dashboard</a>
</li>
<li>
<a href="/article/linux-performance-monitor-dashboard-netdata-md/">Linux 底下極其詳細的System performace Monitor Dashboard - Netdata</a>
</li>
<li>
<a href="/article/syntax-test/">Syntax Test</a>
</li>
<li>
<a href="/article/psql-create-role-and-assign-priviledges/">psql create role and assign priviledges</a>
</li>
<li>
<a href="/article/study-url/">Study URL</a>
</li>
<li>
<a href="/article/rsync-time-backup/">[筆記] Linux 底下好用的備份工具 rsync-time-backup</a>
</li>
</ul>
</div>
<div class="categories">
<a href="/categories/"><strong>Categories</strong></a>
<ul>
<li>
<a href="/categories/%E6%9C%AA%E5%88%86%E9%A1%9E">未分類 (86)</a>
</li>
<li>
<a href="/categories/%E5%B7%A5%E4%BD%9C%E7%AD%86%E8%A8%98">工作筆記 (68)</a>
</li>
<li>
<a href="/categories/%E5%85%B6%E4%BB%96">其他 (46)</a>
</li>
<li>
<a href="/categories/%E7%AD%86%E8%A8%98">筆記 (30)</a>
</li>
<li>
<a href="/categories/%E5%89%AA%E5%A0%B1">剪報 (18)</a>
</li>
<li>
<a href="/categories/starting">Starting (5)</a>
</li>
<li>
<a href="/categories/blog">Blog (4)</a>
</li>
</ul>
</div>
<div class="right">
<div class="external-profiles">
<strong>Social media</strong>
<a href="https://twitter.com/TheRealLednerb" target="_blank"><i class="fa fa-twitter-adblock-proof"></i></a>
<a href="https://github.com/Lednerb" target="_blank"><i class="fa fa-github"></i></a>
</div>
<div class="languages">
<strong>Other languages</strong>
<a href="/en" class="active">en</a>
<a href="/de">de</a>
</div>
</div>
</div>
</footer>
<div class="credits">
<div class="container">
<div class="copyright">
<a href="https://github.com/Lednerb" target="_blank">
&copy;
2017
by Lednerb
</a>
</div>
<div class="author">
<a href="https://github.com/Lednerb/bilberry-hugo-theme" target="_blank">Bilberry Hugo Theme</a>
</div>
</div>
</div>
<script type="text/javascript" src="https://h.cowbay.org/js/externalDependencies.39c47e10e241eae2947b3fe21809c572.js" integrity="md5-OcR&#43;EOJB6uKUez/iGAnFcg=="></script>
<script type="text/javascript" src="https://h.cowbay.org/js/theme.ff50ae6dc1bfc220b23bf69dbb41b54e.js" integrity="md5-/1CubcG/wiCyO/adu0G1Tg=="></script>
<script>
$(".moment").each(function() {
$(this).text(
moment( $(this).text() )
.locale( "en" )
.format('LL')
);
});
$(".footnote-return sup").html("");
</script>
<script>
var client = algoliasearch("Y2C4RWMPXW", "50ea7f8c41c0ad233926e0be2b769ed1");
var index = client.initIndex("default-content");
$('#search').autocomplete({ hint: false, autoselect: true, debug: false },
[
{
source: $.fn.autocomplete.sources.hits(index, { hitsPerPage: 5, filters: 'language: en' }),
displayKey: function(suggestion) {
return suggestion.title || suggestion.author
},
templates: {
suggestion: function(suggestion) {
return "<span class='entry " + suggestion.type + "'>"
+ "<span class='title'>" + suggestion.title + "</span>"
+ "<span class='fa fa-fw " + suggestion.iconClass + "'></span>"
+ "</span>"
;
},
empty: function() {
return "<span class='empty'>Nothing found.</span>"
},
footer: function() {
return '<div class="branding">Powered by <img src="https:\/\/h.cowbay.org\/dist\/algolia-logo-light.svg" /></div>'
}
},
}
])
.on('autocomplete:selected', function(event, suggestion, dataset) {
window.location = (suggestion.url);
})
.keypress(function (event, suggestion) {
if (event.which == 13) {
window.location = (suggestion.url);
}
});
</script>
</body>
</html>