First, use scenarios
The company has multiple departments, such as software department and finance department, which need a shared storage space to facilitate resource sharing and document collaboration. The usage requirements are as follows:
- A common directory that all colleagues in the company can read and write
- Each department has its own directory, which can only be read and written by the department personnel
- Each department cannot see the directories of other departments
According to the above requirements, this article is implemented with Samba and NFS respectively.
Ii. Server
CentOS7. 64 x
Samba shared storage
1, install,
yum install -y samba
Copy the code
2, configuration,
Back up the original configuration file smb.conf
cp /etc/samba/smb.conf /etc/samba/smb.conf.org
vim /etc/samba/smb.conf
Add the following configuration
Copy the code
[global]
workgroup = WORKGROUP
security = user
server string = seal samba server %v
netbios name = SealSamba
# map to guest = Bad User
passdb backend = tdbsam
config file = /etc/samba/%G.smb.conf
Copy the code
Conf file and finance file finance.smb.conf file
vim /etc/samba/software.smb.conf
vim /etc/samba/finance.smb.conf
Add the following configuration
Copy the code
[Public] comment = Public Stuff path = /home/share/ Public Public = no Read only = no writable = yes create mask = 0644 directory mask = 0755 force user = nobody force group = nobody valid users = @software admin users = @software read list = @software Write list = @software [Software department] comment = Software Department Path = /home/share/software public = no valid users = @software admin users = @software read list = @software write list = @software read only = no writable = yes create mask = 0644 directory mask = 0755Copy the code
[public] comment = public path = /home/share/public public = no valid users = @finance admin users = @finance read list = @finance write list = @finance writable = yes create mask = 0644 directory mask = 0755 force user = nobody force group = Nobody [finance] comment = Finance path = /home/share/ Finance public = no valid users = @finance admin users = @finance read list = @finance write list = @finance writable = yes create mask = 0644 directory mask = 0755Copy the code
3. Create users and user groups and assign rights to them
Create a user group: Software department
groupadd software
Create a new user group: Finance department
groupadd finance
Create a user and add it to the user group of software Department
useradd -g software zhangsan
# Create user: Li Si and add it to the finance department user group
useradd -g finance lisi
Delete user groups and usersGroupdel User group userdel userAdd to Samba
smbpasswd -a zhangsan
smbpasswd -a lisi
In addition, Samba deletes the userThe smbpasswd - x usersCopy the code
4. Create a shared directory
Mkdir -p /home/share/public mkdir -p /home/share/software mkdir -p /home/share/finance# Modify a user group
chown -R nobody:nobody /home/share/public
Copy the code
5. Start the service and access
systemctl start smb
Copy the code
5.1 Windows access
- In the explorer address bar, type: \\ server
- Mapping a Network Drive
- The effect
5.2 Mac access
2. NFS shared storage
1. Server installation
yum install -y nfs-utils
# Enable service
systemctl start rpcbind
systemctl start nfs
# firewall configuration
firewall-cmd --zone=public --permanent --add-service={rpc-bind,mountd,nfs}
firewall-cmd --reload
Copy the code
2. Configure the shared directory
mkdir /data
chmod 755 /data
vim /etc/exports
Add the following configuration
Copy the code
/ data / 192.168.0.0/24 (rw, sync, no_root_squash no_all_squash)Copy the code
- /data: indicates the location of the shared directory.
- 192.168.0.0/24: indicates the client IP address range. * indicates all IP addresses.
- Rw: permission Settings, read and write.
- Sync: synchronizes shared directories.
- No_root_squash: Root authorization can be used.
- No_all_squash: Common user authorization can be used.
Save the Settings and restart the NFS service
systemctl restart nfs
Check the local shared storage directory
showmount -e localhost
The results are as follows:
Copy the code
Export list forLocalhost: / data 192.168.0.0/24Copy the code
3. Windows client
3.1 installation
Windows The installation method of an NFS client varies with Windows versions
- Windows Server 2008
- servermanagercmd.exe -install FS-NFS-Services
- Windows 7
- Programs and Functions – Enable or disable Widnows functions-NFS service
- Windows Server 2012
- Add a function – Add a File Printing service – NFS client
- Windows 10
- Programs and Functions – Enable or disable Widnows functions-NFS service
3.2 Checking the UID and GID of the server
id root
# uid=0(root) gid=0(root) groups=0(root)
Note: This example uses root as an example. For security reasons in the production environment, please change it to the corresponding user with permission
Copy the code
You can see that uid=0, GID =0, need to configure on the Windows client
3.2 Windows configuration
# registry configuration
regedit
Copy the code
- Locate the item HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default
- Create two DWORD values named AnonymousUid and AnonymousGid
- Set the UID and GID values. In this example, set them to 0
- Restart the Windows operating system (or NFS Client service).
3.3 Mounting a Folder
The mount 192.168.0.110: / data X:# uninstall
umount X:
Note: This command is used to mount the server. When the server restarts, it will not be mounted automatically.
Copy the code
3.4 Automatic Mounting
- Click on this computer
- In the computer dialog box that pops up, locate the mapped network drive in the toolbar
- Drive address enter X:
- Enter 192.168.0.110:/data for folder
- Ensure that reconnection is selected during login. This configuration indicates that the shared directory is automatically mounted during login.
4. Use Linux clients
4.1 installation
yum install -y nfs-utils
systemctl enable rpcbind
systemctl start rpcbind
Copy the code
4.2 Client Connection
# Client view
showmount -e 192.168.0.110
# client create directory
mkdir /data
# Client mountMount -t NFS 192.168.0.101:/data /data# client view mount status
mount
Copy the code
4.3 test the NFS
cd /data
touch 1.txt
Copy the code
4.4 Automatic Client Mounting
vim /etc/fstab
Add the following configuration:
Copy the code
#
# /etc/fstab
# Created by anaconda on Thu May 25 13:11:52 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#/dev/mapper/cl-root / xfs defaults 0 0 UUID=414ee961-c1cb-4715-b321-241dbe2e9a32 /boot xfs defaults 0 0 /dev/mapper/cl-home /home XFS defaults 0 0 /dev/mapper/cl-swap swap defaults 0 0 192.168.0.110:/data /data NFS defaults 0 0Copy the code
Fstab has been modified and systemctl needs to be reloaded
systemctl daemon-reload
# mount Check the mount status
mount
Copy the code
The most correct way to use shared storage is Samba and NFS