欢迎光临

我们一直在努力
扫描二维码在手机上浏览

阿里云oss挂载到linux服务器做硬盘使用

阿里云对象存储 OSS 挂载到 Linux 系统的云服务器,通过内网极速上传数据到 Bucket ,可以大大节省您上传数据的时间。通常我们采用的方法是将云服务器的数据下载到本地,然后通过本地上传到 OSS,但这种方法要经历原始数据的下载和上传两个步骤,采用君哥在这篇教程的方法,可以大大提高运维的工作效率将阿里云对象存储 OSS 挂载到云服务器使用的工具是 ossfs 。 ossfs能让您在Linux系统中,将对象存储OSS的存储空间(Bucket)挂载到云服务器的文件系统中,您能够像操作本地文件一样操作OSS的对象(Object),实现数据的共享。
个人理解挂载oss做硬盘的好处:
不用担心服务商跑路,如果服务器用不了了或者服务商跑路了你的网站数据依然保存在阿里云oss存储中,这个时候你只要重新找台服务器重新挂载就可以恢复你的数据,价格便宜,对一些流量较少的用户来说基本上就是免费的,对一些流量大的用户一个月也用不到几个钱,具体多少自己看阿里云oss流量费用咯,我的话一个月就3-4块钱

使用下面的命令下载 ossfs 安装包

wget http://gosspublic.alicdn.com/ossfs/ossfs_1.80.6_centos7.0_x86_64.rpm
注意:ossfs不同的版本下载地址不同,下载时请根据自己的操作系统,选择合适的版本,用正确的安装包名称替换上面命令中的 ossfs_1.80.6_centos7.0_x86_64.rpm,君哥的这篇教程以 CentOS 7.0 (x64) 版本为例,所以使用的安装包名称 ossfs_1.80.6_centos7.0_x86_64.rpm 进行下载。
Linux发行版安装包名称
Ubuntu 18.04 (x64)ossfs_1.80.6_ubuntu18.04_amd64.deb
Ubuntu 16.04 (x64)ossfs_1.80.6_ubuntu16.04_amd64.deb
Ubuntu 14.04 (x64)ossfs_1.80.6_ubuntu14.04_amd64.deb
CentOS 7.0 (x64)ossfs_1.80.6_centos7.0_x86_64.rpm
CentOS 6.5 (x64)ossfs_1.80.6_centos6.5_x86_64.rpm

安装ossfs ,不同 liunx 系统安装方法不同,请童鞋们根据自己的操作系统选择命令进行安装。 

  • Ubuntu系统的安装命令:
sudo apt-get update
sudo apt-get install gdebi-core
sudo gdebi ossfs_1.80.6_centos7.0_x86_64.rpm
  • CentOS6.5及以上系统版本的安装命令:
sudo yum localinstall ossfs_1.80.6_centos7.0_x86_64.rpm

注意:说明 对于使用yum安装rpm包的客户端,如果客户端节点网络环境特殊,无法直接用yum下载依赖包。可以在网络正常的、相同版本操作系统的节点上,使用yum下载依赖包并拷贝到网络特殊的节点。例如,ossfs需要依赖fuse 2.8.4以上版本,可使用如下命令,下载yum源中最新的fuse到本地:(如果需要下载其他依赖包,则将fuse换成对应包的名称。)

sudo yum install --downloadonly --downloaddir=./ fuse

CentOS5系统版本的安装命令:

sudo yum localinstall ossfs_1.80.6_centos7.0_x86_64.rpm --nogpgcheck

使用的是centos7.0系统的阿里云ECS,执行相应安装命令时,结果如下图所示:(命令执行过程中,出现 Is this ok [y/d/N] 时输入 y ,然后回车继续,等待安装完成,出现complete)。

配置账号访问信息

将 Bucket 名称以及具有此Bucket访问权限的 AccessKeyId、AccessKeySecret 信息存放在 /etc/passwd-ossfs 文件中。注意这个文件的权限必须正确设置,建议设为640。(下面的两行是两条命令哦!!!)

echo my-bucket:my-access-key-id:my-access-key-secret > /etc/passwd-ossfs chmod 640 /etc/passwd-ossfs

注意命令中的替换项一定要进行替换:

my-bucket 替换为您在阿里云OSS创建的 Bucket 名称

  • my-access-key-id  替换为您的AccessKey
  • my-access-key-secret 替换为您的AccessKeySecret

注意AccessKey和AccessKeySecret的获取方法如下:

① 登录阿里云官网,进入控制台,鼠标移动到右上角头像处,点击【 AccessKeys 】。

② 在弹出的对话框中选择【继续使用AccessKey】,如果您之前创建过accesskeys,则直接在页面中进行复制,如果没有创建过,则点击右侧【创建AccessKey】,在弹出的对话框中获取手机验证码并且输入,会提示新建AccessKey成功。

将Bucket挂载到指定目录 

mkdir /directory
ossfs my-bucket my-mount-point -ourl=my-oss-endpoint

注意命令中的替换项一定要进行替换

  • directory 新建您要挂载 OSS 的目录名称,君哥这里给根目录新建了一个名称为 OSS 的目录,用于挂载Bucket。
  • my-bucket 您的 Bucket 名称,君哥的Bucket名称是:bf-2020 。
  • my-mount-point 替换为您要挂载的目录路径,君哥这里的路径是 /oss 。
  • my-oss-endpoint 替换为您的 EndPoint(地域节点),在地域节点前面加上 http:// 。
    • 如果的云服务器和对象存储 OSS 不在同一个区域,则选择外网访问的EndPoint(地域节点)。
    • 如果的云服务器和对象存储 OSS 是同一个区域,则选择内网访问的EndPoint(地域节点)。
    • EndPoint(地域节点)获取方法如下图所示:

把数据复制到对象存储 OSS 。 

登录宝塔面板,在首页能看到多了一个 /oss 的文件夹,进行数据复制。

如果没有安装宝塔面板,则通过下面的命令复制指定文件夹内的所有内容到 OSS 。

cp [options] source... directory

如果您不希望继续挂载此Bucket,您可以执行下面的命令将其卸载。 

fusermount -u /directory

注意命令中的 /directory 替换为您挂载OSS的目录路径。君哥如果不想挂载了,则把 /directory 替换为 /OSS 执行命令进行卸载。

 

 

赞 0 打赏
分享到: 更多 (0)
分享海报
版权声明
未经允许不得转载:
文章地址:ZQ博客 » 阿里云oss挂载到linux服务器做硬盘使用

评论 27

  • *
  • *
  • Q Q(选填)
  1. #-49

    666

    爸爸11个月前 (06-14)Linux | Chrome 77.0.3865.120
  2. #-48

    Hi just wanted to give you a quick heads up and let you know a few
    of the images aren’t loading properly. I’m not
    sure why but I think its a linking issue. I’ve tried it in two
    different internet browsers and both show the same results.

    0mniartist asmr

    asmr https://0mniartist.tumblr.com4周前 (04-10)Windows NT | Chrome 63.0.3239.26
  3. #-47

    Hey there, You’ve done a great job. I will certainly digg it and personally suggest to my friends.
    I am sure they will be benefited from this web site.
    0mniartist asmr

    asmr https://0mniartist.tumblr.com4周前 (04-10)Windows NT | Chrome 63.0.3239.132
  4. #-46

    Very good information. Lucky me I ran across your website
    by accident (stumbleupon). I’ve book marked it for
    later! asmr 0mniartist

    asmr https://0mniartist.tumblr.com4周前 (04-10)Windows NT | Chrome 48.0.2564.116
  5. #-45

    Hello! I just wanted to ask if you ever have any trouble with hackers?
    My last blog (wordpress) was hacked and I ended
    up losing many months of hard work due to no backup.

    Do you have any solutions to protect against hackers?
    0mniartist asmr

    asmr https://0mniartist.tumblr.com4周前 (04-11)Windows NT | Chrome 64.0.3282.39
  6. #-44

    great issues altogether, you just received a logo new reader.
    What may you recommend in regards to your put up that you simply made some days in the past?

    Any positive? asmr 0mniartist

    asmr https://0mniartist.tumblr.com4周前 (04-11)Windows NT | Chrome 64.0.3282.186
  7. #-43

    First of all I want to say wonderful blog! I had a quick question in which I’d like to ask
    if you do not mind. I was interested to find out how
    you center yourself and clear your mind prior to writing. I’ve had a
    hard time clearing my thoughts in getting my ideas out.

    I truly do enjoy writing however it just seems like the first 10 to 15 minutes are
    usually lost just trying to figure out how to begin. Any recommendations or
    tips? Thanks! 0mniartist asmr

    asmr https://0mniartist.tumblr.com4周前 (04-11)Windows NT | Chrome 56.0.2924.92
  8. #-42

    I loved as much as you will receive carried out right here.
    The sketch is attractive, your authored material
    stylish. nonetheless, you command get bought
    an nervousness over that you wish be delivering the following.
    unwell unquestionably come further formerly again as exactly the same nearly a lot
    often inside case you shield this hike. 0mniartist asmr

    0mniartist4周前 (04-12)Windows NT | Chrome 63.0.3239.26
  9. #-41

    I know this if off topic but I’m looking into starting my own blog
    and was curious what all is needed to get set up?
    I’m assuming having a blog like yours would cost a pretty penny?

    I’m not very internet savvy so I’m not 100% sure. Any recommendations or advice would
    be greatly appreciated. Appreciate it asmr 0mniartist

    http://tinyurl.com/3周前 (04-14)Windows XP | Maxthon 4.9.4.3000
  10. #-40

    Its like you read my mind! You seem to know so much about this,
    like you wrote the book in it or something. I think that you
    could do with a few pics to drive the message home a bit, but instead
    of that, this is excellent blog. A fantastic read. I’ll definitely be back.

    asmr 0mniartist

    http://j.mp/3a8wFhV3周前 (04-14)Windows NT | Chrome 65.0.3325.181
  11. #-39

    If you would like to take a great deal from
    this paragraph then you have to apply such techniques to your won webpage.
    0mniartist asmr

    bitly.com3周前 (04-14)Windows NT | Chrome 65.0.3325.181
  12. #-38

    Hi Dear, are you truly visiting this web page on a regular basis,
    if so then you will absolutely get pleasant knowledge.
    0mniartist asmr

    j.mp3周前 (04-15)Windows XP | 搜狗浏览器 2.X
  13. #-37

    Hi! Do you know if they make any plugins to help with Search Engine Optimization? I’m trying to get my blog
    to rank for some targeted keywords but I’m not seeing very good
    results. If you know of any please share. Many thanks!
    0mniartist asmr

    j.mp3周前 (04-16)Windows NT | Firefox 38.0
  14. #-36

    I know this website provides quality based articles or reviews and additional stuff, is
    there any other web page which offers such information in quality?
    asmr 0mniartist

    http://bitly.com/3acu8mK3周前 (04-16)Windows NT | Chrome 56.0.2924.92
  15. #-35

    Very nice post. I absolutely love this site. Keep it up!

    asmr 0mniartist

    tinyurl.com3周前 (04-16)Windows NT | Chrome 67.0.3381.1
  16. #-34

    Howdy, i read your blog from time to time and i own a similar one and i was just curious if you
    get a lot of spam responses? If so how do you prevent it, any plugin or anything you can suggest?
    I get so much lately it’s driving me mad so any help is very much appreciated.

    gamefly when1周前 (04-28)Windows NT | Chrome 65.0.3325.181
  17. #-33

    I’ve read a few just right stuff here. Definitely worth bookmarking for revisiting.
    I wonder how much attempt you set to create this sort of fantastic informative web
    site.

    why gamefly1周前 (04-28)Windows NT | 未知浏览器
  18. #-32

    Hello are using WordPress for your blog platform?

    I’m new to the blog world but I’m trying to get started and create my own. Do you need any html coding expertise to make your own blog?
    Any help would be greatly appreciated!

    when asmr1周前 (04-29)Windows Vista | Chrome 65.0.3325.181
  19. #-31

    I got this web site from my pal who informed me on the topic of this
    website and at the moment this time I am browsing this site and reading very informative articles or reviews
    here.

    asmr it1周前 (04-29)Windows NT | Chrome 62.0.3202.9
  20. #-30

    Hey I know this is off topic but I was wondering if
    you knew of any widgets I could add to my blog that automatically tweet my newest twitter updates.
    I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some
    experience with something like this. Please let me know if you run into anything.

    I truly enjoy reading your blog and I look forward to your new updates.

    asmr are1周前 (04-29)Windows Vista | Firefox 50.0
  21. #-29

    Does your website have a contact page? I’m having trouble locating it
    but, I’d like to send you an e-mail. I’ve got some ideas for your blog you might be interested in hearing.
    Either way, great blog and I look forward to seeing it improve over time.

    when asmr1周前 (04-29)Windows NT | Chrome 67.0.3396.87
  22. #-28

    What’s up, yup this paragraph is actually nice
    and I have learned lot of things from it on the topic of blogging.
    thanks.

    for asmr1周前 (04-29)Windows NT | Chrome 65.0.3325.181
  23. #-27

    It’s really a great and helpful piece of info. I’m satisfied that you simply shared this useful info with us.
    Please stay us informed like this. Thanks for sharing.

    asmr on1周前 (04-30)Windows XP | Firefox 52.0
  24. #-26

    Write more, thats all I have to say. Literally, it seems as though you relied on the video
    to make your point. You clearly know what youre talking
    about, why waste your intelligence on just posting videos to your weblog when you could
    be giving us something informative to read?

    of gamefly3天前Windows NT | Chrome 63.0.3239.26
  25. #-25

    Hi to all, the contents existing at this web page are actually amazing for people knowledge, well, keep up the good work fellows.

    my gamefly3天前Windows NT | Chrome 67.0.3396.18
  26. #-24

    Great goods from you, man. I have understand your stuff previous
    to and you are just extremely excellent. I actually like what you have acquired here, certainly like what you’re
    stating and the way in which you say it. You
    make it entertaining and you still care for to keep it
    wise. I can’t wait to read much more from you. This is really
    a great site.

    asmr but3天前Windows 7 | Firefox 59.0
  27. #-23

    Hey! I know this is somewhat off-topic however I had to ask.
    Does operating a well-established website such as yours take a lot
    of work? I’m completely new to operating a blog but I do write in my journal
    on a daily basis. I’d like to start a blog so I can share my
    experience and thoughts online. Please let me know if you have
    any recommendations or tips for new aspiring bloggers.
    Thankyou!

    and asmr2天前Windows NT | Chrome 66.0.3359.170
图片正在生成中,请稍后...

周五

05/07

阿里云oss挂载到linux服务器做硬盘使用

阿里云对象存储 OSS 挂载到 Linux 系统的云服务器,通过内网极速上传数据到 Bucket ,可以大大节省您上传数据的时间。通常我们采用的方法是将云服务器的数据下载到本地,然后通过本地上传到 OSS,但这种方法要经历原始数据的下载和上传两个步骤,采用君哥在这篇教程的方法,可以大大提高运维的工作效率将阿里云对象存储 OSS 挂载到云服务器使用的工具是 ossfs 。 ossfs能让您在Linu

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

登录

记住我

注册