日度归档:2021年5月18日

动态分区LVM方式挂载两块新增的硬盘到系统 2021-05-18

需求描述
动态分区LVM方式挂载两块新增的硬盘到系统 2021-05-18


# 第一步
# 查看系统内可用的硬盘
root@SERVER:~# fdisk -l
...
Disk /dev/vdb: 2 GiB, 2147483648 bytes, 4194304 sectors  #新增的硬盘1,大小2GB
Disk model: HARDDISK        
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xacc559c1

Device     Boot Start     End Sectors Size Id Type
/dev/vdb1        2048 4194303 4192256   2G 8e Linux LVM


Disk /dev/vdc: 3 GiB, 3221225472 bytes, 6291456 sectors  #新增的硬盘1,大小3GB
Disk model: HARDDISK        
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes




# 第二步
# 依次对刚刚的/dev/vdb  /dev/vdc 进行文件系统的创建
root@SERVER:~# fdisk /dev/vdb 
p   #这个地方如果显示了分区,记得按d逐个删除掉
n
[enter]
[enter]
[enter]
[enter]
t
L
8e
p 
w

root@SERVER:~# fdisk /dev/vdc
p   #这个地方如果显示了分区,记得按d逐个删除掉
n
[enter]
[enter]
[enter]
[enter]
t
L
8e
p 
w

root@SERVER:~# 
root@SERVER:~# fdisk -l
...
Disk /dev/vdb: 2 GiB, 2147483648 bytes, 4194304 sectors
Disk model: HARDDISK        
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xec2d5eb5

Device     Boot Start     End Sectors Size Id Type
/dev/vdb1        2048 4194303 4192256   2G 8e Linux LVM


Disk /dev/vdc: 3 GiB, 3221225472 bytes, 6291456 sectors
Disk model: HARDDISK        
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x228299a9

Device     Boot Start     End Sectors Size Id Type
/dev/vdc1        2048 6291455 6289408   3G 8e Linux LVM

...
root@SERVER:~#









# 第三步
# 物理卷是将在LVM配置中使用的实际存储设备,它可以是整个磁盘,
# pvcreate命令初始化这些磁盘,以便它们可以构成卷组
# 如果没有该命令,使用apt-get install lvm2安装组件
root@SERVER:~# pvcreate /dev/vdb1 /dev/vdc1
  Physical volume "/dev/vdb1" successfully created.
  Physical volume "/dev/vdc1" successfully created.
root@SERVER:~# 
root@SERVER:~# pvs
  PV         VG Fmt  Attr PSize  PFree 
  /dev/vdb1     lvm2 ---  <2.00g <2.00g
  /dev/vdc1     lvm2 ---  <3.00g <3.00g
root@SERVER:~# 



# 第四步
# 物理卷被合并为卷组(VG)。它创建了一个磁盘空间池,可以在其中分配逻辑卷
# 逻辑卷被分配到与物理盘区大小相同的逻辑盘区中。
# 因此,卷大小对于卷组中的所有逻辑卷都相同。卷组将逻辑盘区映射到物理盘区
root@SERVER:~# vgcreate vg01 /dev/vdb1 /dev/vdc1
  Volume group "vg01" successfully created
root@SERVER:~# vgs
  VG   #PV #LV #SN Attr   VSize VFree
  vg01   2   0   0 wz--n- 4.99g 4.99g
root@SERVER:~# 




# 第五步
# 卷组分为逻辑卷。因此,如果您早先创建了vg01,则可以从该VG创建逻辑卷
root@SERVER:~# lvcreate -l 100%VG -n lv01 vg01
  Logical volume "lv01" created.
root@SERVER:~# lvs
  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv01 vg01 -wi-a----- 4.99g                                                    
root@SERVER:~# 

# 如果是指定大小为50G,命令语法为
root@SERVER:~# lvcreate -L 50G -n lv01 vg01



# 第六步
# 创建需要挂在数据盘的分区目录
root@SERVER:~# mkdir -p /u1

# 第七步
# 创建需要LV盘的文件系统
root@SERVER:~# mkfs -t xfs  /dev/vg01/lv01
mke2fs 1.44.5 (15-Dec-2018)
Found a dos partition table in /dev/vg01/lv01
Proceed anyway? (y,N) y
Creating filesystem with 1308672 4k blocks and 327680 inodes
Filesystem UUID: e0fa3f74-3600-408a-b1c5-324694303b65
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736

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

root@SERVER:~# 



# 第八步
# 挂载LV分区到系统的文件系统
root@SERVER:~# mount /dev/vg01/lv01 /u1
root@SERVER:~# df -h
Filesystem             Size  Used Avail Use% Mounted on
udev                   977M     0  977M   0% /dev
tmpfs                  200M  6.0M  194M   4% /run
/dev/vda1               14G  4.0G  9.1G  31% /
tmpfs                  998M     0  998M   0% /dev/shm
tmpfs                  5.0M  4.0K  5.0M   1% /run/lock
tmpfs                  998M     0  998M   0% /sys/fs/cgroup
tmpfs                  200M   28K  200M   1% /run/user/117
tmpfs                  200M     0  200M   0% /run/user/1000
/dev/mapper/vg01-lv01  4.9G   20M  4.6G   1% /u1   #此处可见挂载成功
root@SERVER:~# 


# 第九步
# 添加如下内容到开机启动文件 /etc/fstab
/dev/vg01/lv01 /u1 xfs defaults 0 0



# 第十步
# 重启验证一下开机启动是否有效
root@SERVER:~# reboot




# 附录
# 如果前面的操作错误,需要删除vg01 lv01,则按如下步骤删除
root@SERVER:~# lvchange -an /dev/mapper/vg01-lv01
root@SERVER:~# lvremove /dev/mapper/vg1-lv1
  Logical volume "lv1" successfully removed
root@SERVER:~# vgremove vg1
  Volume group "vg1" successfully removed
root@SERVER:~# 
root@SERVER:~# vgremove vg01
  Volume group "vg01" successfully removed
root@SERVER:~# pvremove /dev/vdb /dev/vdc
  Labels on physical volume "/dev/vdb" successfully wiped.
  Labels on physical volume "/dev/vdc" successfully wiped.
root@SERVER:~# 

Donate
云乞讨

某次发现SSH登录服务器报错的事件记录 2021-05-18

需求描述
某次发现SSH登录服务器报错的事件记录 2021-05-18

user@server:~$ ssh -v root@10.6.8.56
OpenSSH_7.6p1 Ubuntu-4ubuntu0.3, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 10.6.8.56 [10.6.8.56] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/fd/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/fd/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/fd/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/fd/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/fd/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/fd/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/fd/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/fd/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3


// 后审阅message日志,发现是系统内存不够了,重启就好了

Donate
云乞讨