linux——管理系统设备之磁盘的加密、加密磁盘的挂载及磁盘阵列、配额
一、磁盤加密
1.磁盤加密
命令祥解:
[root@localhost ~]# cryptsetup luksFormat /dev/vdb1? ##對設備/dev/vdb1進行加密
WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.
Are you sure? (Type uppercase yes): yes??? ##小寫的yes,直接退出,無效
[root@localhost ~]# cryptsetup luksFormat /dev/vdb1
WARNING!
========
This will overwrite data on /dev/vdb1 irrevocably.
Are you sure? (Type uppercase yes): YES?? ##大寫的YES,確認并添加加密密碼
Enter passphrase:
Verify passphrase:
[root@localhost ~]# mount /dev/vdb1 /mnt/?? ##掛載設備/dev/vdb1
mount: unknown filesystem type 'crypto_LUKS'?? ##掛載失敗,設備已被加密
[root@localhost ~]# ls /dev/mapper/??? ##查看/dev/mapper/目錄
control
[root@localhost ~]# cryptsetup open /dev/vdb1 butterfly??? ##對設備解密
Enter passphrase for /dev/vdb1:???????????? ##需手動輸入密碼
[root@localhost ~]# ls /dev/mapper/
butterfly? control
[root@localhost ~]# mkfs.xfs /dev/mapper/butterfly?? ##將解密后生成的設備butterfly格式化
[root@localhost ~]# mount /dev/mapper/butterfly /mnt/??? ##掛載設備butterfly
[root@localhost ~]# touch /mnt/tutu{1..3}?? ##對設備進行讀寫操作
[root@localhost ~]# ls /mnt/
tutu1? tutu2? tutu3
[root@localhost ~]# umount /mnt/?? ##卸載設備
[root@localhost ~]# ls /mnt/
[root@localhost ~]# cryptsetup close butterfly??? ##將設備butterfly關閉
[root@localhost ~]# ll /dev/mapper/
total 0
crw-------. 1 root root 10, 236 May? 2 06:23 control
[root@localhost ~]# mount /dev/mapper/butterfly /mnt/
mount: special device /dev/mapper/butterfly does not exist
[root@localhost ~]# mount /dev/vdb1 /mnt/
mount: unknown filesystem type 'crypto_LUKS'
[root@localhost ~]# cryptsetup open /dev/vdb1 butterfly
Enter passphrase for /dev/vdb1:
[root@localhost ~]# mount /dev/vdb1 /mnt/
mount: unknown filesystem type 'crypto_LUKS'
[root@localhost ~]# mount /dev/mapper/butterfly /mnt/
[root@localhost ~]# df
[root@localhost ~]#
磁盤加密,就像把設備放在一個有蓋子的容器中,命令cryptsetup open /dev/vdb1 butterfly 就是打開蓋子,將設備拿出來,進行一系列操作后,再用命令cryptsetup close butterfly 將設備放回容器中并蓋上蓋子。這樣,可以提高安全性能。
圖解:
2.加密磁盤的永久掛載
[root@localhost ~]# vim /root/diskpass??? ##加密字符存放處
[root@localhost ~]# chmod 600 /root/diskpass?? ##給該文件加權限
[root@localhost ~]# cryptsetup luksAddKey /dev/vdb1 /root/diskpass??? ##將密碼文件做成容器的"蓋子"
Enter any passphrase:
[root@localhost ~]# vim /etc/crypttab???? ##設置設備解密后的管理文件
[root@localhost ~]# vim /etc/fstab?? ##永久掛載設置
[root@localhost ~]# df
[root@localhost ~]# umount /mnt/
[root@localhost ~]# reboot
[root@localhost ~]# df
[root@localhost ~]#
編寫的三份文件的內容:
[root@localhost ~]# cat /root/diskpass
147westos
[root@localhost ~]# cat /etc/crypttab
butterfly ??? ?? /dev/vdb1 ? ? ?? /root/diskpass?
解密后設備管理文件????? 設備??? 加密字符存放文件
[root@localhost ~]# cat /etc/fstab | tail -n 2
UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 /?????????????????????? xfs???? defaults??????? 1 1?? ##文件本身存在
/dev/mapper/butterfly? /mnt? xfs? defaults? 0 0? ##編寫內容
[root@localhost ~]#
3.加密清除
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# > /etc/crypttab
[root@localhost ~]# rm -fr /root/diskpass
[root@localhost ~]# umount /mnt/
[root@localhost ~]# cryptsetup close butterfly
[root@localhost ~]# mkfs.xfs /dev/vdb1
mkfs.xfs: /dev/vdb1 appears to contain an existing filesystem (crypto_LUKS).
mkfs.xfs: Use the -f option to force overwrite.
[root@localhost ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed May? 7 01:22:57 2014
#
# 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
#
UUID=9bf6b9f7-92ad-441b-848e-0257cbb883d1 /?????????????????????? xfs???? defaults??????? 1 1
[root@localhost ~]#
?4.磁盤陣列
1.建立三個新分區用t改換為fd類型分區
fdisk???/dev/vdb
?
mdadm??-C???/dev/md0??-a??yes??-l??1??-n??2??-x??1??/dev/vdb{1..3}
##-C表示進入創建模式?、-l級別、-a?yes?,查看是否有設備文件,如果沒有自動為其創建,-n?啟用設備數,-x?閑置設備數
watch?-n?1?cat?/proc/mdstat
mkfs.xfs??/dev/md0
mount?/dev/md0??/mnt/
?mdadm?-D?/dev/md0??????????????????#查看狀態信息
?
mdadm?-f?/dev/md0??/dev/vdb1??????#強制損壞
mdadm?-D?/dev/md0
mdadm?-r?/dev/md0??/dev/vdb1??????#刪除
mdadm?-D?/dev/md0
mdadm?-a?/dev/md0?/dev/vdb1????????#重新加入
mdadm?-D?/dev/md0
umount?/mnt/
mdadm??-S??/dev/md0????????????????#停止陣列
5.配額
只針對設備,不針對用戶
配額會較為平均的分配
mount -o usrquota /dev/vdb1 /mnt?? ##加載配額,針對xfs類型的設備
quotaon -uv /dev/vdb1??? ##激活配額,-u檢測用戶,-v顯示設備,針對ext的設備
xfs——一個64位的文件系統,最大支持8EB減1字節的單個文件系統
ext4——第四代擴展文件系統(Fourth EXtended filesystem),文件系統容量達到1EB,文件容量則達到16TB
edquota -u student? ##編輯指定用戶的磁盤配額
Filesystem ##表示本行配置記錄對應的文件系統(分區),即配額的作用范圍
blocks ##表示一個事實,用戶當前已使用的磁盤空間容量,默認單位為KB
soft ##第三列的soft表示對應磁盤容量的軟限制數值,默認單位為KB;第六列的soft表示對應文件數量的軟限制數值,默認單位為個
hard ##第四列的hard表示對應磁盤容量的硬限制數值,默認單位為KB;第六列的hard表示對應文件數量的硬限制數值,默認單位為個
inodes ##表示已有文件數量多少
指定用戶中的操作:
dd if=/dev/zero of=/mnt/studentfile bs=1M count=1 ##截取命令
從無限零設備/dev/zero中截取數據到/mnt/studentfile, bs=1M(一塊的大小)? count=1(塊數)
quota? ##顯示磁盤使用情況和限額,-u 只顯示用戶限額
練習+解釋說明
- 建立一個dos類型,大小為100M的主分區(設備/dev/vdb1)
- fdisk -l 查看當前分區屬性
- 將設備/dev/vdb1格式化,-f,強制
- 加載類型為xfs的設備/dev/vdb1的配額,并掛載在/mnt上
- 給/mnt賦予權限777
- 編輯用戶student的磁盤配額
- 切換到student用戶
- 從無限零設備/dev/zero中截取數據到/mnt/studentfile, bs=1M? count=10,無報錯
- 從無限零設備/dev/zero中截取數據到/mnt/studentfile, bs=1M? count=20,無報錯
- 從無限零設備/dev/zero中截取數據到/mnt/studentfile, bs=1M? count=21,出現報錯,原因此分配不均
dd: error writing ‘/mnt/studentfile’: Disk quota exceeded
21+0 records in
21+0 records out
20971520 bytes (21 MB) copied, 0.306071 s, 68.5MB/s
##顯示是21+0 records in和21+0 records out,但實際上只分配到了20M
開機自動掛載設置? vim /etc/fstab
總結
以上是生活随笔為你收集整理的linux——管理系统设备之磁盘的加密、加密磁盘的挂载及磁盘阵列、配额的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux——管理系统存储之设备分区:M
- 下一篇: linux——vim命令详细说明