案例——NFS实现web集群后端存储
1、创建NFS-Server服务
[root@nfs-server share]# mkdir /share/web
[root@nfs-server share]# ls
nfs web
[root@nfs-server share]# echo "this is the test page of nfs-web" >/share/web/index.html
[root@nfs-server share]# vim /etc/exports
/share/web 192.168.221.0/24(ro)
[root@nfs-server share]# service nfs restart
Shutting down NFS daemon: [ OK ]
Shutting down NFS mountd: [ OK ]
Shutting down NFS services: [ OK ]
Shutting down RPC idmapd: [ OK ]
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
2、 web1端挂载NFS服务器
[root@web ~]# mount.nfs 192.168.221.129:/share/web /var/www/html/
[root@web ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_min1-lv_root 13G 1.6G 11G 14% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/sr0 4.2G 4.2G 0 100% /mnt/dvd
192.168.221.129:/share/web 13G 1.3G 11G 11% /var/www/html
[root@web ~]# cd /var/www/html/
[root@web html]# ls
index.html
[root@web html]# cat index.html
this is the test page of nfs-web
//挂载访问成功
[root@web ~]# curl 192.168.221.139
this is the test page of nfs-web
//web访问成功
3、 web2端挂载NFS服务器
[root@web2 ~]# mount.nfs 192.168.221.129:/share/web /var/www/html/
[root@web2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_min3-lv_root 13G 2.8G 9.5G 23% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 485M 33M 427M 8% /boot
/dev/sr0 4.2G 4.2G 0 100% /mnt/dvd
192.168.221.129:/share/web 13G 1.3G 11G 11% /var/www/html
[root@web2 ~]# cd /var/www/html/
[root@web2 html]# ls
index.html
[root@web2 html]# cat index.html
this is the test page of nfs-web
//挂载访问成功
[root@web2 html]# curl 192.168.221.134
this is the test page of nfs-web
//web访问成功
总结:
使用nfs服务将web需要访问的页面挂载到各个web中,达到访问不同web服务器,访问的内容相同的目的。