Deploy YUM warehouse and NFS sharing service
1. Overview of YUM
(一)YUM:Yellow dog Updater Modified
1. Software update mechanism based on RPM package construction
2. Can automatically resolve dependencies
3. All software packages are provided by the centralized YUM software warehouse
(2) Prepare the installation source
1. How to provide the source warehouse (emphasis)
- FTP service: ftp://...
- HTTP service: http://...
- Local directory: file://...
2. The source of the RPM package
- A collection of RPM packages released by CentOS
- A collection of RPM packages released by third-party organizations
- User-defined RPM package collection
3. Supplement the Alibaba Cloud warehouse as a yum source
Step 1: Move the created local.repo file to the repo.bak directory (it can also be another backup directory)
Step 2: Turn on the system that can connect to the Internet, and execute wget -O /etc/yum.repos .d / CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo Ali cloud images will be downloaded to the directory under /etc/yum.repos.d/
third step: to refresh the cache, yum claen all && yum makecache #Clean up the cache and generate a new cache. Then you can directly use the package installation files in the Alibaba Cloud warehouse. They are all the latest packages, but they can only be used in an Internet environment. If you want to use the software in the yum warehouse without the Internet, you need to download the Alibaba Cloud warehouse locally, which takes up a lot of space
YUM configuration file (emphasis)
- Basic settings: /etc/yum.conf
- Warehouse settings: /etc/yum.repos.d/*.repo
- Log file: /var/log/yum.log
Local yum source warehouse configuration commands
mount /dev/cdrom /mnt/ 把光盘挂载到/mnt目录下
cd /etc/yum.repos.d/ 包含了一些安装包不建议删除,可以创建一个目录做备份
mkdir repos.bak 创建备份目录
mv *.repo repos.bak 移动所有以.repo为后缀的文件到备份目录中
vim local.repo[local] 仓库类别
name=local 仓库名称与所创建的文件名一致
baseurl=file:///mnt 指定URL 访问路径为光盘挂载目录,
file://(格式)/mnt(目录)
enabled=1 开启此yum源,此为默认项,可省略
gpgcheck=0 不验证软件包的签名
yum clean all && yum makecache 删除yum缓存并更新
可以拆分成两个步骤来进行
yum clean
yun makecache
2. NFS shared storage service
Overview
- 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 like a local directory
- 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 clear text on the network, the security is very poor, and it can only be used in the local area network.
- The realization of the NFS service relies on the RPC (Remote Process Call) mechanism to complete the remote-to-local mapping process. So you need to install the nfs-utils and rpcbind packages to provide NFS sharing services. The former is used for NFS sharing publishing and access, and the latter is used for RPC support.
working principle
(1) NFS (Network File System) network file system
Rely on RPC (Remote Procedure Call)
- Need to install nfs-utils, rpcbind software package
- System service: nfs, rpcbind
- Shared configuration file: /etc/exports
NFS configuration file ==
NFS configuration file is /etc/exports (server configuration)
== The format is:
Shared directory location client address (permission option)
Third, use NFS to publish shared resources on the file server
(1) Sharing resources
1. Install the nfs-utils and rpcbind software packages
rpm -q rpcbind nfs-utils
yum -y install nfs-utils rpcbind
2. Set up a shared directory
mkdir -p /opt/nfs.share
chmod 777 /opt/nfs.share
修改nfs配置文件
vim /etc/exports
/opt/nfs.share 192.168.71.0/24(rw,sync,no_root_squash)
客户机地址可以是主机名、IP 地址、网段地址,允许使用“*”、 “?”通配符。rw 表示允许读写
ro 表示为只读
sync 表示同步写入到内存与硬盘中
no_root_squash 表示当客户机以root身份访问时赋予本地root权限(默认是root_squash)
root_squash 表示客户机用root用户访问该共享目录时,将root用户映射成匿名用户
其它常用选项:
all_squash 所有访问用户都映射为匿名用户或用户组
async 将数据先保存在内存缓冲区中,必要时才写入磁盘subtree_check(默认) 若输出目录是一个子目录,则nfs服务器将检查其父目录的权限
no_subtree_check 即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率
3. Turn off the firewall security mechanism and turn on the service
systemctl stop firewalld
setenforce 0
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind //开机自启动服务
systemctl enable nfs
4. View the NFS shared directory published by this machine
exportfs -rv //发布共享
showmount -e //查看共享
(2) Access NFS shared resources in the client
1. Install the nfs-utils and rpcbind software packages
rpm -q rpcbind nfs-utils
yum -y install nfs-utils rpcbind
systemctl start rpcbind
systemctl enable rpcbind
2. Check which directories are shared on the NFS server
showmount -e 192.168.71.20
mkdir /nfs_share //手动挂载 NFS 共享目录
mount 192.168.71.20:/opt/nfs.share //可以设置自动挂载
df -Th
3. Add a directory on the shared resource on the client
4. See if there is any content added on the server
Automatically mount NFS shared directories
vim /etc/fstab
92.168.153.10:/opt/share /share nfs defaults,_netdev 0 0
Forcibly uninstall 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, you need to add -lf option to uninstall.
umount -lf /nfs_share