1. 程式人生 > >Linux磁碟空間不夠用怎麼辦?

Linux磁碟空間不夠用怎麼辦?

起因

VPS上mysql突然拒絕服務了,SSH上去檢查一下發現是使用者上傳大量圖片,導致磁碟空間滿了。
聯絡IDC,給增加了一塊硬碟,嗯,這下空間足夠了。

啟用新硬碟

使用 fdisk -l 檢視新增的硬碟

Disk /dev/sdb: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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: 0x1d2d511e

使用 fdisk /dev/sdb 建立分割槽,然後格式化

mkfs.ext4 /dev/sdb1 #就分了一個區

同步資料


mount /mnt/sdb1 /dev/sdb1   #掛載分割槽
mkdir /mnt/sdb1/upload
rsync -azvP /data/wwwroot/upload/ /mnt/sdb1/upload/ #資料同步
ln -s /mnt/sdb1/upload/ /data/wwwroot/upload/ #軟連線過去

小問題

軟連線特殊處理

du -shL DIR
rsync -azvPl SRC TAR

使用中發現vsftpd不支援軟連線,改用mount

mount --bind /mnt/sdb1/upload /data/wwwroot/upload/

這樣就可以解決vsftpd的問題了

如何在不重啟的情況下檢測新硬碟

[root@localhost ~]# ll /sys/class/scsi_host/
lrwxrwxrwx  1 root root 0 2017-08-22 00:43:19 host0 -> ../../devices/pci0000:00/0000:00:10.0/host0/scsi_host/host0
lrwxrwxrwx  1 root root 0 2017-08-22 00:43:19 host1 -> ../../devices/pci0000
:00/0000:00:07.1/host1/scsi_host/host1 lrwxrwxrwx 1 root root 0 2017-08-22 00:43:19 host2 -> ../../devices/pci0000:00/0000:00:07.1/host2/scsi_host/host2 [root@localhost ~]# echo "- - -" > /sys/class/scsi_host/host0/scan #立即掃描scsi_host0 [root@localhost ~]# echo "- - -" > /sys/class/scsi_host/host1/scan #立即掃描scsi_host1 [root@localhost ~]# echo "- - -" > /sys/class/scsi_host/host2/scan #立即掃描scsi_host2 [root@localhost ~]# fdisk -l Disk /dev/sda: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 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: 0x000078ed Device Boot Start End Blocks Id System /dev/sda1 * 1 128 1024000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 128 2168 16384000 82 Linux swap / Solaris /dev/sda3 2168 7833 45505536 83 Linux Disk /dev/sdb: 64.4 GB, 64424509440 bytes 255 heads, 63 sectors/track, 7832 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: 0x1d2d511e Device Boot Start End Blocks Id System /dev/sdb1 1 7832 62910508+ 83 Linux Disk /dev/sdc: 1073.7 GB, 1073741824000 bytes 255 heads, 63 sectors/track, 130541 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: 0x3fb96501 Device Boot Start End Blocks Id System /dev/sdc1 1 130541 1048569558+ 83 Linux

這樣就能看到新增的第三塊硬碟了