可搜索,可注册,可登录,致敬逗比大佬!尽在救援版逗比根据地 dbgjd.com
投稿文章 | 广告合作 | Telegram 群组 / 公告频道 / 使用教程

vps硬盘不够了怎么办

自从搭建了一个图床之后,我开始发现vps的硬盘空间开始慢慢不够用了。随着时间的增长,上传的图片也越来越多。贫穷总是会限制我的想象力,那么有哪些解决方案呢?

世界加钱可及

加钱升级配置

加钱,去服务商那里升级配置就好了,好多钱钱~

使用block storage

有些服务商可能提供类似block storage这种存储服务(如vultr、DigitalOcean),那就花钱钱买点,然后挂载上就好了。假如不提供这些服务的话,可以考虑试试Google Cloud Storage,然后挂载到本地,价格也还是可以接受的~

使用rclone挂载网络硬盘

可是我是穷人唉,$1都出不起,那该怎么办呢……可不可以把Google Drive、OneDrive、Dropbox什么的挂载上呢?Google Drive有15G,Dropbox有2G,OneDrive有5G,这加起来就是22G,那就是$2.2呢!

淘宝花个几块钱扩容什么的,那就是血赚啊!

rclone挂载Google Drive什么的很容易,有很多人写文件介绍过,比如说这篇,只不过有两点需要注意的:

使用mount挂载之后,这个程序会“阻塞”,另开一个窗口df –h就会发现有了

vps硬盘不够了怎么办

5T滑稽?

但是咱也不能一直开着,跑个screen也不好,所以还是写个systemd单元文件吧

[Unit] Description=Google Drive mounter After=network.target network-online.target nss-lookup.target  [Service] Restart=on-failure Type=simple ExecStart=/usr/bin/rclone mount gdrive_goldstein:/ /mnt/gdrive/ --allow-non-empty --vfs-cache-mode writes --allow-other  [Install] WantedBy=multi-user.target 

非常需要注意这个--allow-other参数,如果没有的话,从nginx的webroot下做过来的符号链接www用户无权访问,那就403了哦

iSCSI

这网络存储有的时候可能也有点不太够(5T都不够吗?),那该怎么办呢?不如买个大硬盘的vps,然后试试iSCSI!(看来这RHCE是没白考啊ε=ε=ε=(~ ̄▽ ̄)~

iSCSI是个啥呢?Internet小型计算机系统接口,简单理解就是客户端可以通过网络让自己有/dev/sd*这样的“真实”的物理设备,然后随便格式化挂载什么的。

iSCSI一般来说是局域网使用的,一般不会跨公网玩,因为这东西对延迟丢包有点敏感。当然了用是能用的,只不过配置起来有点麻烦,而且传输过程是不加密的。(′д` )…彡…彡

iSCSI传输不是加密的这个消息不太好,但是有一些解决方案的,比如套个IPSec啦,比如走个SSH隧道啦。

本着灵活应用的道理,咱就来挂载个玩玩……

概念解析

target – 理解成服务器;initiator – 理解成客户端

准备“硬盘”

对于服务端来说,提供服务的“硬盘”可以选择块设备(硬盘啊,U盘啊什么的),也可以选择文件设备,甚至内存够大做ramdisk都是可以的~

为了方便扩展,我们这里就做一个逻辑卷,这样以后也可以看心情随时扩容的。

首先~登录到server,需要进行一下分区,总之就是搞出来一个sdb2这种分区做逻辑卷。使

分区

用fdisk进行类似操作:

[email protected]:~# fdisk /dev/sda Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.  Command (m for help): p Disk /dev/sda: 20 GiB, 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 Disklabel type: gpt Disk identifier: DCBEF2AD-7269-4B63-BA34-AE2F15A6D9F7 Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 20975615 20971520 10G Linux filesystem  Command (m for help): n  Partition number (3-128, default 3): First sector (20975616-41943006, default 20975616): Last sector, +sectors or +size{K,M,G,T,P} (20975616-41943006, default 41943006): Created a new partition 3 of type 'Linux filesystem' and of size 10 GiB.  Command (m for help): w  The partition table has been altered. Syncing disks. 

输入partprobe更新分区表,这里新分区为sda3,大小10G

创建逻辑卷

[email protected]:~# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created. 

默认的Volume Group大小是4MiB,当然这个创建vg的时候可以改。

[email protected]:~# vgcreate idata /dev/sda3 Volume group "idata" successfully created 

创建Logic Volume的时候,n表示名字;大小方面,可以指定是多少个PE,也可以直接写大小,使用l指定多少个PE,256个也就是1G了,L指定大小,

[email protected]:~# lvcreate -n iscsi_data -l 256 idata Logical volume "iscsi_data" created.  # 直接指定3G [email protected]:~# lvcreate -n test -L 3G idata Logical volume "test" created. 

查看一下 确定信息无误

[email protected]:~# lvdisplay  --- Logical volume --- LV Path /dev/idata/iscsi_data LV Name iscsi_data VG Name idata LV UUID ueP2uS-zEOG-6B1q-5GuD-9L5f-1ZyZ-86E4ee LV Write Access read/write LV Creation host, time server, 2019-06-23 06:19:06 +0000 LV Status available # open 0 LV Size 1.00 GiB Current LE 256 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 
叮咚提示:

有些vps上来就是一个/,这种情况下根本用不了fdisk给分出来空间的。那咋办呢?有这么几种思路,fileio,livecd用gparted,手动重装系统

配置target

就假定服务端和客户端都是Ubuntu 啦,16.04之后应该操作都差不多的

apt install targetcli-fb 

输入targetcli进入交互页面,输入ls可以看下大体情况

vps硬盘不够了怎么办

我们要做这么几件事情:创建backstore,给backstore增加LUNS,ACL,PORTAL

创建backstore

创建block设备

/backstores/block create name=client1_data dev=/dev/idata/iscsi_data 

/dev/idata/iscsi_data 就是我们刚刚创建的逻辑卷,name 是名字

创建iSCSI

/iscsi create wwn=iqn.2019-06.com.bennythink:server 

回车之后会发现自动帮我们创建好了portal

创建luns,这里的client1_data就是我们第一步创建的name

/iscsi/iqn.2019-06.com.bennythink:server/tpg1/luns create /backstores/block/client1_data 

创建acl

[email protected]:~# fdisk /dev/sda Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.  Command (m for help): p Disk /dev/sda: 20 GiB, 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 Disklabel type: gpt Disk identifier: DCBEF2AD-7269-4B63-BA34-AE2F15A6D9F7 Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 20975615 20971520 10G Linux filesystem  Command (m for help): n  Partition number (3-128, default 3): First sector (20975616-41943006, default 20975616): Last sector, +sectors or +size{K,M,G,T,P} (20975616-41943006, default 41943006): Created a new partition 3 of type 'Linux filesystem' and of size 10 GiB.  Command (m for help): w  The partition table has been altered. Syncing disks. 

0

这几步都做完了之后,ls一下,大概的结构应该是这样的:

vps硬盘不够了怎么办

saveconfig保存退出

配置客户端

客户端的配置相比之下就简单多了,只需要改下配置文件就好了

安装与修改配置

[email protected]:~# fdisk /dev/sda Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.  Command (m for help): p Disk /dev/sda: 20 GiB, 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 Disklabel type: gpt Disk identifier: DCBEF2AD-7269-4B63-BA34-AE2F15A6D9F7 Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 20975615 20971520 10G Linux filesystem  Command (m for help): n  Partition number (3-128, default 3): First sector (20975616-41943006, default 20975616): Last sector, +sectors or +size{K,M,G,T,P} (20975616-41943006, default 41943006): Created a new partition 3 of type 'Linux filesystem' and of size 10 GiB.  Command (m for help): w  The partition table has been altered. Syncing disks. 

1

启动服务

[email protected]:~# fdisk /dev/sda Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.  Command (m for help): p Disk /dev/sda: 20 GiB, 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 Disklabel type: gpt Disk identifier: DCBEF2AD-7269-4B63-BA34-AE2F15A6D9F7 Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 20975615 20971520 10G Linux filesystem  Command (m for help): n  Partition number (3-128, default 3): First sector (20975616-41943006, default 20975616): Last sector, +sectors or +size{K,M,G,T,P} (20975616-41943006, default 41943006): Created a new partition 3 of type 'Linux filesystem' and of size 10 GiB.  Command (m for help): w  The partition table has been altered. Syncing disks. 

2

发现与登录节点

server可以写服务端的域名,或者IP也可以

[email protected]:~# fdisk /dev/sda Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.  Command (m for help): p Disk /dev/sda: 20 GiB, 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 Disklabel type: gpt Disk identifier: DCBEF2AD-7269-4B63-BA34-AE2F15A6D9F7 Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 20975615 20971520 10G Linux filesystem  Command (m for help): n  Partition number (3-128, default 3): First sector (20975616-41943006, default 20975616): Last sector, +sectors or +size{K,M,G,T,P} (20975616-41943006, default 41943006): Created a new partition 3 of type 'Linux filesystem' and of size 10 GiB.  Command (m for help): w  The partition table has been altered. Syncing disks. 

3

此时就应该多出来一个/dev/sdb

分区、格式化与挂载

使用fdisk对sdb进行分区,这里想怎么分都行,我就直接都分一个主分区了

[email protected]:~# fdisk /dev/sda Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.  Command (m for help): p Disk /dev/sda: 20 GiB, 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 Disklabel type: gpt Disk identifier: DCBEF2AD-7269-4B63-BA34-AE2F15A6D9F7 Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 20975615 20971520 10G Linux filesystem  Command (m for help): n  Partition number (3-128, default 3): First sector (20975616-41943006, default 20975616): Last sector, +sectors or +size{K,M,G,T,P} (20975616-41943006, default 41943006): Created a new partition 3 of type 'Linux filesystem' and of size 10 GiB.  Command (m for help): w  The partition table has been altered. Syncing disks. 

4

进行格式化、挂载

[email protected]:~# fdisk /dev/sda Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.  Command (m for help): p Disk /dev/sda: 20 GiB, 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 Disklabel type: gpt Disk identifier: DCBEF2AD-7269-4B63-BA34-AE2F15A6D9F7 Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 20975615 20971520 10G Linux filesystem  Command (m for help): n  Partition number (3-128, default 3): First sector (20975616-41943006, default 20975616): Last sector, +sectors or +size{K,M,G,T,P} (20975616-41943006, default 41943006): Created a new partition 3 of type 'Linux filesystem' and of size 10 GiB.  Command (m for help): w  The partition table has been altered. Syncing disks. 

5

vps硬盘不够了怎么办

重启之后自动挂载

为了确保重启之后自动挂载,我们需要更改fstab

[email protected]:~# fdisk /dev/sda Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.  Command (m for help): p Disk /dev/sda: 20 GiB, 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 Disklabel type: gpt Disk identifier: DCBEF2AD-7269-4B63-BA34-AE2F15A6D9F7 Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 20975615 20971520 10G Linux filesystem  Command (m for help): n  Partition number (3-128, default 3): First sector (20975616-41943006, default 20975616): Last sector, +sectors or +size{K,M,G,T,P} (20975616-41943006, default 41943006): Created a new partition 3 of type 'Linux filesystem' and of size 10 GiB.  Command (m for help): w  The partition table has been altered. Syncing disks. 

6

安全使用iSCSI

由于iSCSI的传输数据的过程并不是加密的,所以如果跨公网使用,给人的感觉总是不好。为了解决这一问题,我们可以在客户端挂个VPN到服务端,可以用SSH隧道,可以用IPSec保护iSCSI,也可以加密sdb(比如用LUKS、VeraCrypt等呗)

咱这里就开个SSH隧道吧!要在配置客户端之前做好哦

修改服务端配置vim /etc/ssh/sshd_config,修改如下配置

[email protected]:~# fdisk /dev/sda Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.  Command (m for help): p Disk /dev/sda: 20 GiB, 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 Disklabel type: gpt Disk identifier: DCBEF2AD-7269-4B63-BA34-AE2F15A6D9F7 Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 20975615 20971520 10G Linux filesystem  Command (m for help): n  Partition number (3-128, default 3): First sector (20975616-41943006, default 20975616): Last sector, +sectors or +size{K,M,G,T,P} (20975616-41943006, default 41943006): Created a new partition 3 of type 'Linux filesystem' and of size 10 GiB.  Command (m for help): w  The partition table has been altered. Syncing disks. 

7

然后重启sshd

[email protected]:~# fdisk /dev/sda Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.  Command (m for help): p Disk /dev/sda: 20 GiB, 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 Disklabel type: gpt Disk identifier: DCBEF2AD-7269-4B63-BA34-AE2F15A6D9F7 Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 20975615 20971520 10G Linux filesystem  Command (m for help): n  Partition number (3-128, default 3): First sector (20975616-41943006, default 20975616): Last sector, +sectors or +size{K,M,G,T,P} (20975616-41943006, default 41943006): Created a new partition 3 of type 'Linux filesystem' and of size 10 GiB.  Command (m for help): w  The partition table has been altered. Syncing disks. 

8

然后输入如下命令,其中[email protected]替换成自己的服务器

[email protected]:~# fdisk /dev/sda Welcome to fdisk (util-linux 2.31.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command.  Command (m for help): p Disk /dev/sda: 20 GiB, 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 Disklabel type: gpt Disk identifier: DCBEF2AD-7269-4B63-BA34-AE2F15A6D9F7 Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 20975615 20971520 10G Linux filesystem  Command (m for help): n  Partition number (3-128, default 3): First sector (20975616-41943006, default 20975616): Last sector, +sectors or +size{K,M,G,T,P} (20975616-41943006, default 41943006): Created a new partition 3 of type 'Linux filesystem' and of size 10 GiB.  Command (m for help): w  The partition table has been altered. Syncing disks. 

9

之后再开一个窗口,discover & login

[email protected]:~# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created. 

0

当然理想方式是用key,然后systemd管这个SSH Tunnel啦!

(′д` )…彡…彡还是用wireguard

iSCSI空间不够了怎么办

还记得我们是使用的Logical Volume创建的吗!此时只需要lvextend -L 10G /dev/idata/iscsi_data就可以把分区调整为10G,然后客户端那边fdisk就能看见

 

其他类似技术

NFS、Samba

同理?

GlusterFS

萌新不懂,萌新瑟瑟发抖

总结

折腾一大圈,不还是得买大盘鸡吗?还不是贫穷限制了我的想象力

 


转载请注明:逗比根据地 » vps硬盘不够了怎么办

喜欢 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(1)个小伙伴在吐槽
  1. 豆豆,很喜欢你的文章,我在作者的位置注明转载自你的网站可以吗?
    Toyo+2019-08-27 01:53 回复