你是否需要一個便宜的檔案伺服器,易於安裝,“堅如磐石”可靠的電子郵件警報?將向您展示如何使用Ubuntu、軟體RAID和SaMBa來實現這一點。
儘管最近流行將所有內容移動到“全能”雲上,但有時您可能不希望您的資訊位於其他伺服器上,或者每次從internet下載所需的大量資料(例如映像部署)都是不可行的。因此,在您為儲存解決方案在預算中劃出一塊地方之前,請考慮一種Linux免費許可的配置。
儘管如此,廉價/免費並不意味著“拋開謹慎”,為此,我們將注意到除使用軟體RAID外,還應設定的配置,以實現最大的價效比。
Filomena Scalise影象
顧名思義,這是一種RAID(廉價磁碟冗餘陣列)設定,完全由軟體完成,而不是使用專用硬體卡。這樣做的主要優點是成本,因為這種專用卡是系統基本配置的額外優勢。主要缺點是效能和一些可靠性,因為這樣的卡通常帶有自己的RAM+CPU來執行冗餘數學所需的計算,資料快取以提高效能,以及可選的備用電池,用於在斷電情況下恢復供電之前,將未寫入的操作儲存在快取中。
使用軟體RAID設定,您可以犧牲一些系統CPU效能以降低系統總成本,但是使用今天的CPU,開銷相對可以忽略不計(特別是如果您打算將此伺服器主要用作“檔案伺服器”)。就磁碟效能而言,會有一個損失……不過,我從未遇到過來自伺服器的磁碟子系統的瓶頸來說明它有多嚴重。Tom's Hardware guide“Tom's goes RAID5”是一篇關於這個主題的老生常談但又非常詳盡的文章,我個人將其作為參考,然而,在談到軟體RAID的windows實現時,對基準測試持一點保留態度(與其他所有內容一樣,我相信Linux要好得多:P)。
避免陷阱的第一步是知道它的存在(來自沙丘的Thufir Hawat)。
選擇磁碟是一個至關重要的步驟,不應掉以輕心,明智的做法是利用您的真實經驗並注意以下警告:
不要使用“消費級”驅動器來建立陣列,請使用“伺服器級”驅動器!!!!!!
現在我知道你在想什麼了,我們不是說要便宜點嗎?是的,我們做到了,但是,這正是這樣做是魯莽的,應該避免的地方之一。儘管價格誘人,但消費級硬碟並不是設計成24/7“開”型的。相信我,你真的為你試過了。在我這樣設定的3臺伺服器中,至少有4臺消費級驅動器(由於預算限制)在伺服器首次推出後的1.5~1.8年後出現故障。雖然沒有資料丟失,但因為RAID做得很好並且倖存了下來…像這樣的時刻縮短了系統管理員的預期壽命,更不用說公司的伺服器維護停機時間(這可能會比更高級別的驅動器更貴)。
有人可能會說這兩種型別的失敗率沒有差別。這可能是真的,但是儘管有這些說法,伺服器級驅動器仍然有更高級別的S.M.a.R.T限制和QAing(這一點可以從一個事實上觀察到,它們並沒有在消費級驅動器上市後立即上市),因此我仍然強烈建議您為升級支付額外的$$$。
雖然我不打算討論所有可用的選項(這在raid*********條目中有很好的記錄),但我確實覺得值得注意的是,您應該始終選擇至少raid6或更高版本(我們將使用Linux RAID10)。這是因為當一個磁碟發生故障時,相鄰磁碟發生故障的可能性更高,然後您就有了“雙磁碟”故障。此外,如果您打算使用大型驅動器,因為較大的磁碟在盤面上的資料密度較高,則發生故障的可能性較高。2T及更高版本的IMHO磁碟總是屬於這一類,因此請注意。
分割槽磁碟
而在Linux/GNU中,我們可以使用整個塊裝置來滿足儲存需求,我們將使用分割槽,因為這樣可以更容易地使用磁碟救援工具,以防系統崩潰。我們在這裡使用的是“fdisk”程式,但是如果您要使用大於2T的磁碟,則需要使用支援GPT分割槽的分割槽程式,如parted。
sudo fdisk /dev/sdb
注意:我已經注意到在不改變分割槽型別的情況下建立陣列是可能的,但是因為這是整個網路中描述的方式,所以我將遵循這個方法(同樣當使用整個塊裝置時,這是不必要的)。
進入fdisk後,按鍵為:
n;對於新分割槽entrep;對於主分割槽enter1;分割槽數enter;接受defaultenter;接受defaultt;更改型別fd;將型別設定為“Linux raid auto detect”(83h)w;將更改寫入磁碟並退出
對將成為陣列一部分的所有磁碟進行沖洗和重複。
使用“LinuxRAID10”的優勢在於,它知道如何利用非偶數個磁碟來提高效能和恢復能力,甚至比普通raid10還要高,此外,使用“10”陣列只需一步即可建立。
透過發出以下命令,從我們在上一步中準備的磁碟建立陣列:
sudo mdadm --create /dev/md0 --chunk=256 --level=10 -p f2 --raid-devices=5 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 --verbose
注意:儘管表示法將其分成兩行,但這都只是一行。
我們來分解引數:
注意:我們使用“far”計劃是因為這會導致磁碟上的物理資料佈局不同。這有助於克服其中一個驅動器的硬體由於**故障而出現故障的情況(不要認為“這不會發生在我身上”,就像你真正的那樣)。由於這兩個磁碟的品牌和型號相同,使用方式相同,而且傳統上一直將資料儲存在同一物理位置……因此存在這樣的風險:儲存資料副本的驅動器也出現故障,或者接近,並且在替換磁碟到達之前無法提供所需的恢復能力。“far”計劃使資料分發到複製驅動器上的一個完全不同的物理位置,此外還使用計算機機箱中彼此不靠近的磁碟。更多資訊可以在這裡和下面的連結中找到。
一旦建立了陣列,它就會開始同步過程。雖然您可能希望等待傳統(因為這可能需要一段時間),但您可以立即開始使用陣列。
可以透過以下方法觀察進展:
watch -d cat /proc/mdstat
建立mdadm.conf檔案配置檔案
While it has been proven that Ubuntu simply knows to scan and activate the array automatically on startup, for completeness sake and courtesy for the next sysadmin we will create the file. Your system doesn’t automatically create the file and trying to remember all the components/partiti*** of your RAID set, is a waist of the system admin’s sanity. This information can, and should be kept in the mdadm.conf file. The formatting can be tricky, but fortunately the output of the mdadm –detail –scan –verbose command provides you with it.
Note: It has been said that: “Most distributi*** expect the mdadm.conf file in /etc/, not /etc/mdadm. I believe this is a “ubuntu-i**” to have it as /etc/mdadm/mdadm.conf”. Due to the fact that we are using Ubuntu here, we will just go with it.
sudo mdadm --detail --scan --verbose > /etc/mdadm/mdadm.conf
IMPORTANT! you need to remove one “0” from the newly created file because the syntax resulting from the command above isn’t completely correct (GNU/Linux isn’t an OS yet).
If you want to see the problem that this wrong configuration causes, you can issue the “scan” command at this point, before making the adjustment:
mdadm --examine --scan
To overcome this, edit the file /etc/mdadm/mdadm.conf and change:
metadata=00.90
To read:
metadata=0.90
Running the mdadm –examine –scan command now should return without an error.
I used ext4 for this example because for me it just built upon the familiarity of the ext3 filesystem that came before it while providing promised better performance and features. I suggest taking the time to investigate what filesystem better suits your needs and a good start for that is our “Which Linux File System Should You Choose?” article.
sudo mkfs.ext4 /dev/md0
Note: In this case i didn’t partition the resulting array because, i simply didn’t need it at the time, as the requesting party specifically requested at least 3.5T of continuous space. With that said, had i wanted to create partiti***, i would have had to use a GPT partitioning capable utility like “parted”.
Create the mount point:
sudo mkdir /media/raid10
Note: This can be any location, the above is only an example.
Because we are dealing with an “assembled device” we will not use the filesystem’s UUID that is on the device for mounting (as recommended for other types of devices in our “what is the linux fstab and how does it work” guide) as the system may actually see part of the filesystem on an individual disk and try to incorrectly mount it directly. to overcome this we want to explicitly wait for the device to be “assembled” before we try mounting it, and we will use the assembled array’s name (“md”) within fstab to accomplish this. Edit the fstab file:
sudo vim /etc/fstab
And add to it this line:
/dev/md0 /media/raid10/ ext4 defaults 1 2
Note: If you change the mount location or filesystem from the example, you will have to adjust the above accordingly.
Use mount with the automatic parameter (-a) to simulate a system boot, so you know that the configuration is working correctly and that the RAID device will be automatically mounted when the system restarts:
sudo mount -a
You should now be able to see the array mounted with the “mount” command with no parameters.
Unlike with hardware RAID arrays, with a software array there is no controller that would start beeping to let you know when something went wrong. Therefore the Email alerts are going to be our only way to know if something happened to one or more disks in the array, and thus making it the most important step.
Follow the “How To Setup Email Alerts on Linux Using Gmail or SMTP” guide and when done come back here to perform the RAID specific steps.
Confirm that mdadm can Email The command below, will tell mdadm to fire off just one email and close.
sudo mdadm --monitor --scan --test --oneshot
If successful you should be getting an Email, detailing the array’s condition.
Set the mdadm configuration to send an Email on startup While not an absolute must, it is nice to get an update from time to time from the machine to let us know that the email ability is still working and of the array’s condition. your probably not going to be overwhelmed by Emails as this setting only affects startups (which on servers there shouldn’t be many). Edit the mdadm configuration file:
sudo vim /etc/default/mdadm
Add the –test parameter to the DAEMON_OPTIONS section so that it would look like:
DAEMON_OPTIONS="--syslog --test"
You may restart the machine just to make sure your “in the loop” but it isn’t a must.
Installing SaMBa on a Linux server enables it to act like a windows file server. So in order to get the data we are hosting on the Linux server available to windows clients, we will install and configure SaMBa. It’s funny to note that the package name of SaMBa is a pun on the Microsoft’s protocol used for file sharing called SMB (Service Message Block).
In this guide the server is used for testing purposes, so we will enable access to its share without requiring a password, you may want to dig a bit more into how to setup permissi*** once setup is complete.
Also it is recommended that you create a non-privileged user to be the owner of the files. In this example we use the “geek” user we have created for this task. Explanati*** on how to create a user and manage ownership and permissi*** can be found in our “Create a New User on Ubuntu Server 9.10” and “The Beginner’s Guide to Managing Users and Groups in Linux” guides.
Install Samba:
aptitude install samba
Edit the samba configuration file:
sudo vim /etc/samba/**b.conf
Add a share called “general” that will grant access to the mount point “/media/raid10/general” by appending the below to the file.
[general] path = /media/raid10/general force user = geek force group = geek read only = No create mask = 0777 directory mask = 0777 guest only = Yes guest ok = Yes
The settings above make the share addressable without a password to anyone and makes the default owner of the files the user “geek”.
For your reference, this **b.conf file was taken from a working server.
Restart the samba service for the settings to take affect:
sudo /etc/init.d/samba restart
Once done you can use the testparm command to see the settings applied to the samba server. that’s it, the server should now be, accessible from any windows box using:
\server-namegeneral
When you need to troubleshoot a problem or a disk has failed in an array, I suggest referring to the mdadm cheat sheet (that’s what I do…).
In general you should remember that when a disk fails you need to “remove” it from the array, shutdown the machine, replace the failing drive with a replacement and then “add” the new drive to the array after you have created the appropriate disk layout (partiti***) on it if necessary.
Once that’s done you may want to make sure that the array is rebuilding and watch the progress with:
watch -d cat /proc/mdstat
Good luck! :)
References: mdadm cheat sheet RAID levels break down Linux RAID10 explained mdadm command man page mdadm configuration file man page Partition limitati*** explained
Using software RAID won’t cost much… Just your VOICE ;-)
有興趣建立一個家庭網路伺服器?最簡單的方法是在備用計算機上安裝Linux。由於Linux的簡單性,這非常簡單,為您提供了一種負擔得起的網站或部落格宿主方式。 ...
如果要設定Linux伺服器,則需要FTP訪問。這意味著首先在Linux上安裝FTP伺服器。這應該是安裝伺服器作業系統後首先要做的事情之一。 ...
...索http頭 使用-I(head)選項,您只能檢索HTTP頭。這與向web伺服器傳送HTTP HEAD命令相同。 curl -I www.twitter.com 此命令僅檢索資訊;它不下載任何網頁或檔案。 下載多個URL 使用xargs我們可以一次下載多個url。也許我們想下載一系列...
...的,其中有兩個熟悉的選項。您可以使用Xorg或Wayland顯示伺服器啟動Ubuntu。 雅魯主題已經更新,有許多新的圖示。這與19.04的視覺效果並沒有太大的不同,但是來自早期版本的Ubuntu的使用者將會看到Ubuntu Ambiance預設主題的很大變...
...所做的更改。然而,雖然Ubuntu 17.10預設使用了Wayland顯示伺服器,但Ubuntu 18.04切換回已嘗試的真正的Xorg顯示伺服器。 更新:經過一點延遲,最終的ubuntu18.04lts圖片現在可以下載了。 gnome外殼取代了unity桌面 對於ubuntu16.04lts使用...
...保護方法,旨在作為防止硬碟故障的實時故障安全措施。伺服器和NAS機箱中防止資料丟失的常見冗餘功能是RAID(代表獨立磁碟冗餘陣列),它跨多個硬碟驅動器建立檔案的多個副本。如果陣列中的一個硬碟驅動器出現故障,其...
...的Linux發行版,那麼您可能正在測試將在執行suselinux企業伺服器或Debian的伺服器上執行的軟體,或者您需要Kali-Linux中的安全測試工具,它們可以在Ubuntu的商店中找到。 訪問bash中的windows檔案,並在windows中訪問bash檔案 相關:如...
命令列使用者知道如何閱讀手冊:鍵入“man”,然後輸入命令名,您將看到詳細的解釋。這些手冊很有用,但冗長,用數百字來解釋命令的每一個細節。 當你想知道一切的時候,這很好,但是大多數時候你都在尋找一個特定的...
...來,這樣我們就可以進入所有有趣的專案了一個具有類似伺服器的功能的小型NAS可以促進。 什麼是總論(a synology nas)? Synology是一家成立於2000年的公司,專門從事網路連線儲存(NAS)裝置。簡單地說,NAS是一種為資料儲存而最佳...