管理系统存储

来源:互联网 发布:火车票网络退票手续费 编辑:程序博客网 时间:2024/05/19 21:44

4.管理系统存储

fdisk -l 查看系统分区状态



1.分区划分
fdisk /dev/vdb
elcome 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.


Command (m for help): m            ##帮助
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition        ##删除分区
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types    ##列出系统可用的分区类型
   m   print this menu
   n   add a new partition        ##新建分区
   o   create a new empty DOS partition table
   p   print the partition table    ##显示分区
   q   quit without saving changes    ##推出
   s   create a new empty Sun disklabel
   t   change a partition's system id    ##修改分区功能id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit    ##保存更改到分区表中
   x   extra functionality (experts only)
Command (m for help): n            ##新建分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)    ##分区类型位主分区
   e   extended                    ##分区类型位扩展分区
Select (default p):                 ##默认位主分区
Using default response p
Partition number (1-4, default 1): 1        ##主分区id
First sector (2048-20971519, default 2048):     ##此分区起始位置
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +100M    ##分区大小
Partition 1 of type Linux and of size 100 MiB is set
Command (m for help): p

Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x193488c3

   Device Boot      Start         End      Blocks   Id  System

/dev/vdb1            2048      206847      102400   83  Linux



Command (m for help): wq        ##保存推出,如果安q表示放弃更改退出

[root@localhost mnt]# partprobe     ##同步分区表
cat /proc/partitions            ##查看系统识别的分区信息


 mkfs.xfs  /dev/vdb1            ##格式化


mount /dev/vdb5     /mnt            ##临时挂载

vim /etc/fstab                ##永久挂载


devic    mountpoint    ftype    defaults(mountpoint)    0 0
/dev/vdb1    /mnt    xfs    defaults    0 0
 mount -a                #使/etc/fstab中记录的挂载策略生效

#### 设定分区方式为gpt ####

GPT分区 全局唯一标识分区表,是一个较新的分区机制,解决了MBR很多缺点。

  用法:parted [选项]... [设备 [命令 [参数]...]...] 
 

将带有“参数”的命令应用于“设备”。如果没有给出“命令”,则以交互模式运行.  

帮助选项:

-h, --help 显示此求助信息 

-l, --list 列出所有设别的分区信息

-i, --interactive 在必要时,提示用户 

-s, --script从不提示用户 

-v, --version显示版本



[root@server0 ~]# parted /dev/vdb
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel                                                          
New disk label type? gpt                                                  
Warning: The existing disk label on /dev/vdb will be destroyed and all data on this disk will be lost. Do you
want to continue?
Yes/No? y                                                                 

(parted) quit 

                                                          






####2.swap####
1.fdisk /dev/vdb    #分区
2.fdisk 中修改swap分区标识
gpt    14
doc    82


3.

mkswap /dev/vdbn
4.

swapon -a /dev/vdbn


5.
vim /etc/fstab

/dev/vdbn    swap    swap    defaults,pri=1    0 0


6.
swapoff /dev/vdbn              ##卸载


####3.磁盘加密####
1.磁盘加密
fdisk  /dev/vdb                        创建新的分区
cryptsetup luksFormat /dev/vdb1        加密
cryptsetup open /dev/vdb1 westos    打开加密的分区

mkfs.xfs  /dev/mapper/westos        格式化分区为xfs格式


mount /dev/mapper/westos  /mnt/        挂载
umount /mnt/                        卸载
cryptsetup close westos                关闭加密分区

2.加密磁盘的永久挂载
vim /etc/crypttab                    
解密后设备管理文件    设备        加密字符存放文件

westos            /dev/vdb1    /root/lukspsfile


vim /root/lukspsfile                加密字符文件

chmod 600 /root/lukspsfile            密码文件600权限

cryptsetup luksAddKey /dev/vdb1  /root/lukspsfile        关联设备和密码文件


vim /etc/fstab                                             自动挂载

/dev/mapper/westos    /mnt    xfs    defaults    0 0


mount -a                                                检测/etc/fstab自动挂载


3.加密清除

vim /etc/fstab
> /etc/crypttab
rm -fr /root/lukspsfile
umount /mnt/
cryptsetup close westos
mkfs.xfs  /dev/vdb1



####4.磁盘阵列####

fdisk  /dev/vdb            创建三个分区,分区标示为raid

watch -n 1 cat /proc/mdstat                监控

mdadm  -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/vdb{1..3}        制作双磁盘一个闲置

mkfs.xfs  /dev/md0                        格式化


mount /dev/md0  /mnt/                    挂载





mdadm -f /dev/md0  /dev/vdb1            失效指定硬盘

mdadm -D /dev/md0                        查看raid状态


mdadm -r /dev/md0  /dev/vdb1             删除指定硬盘


mdadm -a /dev/md0 /dev/vdb1                添加指定硬盘
umount /mnt/                            取消挂载

mdadm  -S /dev/md0                        停止使用


fdisk /dev/vdb
删除分区
partprobe同步分区表

####5.配额####
mount -o usrquota /dev/vdb1 /westos        挂载,加上配额参数打开,默认是关闭的,加-o


edquota -u student                        打开配置配额文件   

Disk quotas for user student (uid 1000):
    设备                    以存在文件        软额度    最大额度    存在文件数量
  Filesystem                   blocks       soft       hard     inodes             soft     hard
  /dev/vdb1                    102400          0       40000       1            0        0

[root@localhost ~]# quota student             ##查看当前用户quota限制  

Disk quotas for user student (uid 1000):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/vdb1  102400       0  500000               1       0       0

  
[root@localhost ~]# su - student
Last login: Sun Nov 19 08:12:57 EST 2017 on pts/0
[student@localhost ~]$ dd if=/dev/zero of=/westos/studentfile bs=1M count=300
300+0 records in
300+0 records out
314572800 bytes (315 MB) copied, 0.696165 s, 452 MB/s
[student@localhost ~]$ dd if=/dev/zero of=/westos/studentfile bs=1M count=500
dd: error writing ‘/westos/studentfile’: No space left on device           ##由于最大额度为500000K,所以当截取额度大于500M时,出现错误。
472+0 records in
471+0 records out
494387200 bytes (494 MB) copied, 7.76268 s, 63.7 MB/s
[student@localhost ~]$ dd if=/dev/zero of=/westos/studentfile bs=1M count=800
dd: error writing ‘/westos/studentfile’: No space left on device
472+0 records in
471+0 records out
494387200 bytes (494 MB) copied, 1.02759 s, 481 MB/s



  


原创粉丝点击