Study Notes(12)

Note: When filling 512 bytes, pay attention to the size of bs if you use 1 byte to fill dd if=/dev/zero of=/dev/sdb bs=1 count=2 skip=510 seek=510

Before deleting the hard disk, it is best to execute it in a shutdown state, and it is also best to do the same in the virtual machine simulation environment (Vmware).

Supplement: Create pv can either partition or disk

1. Create a soft raid (4 disks with the same file system)

  fdisk modify t and then select 1 (specify which partition to modify, 1 is the partition number) for the need to modify the id of the partition to fd for raid

  dd if=/dev/sdb of=/dev/sdc bs=1 count=66 skip=446 seek=446 (including the last two bytes of 55aa, this mark indicates whether the disk is partitioned, without 55aa, lsblk Can't see the partition information) need to skip the bootloader bootloader, because the added disk is not used as a boot disk, you need to skip 446 bytes

  partx -a /dev/sdc (in centos6) centos7 uses partprobe, if it is not synchronized, the newly added partition cannot be viewed using lsblk

  partx -d --nr 1 /dev/sdc is used when deleting, note that there is no number after sdc, because there is a number 1 in front, you can write the range of 1-3 partition numbers

  (Clear the file system dd if=/dev/zero of=/dev/sdb1, you don't need to fill 0 completely, just fill the superblock block, wait for a while)

  mdadm -C /dev/md0 -a yes -l5 -c32 -n3 -x1 /dev/sd{b1,c1,d,e1} The -l option specifies that the chunk size is 32K, which should be defined in order, the last one Yes x1 (spare hard disk) e1

  mdadm -D /dev/md0

  blkid can view the UUID information of the raid

  blkid /dev/md0 does not have any output information, because no file system is created, using raid mode requires all the same installation file system

  mkfs.ext4 /dev/md0 -L raid5

  blkid /dev/md0 After creating the operating system, you can view the file system information of md0


  vim /etc/fstab

  :r!blkid /dev/md0 

  UUID=a7998bb6-6912-40d0-89fa-5be633ad3477  /mnt/raid        ext4   defaults       0 0


  mdadm -Ds /dev/md0 >/etc/mdadm.conf will prevent the configuration file not being found after restarting the raid device

   

  Test the write speed of a Raid disk

  dd if=/dev/zero of=/mnt/raid/f1 bs=1M count=1024

  

  Add dd if=/dev/zero of=/mnt/raid/f2 bs=1M count=1024 conv=fdatasync ends writing to disk, not writing to buffer


  The reading speed may be caused by data in the buffer and cache. You can use free -m to view the buffer cache to

  Test the read speed of Soft Raid

  dd if=/root/f1 of=/dev/null Test read speed


  umount /mnt/raid (execute the following -S command to umount first)

  mdadm -S /dev/md0 disable raid

  mdadm -A /dev/md0 enable raid

  [root@centos7 ~]#mdadm -A /dev/md0 Problems caused by not creating a configuration file

  mdadm: /dev/md0 not identified in config file.

  mdadm -D /dev/md0 View raid status


  mdadm /dev/md0 -f /dev/sdd1 simulate a damaged disk, and the spare disk immediately replaces the damaged disk

  [root@centos6 ~]# mdadm /dev/md0 -f /dev/sdb1

  mdadm: set /dev/sdb1 faulty in /dev/md0 The prompt information is not very friendly. I thought there was something wrong with my command?! In fact, it is a normal prompt information


  View the build process: watch -n 1 mdadm -D /dev/md0 Refresh every second, you can view the percentage of the process that the spare disk replaces the bad disk


  mdadm -D /dev/md0 information interception:

  Number   Major   Minor   RaidDevice State

   3       8       81        0      spare rebuilding   /dev/sdf1

   1       8       49        1      active sync   /dev/sdd1

   4       8       65        2      active sync   /dev/sde1


   0       8       17        -      faulty   /dev/sdb1


  mdadm /dev/md0 -r /dev/sdd1 remove device sdd1 from raid 

  mdadm /dev/md0 -a /dev/sdd1 add back sdd1 from raid 


  The usage style of the parted command is not much.


  Remove the spare disk and the raid disk in the virtual machine vm to check the fault tolerance

  mdadm -D /dev/md0 state: degraded For downgraded use, the data of the damaged hard disk needs to be calculated, so the performance of the system is consumed, because the CPU needs to calculate the data of the faulty hard disk through calculation

  state: clean is normal

2. Homework: Implement raid10 The following are two 1s and two 1s and then form raid0

  mdadm -C /dev/md0 -a yes -l1 -n2 /dev/sd{b,c} -c32 can specify the chunk size

  mdadm -C /dev/md0 -a yes -l1 -n2 /dev/sd{d,e}

  mdadm -C /dev/md0 -a yes -l0 -n2 /dev/md{0,1}

  or

  mdadm -C /dev/md0 -a yes -l10 -n4 /dev/sd{b,c,d,e} create raid10 directly


3. Add raid members 

  The partitions are out of sync. Use lsblk to view the partition centos6, use partx 7, use partprobe

  mdadm -G /dev/md0 -n4 -a /dev/sdb3 Newly added /dev/sdb3 partition

  mdadm -D /dev/md0 View detailed information of /dev/md0 (mdadm /dev/md0 View simple information of /dev/md0)

  df -h can't see

  resize2fs /dev/md0 Synchronize all file system space (only for ext series) This command has a delay, the first time was unsuccessful, the second time was successful


**************************************************************************  

[root@centos6 ~]# resize2fs /dev/md0

resize2fs 1.41.12 (17-May-2010)

The filesystem is already 5236992 blocks long.  Nothing to do!


[root@centos6 ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3       9.5G  4.2G  4.9G  46% /

tmpfs           491M  224K  491M   1% /dev/shm

/dev/sda1       969M   35M  885M   4% /boot

/dev/sda2        48G   52M   46G   1% /data

/ dev / sr0 3.7G 3.7G 0 100% /media/CentOS_6.9_Final

/dev/md0         20G   44M   19G   1% /mnt/raid5

[root@centos6 ~]# resize2fs /dev/md0

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/md0 is mounted on /mnt/raid5; on-line resizing required

old desc_blocks = 2, new_desc_blocks = 2

Performing an on-line resize of /dev/md0 to 7855488 (4k) blocks.

The filesystem on /dev/md0 is now 7855488 blocks long.


[root@centos6 ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda3       9.5G  4.2G  4.9G  46% /

tmpfs           491M  224K  491M   1% /dev/shm

/dev/sda1       969M   35M  885M   4% /boot

/dev/sda2        48G   52M   46G   1% /data

/ dev / sr0 3.7G 3.7G 0 100% /media/CentOS_6.9_Final

/dev/md0         30G   44M   28G   1% /mnt/raid5

******************************************************************************


  resize2fs /dev/vg0/lv0 synchronously expand or reduce the file system space (df to check whether the space is synchronized) Two places to use this command are to increase or decrease and reduce the space of the raid (only available on the ext series file system), One is to increase or decrease the space of lvs. This experiment has not been done yet.

  (There is no file system to use df to view, so use df to view the partition that does not create a file system)

  After xfs_growfs /mnt/raid is the mount point used when expanding,

  Because the xfs system cannot reduce the lv, you cannot use the /dev/md0 xfs system to synchronously increase or decrease the space. Use commands to synchronize the file system and unify the file systems of all disk partitions in the raid. The raid is a unified management file system, so it can be used The method of synchronizing the file system to modify the file system of the newly added disk partition


4.mdadm -D /dev/md0 (cat/proc/mdstat to view the disk)

5. Delete raid 

  umount /mnt/raid

  Delete mount information in /etc/fstab

  rm -rf /etc/mdadm.conf

  Some commands have a delay, such as mdadm -S /dev/md0 ll /dev/md0 can still be viewed, but disappear after a while

  The next time you use the partition as a raid, if there is residual information, you can use blkid to view it and clear it.

  mdadm --zero-superblock /dev/sdb1 Use this command to eliminate residual raid information before deleting, and use blkid to check that there is no raid information.

  If the partition is unavailable, you can directly use dd if=/dev/zero of=/dev/sdb1 to destroy the file system without waiting for the process to complete


  Replenish:

  Let the system default disk not be divided into partitions and directly fill the last 55AA two bytes with zero devices, dd if=/dev/zero of=/dev/sdb bs=1 count=2 seek=510, after the process is completed, you can use lsblk To check, you will find that the partition has disappeared. Of course, you can also use fdisk's d command to delete partitions 


  fdisk -l /dev/sdc is the partition information found from the hard disk

  lsblk is the partition information searched from the memory. If you can't view it with lsblk, you can use partprobe (centos7), partx -a /dev/sdc (centos6) to synchronize

  

  To create the same partition for different disks, you can use the dd command. You only need to fill in the last 66 bytes. Because it is not a boot disk, you do not need to fill in the first 446 bytes.

  dd if=/dev/sdb of=/dev/sdd bs=1 count=66 skip=446 seek=446 Note to use skip


  The information viewed by df is that the file system already exists and has been mounted for use

  What lsblk sees is the information of the block device, including whether it can be divided into partitions

  fdisk can view the id number of the system, including fd (RAID), 82 (swap), 83 (LINUX), 8e (LVM)


  Don't forget to use the use of d0 and d$, as well as the use of c0 and c$ in vi editing


6. pv vg lv memory order from bottom to top 

7. The volume group division unit is PE, the smallest unit for allocating space for LV

8. fdisk can view the partition id, fdisk -l /dev/sda1, because it can be modified, so of course you can view it.

9. Create LVM

  pvcreate /dev/sd{a7,c1}

  (There is partition information in the super block, and the previous md0 has super block information dd to kill the super block information)

  pvdisplay

  vgs view volume group

  vgdisplay view volume group

  vgcreate -s 16M vg0 /dev/sd{a7,c1} 16M PE PE is the smallest unit of vg, PE is used in the partition, the new disk is not

  pvs List simple information about pvs

  pvdisplay lists details of pvs

  vgs

  vgdisplay

  lvcreate -n lv0 -l 100 vg0 (-L specifies the capacity, -l specifies the number of PEs) -l is more accurate 

  Supplement: lvcreate -n lv0 -L +10G|10G # +10G means increase or decrease 10G, 10G means increase to 10G

  lvs

  lvdisplay


  lvcreate -n lv1 -l 100%free (use all space) vg0

  lvs  


  The link of the two lv needs to be specified when making a file system, and also needs to be specified when mounting. You can choose one of them.

  /dev/mapper/vg0-lv0

  /dev/vg0/lv1 

  [root@centos7 ~]#ll /dev/vg0/lv0 

  lrwxrwxrwx 1 root root 7 Apr 26 06:42 /dev/vg0/lv0 -> ../dm-0

  [root@centos7 ~]#ll /dev/mapper/vg0-lv0 

  lrwxrwxrwx 1 root root 7 Apr 26 06:42 /dev/mapper/vg0-lv0 -> ../dm-0


  mkfs.ext4 /dev/vg0/lv0          creates a filesystem

  mkfs.ext4 /dev/mapper/vg0-lv0    creates a filesystem


  Test read and write performance

  dd if=/dev/zero of=/mnt/lv0/f2 bs=1M count=500 conv=fdatasync plus the conv=fdatasync option will write the data directly to the disk, not the cache.


  Replenish:

  echo '- - -' > /sys/class/scsi_host/host2/scan is used to detect newly added disks

  partprobe(centos7), partx(centos6) are used to identify newly added partitions and information when deleting partitions, used when lsblk partitions are not synchronized

  partx -a /dev/sdc centos6 is used to synchronize partitions when adding partitions (whether it is recognized to use lsblk to view)

  partx -d --nr 1-3 /dev/sdc centos6 to synchronize when partitions 1, 2, and 3 are deleted (using dd if=/dev/zero of=/dev/sdc bs=1 count=2 seek=510 After completion, use lsblk to find that the partition has not disappeared, and the partition will disappear after using partx -d --nr 1 /dev/sdc)

  pvcreate /dev/sdd You can directly use the entire disk without partitioning before creating pv, or you can create pv after partitioning

  vgextend vg0 /dev/sdd1

  pvs

  vgdisplay

  lvdisplay

  lvextend -L +5G(5G) /dev/vg0/lv0 +5G is added to 5G 5G is added to 5G

  lvs

  df -h

  resize2fs /dev/vg0/lv0 Synchronous expansion or reduction of system space (df to check whether the space is synchronized) Use this command in two places, one is to increase or decrease the space of raid, and the other is to increase or reduce the space of lvs

  Mainly for raid and lvm because it is composed of multiple blocks, lvextnd -r can directly synchronize the file system


  lvextend -r -l +100%FREE /dev/vg0/lv0 -r option can directly synchronize the file system space, no need to use resize2fs /dev/vg0/lv0 to synchronize


  Backup before lvm reduces space


  The xfs file system cannot reduce the space, but can expand the space, and the ext series file system can reduce the space and expand the space


  Notice:

  To expand lv, you need to expand the logical volume LVM first, and then expand the file system (resize2fs when the lvextend -r option is not used)

  However, reducing LVM requires reducing the file system first, and then reducing the logical volume space.


  1.umount /mnt/lv0 to uninstall

  2.fsck -f /dev/vg0/lv0 Because the file system needs to be detected before resize2fs, the -f option must be given

  3.resize2fs /dev/vg0/lv0 10G No need to specify the size when expanding the file system space

  4.lvreudce -L 10G /dev/vg0/lv0 reduce logical volume

  5.mount -a remount


  remove hard drive in lvm

  1.pvmove /dev/sdd moves the data of the current pv to other pv in the volume group, and moves to those members is automatically determined by the system, no need to be specified

  2. vgredunce vg0 /dev/sdd removes sdd from the volume group

  3.pvremove /dev/sdd to restore to ordinary hard disk

10. vg, lv modify the name (used to conflict with the lvm name of the target server when migrating the logical volume lvm)

   vgrename vg0 centos6vg0 

   vgdisplay

   lvrename /dev/centos6vg0/lv0 /dev/centos6vg0/cento6lv0

   lvrename /dev/centos6vg0/lv1 /dev/centos6vg1/cento6lv1

11. To migrate a logical volume, you need to move the lv data that needs to be moved to a hard disk (/dev/sda), and then remove the hard disk and install it on another server. Before migrating, be careful not to conflict with the lvm name of the target server

   umount /mnt/lv0

   pvmove /dev/sda7  

   vgreduce vg0 /dev/sda7 removes the /dev/sda7 partition from vg0

   vgchange -an centos6vg0 disable volume group vg

   lvdisplay

   vgexport centos6vg0 Export volume group vg, set the state to export state to prepare for export vg

   vgdisplay sees that the status is exporting

   pvdisplay All pvs are also in the exporting state

   Remove the virtual machine hard disk, find the specified hard disk file, and cut the file to the path of the target virtual machine, add the virtual machine disk, find and add the existing disk

   (It is very convenient to write the path to find the file during operation, copy the hard disk file)

   vgimport cento6vg0 Set the vg of the newly added or reduced disk to the import state

   vgdisplay

   lvdisplay

   vgchange -ay centos6vg0 activates the volume group, and lvm also becomes available

   mkdir /mnt/centos6lv0

   mount /dev/centos6vg0/centos6lv0 /mnt/centos6lv0


12. The snapshot first allocates only one space (fast speed), and when the file is modified, the original file is not modified and transferred into the snapshot space

13. Create a logical volume snapshot

   Before creating a logical volume, check whether the current volume group has space to create a snapshot of the logical volume, because the space used by the snapshot is also in the volume group of the current snapshot that needs to be created.

   lvcreate -n lv0-snapshot -s -L 1G -pr /dev/vg0/lv0 -s specifies the snapshot option -pr read-only mode cannot modify the snapshot content

   lvdisplay

   mkdir /mnt/lv0-snapshot

       After mounting the created snapshot, you will find that the file is the same as the original logical volume. In fact, the displayed file is from the original logical volume (Note: The snapshot data before the data is not modified is actually from the source file, just to show that the snapshot has been effective)

   Snapshot recovery file

   umount /mnt/snap

   umount /mnt/centos6lv0

   lvconvert --merge /dev/centos6vg0/centos6lv0   


   xfs snapshot

   mount -o nouuid ... does not check the UUID, otherwise the same UUID will report an error, because the UUID of the snapshot is the same


  (Snapshot size <= original space size, only the files before the modified data are stored)

15. Delete the logical volume

   1.先umount

   2.lvremove delete

16. Snapshots will be deleted after recovery

   In order to ensure that the file system of the ext4 series is not damaged, use the -pr option, and use lvconvert --merge /dev/centos6vg0/centos6lv0 to restore the image content 

   Do not add -pr to xfs, otherwise an error will be reported

   xfs mount -o nouuid needs to add this option, not for ext series

17. One way to back up the mysql database is to use lvm snapshots. If cp is too slow, data will be modified. You can use snapshots to restore the files modified during the cp process.

Lab: Snapshots of Logical Volumes, Migrating Logical Volumes


Bandwidth is in bits, downloaded files are in bytes, so divide by 8

18. The network card in promiscuous mode will receive even if it is not its own message

19. Switching is done automatically in the switch, no need to use a crossover cable

   The two computers are connected using twisted pair cables, and the 13 and 26 lines should be swapped

20.T568B line sequence: orange white orange green white blue blue white green brown white brown

   T568A line sequence (1, 3 and 2, 6 are reversed): green white green orange white blue blue white orange brown white brown

21. MBR data in the hard disk of the hard disk 0 cylinder, 0 head, 0 sector (the first sector), DPT (Disk partition table), the partition valid mark 55AA


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324899217&siteId=291194637
Recommended