NAS之NFS
为集群中的 Web Server 配置后端存储
NFS:Network File System 网络文件系统,Unix系统之间共享文件的一种协议
NFS 的客户端主要为Linux
支持多节点同时挂载以及并发写入
========================================================
nas 192.168.122.59
web1 192.168.122.85
web2 192.168.122.166
web3 192.168.122.111
nas web1 web2 web3
# sed -ri ‘/^SELINUX=/cSELINUX=disabled‘ /etc/selinux/config
# setenforce 0
centos6
# iptables -F
# service iptables save
centos7
# systemctl stop firewalld
# systemctl disable firewalld
# vim /etc/hosts [可选]
192.168.122.59 nas
192.168.122.85 web1
192.168.122.166 web2
192.168.122.111 web3
一、nas(存储端)
[[email protected] ~]# yum -y install nfs-utils
[[email protected] ~]# mkdir /webdata //存储网站代码
[[email protected] ~]# echo "nfs test..." > /webdata/index.html
[[email protected] ~]# vim /etc/exports
/webdata 192.168.122.0/24(rw,sync,no_root_squash) //不压制root(当client端使用root挂载时,也有root权限)
[[email protected] ~]# systemctl start nfs-server
[[email protected] ~]# systemctl enable nfs-server
[[email protected] ~]# exportfs -v
/webdata 192.168.122.0/24(rw,wdelay,no_root_squash,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)
二、web1 web2 web3 客户端
以web1为例:
[[email protected] ~]# yum -y install nfs-utils httpd
[[email protected] ~]# systemctl start httpd
[[email protected] ~]# systemctl enable httpd
1. 查看存储端共享 [可选]
[[email protected] ~]# showmount -e nas
Export list for nas:
/webdata 192.168.122.0/24
2. 手动挂载 [可选]
[[email protected] ~]# mount -t nfs nas:/webdata /var/www/html/
[[email protected] ~]# umount /var/www/html/
3. 自动挂载到网站主目录
[[email protected] ~]# vim /etc/fstab
nas:/webdata /var/www/html nfs defaults 0 0
[[email protected] ~]# mount -a
4. 查看挂载
[[email protected] ~]# df
nas:/webdata 7923136 692416 6821568 10% /var/www/html
[[email protected] ~]# ls /var/www/html/
index.html
5. web2 web3同上
三、测试网站访问
# firefox 192.168.122.85
# firefox 192.168.122.111
# firefox 192.168.122.166
NAS之CIFS
CIFS:Common Internet File System Windows和Unix系统之间共享文件的一种协议
CIFS:客户端主要是Windows
支持多节点同时挂载以及并发写入
========================================================
一、Samba服务器 (存储端)
1. 安装软件
[[email protected] ~]# yum -y install samba
2. 建立共享所需要目录
[[email protected] ~]# mkdir /data
[[email protected] ~]# chmod 777 /data
[[email protected] ~]# cp -rf /etc/hosts /data/
3. 建立访问用户
[[email protected] ~]# useradd alice
[[email protected] ~]# useradd jack
[[email protected] ~]# smbpasswd -a alice
[[email protected] ~]# smbpasswd -a jack
4. 通过Samba共享
[[email protected] ~]# vim /etc/samba/smb.conf
[data]
path = /data
;valid users = alice jack
;hosts allow = 192.168.122.
;write list = jack
writable = yes
5. 启动Samba服务
[[email protected] ~]# systemctl start nmb smb
[[email protected] ~]# systemctl enable nmb smb
6. firewalld
[[email protected] ~]# firewall-cmd --permanent --add-service=samba
[[email protected] ~]# firewall-cmd --permanent --add-service=samba-client
[[email protected] ~]# firewall-cmd --permanent --add-service=mouted
[[email protected] ~]# firewall-cmd --reload
7. SELinux
[[email protected] ~]# vim /etc/selinux/config
SELINUX=disabled
[[email protected] ~]# setenforce 0
二、客户端连接测试
Windows端:
1. \\192.168.2.168
2. 映射网络驱动器
Linux端: [了解]
# yum -y install samba-client cifs-utils
1. 查看存储端共享 [可选]
# smbclient -L 192.168.5.240 --user=alice%1 //查看服务器共享
2. 手动挂载 [可选]
# mkdir /mnt/cifs
# mount -t cifs -o user=alice,pass=1 //192.168.122.166/data /mnt/cifs
3. 自动挂载到指定目录
# vim /etc/fstab
//192.168.122.166/data /mnt/cifs cifs user=alice,pass=1 0 0
# mount -a
4. 查看挂载
# df -P
//192.168.122.166/data 7923120 767480 6746504 11% /mnt/cifs
# cp -rf /etc/hosts /mnt/cifs/
# mount
//192.168.122.105/data on /mnt type cifs (rw,relatime,vers=1.0,cache=strict,username=alice,domain=SAMBA,uid=0,noforceuid,gid=0,noforcegid,
addr=192.168.122.105,unix,posixpaths,serverino,acl,rsize=1048576,wsize=65536,actimeo=1)
原文地址:https://www.cnblogs.com/thelovelybugfly/p/12182459.html