Linux_YUM warehouse supplement and NFS sharing service

1. Overview of YUM

1.YUM (Yellow dog Updater Modified)

A software update mechanism based on RPM packages
can automatically resolve dependencies.
All packages are provided by a centralized YUM software warehouse

2. Prepare the installation source

(1) How to provide software warehouse

网络源
    FTP服务: ftp://…
    HTTP服务: http://…
本地源
    本地目录: file://…

(2) The source of the RPM software package

CentOS发布的RPM包集合
第三方组织发布的RPM包集合
用户自定义的RPM包集合

(3) Build a CentOS 7 software warehouse

RPM包来自CentOS 7 DVD光盘
通过FTP方式提供给客户机 (安装并启用vsftpd服务)

(4) Join the unofficial RPM package group in the software warehouse

一般以网络途径获取的
包括存在依赖关系的所有其他RPM包
需使用createrepo工具建立repodata 数据文件仓库
安装包文件存放到 /var/ftp/other 目录下
mkdir -p  /var/ftp/other
cd /var/ftp/other
createrepo -g /dev/cdrom/repodata/repomd.xml ./

3. Visit YUM warehouse

为客户机指定YUM仓库位置
配置文件位置: /etc/yum.repos.d/centos7.repo
vim /etc/yum.repos.d/centos7.repo
[base]        #仓库类别,注意:方括号里面不能有空格。
name=CentOS 7   #仓库名称
baseurl=ftp:///192.168.4.254/CentOS7    #URL访问路径
enabled=1     #启用此软件仓库,默认该选项可以不写。如果值为0,则表示禁用这个软件源。
gpgcheck=1(或0:表示不验证公钥)      #验证软件包的签名
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 (软件校验公钥)     #GPG公钥文件的位置

[other]
name=Other RPM Packages
baseurl=ftp:///192.168.4.254/other
enabled=1
gpgcheck=0

2. NFS shared storage service

1. Overview of NFS

  • NFS is a network file system protocol based on TCP/IP transmission. By using the NFS protocol, the client can access the shared resources in the remote server as if it were accessing a local directory.

2. NFS advantages and disadvantages

  • For most load balancing clusters, it is a common practice to use the NFS protocol to share data storage. NFS is also a protocol that NAS storage devices must support. However, because NFS does not have a user authentication mechanism, and the data is transmitted in plain text on the network, the security is very poor, and it can only be used in a local area network.

3. NFS service realizes the required conditions

  • The realization of the NFS service relies on the RPC (Remote Process Call) mechanism to complete the remote-to-local mapping process.
    Therefore, it is necessary to install the nfs-utils and rpcbind software packages to provide NFS sharing services. The former is used for NFS sharing publishing and access, and the latter is used for RPC support.

Three. NFS sharing service configuration

Use NFS to publish shared resources in the file server

Steps:

1. Install the nfs-utils and rpcbind software packages
rpm -q rpcbind nfs-utils 
yum -y install nfs-utils rpcbind

Insert picture description here

2. Set up a shared directory
mkdir -p /opt/abc
chmod 777 /opt/abc/

vim /etc/exports
/opt/share 192.168.163.0/24(rw,sync,no_root_squash)

客户机地址可以是主机名、IP 地址、网段地址,允许使用“*”、“?”通配符。
常用选项
“rw” 表示允许读写,“ro” 表示为只读;

sync :表示同步写入到内存与硬盘中。
async :将数据先保存在内存缓冲区中,必要时才写入磁盘。

no_root_squash : 表示当客户机以root身份访问时赋予本地root权限(默认是root_squash)。
root_squash :表示客户机用root用户访问该共享目录时,将root用户映射成匿名用户。
all_squash :所有访问用户都映射为匿名用户或用户组。

subtree_check(默认):若输出目录是一个子目录,则nfs服务器将检查其父目录的权限。
no_subtree_check :即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率。

其他例子:
/var/ftp/pub 192.168.163.11(ro) 192.168.163.110(rw)
/share *(rw,sync)

Insert picture description here
Insert picture description here
Insert picture description here

3. Start the NFS service program

When manually loading the NFS sharing service, you should start rpcbind first, and then start nfs

systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfs

netstat  -anpt  |  grep  111     #查看rpcbind端口111是否开启, rpcbind默认使用tcp端口111

Insert picture description here

4. View the NFS shared directory published by this machine

exportfs -rv			#发布共享
showmount -e            #查看共享

Insert picture description here

2. Access NFS shared resources in the client

Install nfs-utils, rpcbind packages

rpm -q rpcbind nfs-utils 
yum -y install nfs-utils rpcbind
systemctl start rpcbind
systemctl enable rpcbind

systemctl stop firewalld.service 
setenforce 0

#查看 NFS 服务器端共享了哪些目录
showmount -e 192.168.163.10

Insert picture description here
Insert picture description here
Mount NFS shared directory

方法一:手动挂载
mkdir /myshare
mount 192.168.163.10:/opt/share /myshare
方法二:自动挂载
vim /etc/fstab
192.168.163.10:/opt/share    /myshare    nfs defaults,_netdev  0  0

_netdev :表示挂载设备需要网络
mount -a     #挂载 fstab 中的所有文件系统

df -Th      #确认挂载结果

Mount manually:

Insert picture description here
Insert picture description hereInsert picture description here
Insert picture description here

Automount

Insert picture description here
Insert picture description here
Insert picture description here
Forcibly uninstalling NFS
If the server-side NFS service suddenly stops while the client is being mounted and used, the client will be stuck when executing the df -h command. At this time, you cannot uninstall directly by using the umount command directly, and you need to add the -lf option to uninstall.

umount -lf /myshare

Guess you like

Origin blog.csdn.net/Wsxyi/article/details/114111895
Recommended