如何在ubuntu上為簡單的檔案伺服器設定軟體raid

你是否需要一個便宜的檔案伺服器,易於安裝,“堅如磐石”可靠的電子郵件警報?將向您展示如何使用Ubuntu、軟體RAID和SaMBa來實現這一點。...

如何在ubuntu上為簡單的檔案伺服器設定軟體raid

你是否需要一個便宜的檔案伺服器,易於安裝,“堅如磐石”可靠的電子郵件警報?將向您展示如何使用Ubuntu、軟體RAID和SaMBa來實現這一點。

概述

儘管最近流行將所有內容移動到“全能”雲上,但有時您可能不希望您的資訊位於其他伺服器上,或者每次從internet下載所需的大量資料(例如映像部署)都是不可行的。因此,在您為儲存解決方案在預算中劃出一塊地方之前,請考慮一種Linux免費許可的配置。

儘管如此,廉價/免費並不意味著“拋開謹慎”,為此,我們將注意到除使用軟體RAID外,還應設定的配置,以實現最大的價效比。

Filomena Scalise影象

關於軟體raid

顧名思義,這是一種RAID(廉價磁碟冗餘陣列)設定,完全由軟體完成,而不是使用專用硬體卡。這樣做的主要優點是成本,因為這種專用卡是系統基本配置的額外優勢。主要缺點是效能和一些可靠性,因為這樣的卡通常帶有自己的RAM+CPU來執行冗餘數學所需的計算,資料快取以提高效能,以及可選的備用電池,用於在斷電情況下恢復供電之前,將未寫入的操作儲存在快取中。

使用軟體RAID設定,您可以犧牲一些系統CPU效能以降低系統總成本,但是使用今天的CPU,開銷相對可以忽略不計(特別是如果您打算將此伺服器主要用作“檔案伺服器”)。就磁碟效能而言,會有一個損失……不過,我從未遇到過來自伺服器的磁碟子系統的瓶頸來說明它有多嚴重。Tom's Hardware guide“Tom's goes RAID5”是一篇關於這個主題的老生常談但又非常詳盡的文章,我個人將其作為參考,然而,在談到軟體RAID的windows實現時,對基準測試持一點保留態度(與其他所有內容一樣,我相信Linux要好得多:P)。

先決條件

  • 耐心點,年輕人,這是一本很長的書。
  • 假設您知道RAID是什麼以及它的用途。
  • 本指南是使用ubuntuserver9.10x64編寫的,因此假設您也有一個基於Debian的系統可以使用。
  • 你會看到我使用VIM作為編輯器程式,這只是因為我習慣了它…你可以使用任何其他編輯器,你想。
  • 我用來編寫本指南的Ubuntu系統安裝在一個磁碟上。這樣做使我可以使用sda1作為RAID陣列的一部分,因此可以根據您的設定進行相應的調整。
  • 根據要建立的RAID型別,系統上至少需要兩個磁碟,在本指南中,我們使用6個驅動器。

選擇構成陣列的磁碟

避免陷阱的第一步是知道它的存在(來自沙丘的Thufir Hawat)。

選擇磁碟是一個至關重要的步驟,不應掉以輕心,明智的做法是利用您的真實經驗並注意以下警告:

不要使用“消費級”驅動器來建立陣列,請使用“伺服器級”驅動器!!!!!!

現在我知道你在想什麼了,我們不是說要便宜點嗎?是的,我們做到了,但是,這正是這樣做是魯莽的,應該避免的地方之一。儘管價格誘人,但消費級硬碟並不是設計成24/7“開”型的。相信我,你真的為你試過了。在我這樣設定的3臺伺服器中,至少有4臺消費級驅動器(由於預算限制)在伺服器首次推出後的1.5~1.8年後出現故障。雖然沒有資料丟失,但因為RAID做得很好並且倖存了下來…像這樣的時刻縮短了系統管理員的預期壽命,更不用說公司的伺服器維護停機時間(這可能會比更高級別的驅動器更貴)。

有人可能會說這兩種型別的失敗率沒有差別。這可能是真的,但是儘管有這些說法,伺服器級驅動器仍然有更高級別的S.M.a.R.T限制和QAing(這一點可以從一個事實上觀察到,它們並沒有在消費級驅動器上市後立即上市),因此我仍然強烈建議您為升級支付額外的$$$。

選擇raid級別。

雖然我不打算討論所有可用的選項(這在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;將更改寫入磁碟並退出

對將成為陣列一部分的所有磁碟進行沖洗和重複。

建立linux raid10陣列

使用“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

注意:儘管表示法將其分成兩行,但這都只是一行。

我們來分解引數:

  • “–chunk=256”–raid條帶的位元組大小,建議新磁碟/大型磁碟使用此大小(用於**本指南的2T驅動器無疑屬於該類別)。
  • “–level=10”–使用Linux raid10(如果需要傳統的raid,無論出於什麼原因,您都必須建立兩個陣列並將它們連線起來)。
  • “-p f2”–使用“far”旋轉計劃(參見下面的註釋)瞭解更多資訊,“2”表示陣列將保留兩個資料副本。

注意:我們使用“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.

Filesystem setup on the array

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”.

Mounting

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.

Email Alerts for the RAID Array

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.

Samba Configuration

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

Troubleshooting

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 ;-)

  • 發表於 2021-04-13 02:47
  • 閱讀 ( 46 )
  • 分類:網際網路

你可能感興趣的文章

livecd的50個酷用法

... 11連線到網路伺服器 ...

  • 發佈於 2021-03-12 09:39
  • 閲讀 ( 52 )

如何用舊計算機構建linux網路伺服器

有興趣建立一個家庭網路伺服器?最簡單的方法是在備用計算機上安裝Linux。由於Linux的簡單性,這非常簡單,為您提供了一種負擔得起的網站或部落格宿主方式。 ...

  • 發佈於 2021-03-17 19:20
  • 閲讀 ( 58 )

如何在ubuntu上安裝ftp伺服器

如果要設定Linux伺服器,則需要FTP訪問。這意味著首先在Linux上安裝FTP伺服器。這應該是安裝伺服器作業系統後首先要做的事情之一。 ...

  • 發佈於 2021-03-30 13:11
  • 閲讀 ( 55 )

如何使用curl從linux命令列下載檔案

...索http頭 使用-I(head)選項,您只能檢索HTTP頭。這與向web伺服器傳送HTTP HEAD命令相同。 curl -I www.twitter.com 此命令僅檢索資訊;它不下載任何網頁或檔案。 下載多個URL 使用xargs我們可以一次下載多個url。也許我們想下載一系列...

  • 發佈於 2021-04-02 22:46
  • 閲讀 ( 67 )

Ubuntu19.10“eoan ermine”的新增功能,現已推出

...的,其中有兩個熟悉的選項。您可以使用Xorg或Wayland顯示伺服器啟動Ubuntu。 雅魯主題已經更新,有許多新的圖示。這與19.04的視覺效果並沒有太大的不同,但是來自早期版本的Ubuntu的使用者將會看到Ubuntu Ambiance預設主題的很大變...

  • 發佈於 2021-04-03 01:40
  • 閲讀 ( 54 )

Ubuntu18.04 lts的新功能“仿生海狸”,現已上市

...所做的更改。然而,雖然Ubuntu 17.10預設使用了Wayland顯示伺服器,但Ubuntu 18.04切換回已嘗試的真正的Xorg顯示伺服器。 更新:經過一點延遲,最終的ubuntu18.04lts圖片現在可以下載了。 gnome外殼取代了unity桌面 對於ubuntu16.04lts使用...

  • 發佈於 2021-04-06 10:38
  • 閲讀 ( 59 )

備份與冗餘:有什麼區別?

...保護方法,旨在作為防止硬碟故障的實時故障安全措施。伺服器和NAS機箱中防止資料丟失的常見冗餘功能是RAID(代表獨立磁碟冗餘陣列),它跨多個硬碟驅動器建立檔案的多個副本。如果陣列中的一個硬碟驅動器出現故障,其...

  • 發佈於 2021-04-06 14:15
  • 閲讀 ( 52 )

windows10的新bashshell所能做的一切

...的Linux發行版,那麼您可能正在測試將在執行suselinux企業伺服器或Debian的伺服器上執行的軟體,或者您需要Kali-Linux中的安全測試工具,它們可以在Ubuntu的商店中找到。 訪問bash中的windows檔案,並在windows中訪問bash檔案 相關:如...

  • 發佈於 2021-04-06 14:44
  • 閲讀 ( 57 )

tldr將手冊頁轉換為簡明、通俗的英語解釋

命令列使用者知道如何閱讀手冊:鍵入“man”,然後輸入命令名,您將看到詳細的解釋。這些手冊很有用,但冗長,用數百字來解釋命令的每一個細節。 當你想知道一切的時候,這很好,但是大多數時候你都在尋找一個特定的...

  • 發佈於 2021-04-07 07:29
  • 閲讀 ( 41 )

如何設定和開始你的概要nas

...來,這樣我們就可以進入所有有趣的專案了一個具有類似伺服器的功能的小型NAS可以促進。 什麼是總論(a synology nas)? Synology是一家成立於2000年的公司,專門從事網路連線儲存(NAS)裝置。簡單地說,NAS是一種為資料儲存而最佳...

  • 發佈於 2021-04-07 12:37
  • 閲讀 ( 60 )
unknracke
unknracke

0 篇文章

作家榜

  1. admin 0 文章
  2. 孫小欽 0 文章
  3. JVhby0 0 文章
  4. fvpvzrr 0 文章
  5. 0sus8kksc 0 文章
  6. zsfn1903 0 文章
  7. w91395898 0 文章
  8. SuperQueen123 0 文章

相關推薦