现在的服务器很便宜。但是硬盘却很小,搞到大家也不敢轻易让用户上传文件。因为根本不够用。再买硬盘的话,也不便宜。OSS就相对来说要便宜很多。去年阿里云还搞过活动99元1T 三年。
用OSS插件可以实现把附件存放到OSS,但是还存在一个小问题,就是要单独的买流量。而不能使用服务器的自身流量。
现在跟大家分享一下,使用阿里云提供的 ossfs 工具,可以把OSS映射到服务器里边,当硬盘来使用。
登录到linux服务器,下载OSSFS工具
wget http://gosspublic.alicdn.com/ossfs/ossfs_1.80.6_centos7.0_x86_64.rpm
安装
yum localinstall ossfs_1.80.6_centos7.0_x86_64.rpm
写入配置文件
echo x1-upload:ID:KEY > /etc/passwd-ossfs
注意x1-upload换成你的OSS新建的bucket目录名 ID是 KEY都分别换成你的 accessKeyID accessKeySecret
chmod 640 /etc/passwd-ossfs
挂载
ossfs x1-upload /www/wwwroot/x1.php168.com/public/uploads -ourl=http://oss-cn-beijing-internal.aliyuncs.com -o allow_other
注意x1-upload换成你的OSS新建的bucket目录名,/www/wwwroot/x1.php168.com/public/uploads换成你的网址相应的目录,http://oss-cn-beijing-internal.aliyuncs.com 换成你的相应地区的内网域名,这样才不占用流量
这样就可以加载进来了。加载前,把之前uploads目录的内容全移走
为了避免重启服务器也生效的话,还需要修改文件
在/etc/fstab中加入下面的命令
ossfs#x1-upload /www/wwwroot/x1.php168.com/public/uploads fuse _netdev,url=http://oss-cn-beijing-internal.aliyuncs.com,allow_other 0 0
注意x1-upload换成你的OSS目录名,/www/wwwroot/x1.php168.com/public/uploads换成你的网址目录,http://oss-cn-beijing-internal.aliyuncs.com换成你的OSS内网域名
还要继续创建一个新文件
在/etc/init.d/目录下建立文件ossfs
加入如下内容
ossfs x1-upload /www/wwwroot/x1.php168.com/public/uploads -ourl=http://oss-cn-beijing-internal.aliyuncs.com -o nonempty allow_other
注意x1-upload换成你的OSS目录名,/www/wwwroot/x1.php168.com/public/uploads换成你的网址目录,http://oss-cn-beijing-internal.aliyuncs.com换成你的OSS内网域名
再运行
chmod a+x /etc/init.d/ossfs
chkconfig ossfs on
这样就可以实现开机自动加载了。

目前评论:0