脚本宝典收集整理的这篇文章主要介绍了NFS共享存储,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
主机名 | WanIP | LanIP | 角色 |
---|---|---|---|
web01 | 10.0.0.7 | 172.16.1.7 | 网站服务(nfs客户端) |
web02 | 10.0.0.8 | 172.16.1.8 | 网站服务(nfs客户端) |
nfs | 10.0.0.31 | 172.16.1.31 | 共享存储(nfs服务端) |
集群没有共享存储
集群有共享存储
1.用户进程访问NFS客户端,使用不同的函数对数据进行处理
2.NFS客户端通过TCP/IP的方式传递给NFS服务端。
3.NFS服务端接收到请求后,会先调用portmap进程进行端口映射。
4.nfsd进程用于判断NFS客户端是否拥有权限连接NFS服务端。
5.Rpc.mount进程判断客户端是否有对应的权限进行验证。
6.idmap进程实现用户映射和压缩
7.最后NFS服务端会将对应请求的函数转换为本地能识别的命令,传递至内核,由内核驱动硬件。
nfs共享参数 | 参数作用 |
---|---|
rw* | 读写权限 |
ro | 只读权限 |
root_squash | 当NFS客户端以root管理员访问时,映射为NFS服务器的匿名用户(不常用) |
no_root_squash | 当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员(不常用) |
all_squash | 无论NFS客户端使用什么账户访问,均映射为NFS服务器的匿名用户(常用) |
no_all_squash | 无论NFS客户端使用什么账户访问,都不进行压缩 |
sync* | 同时将数据写入到内存与硬盘中,保证不丢失数据 |
async | 优先将数据保存到内存,然后再写入硬盘;这样效率更高,但可能会丢失数据 |
anonuid* | 配置all_squash使用,指定NFS的用户UID,必须存在系统 |
anongid* | 配置all_squash使用,指定NFS的用户UID,必须存在系统 |
## C5 C6安装nfs服务
[root@nfs ~]# yum install -y nfs rpcbind
## C7安装nfs服务
[root@nfs ~]# yum install -y nfs-utils
## 配置NFS服务端
NFS配置文件的位置
[root@nfs ~]# ll /etc/exports
-rw-r--r--. 1 root root 0 Jun 7 2013 /etc/exports
[root@nfs ~]# vim /etc/exports
# 共享目录 允许访问NFS服务端的网段 (可读可写,同步,任何用户都映射成nfs的匿名用户)
/data 172.16.1.0/24(rw,sync,all_squash)
## 创建共享目录
[root@nfs ~]# mkdir /data
## 修改共享目录的属主和属组为nfs的匿名用户
[root@nfs ~]# chown nfsnobody.nfsnobody /data
## 启动服务
[root@nfs ~]# systemctl start nfs
## 加入开机自启
[root@nfs ~]# systemctl enable nfs
## 检查进程
[root@nfs ~]# ps -ef|grep nfs
## 检测配置文件是否生效
[root@nfs ~]# cat /var/lib/nfs/etab
/data
172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check
,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,secure,root_squash,all_squash)
# 1.安装nfs
[root@web01 ~]# yum install -y nfs-utils
[root@web02 ~]# yum install -y nfs-utils
# 2.查看哪些目录可以挂载
[root@web01 ~]# showmount -e 172.16.1.31
[root@web02 ~]# showmount -e 172.16.1.31
[root@web01 ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data 172.16.1.0/24
## 3.挂载共享目录
[root@web01 ~]# mount -t nfs 172.16.1.31:/data /opt
[root@web02 ~]# mount -t nfs 172.16.1.31:/data /opt
主机名 | WanIP | LanIP | 角色 | 部署应用 |
---|---|---|---|---|
web01 | 10.0.0.7 | 172.16.1.7 | 网站服务(nfs客户端) | httpd、php、nfs |
web02 | 10.0.0.8 | 172.16.1.8 | 网站服务(nfs客户端) | httpd、php、nfs |
nfs | 10.0.0.31 | 172.16.1.31 | 共享存储(nfs服务端) | nfs |
# 1.安装apache和php
[root@web01 ~]# yum install -y httpd php
[root@web02 ~]# yum install -y httpd php
# 2.下载代码(到站点目录下)
[root@web01 html]# ll
-rw-r--r-- 1 root root 26927 May 18 09:33 kaoshi.zip
[root@web01 html]# pwd
/var/www/html
# 3.解压代码
[root@web01 html]# unzip kaoshi_modify.zip
[root@web02 html]# unzip kaoshi_modify.zip
# 4.启动apache服务
[root@web01 html]# systemctl start httpd
[root@web02 html]# systemctl start httpd
# 5.检查进程
[root@web01 html]# ps -ef|grep 'httpd'
[root@web02 html]# ps -ef|grep 'httpd'
[root@web02 html]# ps -ef|grep [h]ttpd
root 7633 1 0 11:58 ? 00:00:04 /usr/sbin/httpd -DFOREGROUND
apache 7634 7633 0 11:58 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 7635 7633 0 11:58 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 7636 7633 0 11:58 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 7637 7633 0 11:58 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 7638 7633 0 11:58 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 7665 7633 0 12:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 7666 7633 0 12:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 7667 7633 0 12:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
# 6.端口检查
[root@web01 html]# netstat -lntup|grep httpd
tcp6 0 0 :::80 :::* LISTEN 7633/httpd
[root@web02 html]# netstat -lntup|grep httpd
tcp6 0 0 :::80 :::* LISTEN 7633/httpd
# 7.打开浏览器访问
http://10.0.0.7/
http://10.0.0.8/
# 8.授权站点目录
chown apache.apache /var/www/html
# 查看结果
[root@web01 html]# ll user_data
total 84
-rw-r--r-- 1 apache apache 83411 May 18 21:25 12_kobe.jpeg
[root@web02 html]# ll user_data
total 64
-rw-r--r-- 1 apache apache 63208 May 18 12:10 11_ok.jpg
# 创建用户和用户组 www用户uid是666 gid也是666
[root@nfs ~]# groupadd www -g 666
[root@nfs ~]# useradd www -u 666
# C5 C6安装nfs服务
[root@nfs ~]# yum install -y nfs rpcbind
# C7安装nfs服务
[root@nfs ~]# yum install -y nfs-utils
# 配置NFS服务端
NFS配置文件的位置
[root@nfs ~]# ll /etc/exports
-rw-r--r--. 1 root root 0 Jun 7 2013 /etc/exports
[root@nfs ~]# vim /etc/exports
# 共享目录 允许访问NFS服务端的网段 (可读可写,同步,指定用户映射成nfs的匿名用户)
/data 172.16.1.0/24(rw,sync,anonuid=666,anongid=666,all_squash)
# 创建共享目录
[root@nfs ~]# mkdir /data
# 修改共享目录的属主和属组为nfs的匿名用户
[root@nfs ~]# chown www.www /data
# 启动服务
[root@nfs ~]# systemctl start nfs
# 加入开机自启
[root@nfs ~]# systemctl enable nfs
# 检查进程
[root@nfs ~]# ps -ef|grep nfs
## 检测配置文件是否生效
[root@nfs ~]# cat /var/lib/nfs/etab
/data 172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=666,anongid=666,sec=sys,rw,secure,root_squash,all_squash)
# 1.创建用户和用户组 www用户uid是666 gid也是666
[root@web01 html]# groupadd www -g 666
[root@web01 html]# useradd www -u 666 -g 666
[root@web02 html]# groupadd www -g 666
[root@web02 html]# useradd www -u 666 -g 666
# 2.修改站点目录的属主和属组为nfs的匿名用户
[root@web01 html]# chown www.www /var/www/html/
[root@web01 html]# ll /var/www/html -d
drwxr-xr-x 3 www www 119 May 18 21:25 /var/www/html
[root@web02 html]# chown www.www /var/www/html/
# 3.修改apache服务的配置文件里的匿名用户
[root@web01 html]# vim /etc/httpd/conf/httpd.conf
User www
Group www
[root@web02 html]# vim /etc/httpd/conf/httpd.conf
User www
Group www
# 4.重启apache服务
[root@web01 html]# systemctl restart httpd
[root@web02 html]# systemctl restart httpd
# 5.检查进程
[root@web01 html]# ps -ef|grep 'httpd'
[root@web02 html]# ps -ef|grep 'httpd'
[root@web02 html]# ps -ef|grep [h]ttpd
root 7633 1 0 11:58 ? 00:00:04 /usr/sbin/httpd -DFOREGROUND
apache 7634 7633 0 11:58 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 7635 7633 0 11:58 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 7636 7633 0 11:58 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 7637 7633 0 11:58 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 7638 7633 0 11:58 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 7665 7633 0 12:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 7666 7633 0 12:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 7667 7633 0 12:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
# 6.端口检查
[root@web01 html]# netstat -lntup|grep httpd
tcp6 0 0 :::80 :::* LISTEN 7633/httpd
[root@web02 html]# netstat -lntup|grep httpd
tcp6 0 0 :::80 :::* LISTEN 7633/httpd
# 7.打开浏览器访问
http://10.0.0.7/
http://10.0.0.8/
# 8.创建用户数据上传目录
[root@web01 html]# mkdir /var/www/html/user_data/
[root@web02 html]# mkdir /var/www/html/user_data/
# 9.客户端挂载nfs服务端
[root@web01 html]# mount -t nfs 172.16.1.31:/data /var/www/html/user_data/
[root@web02 html]# mount -t nfs 172.16.1.31:/data /var/www/html/user_data/
# 浏览器访问,并上传查看是否同步共享
[root@web01 html]# ll user_data/
total 148
-rw-r--r-- 1 www www 63208 May 18 22:20 11_ok.jpg
-rw-r--r-- 1 www www 83411 May 18 22:09 12_kobe.jpeg
[root@web01 html]# ll user_data/
total 148
-rw-r--r-- 1 www www 63208 May 18 22:20 11_ok.jpg
-rw-r--r-- 1 www www 83411 May 18 22:09 12_kobe.jpeg
以上是脚本宝典为你收集整理的NFS共享存储全部内容,希望文章能够帮你解决NFS共享存储所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。