RHCE note 1
unit 1
查看系统版本
cat /etc/redhat-release查看网络参数
ifconfig查看主机名
hostname查看shell
cat /etc/shells查看当前用户名称
whoami查看当前位置
pwd修改用户密码
passwd username查看当前用户id
id切换用户
su - username查看历史命令并执行
history
!number
或者!加命令前面几个字母
实例:[root@instructor 920]# !ca cat /etc/shells /bin/sh /bin/bash /sbin/nologin /bin/tcsh /bin/csh
快捷输入前一个参数
Alt+.查看后台任务,更改到前台运行,更改到后台运行
jobs,fg number,bg number
实例:[root@instructor 920]# jobs [1]- Running gedit day1.txt & [2]+ Stopped firefox [root@instructor 920]# [root@instructor 920]# [root@instructor 920]# fg 2 firefox
暂停当前任务并移到后台,停止当前命令:
Ctrl+z,Ctrl+c
unit 6
创建文件系统
- mbr区域有512B大小,其中16*4的大小用来记录四个主分区
- 主分区,扩展分区和逻辑分区总数不能超过15
- 查看磁盘信息
实例: ``` [root@instructor 920]# fdisk -l /dev/sda Disk /dev/sda: 320.1 GB, 320072933376 bytes 255 heads, 63 sectors/track, 38913 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0007213a
Device Boot Start End Blocks Id System /dev/sda1 * 1 17 131072 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 17 4096 32768000 8e Linux LVM /dev/sda3 4096 6646 20480000 8e Linux LVM /dev/sda4 6646 38914 259190784 5 Extended /dev/sda5 6646 7952 10485760 83 Linux /dev/sda6 7952 8605 5251727 83 Linux /dev/sda7 8606 8657 417658+ 8e Linux LVM /dev/sda8 8658 8785 1028128+ 8e Linux LVM /dev/sda9 8786 8888 827316 8e Linux LVM /dev/sda10 8889 16722 62926573+ 8e Linux LVM /dev/sda11 16723 18812 16787893+ 8e Linux LVM
- 基本流程:
fdisk 分区 --> mkfs 格式化 --> mount 挂载
1、分区
实例:
fdisk /dev/vda 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 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 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 Command action e extended p primary partition (1-4) e Partition number (1-4): 3 First cylinder (1-27046, default 1): 21328 Last cylinder, +cylinders or +size{K,M,G} (21328-27046, default 27046): Using default value 27046 Command (m for help): p Disk /dev/vda: 14.0 GB, 13958643712 bytes 16 heads, 63 sectors/track, 27046 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00064009 Device Boot Start End Blocks Id System /dev/vda1 * 3 523 262144 83 Linux Partition 1 does not end on cylinder boundary. /dev/vda2 523 21328 10485760 8e Linux LVM Partition 2 does not end on cylinder boundary. /dev/vda3 21328 27046 2882256 5 Extended Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (21328-27046, default 21328): Using default value 21328 Last cylinder, +cylinders or +size{K,M,G} (21328-27046, default 27046): +100M Command (m for help): p Disk /dev/vda: 14.0 GB, 13958643712 bytes 16 heads, 63 sectors/track, 27046 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00064009 Device Boot Start End Blocks Id System /dev/vda1 * 3 523 262144 83 Linux Partition 1 does not end on cylinder boundary. /dev/vda2 523 21328 10485760 8e Linux LVM Partition 2 does not end on cylinder boundary. /dev/vda3 21328 27046 2882256 5 Extended /dev/vda5 21328 21531 102664+ 83 Linux Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [root@demo ~]# partx -a /dev/vda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 [root@demo ~]# [root@demo ~]# partx -a /dev/vda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 BLKPG: Device or resource busy error adding partition 5
2、格式化
实例:
[root@demo ~]# mkfs -t ext4 /dev/vda5
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102664 blocks
5133 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 23 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
3、挂载
实例:
[root@demo ~]# mkdir /togogo [root@demo ~]# [root@demo ~]# mount /dev/vda5 /togogo/ [root@demo media]# mount | grep vda (ro,nosuid,nodev,uhelper=udisks,uid=0,gid=0,iocharset=utf8,mode=0400,dmode=0500) /dev/vda5 on /togogo type ext4 (rw)
4、修改配置文件
实例:
[root@demo ~]# cat /etc/fstab #
/etc/fstab
Created by anaconda on Sun Sep 1 09:14:16 2013
#
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/vgsrv-root / ext4 defaults 1 1 UUID=af186298-194c-4d01-8c3e-a21b28c45740 /boot ext4 defaults 1 2 /dev/mapper/vgsrv-common /common ext4 defaults 1 2 /dev/mapper/vgsrv-home /home ext4 defaults 1 2 /dev/mapper/vgsrv-shrink /shrink ext4 defaults 1 2 /dev/mapper/vgsrv-swap swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 UUID=c061f12f-efa2-4aa2-8091-de8e73549bae /data ext4 defaults,_netdev 0 0 /dev/vda5 /togogo ext4 defaults 0 0
mount -a 可自动挂载已写在配置文件下的分区。
## unit 7
###创建逻辑卷
逻辑卷相对于普通分区的好处是可以动态修改卷的大小,以使用卷内文件数量的变化。
- 基本流程:
fdisk 分区 --\> pvcreate 创建物理卷 --\> vgcreate 创建卷组 --\> lvcreate 创建逻辑卷 --\> mkfs 格式化 --\> mount 挂载
实例:
1、分区,修改分区ID号
[root@demo ~]# fdisk /dev/vda WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to switch off the mode (command ‘c’) and change display units to sectors (command ‘u’). Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (21532-27046, default 21532): Using default value 21532 Last cylinder, +cylinders or +size{K,M,G} (21532-27046, default 27046): +200M Command (m for help): n Command action l logical (5 or over) p primary partition (1-4) l First cylinder (21939-27046, default 21939): Using default value 21939 Last cylinder, +cylinders or +size{K,M,G} (21939-27046, default 27046): +300M Command (m for help): p Disk /dev/vda: 14.0 GB, 13958643712 bytes 16 heads, 63 sectors/track, 27046 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00064009 Device Boot Start End Blocks Id System /dev/vda1 * 3 523 262144 83 Linux Partition 1 does not end on cylinder boundary. /dev/vda2 523 21328 10485760 8e Linux LVM Partition 2 does not end on cylinder boundary. /dev/vda3 21328 27046 2882256 5 Extended /dev/vda5 21328 21531 102664+ 83 Linux /dev/vda6 21532 21938 205096+ 83 Linux /dev/vda7 21939 22549 307912+ 83 Linux 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 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 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): t Partition number (1-7): 6 Hex code (type L to list codes): 8e Changed system type of partition 6 to 8e (Linux LVM) Command (m for help): t Partition number (1-7): 7 Hex code (type L to list codes): 8e Changed system type of partition 7 to 8e (Linux LVM) Command (m for help): p Disk /dev/vda: 14.0 GB, 13958643712 bytes 16 heads, 63 sectors/track, 27046 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00064009 Device Boot Start End Blocks Id System /dev/vda1 * 3 523 262144 83 Linux Partition 1 does not end on cylinder boundary. /dev/vda2 523 21328 10485760 8e Linux LVM Partition 2 does not end on cylinder boundary. /dev/vda3 21328 27046 2882256 5 Extended /dev/vda5 21328 21531 102664+ 83 Linux /dev/vda6 21532 21938 205096+ 8e Linux LVM /dev/vda7 21939 22549 307912+ 8e Linux LVM Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. [root@demo ~]# partx -a /dev/vda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 BLKPG: Device or resource busy error adding partition 5 [root@demo ~]# [root@demo ~]# partx -a /dev/vda BLKPG: Device or resource busy error adding partition 1 BLKPG: Device or resource busy error adding partition 2 BLKPG: Device or resource busy error adding partition 3 BLKPG: Device or resource busy error adding partition 5 BLKPG: Device or resource busy error adding partition 6 BLKPG: Device or resource busy error adding partition 7
2、创建物理卷
[root@demo ~]# pvcreate /dev/vda6 Writing physical volume data to disk “/dev/vda6” Physical volume “/dev/vda6” successfully created [root@demo ~]# pvcreate /dev/vda7 Writing physical volume data to disk “/dev/vda7” Physical volume “/dev/vda7” successfully created
3、创建卷组
[root@demo ~]# vgcreate togogovg /dev/vda6 /dev/vda7
Volume group “togogovg” successfully created
[root@demo ~]# vgdisplay togogovg
— Volume group —
VG Name togogovg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 492.00 MiB
PE Size 4.00 MiB
Total PE 123
Alloc PE / Size 0 / 0
Free PE / Size 123 / 492.00 MiB
VG UUID fd7wDW-R1Ov-8oQh-iyvN-tBur-RMoG-VcYQ5d
4、创建逻辑卷
[root@demo ~]# lvcreate -n lv01 -L 150M togogovg Rounding up size to full physical extent 152.00 MiB Logical volume “lv01” created
5、格式化
[root@demo ~]# mkfs -t ext4 /dev/mapper/togogovg-lv01
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
38912 inodes, 155648 blocks
7782 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
19 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
6、挂载
[root@demo ~]# mkdir /lv01 [root@demo ~]# blkid /dev/mapper/togogovg-lv01 /dev/mapper/togogovg-lv01: UUID=“2460a9a1-f1ea-4aae-95ea-c39762380480” TYPE=“ext4” [root@demo ~]# cat /etc/fstab #
/etc/fstab
Created by anaconda on Sun Sep 1 09:14:16 2013
#
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/vgsrv-root / ext4 defaults 1 1 UUID=af186298-194c-4d01-8c3e-a21b28c45740 /boot ext4 defaults 1 2 /dev/mapper/vgsrv-common /common ext4 defaults 1 2 /dev/mapper/vgsrv-home /home ext4 defaults 1 2 /dev/mapper/vgsrv-shrink /shrink ext4 defaults 1 2 /dev/mapper/vgsrv-swap swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 UUID=c061f12f-efa2-4aa2-8091-de8e73549bae /data ext4 defaults,_netdev 0 0 /dev/vda5 /togogo ext4 defaults 0 0 UUID=2460a9a1-f1ea-4aae-95ea-c39762380480 /lv01 ext4 defaults 0 0 [root@demo ~]# mount /dev/mapper/vgsrv-root on / type ext4 (rw) proc on /proc type proc (rw) sysfs on /sys type sysfs (rw) devpts on /dev/pts type devpts (rw,gid=5,mode=620) tmpfs on /dev/shm type tmpfs (rw,rootcontext=“system_u:object_r:tmpfs_t:s0”) /dev/vda1 on /boot type ext4 (rw) /dev/mapper/vgsrv-common on /common type ext4 (rw) /dev/mapper/vgsrv-home on /home type ext4 (rw) /dev/mapper/vgsrv-shrink on /shrink type ext4 (rw) none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) /dev/vda5 on /togogo type ext4 (rw) /dev/mapper/togogovg-lv01 on /lv01 type ext4 (rw)
- 扫描,查看物理卷,卷组,逻辑卷信息:
pvscan,pvdisplay
vgscan,vgdisplay
lvscan,lvdisplay
实例:
[root@demo ~]# vgscan
Reading all physical volumes. This may take a while…
Found volume group “togogovg” using metadata type lvm2
Found volume group “vgsrv” using metadata type lvm2
[root@demo ~]#
[root@demo ~]# pvscan
PV /dev/vda6 VG togogovg lvm2 [196.00 MiB / 44.00 MiB free]
PV /dev/vda7 VG togogovg lvm2 [296.00 MiB / 296.00 MiB free]
PV /dev/vda2 VG vgsrv lvm2 [9.97 GiB / 4.75 GiB free]
Total: 3 [10.45 GiB] / in use: 3 [10.45 GiB] / in no VG: 0 [0 ]
[root@demo ~]# pvdisplay /dev/vda6
— Physical volume —
PV Name /dev/vda6
VG Name togogovg
PV Size 200.29 MiB / not usable 4.29 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 49
Free PE 11
Allocated PE 38
PV UUID pjxkza-zEAg-3JF6-G7Gg-1oju-xcuZ-bJdF5x
[root@demo ~]# vgdisplay togogovg
— Volume group —
VG Name togogovg
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size 492.00 MiB
PE Size 4.00 MiB
Total PE 123
Alloc PE / Size 38 / 152.00 MiB
Free PE / Size 85 / 340.00 MiB
VG UUID fd7wDW-R1Ov-8oQh-iyvN-tBur-RMoG-VcYQ5d
[root@demo ~]# lvdisplay /dev/mapper/togogovg-lv01
— Logical volume —
LV Path /dev/togogovg/lv01
LV Name lv01
VG Name togogovg
LV UUID BMsz8a-ye5Q-77oH-rm5y-O3I6-moKB-YeOXmP
LV Write Access read/write
LV Creation host, time demo.example.com, 2013-09-15 14:56:43 -0400
LV Status available
# open 1
LV Size 152.00 MiB
Current LE 38
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:5
### 扩展逻辑卷
- 一般流程:
新建一个物理卷-->将物理卷加入卷组-->扩展逻辑卷
实例:
1、创建物理卷(略)
2、扩展卷组
[root@demo ~]# vgextend togogovg /dev/vda8 Volume group “togogovg” successfully extended [root@demo ~]# vgdisplay togogovg
VG Name togogovg
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 3
VG Size 788.00 MiB
PE Size 4.00 MiB
Total PE 197
Alloc PE / Size 38 / 152.00 MiB
Free PE / Size 159 / 636.00 MiB
VG UUID fd7wDW-R1Ov-8oQh-iyvN-tBur-RMoG-VcYQ5d
3、扩展逻辑卷
[root@demo ~]# lvextend -L +148M /dev/mapper/togogovg-lv01 Extending logical volume lv01 to 300.00 MiB Logical volume lv01 successfully resized [root@demo ~]# lvdisplay /dev/mapper/togogovg-lv01 — Logical volume — LV Path /dev/togogovg/lv01 LV Name lv01 VG Name togogovg LV UUID BMsz8a-ye5Q-77oH-rm5y-O3I6-moKB-YeOXmP LV Write Access read/write LV Creation host, time demo.example.com, 2013-09-15 14:56:43 -0400 LV Status available # open 1 LV Size 300.00 MiB Current LE 75 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:5 [root@demo ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vgsrv-root 4.0G 2.6G 1.3G 68% / tmpfs 499M 88K 499M 1% /dev/shm /dev/vda1 248M 33M 203M 14% /boot /dev/mapper/vgsrv-common 124M 5.6M 113M 5% /common /dev/mapper/vgsrv-home 248M 46M 191M 20% /home /dev/mapper/vgsrv-shrink 310M 11M 284M 4% /shrink /dev/vda5 98M 5.6M 87M 6% /togogo /dev/mapper/togogovg-lv01 148M 5.6M 135M 4% /lv01 [root@demo ~]# resize2fs /dev/mapper/togogovg-lv01 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/togogovg-lv01 is mounted on /lv01; on-line resizing required old desc_blocks = 1, new_desc_blocks = 2 Performing an on-line resize of /dev/mapper/togogovg-lv01 to 307200 (1k) blocks. The filesystem on /dev/mapper/togogovg-lv01 is now 307200 blocks long. [root@demo ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vgsrv-root 4.0G 2.6G 1.3G 68% / tmpfs 499M 88K 499M 1% /dev/shm /dev/vda1 248M 33M 203M 14% /boot /dev/mapper/vgsrv-common 124M 5.6M 113M 5% /common /dev/mapper/vgsrv-home 248M 46M 191M 20% /home /dev/mapper/vgsrv-shrink 310M 11M 284M 4% /shrink /dev/vda5 98M 5.6M 87M 6% /togogo /dev/mapper/togogovg-lv01 291M 6.1M 270M 3% /lv01 [root@demo ~]# pvscan PV /dev/vda6 VG togogovg lvm2 [196.00 MiB / 0 free] PV /dev/vda7 VG togogovg lvm2 [296.00 MiB / 192.00 MiB free] PV /dev/vda8 VG togogovg lvm2 [296.00 MiB / 296.00 MiB free] PV /dev/vda2 VG vgsrv lvm2 [9.97 GiB / 4.75 GiB free] Total: 4 [10.74 GiB] / in use: 4 [10.74 GiB] / in no VG: 0 [0 ] ```