ansible 番外 nfs提供远程yum源使用

前言

原先想法是打算使用阿里云的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"

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值