一、創建虛擬機
1.FreeNAS 是基於 FreeBSD 的
2.
3.
4. 操作系統版本選擇“FreeBSD“
因為我下載的 FreeNAS 的版本是 32 位的,所以這里選擇 “FreeBSD”。
如果你下載的 FreeNAS 的版本是 64 位的,要選擇 "FreeBSD 64位"。
5.
6.選擇處理器
7. 內存配置為 1G 就夠用了
8.
9.
10. 虛擬磁盤類型-->SCSI(S)
11.
12. 磁盤大小設置為 10G 就夠用了,因為這塊盤上僅安裝 FreeNAS 系統,不需要太大空間。
13.
14. 點擊“自定義硬件”
15. 刪除不必要的設備,如 USB 控制器、聲卡。
16. 點擊“關閉”
17. 點擊“完成”
18. 點擊 “編輯虛擬機設置”,添加用於存儲數據的硬盤。
19. 點擊 "添加"
20. 點擊 "硬盤" --> 點擊 "下一步"
21. 選擇 "SCSI(S)" --> 點擊 "下一步"
22.
23. 磁盤容量設置為 100G
24. 點擊 "完成"
25. 重復 19-24 的步驟,再添加 3 塊同樣的磁盤,添加完成后入下圖所示。
二、安裝 FreeNAS
26.
27.
28. 選擇大小為 10G 的硬盤
29. 選擇 "Yes",鍵入回車確認。
30.
31.
32.
三、配置 FreeNAS
33.
34.
35.
36.
37.
38. 確認 FreeNAS 可以和宿主機通信
39. 在瀏覽器地址欄中輸入 http://192.168.147.111,通過 WEB 頁面管理 FreeNAS。
40. 右上角 Alert 圖標有告警,點擊查看,提示你修改 admin 用戶密碼。
41.
42. 修改 admin 用戶密碼
43. 密碼修改成功
44.
45. 添加卷
卷類型說明:
- Stripe: 至少需要一個磁盤
- Mirror: 至少需要兩個磁盤
- RAIDZ1: 至少需要三個磁盤
- RAIDZ2: 至少需要四個磁盤
- RAIDZ3: 至少需要五個磁盤
- log device: 至少需要一個專用設備,建議使用快速,低延遲,電源保護的SSD
- cache device: 至少需要一個專用設備,建議使用SSD
在添加卷按鈕警告說, 現有的數據將被清除。換句話說,創建新卷將重新格式化選定的磁盤。如果要保留現有數據,請單擊“ 取消”按鈕並參考 導入磁盤和導入卷來查看是否支持現有格式。如果是,請執行該操作。如果當前存儲格式不受支持,則需要將數據備份到外部介質,格式化磁盤,然后將數據恢復到新卷。
4 塊硬盤,用 RaidZ2 方式。
46.
47.
48. 開啟 iSCSI 服務
49.
50. 12 ≤ 密碼長度 ≤ 16
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69. 在 iSCSI 屬性中開啟 CHAP 驗證,選擇組1。
三、Winodws 客戶端配置
這里以 Winodws 7 為例
70.
71. 點擊 "發現門戶"
72.
73.
74.
75.
76. 點擊 "連接"
77. 點擊 "高級"
78.
79.
80.
81.
82. 點擊 "取消"
83. 可以看到 iSCSI 磁盤了
二、linux客戶端連接iscsi共享存儲
#安裝配置 iscsi-initiator
- [root@localhost ~]# yum -y install iscsi-initiator-utils
- [root@localhost ~]# service iscsid start
#連接到iscsi共享存儲
- [root@localhost ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.230
- 192.168.1.230:3260,1 iqn.2011-03.org.example.istgt:iscsiwin8
- 192.168.1.230:3260,1 iqn.2011-03.org.example.istgt:iscsilinux
#登錄到iscsi共享存儲
- [root@localhost ~]# iscsiadm -m node -T iqn.2011-03.org.example.istgt:iscsilinux -p 192.168.1.230:3260 -l
- Logging in to [iface: default, target: iqn.2011-03.org.example.istgt:iscsilinux, portal: 192.168.1.230,3260] (multiple)
- Login to [iface: default, target: iqn.2011-03.org.example.istgt:iscsilinux, portal: 192.168.1.134,3260] successful.
#查看磁盤信息,可以看到多出一塊硬盤設備。
[root@localhost data]# fdisk -l Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000a43f1 Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 419430399 209202176 8e Linux LVM Disk /dev/mapper/centos-root: 205.8 GB, 205759971328 bytes, 401874944 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/centos-swap: 8455 MB, 8455716864 bytes, 16515072 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 4096 bytes / 1048576 bytes
#對設備進行格式化
[root@localhost data]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xd96b07f4. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): First sector (2048-209715199, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): Using default value 209715199 Partition 1 of type Linux and of size 100 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@localhost data]# partprobe Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only. Warning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.
#格式化完成檢查
[root@localhost data]# fdisk -l Disk /dev/sda: 214.7 GB, 214748364800 bytes, 419430400 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x000a43f1 Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 419430399 209202176 8e Linux LVM Disk /dev/mapper/centos-root: 205.8 GB, 205759971328 bytes, 401874944 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/mapper/centos-swap: 8455 MB, 8455716864 bytes, 16515072 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 4096 bytes / 1048576 bytes Disk label type: dos Disk identifier: 0xd96b07f4 Device Boot Start End Blocks Id System /dev/sdb1 2048 209715199 104856576 83 Linux
#指定分區格式
[root@localhost data]# mkfs.ext4 /dev/sdb1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=256 blocks 6553600 inodes, 26214144 blocks 1310707 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2174746624 800 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
#掛載並寫入文件
[root@localhost ~]# mkdir /data/iscsi
[root@localhost ~]# mount -t ext4 /dev/sdb1 /data/iscsi/
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/centos-root 192G 1.4G 191G 1% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 8.7M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 497M 108M 390M 22% /boot
tmpfs 797M 0 797M 0% /run/user/0
/dev/sdb1 99G 61M 94G 1% /data/iscsi
#設置開機自動掛載
echo "/dev/sdb1 /data/iscsi/ ext4 defaults 0 0" >> /etc/fstab
#檢查
[root@localhost mnt]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Fri Nov 10 19:40:13 2017 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/centos-root / xfs defaults 0 0 UUID=115aec57-6962-443e-9878-943f3e207a84 /boot xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 /dev/sdb1 /data/iscsi/ ext4 defaults 0 0
#查看並創建文件
[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 192G 1.4G 191G 1% / devtmpfs 3.9G 0 3.9G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 8.6M 3.9G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 497M 108M 390M 22% /boot tmpfs 797M 0 797M 0% /run/user/0 /dev/sdb1 99G 61M 94G 1% /data/iscsi
[root@localhost ~]# cd /data/iscsi/ [root@localhost iscsi]# touch test2 [root@localhost iscsi]# ll total 16 drwx------ 2 root root 16384 Nov 22 11:30 lost+found -rw-r--r-- 1 root root 0 Nov 22 11:59 test2
#卸載掛載的分區
[root@localhost ~]# umount /dev/sdb1 [root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 192G 1.4G 191G 1% / devtmpfs 3.9G 0 3.9G 0% /dev tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 3.9G 8.6M 3.9G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sda1 497M 108M 390M 22% /boot tmpfs 797M 0 797M 0% /run/user/0
FreeNas11.04 配置iscsi
1、全局配置
2、采用不認證的方式
3、配置后的效果
4、配置認證網絡
5、ALL 或192.168.1.1/24 (某一網段)
6、配置共享賬號
配置共享賬號效果如下:
7、配置Targent不認證方式訪問
8、配置共享目錄名稱,位置,大小,硬盤RPM.
9、Extents配置完成效果圖
10、設置Associated Targets
11、點發現(Discovery)---->Discover Portal:輸入IP和端口號--->ok。(其它地方直接用默認設置,即可)
12、Targets(查看連接狀態)
13、點磁盤管理,會彈出(檢測到了新硬盤),指定GPT格式,再分區格式化,即可使用。
、
如果之前掛載過相同的iscsi磁盤,再掛載時會報錯,只需點再Rescan Disks即可,修復。
14、linux下Targets連接方法
#注意他們的端口號是不一樣的(備注:默認3260時,可以不指定端口號 )
[root@template ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.140
#如果改了端口號,在后面要指定端口號
[root@template ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.140:3261
192.168.1.140:3261,2 iqn.gitlab.11.0
15、登錄到共享存儲(備注:這里測試登錄不同端口的共享盤)
[root@template ~]# iscsiadm -m node -T iqn.gitlab.11.0 -p 192.168.1.140:3261 -l Logging in to [iface: default, target: iqn.gitlab.11.0, portal: 192.168.1.140,3261] (multiple) Login to [iface: default, target: iqn.gitlab.11.0, portal: 192.168.1.140,3261] successful.
16、卸載iscsi
[root@next-cloud-server ~]# iscsiadm -m node -T iqn.netcloud.11.0 -u Logging out of session [sid: 1, target: iqn.netcloud.11.0, portal: 10.0.101.6,3261] Logout of [sid: 1, target: iqn.netcloud.11.0, portal: 10.0.101.6,3261] successful.
17、實現iscsi自動掛載磁盤
- Fedora25設置開機自動掛載
#配置iscsi自動發現
cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.netcloud.11.0
#重新啟動服務
systemctl restart iscsid
systemctl status iscsid
systemctl enable iscsid
#設置開機自動掛載
[root@next-cloud-server ~]# vi /etc/rc.d/rc.local
#!/bin/sh
#mount iscsi disk 5TB
sleep 10
mount -t xfs /dev/sda /data
#授權
chmod +x /etc/rc.d/rc.local
#添加服務
[root@next-cloud-server ~]# vim /usr/lib/systemd/system/rc-local.service
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.d/rc.local is executable.
[Unit]
Description=/etc/rc.d/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
#添加下面兩行代碼,實現rc-local作為服務啟動
[Install]
WantedBy=multi-user.target
#啟動服務
systemctl daemon-reload
systemctl start rc-local.service (備注:去掉這行)
systemctl enable rc-local.service
參考:http://blog.csdn.net/u013372441/article/details/77414471
18、掛載分區5T
分區
fdisk /dev/sda
g #大於5tb
再回車分區到完成
partprobe
mkfs.xfs -f /dev/sda
mount -t xfs /dev/sda /data/