Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x301a431a.
Command (m forhelp): p #查看分区信息 Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x301a431a
Device Boot Start End Blocks Id System
Command (m forhelp): n #添加新的分区 Partition type: p primary (0 primary, 0 extended, 4 free) e extended
Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +2G # 创建2GB分区 Partition 1 of type Linux and of size 2 GiB is set
Command (m forhelp): p # 查看分区信息 Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x301a431a
Device Boot Start End Blocks Id System /dev/sdb1 2048 4196351 2097152 83 Linux
Command (m forhelp): w # 保存分区信息并退出 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
[root@xy ~]# file /dev/sdb # file 查看 /dev/sdb1 文件属性 /dev/sdb1: cannot open (No such file or directory) [root@xy ~]# partprobe #partprobe 同步分区信息到系统内核 [root@xy ~]# file /dev/sdb1 /dev/sdb1: block special
Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Command (m forhelp): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended
Select (default p): p Partition number (2-4, default 2): 2 First sector (4196352-41943039, default 4196352): Using default value 4196352 Last sector, +sectors or +size{K,M,G} (4196352-41943039, default 41943039): +5G Partition 2 of type Linux and of size 5 GiB is set
Command (m forhelp): p Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x301a431a
Device Boot Start End Blocks Id System /dev/sdb1 2048 4196351 2097152 83 Linux /dev/sdb2 4196352 14682111 5242880 83 Linux
Command (m forhelp): 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.
8.2 格式化:
1 2 3 4 5 6 7 8 9 10 11 12
[root@xy ~]# mkswap /dev/sdb2 # 格式化 mkswap /dev/sdb2: No such file or directory [root@xy ~]# partprobe [root@xy ~]# partprobe [root@xy ~]# mkswap /dev/sdb2 Setting up swapspace version 1, size = 5242876 KiB no label, UUID=ffe8494a-c2f5-4af4-becf-985b130d395c [root@xy ~]# free -m total used free shared buffers cached Mem: 1987 1137 850 9 1 279 -/+ buffers/cache: 856 1131 Swap: 0 0 0
[root@xy ~]# reboot [root@xy ~]# mount | grep boot /dev/sda1 on /boot type xfs (rw,relatime,seclablel,attr2,inode64,usrquota) [root@xy ~]# useradd tom [root@xy ~]# chmod -Rf o+w /boot # other write [root@xy ~]# xfs_quota -x -c 'limit bsoft=3m bhard=6m isoft=3 ihard=6 tom' /boot [root@xy ~]# xfs_quota -x -c report /boot # xfs_quota -x -c User quota on /boot (/dev/sda1) Blocks User ID Used Soft Hard Warn/Grace ----------- ---------------------------------------------- root 95084 0 0 00 [--------] tom 0 3072 6144 00 [--------]
[root@xy ~]# su - tom [tom@xy ~]$ ddif=/dev/zero of=/boot/tom bs=5M count=1 1+0 records in 1+0 records out 5242880 bytes (5.2 MB) copied, 0.123996 s, 42.3 MB/s
[tom@xy ~]$ ddif=/dev/zero of=/boot/tom bs=8M count=1 dd: error writing '/boot/tom': Disk quato exceeded # 限制 1+0 records in 1+0 records out 6291456 bytes (6.3 MB) copied, 0.0201596s, 312MB/s
[root@xy ~]# edquota -u tom # edquota -u 按需修改配额 Disk quotas for user tom (uid 1001): Filesystem blocks soft hard inodes soft hard /dev/sda 6114 3072 8192 1 3 6
[root@xy ~]# su - tom [tom@xy ~]$ ddif=/dev/zero of=/boot/tom bs=8M count=1 1+0 records in 1+0 records out 8388608 bytes (8.4 MB) copied, 0.0238044s, 313MB/s [tom@xy ~]$ ddif=/dev/zero of=/boot/tom bs=10M count=1 dd: error writing '/boot/tom': Disk quato exceeded 1+0 records in 1+0 records out 8388608 bytes (8.4 MB) copied, 0.0238044s, 313MB/s
[root@xy ~]# mkfs.ext4 /dev/md0 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=128 blocks, Stripe width=256 blocks 2621440 inodes, 10477312 blocks 523865 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2157969408 320 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624
Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
[root@xy ~]# mkfs.ext4 /dev/md0 # 格式化 ext4 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=128 blocks, Stripe width=256 blocks 2621440 inodes, 10477312 blocks 523865 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2157969408 320 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624
Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done
[root@xy ~]# mdadm -D /dev/md0 # 查看 /dev/md0 磁盘阵列详细信息 /dev/md0: Version : 1.2 Creation Time : Mon Jul 9 20:07:08 2018 Raid Level : raid10 Array Size : 41909248 (39.97 GiB 42.92 GB) Used Dev Size : 20954624 (19.98 GiB 21.46 GB) Raid Devices : 4 Total Devices : 4 Persistence : Superblock is persistent
Update Time : Mon Jul 9 20:10:35 2018 State : active, resyncing Active Devices : 4 Working Devices : 4 Failed Devices : 0 Spare Devices : 0
Layout : near=2 Chunk Size : 512K
Resync Status : 96% complete
Name : xy.com:0 (local to host xy.com) UUID : 111c244f:e080b0c1:3316b6f2:986fa663 Events : 16
Number Major Minor RaidDevice State 0 8 32 0 active sync /dev/sdc 1 8 48 1 active sync /dev/sdd 2 8 64 2 active sync /dev/sde 3 8 80 3 active sync /dev/sdf
/dev/md0: Version : 1.2 Creation Time : Mon Jul 9 20:07:08 2018 Raid Level : raid10 Array Size : 41909248 (39.97 GiB 42.92 GB) Used Dev Size : 20954624 (19.98 GiB 21.46 GB) Raid Devices : 4 Total Devices : 4 Persistence : Superblock is persistent
Update Time : Mon Jul 9 21:04:28 2018 State : clean, degraded, recovering Active Devices : 3 Working Devices : 4 Failed Devices : 0 Spare Devices : 1
Layout : near=2 Chunk Size : 512K
Rebuild Status : 19% complete
Name : xy.com:0 (local to host xy.com) UUID : 111c244f:e080b0c1:3316b6f2:986fa663 Events : 32
Number Major Minor RaidDevice State 4 8 32 0 spare rebuilding /dev/sdc 1 8 48 1 active sync /dev/sdd 2 8 64 2 active sync /dev/sde 3 8 80 3 active sync /dev/sdf
[root@xy ~]# vgdisplay storage --- Volume group --- VG Name storage 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 39.99 GiB PE Size 4.00 MiB # -s 8M 指定PE大小 Total PE 10238 Alloc PE / Size 0 / 0 Free PE / Size 10238 / 39.99 GiB VG UUID pjR9cJ-VoyM-TZsz-NdMb-s05a-0VQZ-wHhEBo
[root@xy ~]# lvdisplay --- Logical volume --- LV Path /dev/storage/vo LV Name vo VG Name storage LV UUID bDRxSW-f9X3-KkjE-UPJL-wsrj-2zXm-pCNpcq LV Write Access read/write LV Creation host, time xy.com, 2018-07-10 10:03:43 +0800 LV Status available open 0 LV Size 148.00 MiB Current LE 37 Segments 1 Allocation inherit Read ahead sectors auto currently set to 8192 Block device 253:2
[root@xy ~]# vgdisplay --- Volume group --- VG Name storage System ID Format lvm2 ... Total PE 10238 Alloc PE / Size 37 / 148.00 MiB # PE 创建快照大小依据 Free PE / Size 10201 / 39.85 GiB VG UUID 6YZPns-qgdy-yEFx-hEZ3-bLwe-2eDd-PFEip8
[root@xy ~]# echo"Welcome to linux" > /LVM/readme.txt [root@xy ~]# lvcreate -L 148M -n SNAP -p r -s /dev/storage/vo # -s创建快照卷 Logical volume "SNAP" created
[root@xy ~]# lvdisplay
--- Logical volume --- LV Path /dev/storage/vo LV Name vo VG Name storage ... LV snapshot status source of SNAP [active] LV Status available open 1 LV Size 148.00 MiB ... currently set to 8192 Block device 253:2
--- Logical volume --- LV Path /dev/storage/SNAP LV Name SNAP VG Name storage LV UUID dERsif-hvjx-20JJ-1BLn-dPxb-aYtw-n1zetn LV Write Access read/write LV Creation host, time xy.com, 2018-07-10 14:00:46 +0800 LV snapshot status active destination for vo LV Status available open 0 LV Size 148.00 MiB ... Block device 253:3
[root@xy ~]# ssh-keygen -t rsa -b 2048 # 用此命令的 留下 私钥 Generating public/private rsa key pair. Enter file inwhich to save the key (/root/.ssh/id_rsa): 回车或设置密钥存储路径 Enter passphrase (empty for no passphrase): 直接按回车或设置密钥密码 Enter same passphrase again: 再次按回车或设置密钥密码 Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 81:e1:46:ce:a2:1a:a2:45:e2:5e:46:05:9f:ce:c1:12 root@xy.com The key's randomart image is: ....
客户端主机生成的公钥传送至远程主机上
1 2 3 4
[root@xy ~]# ssh-copy-id 192.168.37.10 # ssh-copy-ip 只能拷贝公钥 Number of key(s) added: 1 Now try logging into the machine, with: "ssh '192.168.37.10'" and check to make sure that only the key(s) you wanted were added.
对服务器进行设置只允许密钥验证
1 2
[root@xy ~]# vim /etc/ssh/sshd_config PasswordAuthentication no
[root@xy ~]# vim /etc/selinux/config # SELinux 配置文件路径 1 #This file controls the state of SELinux on the system. 2 # SELINUX= can take one of these three values: 3 # enforcing - SELinux security policy is enforced. 'enforce' 4 # permissive - SELinux prints warnings instead of enforcing. 'permissive' 5 # disabled - No SELinux policy is loaded. 'disabled SELINUX=enforcing 6 # SELINUXTYPE= can take one of these two values: 7 # targeted - Targeted processes are protected, 8 # minimum - Modification of targeted policy. Only selected processes are protected. 9 # mls - Multi Level Security protection.