Demand background

Believe doing Java development friend could meet the requirements, on multiple machines in a production environment need to access data on a machine, such data are generally in order to unified management and storage, and yet, this data is compared commonly big, not easy to migrate, so I need more machines to access the data on the function of a machine.

Technical Route 1

About Samba

Samba is the standard Windows interoperability suite of programs for Linux and Unix.

Samba is Free Software licensed under the GNU General Public License, the Samba project is a member of the Software Freedom Conservancy.

Since 1992, Samba has provided secure, stable and fast file and print services for all clients using the SMB/CIFS protocol, such as all versions of DOS and Windows, OS/2, Linux and many others.

Samba is an important component to seamlessly integrate Linux/Unix Servers and Desktops into Active Directory environments. It can function both as a domain controller or as a regular domain member.

Install Samba and configure it

/etc/samba/smb.conf [global] workgroup = # /etc/samba/smb.conf [global] workgroup = WORKGROUP server string = Samba Server %v netbios name = centos security = user map to guest = bad user dns proxy = no #  Share Definition [Anonymous] path = /samba/anonymous browsable =yes writable = yes guest ok = yes read only = noCopy the code

Add user

 useradd -s /sbin/nologin/sambauser
Copy the code

Set the password

 smbpasswd -a sambauser
Copy the code

Check whether the user is added successfully

 pdbedit -L
Copy the code

Set the Samba service to start automatically upon startup

 systemctl enable smb.service
 systemctl enable nmb.service
 systemctl restart smb.service
 systemctl restart nmb.service
Copy the code

Configure the Samba service to be defended by the firewall

 firewall-cmd --permanent --zone=public --add-service=samba
 firewall-cmd --reload
Copy the code

Test for correct syntax

 testparam
Copy the code

Began to mount

 Mount –t cift //192.168.10.18:/share /share –o username=sambatest,password=xxxy
Copy the code

Modifying a Service Port

The Samba service uses port 445 by default. You can modify the port in the following ways:

Vim /etc/samba/smb.conf # add a line in [global] to SMB ports = 4455 #Copy the code

Viewing Service Status

 systemctl status smbd
Copy the code
 tail /var/log/samba/log.smbd
Copy the code

Check whether the service is running on port 4455

 lsof -i:4455
Copy the code

To different versions of Windows to do the packet capture test, found that WinXP only access port 139, Win7 access port 139 and port 445, Win10 only access port 445

Technical Route 2

About nfs

NFS is an abbreviation of Network FileSystem, originally developed by Sun. Its biggest function is through the network, so that different machines, different operating systems, can share files with each other.

Online NFS installation on the server

# yum -y install nfs-utils # yum -y install nfs-utils # yum -y install nfs-utils # yum -y install nfs-utils # yum -y install nfs-utils # yum -y install nfs-utils # yum -y install nfs-utils 192.168.0.0/24 = 192.168.0.4, 192.168.0.4 = 192.168.0.4, 192.168.0.4 = 192.168.0.4 192.168.227.0/24 / opt/NFS 192.168.0.150 (rw, sync and fsid = 0) 192.168.0.151 (rw, sync and fsid = 0)Copy the code

Set the NFS server to start automatically upon startup

 systemctl enable rpcbind.service    
 systemctl enable nfs-server.service
 ​
 systemctl start rpcbind.service    
 systemctl start nfs.service  
Copy the code

Verify that the NFS server is started successfully

 rpcinfo -p   
Copy the code

Check whether NFS is started by checking whether NFS services exist in the Service column

Showmount -e 192.168.0.3 // Host IP addressCopy the code

Install the NFS service on the client

 yum install -y nfs-utils
 ​
 systemctl enable rpcbind.service
 ​
 systemctl start rpcbind.service
Copy the code

Note: The client does not need to start the NFS service, only the rpcbind service.

Check whether there are directory shares on the NFS server

Showmount -e 192.168.0.3Copy the code

Run mount to mount the /opt/ NFS directory on server A to the /opt/ NFS directory on client B

[root@localhost ~]# mkdir /opt/ NFS [root@localhost ~]# mount -t NFS 192.168.0.3:/opt/ NFS / /opt/ NFS/mount 102.64.102.134: / MNT/data/Z: (102.64.102.134 Storage Share) [root@localhost ~]# df -h File system capacity Used Available Used % Mount point /dev/mapper/centos-root 11G 1.3g 9.1g 13% / Dev TMPFS 911M 0 911M 0% /dev/shm TMPFS 921M 8.5m 912M 1% /run TMPFS 921M 0 921M 0% /sys/fs/cgroup /dev/sda1 497M 170M 328M 35% /boot TMPFS 185M 0 185M 0% /run/user/0 192.168.227.3:/opt/ NFS 11G 1.3g 9.1g If A file is written to the shared directory /opte/ NFS on server A, it can be seen on servers B and C, but files cannot be written to this directory.Copy the code

To ensure that all machines A, B, and C can write files to the shared directory, perform the following operations:

[root@localhost home]# id root uid=0(root) gid=0(root) group =0(root) mkdir /opt/nfs1 # vim /etc/exports / opt/NFS 192.168.0.4 (rw, sync and fsid = 0) 192.168.0.5 (rw, sync and fsid = 0)/opt/nfs1 192.168.0.0/24(rw,sync,all_squash,anonuid=0,anongid=0) Add the second row. Anonuid =0,anongid=0 is the ROOT user ID. Exportfs -arv exportfs is used to change the /etc/exports configuration file without restarting the NFS service. Its common options are [-aruv]. -r: remount. -u: uninstalls a directory. -v: displays the shared directory. Showmount -e 192.168.0.3 # Showmount -e 192.168.0.3 # Showmount -e 192.168.0.3 # Showmount -e 192.168.0.3 Mkdir nfs1 mount -t NFS 192.168.0.3:/opt/nfs1/ /opt/nfs1/ll / >/opt/nfs1/ll.txt (Umount /home/nfs1/) 6. To mount the vm on clients B and C after startup, edit /etc/fstab: vim /etc/fstab and add the following information: 192.168.0.3:/opt/ NFS /opt/ NFS NFS nolock 0 0 192.168.0.3:/opt/nfs1 /opt/nfs1 NFS nolock 0 0 Save the Settings and mount the mount againCopy the code

\