FreeNAS是一套免費的NAS伺服器,它能将一部普通PC變成網絡存儲伺服器。該軟體基于FreeBSD,Samba 及PHP,支援CIFS (samba), FTP, NFS protocols, Software RAID (0,1,5),ISCSI及 web 界面的設定工具。
使用者可通過Windows,linux,Mac來通路存儲伺服器;FreeNAS可被安裝于硬碟或移動媒體USB Flash Disk上。FreeNAS 伺服器前途無量;它的開發工作十分活躍。單是2006年前4個月就釋出11個修正版本。
它是組建簡單網絡存儲伺服器的絕佳選擇,免去安裝整套Linux或 FreeBSD 的煩惱。而且FreddNAS還有監控網絡情況的作用,重要的一點Freenas 8及其後續版本不支援系統檔案與存儲共同使用同一塊硬碟,
系統檔案單獨使用一個裝置,該裝置可以是USB記憶體卡、U盤、單獨的一塊硬碟等,存儲使用另一磁盤裝置。
這裡介紹FreeNAS11安裝和iSCSI配置,NFS、CIFS、FTP等配置請期待後續文章,另外後續還會寫openfiler虛拟存儲。
1、下載下傳FreeNAS 11鏡像檔案
下載下傳連結:https://download.freenas.org/11.2/STABLE/U1/x64/FreeNAS-11.2-RELEASE-U1.iso
2、安裝FreeNAS 11
選擇其他---FreeBSD 64位,如下圖:

磁盤配置設定10G,用于安裝freenas11,如下圖:
添加兩個15G磁盤,選擇SCSI接口,如下圖:
按Enter鍵安裝freenas11,如下圖:
選中Install/Upgrade,然後選擇OK後回車,如下圖:
選擇Yes後回車後回車,如下圖:(freenas伺服器最好8G以上記憶體,用于測試請忽略)
選擇将freenas安裝在哪個硬碟中,這裡選擇安裝在10G硬碟中,如下圖:
設定root賬号密碼,如下圖:
按照預設選擇後回車,如下圖:
選擇OK後按回車,成功完成安裝,如下圖:
選擇Reboot System重新開機伺服器,或者Shutdown System關機伺服器,如下圖:
3、配置FreeNAS 11
設定freenas管理IP,如下圖:
使用root賬号密碼登陸freenas web控制台,如下圖:
确認磁盤,如下圖:
Storage---Pools---ADD裡面添加池,選擇可選擇的硬碟,然後選擇是“條帶(Stripe)”還是“鏡像”,如下圖:
卷類型說明:
Stripe: 至少需要一個磁盤
Mirror: 至少需要兩個磁盤
RAIDZ1: 至少需要三個磁盤
RAIDZ2: 至少需要四個磁盤
RAIDZ3: 至少需要五個磁盤
log device: 至少需要一個專用裝置,建議使用快速,低延遲,電源保護的SSD
cache device: 至少需要一個專用裝置,建議使用SSD
備注:可以再在pool1上建立Dataset資料集。
在Services中點選iSCSI後面的編輯按鈕,如下圖:
Authorized Access---ADD,添加授權通路使用者,使用者名gxm,密碼ab12cd34ef98gh(注意密碼需要12到16位,否則SAVE不可點),如下圖:
Portals---ADD,新增入口設定iSCSI用戶端連接配接的IP位址和端口。如下圖:
Initiators---ADD,設定指定網卡運作通路,這裡全部允許,如下圖:
Targets---ADD,添加iSCSI目标,Target名稱最好以iqn開頭,這樣可以随機啟動,如下圖:
Extents---ADD,設定挂載目錄,如下圖/mnt/pool1/oracle:
Associated Targets---ADD,設定關聯Targets,如下圖:
備注:如果用不慣新版本的風格,也可以用以前版本的模式設定。
4、windows iSCSI連接配接
5、linux iSCSI連接配接
備注:配置檔案介紹:
/etc/iscsi/iscsid.conf:主要的配置檔案,用來連結到 iSCSI target 的設定;
/sbin/iscsid:啟動 iSCSI initiator 的主要服務程式;
/sbin/iscsiadm:用來管理 iSCSI initiator 的主要設定程式;
iscsid服務:讓本機模拟成為 iSCSI initiater 的主要服務;
iscsi服務:在本機成為 iSCSI initiator 之後,啟動此腳本,讓我們可以登入 iSCSI target。是以 iscsid 先啟動後,才能啟動這個服務。為了防呆,是以 /etc/init.d/iscsi 已經寫了一個啟動指令, 啟動 iscsi 前尚未啟動 iscsid ,則會先呼叫 iscsid 才繼續處理 iscsid
這裡以兩台伺服器挂載iSCSI分區為例,用于高可用方案。
第一台:
[root@localhost ~]# yum install iscsi-initiator-utils
[root@localhost ~]# systemctl enable iscsid
[root@localhost ~]# systemctl enable iscsi
#不需要啟動
[root@localhost ~]# vi /etc/iscsi/iscsid.conf
# *************
# CHAP Settings
# *************
# To enable CHAP authentication set node.session.auth.authmethod
# to CHAP. The default is None.
node.session.auth.authmethod = CHAP
# To set a CHAP username and password for initiator
# authentication by the target(s), uncomment the following lines:
node.session.auth.username = gxm
node.session.auth.password = ab12cd34ef98gh
# To set a CHAP username and password for target(s)
# authentication by the initiator, uncomment the following lines:
#node.session.auth.username_in = username
#node.session.auth.password_in = password
# To enable CHAP authentication for a discovery session to the target
# set discovery.sendtargets.auth.authmethod to CHAP. The default is None.
discovery.sendtargets.auth.authmethod = CHAP
# To set a discovery session CHAP username and password for the initiator
# authentication by the target(s), uncomment the following lines:
discovery.sendtargets.auth.username = gxm
discovery.sendtargets.auth.password = ab12cd34ef98gh
[root@localhost ~]# iscsiadm -m discovery -t sendtargets -p 192.168.146.104
192.168.146.104:3260,1 iqn.freenas
選項與參數:-m discovery :使用偵測的方式進行 iscsiadmin 指令功能;-t sendtargets :透過 iscsi 的協定,偵測後面的裝置所擁有的 target 資料-p IP:port :就是那部 iscsi 裝置的 IP 與埠口,不寫埠口預設是 3260 啰!
[root@localhost ~]# vi /etc/iscsi/initiatorname.iscsi
InitiatorName=192.168.146.104:3260,1 iqn.freenas
[root@localhost ~]# iscsiadm -m node -T iqn.freenas -p 192.168.146.104 -l
Logging in to [iface: default, target: iqn.freenas, portal: 192.168.146.104,3260] (multiple)
Login to [iface: default, target: iqn.freenas, portal: 192.168.146.104,3260] successful.
[root@localhost ~]# fdisk -l
磁盤 /dev/sda:21.5 GB, 21474836480 位元組,41943040 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/實體):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁盤标簽類型:dos
磁盤辨別符:0x000b0c8a
裝置 Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 41943039 20458496 8e Linux LVM
磁盤 /dev/mapper/rhel-root:18.8 GB, 18756927488 位元組,36634624 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/實體):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁盤 /dev/mapper/rhel-swap:2147 MB, 2147483648 位元組,4194304 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/實體):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁盤 /dev/sdb:21.5 GB, 21474836480 位元組,41943040 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/實體):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 1048576 位元組
[root@localhost ~]# pvcreate /dev/sdb
[root@localhost ~]# vgcreate vg-oracle /dev/sdb
[root@localhost ~]# vgdisplay
[root@localhost ~]# lvcreate -l 5119 -n da_oracle vg-oracle
[root@localhost ~]# lvdisplay
[root@localhost ~]# mkfs -t ext4 /dev/vg-oracle/da_oracle
[root@localhost ~]# mkdir /oracle
[root@localhost ~]# mount /dev/mapper/vg--oracle-da_oracle /oracle/
[root@localhost ~]# df -h
[root@localhost /]# umount /dev/mapper/vg--oracle-da_oracle
[root@localhost /]# iscsiadm -m node -T iqn.freenas -p 192.168.146.104 -u
Logging out of session [sid: 15, target: iqn.freenas, portal: 192.168.146.104,3260]
Logout of [sid: 15, target: iqn.freenas, portal: 192.168.146.104,3260] successful.
[root@localhost ~]# yum install iscsi-initiator-utils
[root@localhost ~]# systemctl start iscsi
[root@localhost ~]# systemctl enable iscsi
[root@localhost ~]# vi /etc/iscsi/iscsid.conf
# *************
# CHAP Settings
# *************
# To enable CHAP authentication set node.session.auth.authmethod
# to CHAP. The default is None.
node.session.auth.authmethod = CHAP
# To set a CHAP username and password for initiator
# authentication by the target(s), uncomment the following lines:
node.session.auth.username = gxm
node.session.auth.password = ab12cd34ef98gh
# To set a CHAP username and password for target(s)
# authentication by the initiator, uncomment the following lines:
#node.session.auth.username_in = username
#node.session.auth.password_in = password
# To enable CHAP authentication for a discovery session to the target
# set discovery.sendtargets.auth.authmethod to CHAP. The default is None.
discovery.sendtargets.auth.authmethod = CHAP
# To set a discovery session CHAP username and password for the initiator
# authentication by the target(s), uncomment the following lines:
discovery.sendtargets.auth.username = gxm
discovery.sendtargets.auth.password = ab12cd34ef98gh
[root@localhost ~]# iscsiadm -m discovery -t sendtargets -p 192.168.146.104
192.168.146.104:3260,1 iqn.freenas
選項與參數:-m discovery :使用偵測的方式進行 iscsiadmin 指令功能;-t sendtargets :透過 iscsi 的協定,偵測後面的裝置所擁有的 target 資料-p IP:port :就是那部 iscsi 裝置的 IP 與埠口,不寫埠口預設是 3260 啰!
[root@localhost ~]# vi /etc/iscsi/initiatorname.iscsi
InitiatorName=192.168.146.104:3260,1 iqn.freenas
[root@localhost ~]# iscsiadm -m node -T iqn.freenas -p 192.168.146.104 -l
Logging in to [iface: default, target: iqn.freenas, portal: 192.168.146.104,3260] (multiple)
Login to [iface: default, target: iqn.freenas, portal: 192.168.146.104,3260] successful.
[root@localhost ~]# vgchange -ay
1 logical volume(s) in volume group "vg-oracle" now active
2 logical volume(s) in volume group "rhel" now active
[root@localhost ~]# lvscan
ACTIVE '/dev/vg-oracle/da_oracle' [20.00 GiB] inherit
ACTIVE '/dev/rhel/swap' [2.00 GiB] inherit
ACTIVE '/dev/rhel/root' [17.47 GiB] inherit
[root@localhost ~]# fdisk -l
磁盤 /dev/sda:21.5 GB, 21474836480 位元組,41943040 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/實體):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁盤标簽類型:dos
磁盤辨別符:0x000b0c8a
裝置 Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 41943039 20458496 8e Linux LVM
磁盤 /dev/mapper/rhel-root:18.8 GB, 18756927488 位元組,36634624 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/實體):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁盤 /dev/mapper/rhel-swap:2147 MB, 2147483648 位元組,4194304 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/實體):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 512 位元組
磁盤 /dev/sdb:21.5 GB, 21474836480 位元組,41943040 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/實體):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 1048576 位元組
磁盤 /dev/mapper/vg--oracle-da_oracle:21.5 GB, 21470642176 位元組,41934848 個扇區
Units = 扇區 of 1 * 512 = 512 bytes
扇區大小(邏輯/實體):512 位元組 / 512 位元組
I/O 大小(最小/最佳):512 位元組 / 1048576 位元組
[root@localhost ~]# mount /dev/mapper/vg--oracle-da_oracle /oracle
[root@localhost ~]# df -h
檔案系統 容量 已用 可用 已用% 挂載點
/dev/mapper/rhel-root 18G 1.3G 17G 7% /
devtmpfs 903M 0 903M 0% /dev
tmpfs 913M 0 913M 0% /dev/shm
tmpfs 913M 8.6M 904M 1% /run
tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/sda1 497M 125M 373M 26% /boot
tmpfs 183M 0 183M 0% /run/user/0
/dev/mapper/vg--oracle-da_oracle 20G 45M 19G 1% /oracle
[root@localhost /]# umount /dev/mapper/vg--oracle-da_oracle
[root@localhost /]# iscsiadm -m node -T iqn.freenas -p 192.168.146.104 -u
Logging out of session [sid: 15, target: iqn.freenas, portal: 192.168.146.104,3260]
Logout of [sid: 15, target: iqn.freenas, portal: 192.168.146.104,3260] successful.