Linux 2 unit5

unit5  使用逻辑卷管理灵活存储

###LVM创建###
[[email protected] ~]# mkdir /weixindata   ##建立目录
[[email protected] ~]# pvcreate /dev/vdb1   ##建立pv
  Physical volume /dev/vdb1 notfound
  Can‘t open /dev/vdb1 exclusively.  Mounted filesystem?
[[email protected] ~]# vgcreate vg0 /dev/vdb1  ##建立vg
  Physical volume /dev/vdb1 notfound
  Physical volume /dev/vdb1 notfound
  Can‘t open /dev/vdb1 exclusively.  Mounted filesystem?
  Unable to add physical volume‘/dev/vdb1‘ to volume group ‘vg0‘.

[[email protected] ~]# mkfs.xfs /dev/vg0
/dev/vg0: No such file or directory
Usage: mkfs.xfs
/* blocksize */     [-blog=n|size=num]
/* metadata */      [-m crc=[0|1]
/* data subvol */   [-dagcount=n,agsize=n,file,name=xxx,size=num,
               (sunit=value,swidth=value|su=num,sw=num|noalign),
                sectlog=n|sectsize=num
/* force overwrite */   [-f]
/* inode size */    [-ilog=n|perblock=n|size=num,maxpct=n,attr=0|1|2,
                projid32bit=0|1]
/* no discard */    [-K]
/* log subvol */    [-lagnum=n,internal,size=num,logdev=xxx,version=n
                sunit=value|su=num,sectlog=n|sectsize=num,
                lazy-count=0|1]
/* label */     [-L label (maximum 12characters)]
/* naming */        [-nlog=n|size=num,version=2|ci,ftype=0|1]
/* no-op info only */   [-N]
/* prototype file */    [-p fname]
/* quiet */     [-q]
/* realtime subvol */   [-r extsize=num,size=num,rtdev=xxx]
/* sectorsize */    [-slog=n|size=num]
/* version */       [-V]
            devicename
is required unless -d name=xxx is given.
is xxx (bytes), xxxs (sectors), xxxb (fs blocks), xxxk (xxxKiB),
      xxxm (xxx MiB), xxxg (xxx GiB), xxxt(xxx TiB) or xxxp (xxx PiB).
is xxx (512 byte blocks).
[[email protected] ~]# mdadm -D /dev/md0    ##查看设备信息
mdadm: md device /dev/md0 does not appear to be active.
[[email protected] ~]# mdadm -S /dev/md0    ##停止此设备
mdadm: stopped /dev/md0
[[email protected] ~]# mdadm -a /dev/md0  /dev/vdb2  ##添加一个新设备
[[email protected] ~]# vgcreate vg0 /dev/vdb1

  Volume group "vg0"successfully created
[[email protected] ~]# lvcreate -L 300M -n lv0 vg0  ##创建300M的lv0在vg0下
  Logical volume "lv0"created
[[email protected] ~]# mkfs.xfs /dev/vg0/lv0 ##格式化
meta-data=/dev/vg0/lv0          isize=256    agcount=4,agsize=19200 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=76800, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                  extsz=4096   blocks=0,rtextents=0
[[email protected] ~]# mount /dev/vg0/lv0 /weixindata/  ##挂载
[[email protected] ~]# ll /dev/mapper/vg0-lv0

lrwxrwxrwx. 1 root root 7 Apr 22 03:52 /dev/mapper/vg0-lv0 -> ../dm-0  ##下面测试结果出现/mapper实则和/vg0相同
[[email protected] ~]# ll /dev/vg0/lv0
lrwxrwxrwx. 1 root root 7 Apr 22 03:52 /dev/vg0/lv0 -> ../dm-0

测试结果

口令:watch -n 1 ‘echo ===pvmessage==;pvs;echo===vgmessage===;vgs;echo===lvm message===;lvs;echo ===;df/weixindata‘
===pvmessage==

  PV         VG  Fmt  Attr PSize    PFree
  /dev/vdb1  vg0 lvm2 a--  1020.00m 720.00m
  VG  #PV #LV #SN Attr   VSize    VFree
  vg0   1   1   0 wz--n- 1020.00m 720.00m
  LV  VG   Attr       LSize  Pool Origin Data
%  Move Log Cpy%Sync Convert
  lv0 vg0  -wi-ao---- 300.00m

===
Filesystem          1K-blocks  Used Available U
se% Mounted on
/dev/mapper/vg0-lv0    303788 15520    288268
 6% /weixindata

####设备拉伸####
[[email protected] ~]# lvextend -L 900M /dev/vg0/lv0   ##将原设备拉伸为900M
  Extending logical volume lv0 to 900.00MiB
  Logical volume lv0 successfullyresized
[[email protected] ~]# xfs_growfs /dev/vg0/lv0  ##文件系统的扩展
meta-data=/dev/mapper/vg0-lv0   isize=256    agcount=4,agsize=19200 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=76800, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                  extsz=4096   blocks=0,rtextents=0
data blocks changed from 76800 to 230400
[[email protected] ~]# lvextend -L 1200M /dev/vg0/lv0  ##继续拉伸为1200
  Extending logical volume lv0 to 1.17GiB
  Insufficient free space: 75 extentsneeded, but only 30 available ///提醒剩余空间不足
[[email protected] ~]# pvcreate /dev/vdb2   ##创建另一个pv
  Physical volume "/dev/vdb2"successfully created
[[email protected] ~]# vgextend vg0 /dev/vdb2  ##将另一个pv加入vg中
  Volume group "vg0"successfully extended
[[email protected] ~]# lvextend -L 1200M /dev/vg0/lv0  ##继续拉伸
  Extending logical volume lv0 to 1.17GiB
  Logical volume lv0 successfully resized//拉伸成功
[[email protected] ~]# xfs_growfs /dev/vg0/lv0 ##文件系统的拉伸
meta-data=/dev/mapper/vg0-lv0   isize=256    agcount=12,agsize=19200 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=230400, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                  extsz=4096   blocks=0,rtextents=0
data blocks changed from 230400 to 307200

###系统的缩减###
1)缩减之前所做准备
[[email protected] ~]# umount /weixindata/  ##卸载
[[email protected] ~]# mkfs.ext4 /dev/vg0/lv0 ##更改文件系统

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=0 blocks
76800 inodes, 307200 blocks
15360 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=314572800
10 block groups
32768 blocks per group, 32768 fragments per group
7680 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376,294912

Allocating group tables: done                           
Writing inode tables: done                           
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

[[email protected] ~]# mount /dev/vg0/lv0 /weixindata/  ##挂载
[[email protected] ~]# df  ##查看挂载是否成功

Filesystem          1K-blocks    Used Available Use% Mounted on
/dev/vda1            104739003241020   7232880  31% /
devtmpfs               927072       0   927072   0% /dev
tmpfs                  942660     472   942188   1% /dev/shm
tmpfs                  942660   17080   925580   2% /run
tmpfs                  942660       0   942660   0% /sys/fs/cgroup
/dev/mapper/vg0-lv0   1176704    3600  1095280   1% /weixindata

2)开始缩减
[[email protected] ~]# umount /weixindata/  ##卸载
[[email protected] ~]# e2fsck -f /dev/vg0/lv0 ##扫描(系统自己检测文件系统多大)

e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg0/lv0: 11/76800 files (0.0% non-contiguous), 13924/307200 blocks
[[email protected] ~]# resize2fs /dev/vg0/lv0 300M  ##缩减文件系统为300M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg0/lv0 to 76800 (4k) blocks.
The filesystem on /dev/vg0/lv0 is now 76800 blocks long.

[[email protected] ~]# mount /dev/vg0/lv0 /weixindata/  ##挂载
[[email protected] ~]# lvreduce -L 300 /dev/vg0/lv0 ##缩减设备

  WARNING: Reducing active and openlogical volume to 300.00 MiB
  THIS MAY DESTROY YOUR DATA (filesystemetc.)
Do you really want to reduce lv0? [y/n]: y
  Reducing logical volume lv0 to 300.00MiB
  Logical volume lv0 successfullyresized
[[email protected] ~]# pvmove /dev/vdb1 /dev/vdb2 ##把设备1信息传给设备2
[[email protected] ~]# vgreduce vg0 /dev/vdb1 ##把vdb1从vg0移除

  Removed "/dev/vdb1" fromvolume group "vg0"
  /dev/vdb1: Moved: 1.3%
  /dev/vdb1: Moved: 100.0%
[[email protected] ~]# pvremove /dev/vdb1  把vdb1从pv移除
  Labels on physical volume"/dev/vdb1" successfully wiped

####快照####
[[email protected] ~]# touch /weixindata/file{1..10}
[[email protected] ~]# ls /weixindata/

file1   file2  file4 file6  file8  lost+found
file10  file3  file5 file7  file9
[[email protected] ~]# umount /weixindata/
[[email protected] ~]# cd /weixindata/
[[email protected] weixindata]# ls
[[email protected] weixindata]# cd
[[email protected] ~]# lvcreate  -L 50M -nlv0backup -s /dev/vg0/lv0    ###创建快照

  Rounding up size to full physicalextent 52.00 MiB
  Logical volume "lv0backup"created
[[email protected] ~]# mount /dev/vg0/lv0backup /weixindata/
[[email protected] ~]# cd /weixindata/
[[email protected] weixindata]# ls

file1   file2  file4 file6  file8  lost+found
file10  file3  file5 file7  file9
[[email protected] weixindata]# rm -fr *
[[email protected] weixindata]# ls
[[email protected] weixindata]# cd
[[email protected] ~]# umount /weixindata/
[[email protected] ~]# lvremove /dev/vg0/lvobackup ##删除坏了的快照

  One or more specified logical volume(s)not found.
[[email protected] ~]# lvcreate  -L 50M -nlv0backup -s /dev/vg0/lv0   ##重新快照
  Rounding up size to full physicalextent 52.00 MiB
  Logical volume "lv0backup"already exists in volume group "vg0"
[[email protected] ~]# mount /dev/vg0/lv0backup /weixindata/
[[email protected] ~]# ls /weixindata/

file1   file2  file4 file6  file8  lost+found
file10  file3  file5 file7  file9

监护口令:
watch -n 1 ‘echo ===pvmessage==; pvs;echo===vgmessage===;vgs;echo===lvmmessage===;lvs;echo ===;df /weixindata‘

快照成功时监护界面:
===pvmessage==
  PV         VG  Fmt  Attr PSize    PFree
  /dev/vdb2  vg0 lvm2 a--  1020.00m 668.00m
  VG  #PV #LV #SN Attr   VSize    VFree
  vg0   1   2   1 wz--n- 1020.00m 668.00m
  LV        VG  Attr       LSize   Pool Origin
 Data% Move Log Cpy%Sync Convert
  lv0       vg0 owi-a-s--- 300.00m

lv0backup vg0  swi-a-s--- 52.00m  lv0
   0.00
===
Filesystem     1K-blocks    Used Available Use%
 Mounted on
/dev/vda1       10473900 3240980   7232920 31%
 /

####LVM的删除####
[[email protected] ~]# umount /weixindata/  ##卸载
[[email protected] ~]# lvremove /dev/vg0/lv0backup ##删除快照

Do you really want to remove active logical volume lv0backup? [y/n]: y
  Logical volume "lv0backup"successfully removed
[[email protected] ~]# lvremove /dev/vg0/lv0 ##删除lv0本身
Do you really want to remove active logical volume lv0? [y/n]: y
  Logical volume "lv0"successfully removed
[[email protected] ~]# vgremove vg0   删除vg
  Volume group "vg0"successfully removed
[[email protected] ~]# pvremove /dev/vdb2  删除pv
  Labels on physical volume"/dev/vdb2" successfully wiped

时间: 2024-08-24 12:02:18

Linux 2 unit5的相关文章

linux运维基础篇 unit5

unit5 1.用户理解 *用户就是系统使用者的身份 *在系统中用户存储为若干窜字符+若干个系统配置文件 用户信息涉及到的系统配置文件: 1./etc/passwd                        ###用户信息 用户:密码:uid:gid:说明:家目录:用户使用的shell 2. /etc/shadow                       ###用户认证信息 用户:密码:最后一次密码修改该时间:最短有效期:最长有效期:警告期:非活跃期:帐号到期日 3. /etc/grou

linux的运维管理UNIT5

用户及用户组的相关文件 当用户输入帐号密码时,系统处理了什么? 在 /etc/passwd文件中是否有该帐号---->读取该帐号对应的UID(/etc/passwd)和GID(/etc/group),同时将 该帐号的主文件夹与shell设置也一并读出来---->核对密码表:在/etc/shadow文件中找出对应的帐号与UID,然后核对密码是否正 确---->一切OK,则进入shell 控管的阶段 /etc/passwd [[email protected] Desktop]$ head 

linux实训

目  录 Unit 1 操作系统安装.... 3 1.1 多操作系统安装... 3 1.1.1 VMware简介... 3 1.1.2 VMWare基本使用... 4 1.2 安装Red Hat Linux 9.0. 15 1.3 思考题... 15 [实习报告]... 16 Unit 2  Linux命令接口使用.... 17 2.1 访问Linux系统... 17 2.1.1 创建用户组... 17 2.1.2 删除用户组... 17 2.1.3 创建用户... 18 2.1.4 删除用户.

排查Linux机器是否已经被入侵

随着开源产品的越来越盛行,作为一个Linux运维工程师,能够清晰地鉴别异常机器是否已经被入侵了显得至关重要,个人结合自己的工作经历,整理了几种常见的机器被黑情况供参考 背景信息:以下情况是在CentOS 6.9的系统中查看的,其它Linux发行版类似 1.入侵者可能会删除机器的日志信息,可以查看日志信息是否还存在或者是否被清空,相关命令示例: [[email protected] ~]# ll -h /var/log/* -rw-------. 1 root root 2.6K Jul 7 18

linux下Nginx配置文件(nginx.conf)配置设置详解(windows用phpstudy集成)

linux备份nginx.conf文件举例: cp /usr/local/nginx/nginx.conf /usr/local/nginx/nginx.conf-20171111(日期) 在进程列表里 面找master进程,它的编号就是主进程号. ps -ef | grep nginx 查看进程 cat /usr/local/nginx/nginx.pid 每次修改完nginx文件都要重新加载配置文件linux命令: /usr/local/nginx -t //验证配置文件是否合法 若ngin

Linux下WebSphereV8.5.5.0 安装详细过程

Linux下WebSphereV8.5.5.0 安装详细过程 自WAS8以后安装包不再区别OS,一份介质可以安装到多个平台.只针对Installation Manager 进行了操作系统的区分 ,Websphere产品介质必须通过专门的工具Install Managere安装.进入IBM的官网http://www.ibm.com/us/en/进行下载.在云盘http://yun.baidu.com/share/linkshareid=2515770728&uk=4252782771 中是Linu

Linux centos下让alias自定义永久生效(+常用的别名)

alias可以简化一些复杂的命令串,使一个单词或简化后的命令即可实现复杂(通常是带很多参数的长串)命令. 基本用法: alias 简化命令='实际的长串命令'    //实际长串命令通常为'原命令 -/选项参数' eg. alias ll='ls -a' 获取别名: alias        //即可查看当前设定的所有alias别名 取消别名: unalias 简化命令 eg. unalias ll            //取消ll的别名 永久生效: 直接使用alias命令定义的别名,重启后就

Linux下修改环境变量PATH

1.什么是环境变量(PATH) 在Linux中,在执行命令时,系统会按照PATH的设置,去每个PATH定义的路径下搜索执行文件,先搜索到的文件先执行. 我们知道查阅文件属性的指令ls 完整文件名为:/bin/ls(这是绝对路径), 那你会不会觉得很奇怪:"为什么我可以在任何地方执行/bin/ls这个指令呢? " 为什么我在任何目录下输入 ls 就一定可以显示出一些讯息而不会说找不到该 /bin/ls 指令呢? 这是因为环境变量 PATH 的帮助所致呀! 当我们在执行一个指令癿时候,举例

老男孩Linux运维第41期20170917开班第四周学习重点课堂记录

第1章 必知必会文件 配置文件位置 该文件作用 /etc/sysconfig/network-scripts/ifcfg-eth0 第一块网卡的配置文件 同setup中的network /etc/resolv.conf 客户端DNS配置文件,优先级低于网卡配置文件 /etc/hosts 主要作用是定义IP地址和主机名的映射关系(域名解析),是一个映射IP地址和主机名的规定 /etc/sysconfig/network 用于配置hostname和networking /etc/fstab 开机自动