需要共享的是PHP的服务器;共享给指定的两台httpd主机;所以可以直接指定IP地址;这里单独建立一个分区用于NFS;挂载至web配置文件中指定的DocumentRoot目录;当然也可以先挂载在配置;这里是由于之前已配置好服务;所以直接挂载文件为指定目录:
httpd配置中的路径:
[WEB85]#cat /etc/httpd24/extra/httpd-vhosts.conf
#
<VirtualHost *:80>
ServerAdmin admin@linuxidc.com
DocumentRoot "/usr/local/apache/www/linuxidc" #本地路径
ServerName
ServerAlias linuxidc.com
ErrorLog "/usr/local/apache/logs/linuxidc.error_log"
CustomLog "/usr/local/apache/logs/linuxidc.access_log" combined
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.251.87:9000/var/www/linuxidc/$1
#上面这个路径就是PHP服务器的存放路径;也就是需要共享的NFS路径:/var/www
<Directory "/usr/local/apache/www/linuxidc">
DirectoryIndex index.html index.php
Options none
Require all granted
</Directory>
</VirtualHost>
[PHP87]#mount
/dev/mapper/vg0-root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/vg0-usr on /usr type ext4 (rw)
/dev/mapper/vg0-var on /var type ext4 (rw)
/dev/sda3 on /var/www type ext4 (rw,acl) #这个目录
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
#****注意:挂载时在fstab中写入需要acl属性****
#配置NFS主要是修改/etc/exports文件
[PHP87]#vim /etc/exports
#文件格式很简单:
文件系统 客户端1(文件系统导出属性1...) 客户端2()
/var/www 172.16.251.85(rw) 172.16.251.86(rw)
#rw:读写
#async:异步
#sync:同步
#root_squash:压缩root用户;基于imapd;将root通过网络访问时转为#nfsnobody用户
#no_root_squash:不压缩root权限
#all_squash:压缩所有用户
#anonuid=[num]:指定匿名用户映射为的UID和GID
#anongid=[num]
修改完成后可以查看属性
[PHP87]#exportfs -v
/var/www 172.16.251.85(rw,wdelay,root_squash,no_subtree_check)
/var/www 172.16.251.86(rw,wdelay,root_squash,no_subtree_check)
[PHP87]#其中有很多默认属性的
现在可以去httpd服务器查看该机器的共享NFS
[WEB85]#showmount -e 172.16.251.87
Export list for 172.16.251.87:
/var/www 172.16.251.86,172.16.251.85
[WEB85]#
[WEB86]#showmount -e 172.16.251.87
Export list for 172.16.251.87:
/var/www 172.16.251.86,172.16.251.85
[WEB86]#
3、挂载配置读写权限
mount -t type device dir
-t:指定文件系统类型
[WEB85]#mount -t nfs 172.16.251.87:/var/www/ /usr/local/apache/www/
[WEB85]#mount
/dev/mapper/vg0-root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/vg0-usr on /usr type ext4 (rw)
/dev/mapper/vg0-var on /var type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
172.16.251.87:/var/www/ on /usr/local/apache/www type nfs (rw,vers=4,addr=172.16.251.87,clientaddr=172.16.251.85)
#查看以挂载;第二台httpd也需要同样挂载;挂载完成后记得写入到/etc/fstab中
[WEB85]#vim /etc/fstab
增加下面这行内容
172.16.251.87:/var/www /usr/local/apache/www nfs defaults,_netdev 0 0
挂载完成后;是无法写入数据的
[WEB85]#cd /usr/local/apache/www/
[WEB85]#mkdir aa
mkdir: cannot create directory `aa': Permission denied
[WEB85]#
需要到php服务器配置NFS的权限;为了安全;新建立一个账户;httpd服务器也建立同样的账户
[PHP87]#useradd -u 600 web
[PHP87]#id web
uid=600(web) gid=600(web) groups=600(web)
[PHP87]#setfacl -R -m u:600:rwx /var/www/ -R是因为其下面有其他的目录
[PHP87]#getfacl /var/www/
getfacl: Removing leading '/' from absolute path names
# file: var/www/
# owner: root
# group: root
user::rwx
user:web:rwx
group::r-x
mask::rwx
other::r-x
#httpd两台服务器建立相应的账户
[WEB85]#useradd -u 600 web
[WEB85]#su - web
[web@localhost ~]$ cd /usr/local/apache/www/
[web@localhost www]$ mkdir aaa
[web@localhost www]$ ll
total 52
drwxrwxr-x 2 nobody nobody 4096 Mar 26 16:09 aaa
#测试创建成功