#留着查看路径的,可忽略
[[email protected] uploads]# cd /application/nginx/html/blog/wp-content
第一步:写一篇博客后(插入图片)查看文件位置
[[email protected] ~]# cd /application/nginx/html/blog/
[[email protected] blog]# tree wp-content/uploads/
wp-content/uploads/
└── 2019
└── 09
├── \345\274\240\345\244\247\344\273\231-100x100.jpg
├── \345\274\240\345\244\247\344\273\231-150x150.jpg
├── \345\274\240\345\244\247\344\273\231-300x298.jpg
├── \345\274\240\345\244\247\344\273\231.jpg
├── \345\274\240\347\242\247\346\231\250-100x100.png
├── \345\274\240\347\242\247\346\231\250-147x150.png
└── \345\274\240\347\242\247\346\231\250.png
2 directories, 7 files
第二步:移动文件至临时目录
[[email protected] uploads]# mv 2019 /tmp/
第三步:将blog的资源迁移到nfs(即第一步的信息放进nfs服务器里)
资源目录为:wp-content/uploads/
第四步:建立uid相同的用户(两台服务器的uid相同)
[[email protected] blog]# id www
uid=501(www) gid=501(www) groups=501(www)
[[email protected]01 ~]# useradd -u 501 www
[[email protected] ~]# id www
uid=501(www) gid=501(www) groups=501(www)
修改变量
[[email protected] ~]# vim /etc/exports
/data 172.16.1.0/24(rw,sync,no_all_squash,anonuid=501,anongid=501)
重启
/etc/init.d/nfs reload
第五步:
显示输出目录列表
showmount -e
[[email protected] blog]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data 172.16.1.0/24
同步操作31主机创建07需挂载的目录,并授权
[[email protected] ~]# mkdir /data/nfs-blog
[[email protected] ~]# chown -R www.www /data
第六步:挂载前查看文件,备份
[[email protected] blog]# cd wp-content/uploads/
[[email protected] uploads]# ll
total 4
drwxr-xr-x 3 www www 4096 Sep 11 21:34 2019 (这里2019为创建的文件夹名称,可以这么理解)
[[email protected] uploads]# mv 2019 /tmp/
[[email protected] uploads]# ll
total 0
[[email protected] uploads]# cd ../
第七步:挂载到31的目录下
[[email protected] wp-content]# mount -t nfs 172.16.1.31:/data/nfs-blog /appliication/nginx/html/blog/wp-content/uploads/
df -h 查看信息
[[email protected] wp-content]# which mount
/bin/mount
第八步:挂载目录放入开机自启动
[[email protected] wp-content]# vi /etc/rc.local
mount -t nfs 172.16.1.31:/data/nfs-blog /application/nginx/html/blog/wp-content/uploads/
查看资源目录内容:无信息
[[email protected] wp-content]# ls /application/nginx/html/blog/wp-content/uploads/
博客页面照片不能显示
第九步:把文件复制到当前目录后刷新博客,可以重新看见图片
[[email protected] uploads]# cp -a /tmp/2019/ ./
查看图片位置
[[email protected] ~]# ls /data/nfs-blog/2019/
09
[[email protected] ~]# ls /data/nfs-blog/2019/09/
张大仙-100x100.jpg 张大仙.jpg 张碧晨.png
张大仙-150x150.jpg 张碧晨-100x100.png
张大仙-300x298.jpg 张碧晨-147x150.png
原文地址:https://blog.51cto.com/14078730/2437595