前言
原先想法是打算使用阿里云的yum源来为主机提供软件安装
但是我再测试中发现对网速的要求比较大,因为要3台主机同时去拉取软件包容易出错
这里我决定换为"nfs"共享挂载来为本地使用yum源,虽然可能包不是很齐,但作为练习更方便
挂载光盘(192.168.1.20)
#将镜像文件挂载到/media目录
mount /dev/sr0 /media/
#安装nfs服务
yum -y install rpcbind nfs-utils
systemctl restart rpcbind
systemctl enable rpcbind
#添加要共享的目录信息
vim /etc/exports
#添加
/media *(rw)
#启动nfs服务
systemctl restart nfs
#查看共享目录
[root@web1 yum.repos.d]# showmount -e 192.168.1.20
Export list for 192.168.1.20:
/media *
编写本地yum源文件
vim yum.repo
#添加
[yum]
name=yum
baseurl=file:///yum-source
enable=1
所有节点挂载共享目录
#创建挂载目录
ansible -i hosts web -m file -a "name=/yum-source state=directory"
#将共享卷挂载给所有主机
ansible -i hosts web -m shell -a "mount -t nfs 192.168.1.20:/media /yum-source"
#停用阿里云yum
ansible -i hosts web -m shell -a "chdir=/etc/yum.repos.d/ mv aliyun-yilai.repo aliyun-yilai.repo.bak"
#将本地yum分发到所有主机
ansible -i hosts web -m copy -a "src=yum.repo dest=/etc/yum.repos.d"
#重新建立缓存
ansible -i hosts web -m shell -a "yum clean all"
ansible -i hosts web -m shell -a "yum makecache"
尝试装个服务试试
#安装httpd
ansible -i hosts web -a shell -a "yum -y install httpd"
#卸载
ansible -i hosts web -a shell -a "yum -y remove httpd"