Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux day 50 NFS&&Samba

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Linux day 50 NFS&&Samba

Time: 20180911

Catalogue

NFS (Network FileSystem) network file system

NFS principle

NFS configuration

The meaning of options commonly used in / etc/export

Samba

Principle

Samba installation configuration

Set in the main configuration file / etc/samba/smb.conf configuration file

Create samba user password

Enable the samba service

Samba client uses

Summary

NFS (Network FileSystem) network file system

One can share resources among different hosts through the network. So you can simply think of it as a

File server, NFS service allows client hosts to mount directories shared by remote NFS servers on the network locally

Among the machines on the side, the remote host directory is as convenient as the local disk partition.

NFS principle

1. Mainly with the help of RPC (Remote Procedure Call) to achieve file sharing, RPC through functions (on the remote host

Part of the function is done by the local program, and the other part is done by the function on the remote host.

Complete the sharing of resources.

2. NFS supports many functions, and each function will be started with a different program.

Some ports are enabled to transmit data, so NFS does not have fixed ports, but randomly uses some unused less than

The port of 1024 is used as data transmission. But how does the client know which ports are opened on the server side are NFS ports?

3. Knowing these ports requires remote procedure calls to RPC services, and the main function of RPC is to specify where each NFS function is located

The corresponding port number and feedback the port to the client so that the client can connect to the correct port. RPC learned that NFS

The principle of ports is that when the NFS service is started, several ports will be randomly fetched, and the ports will be actively registered with RPC, so

RPC knows the NFS function corresponding to each port. RPC uses fixed port 111to listen to the client's needs and report to

The client feedback the corresponding port, so the NFS startup must be after the RPC-related services, otherwise an error will be reported.

NFS configuration

The main software packages used are nfs-utils, rpcbind

Install softwar

Yum install-y rpcbind nfs-utils

The NFS configuration file / etc/exports content format is

File system client options to be shared

Client IP,FQDN or DOMAIN,NETWORK

If you want to share the local / data directory with other users on the local LAN, and have read and write permissions

/ data 172.20.48.202 (rw,sync,no_root_squash)

At this point, the simple server is configured.

Start the service

Systemctl start rpcbind nfs

The client queries which file systems are shared by the server

Showmount-e SERVER_IP

After you see the shared directory, you can mount the shared directory locally.

Mount-t nfs SERVER_IP:/path / path/mount_point

Such as

Mount-t nfs 172.20.48.201:/tmp / mnt

At this point, the client has mounted the server's shared directory and can read and write.

Commands for NFS management and maintenance

Exportfs can be used to maintain file system tables exported by exports files

Exportfs-ar reexports all file systems

Exportfs-au shuts down all exported file systems

Exportfs-u FS shuts down the specified exported file system

The meaning of options commonly used in / etc/export

The default option for secure is to use a TCP/IP port below 1024 to connect to NFS. Specify that insecure can be disabled

Async improves performance, that is, asynchronous writes, but restarting the service if the NFS process is not safely shut down may result in data loss

In contrast, there is sync, but if the server does not return write completion when writing, the client will be waiting all the time

Status

No_wdelay turns off write latency. If you set async, this option is ignored

Nohide mounts one directory to another and the original directory is usually hidden. Disable this.

For this kind of behavior, you need to use the hide option

No_subtree_check subtree checks, which perform security checks that you don't want to ignore. Enabled by default

The option no_auth_nlm, which can be specified as insecure_losts, tells the NFS daemon not to lock the

Request authentication. If you are concerned about security, avoid using this option. The default option is auth_nlm

Or secure_locks

Mp (mountpoint=path) by explicitly declaring this option, NFS requires that the exported directory be mounted

Use when recovering from fsid=num failure. Please see the help documentation for details.

Options for user mapping

Root_squash does not allow root users to access mounted NFS volumes

No_root_squash, in contrast to the above, allows root to access the mounted volume

The all_squash option is useful for publicly accessible NFS volumes, which restrict all UID and GID to

Use anonymous users. The default setting is no_all_squash

Anonuid and anongid are used to set anonymous UID and GID to modify to specific user and group accounts

Samba

Function: sharing printer, host name resolution (NetBIOS name) on windows network, device sharing

Disk drive sharing and providing authentication for users to log in to SAMBA

Principle: Samba uses the NetBIOS communication protocol. NetBIOS is Network Basic Input/Output System

The basic input and output system of the network, which defines a software interface and provides

The standard method of communication interface is to provide network and other special functions for local area network. Samba through NetBIOS

Protocol to obtain the NetBIOS name of the other host, and then to locate the location of the host, and then according to the other host

Permissions granted to access available resources. In practice, samba controls these two steps through two services, namely nmb.

And smb two services. Nmb is used to manage workgroups and NetBIOS name parsing, mainly through UDP's 137

Smb is mainly used to manage directories, files, or files shared by samba hosts.

Printers, etc., mainly use the 139,445 ports of the TCP protocol for data transmission

Samba installation configuration

Samba software composition: samba main program, samba-client client program, samba-common other public programs

Install samba

Yum install-y samba

Rpm-ql samba to view the files it generates

The main configuration file / etc/samba/smb.conf configuration file has the following settings

Global settings: the parameters set are valid globally

Share-specific settings: there are several sub-sharing settings

Private home directory

Printer sharing

Custom Shar

Private home directory settings

[homes] # the name of the private home directory is represented by []

Comment = Home Directories # description information

Browseable = no # whether access to the user's home directory is allowed, which is usually set to no

Wriable = yes # whether to allow writing content

; valid user=%S #; denotes comments

; valid users = MYDOMAIN\% S

Printer sharing Settings

[printers]

Comment = ALL Printers

Path = / var/spool/samba

Browseable = no

Guest ok = no

Wriable = no

Printable = yes

Custom Shar

[shared_name]

Path = / path/share_dir # shared content path

Comment = Comment string # description information

Guest ok = {yes | no} # whether visitors are allowed to access

Public = {yes | no} # whether it is public, similar to guest ok

Wriable = {yes | no} # whether it is writable

Read only = {yes | no} # whether read-only

Write list = + GROUP_NAME # user indicates the list of writable users, where + indicates the group name

# indicates that the user in the group is writable

You can use the testparm command to check the configuration file for syntax errors

Create samba user password

It is only mentioned here to create passwords rather than accounts and passwords, because samba users are actually system users, that is, in / etc/passwd

The user defined in, but the password is not the password of the system user, but samba's own password file, so be samba

The user creates the password, which is created through the smbpasswd command.

Smbpasswd

-an add system user as samba user

-d disable users

-e enable users

-x Delete user

For example, add the system user admin to the samba user and set the password for it

Smbpasswd-an admin

Enable the samba service

Systemctl start nmb smb

Samba client uses

Windows uses connections

Open my computer and directly enter\\ IP to connect to sharing.

Linux View samba Server using the smbclient command

List the information shared by the server

Smbclient-L 172.20.48.201-U admin

Interactive data access (directory name is the shared directory found by the previous command)

Smbclient / / 172.20.48.201/sharedir-U admin

Mount the directory locally

Mount-t cifs-o username=admin,password=samba

/ / 172.20.48.201/sharedir / mnt

Mount.cifs-o username=admin,password=samba

/ / 172.20.48.201/sharedir / mnt

The last two lines are all one line, that is, one command

Summary:

Both NFS and Samba services can mount their shared directories on other servers

For FTP service, if you want to change the file on the server, you need to download the file locally and upload it before you can complete the modification.

Unlike NFS and Samba services, you can modify files directly on the server, but if multiple users change the same text

Parts are not allowed, and there will be a locking mechanism to protect files from damage.

What is described here is only a simple samba file sharing, such as virtual users are not used here, and configuration files

Related option

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report