由于各种原因,可能存在一批内网机器无法访问公网又需要批量来安装一些rpm包,在自动化部署的普及之前,打通ssh+配置yum源是一个不错的解决方法
本地使用ISO镜像作为yum源:
mount -o loop centos.iso /mnt/centos/
vim /etc/yum.repo.d/centos-media.repo
加入
[c5-media]
name=CentOS-$releasever – Media
baseurl=file:///mnt/centos/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
保存退出
cp /mnt/centos/RPM-GPG-KEY-CentOS-5 /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
这样就可以使用本地仓库c5-media 来更新了:
yum update –enablerepo=c5-media
现在来配置http服务提供yum源
本地挂载镜像做内网镜像源:
接上面本地目录/mnt/centos 挂载的ISO 目录作为内网共享给其他的内网机使用. 具体步骤:
1. 先将/mnt/centos作为http目录发布(nginx):
配置nginx.conf 添加:
server {
listen 80;
server_name centos.repo;
root /mnt/centos;
location / {
root /mnt/centos/;
index index.html index.htm;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
}
开启自动列表功能,
平滑重启nginx
nginx -s reload
直接访问:
2.添加repo文件:
vim /etc/yum.repos.d/base.repo
添加:
[swhs]
name=swhs RPM Repository for wasu net
baseurl=http://centos.repo/
gpgcheck=1
enabled=1
gpgkey=http://centos.repo/RPM-GPG-KEY-CentOS-5
保存退出,如果在nginx发布时有多个虚拟主机需要在配置时加host解析,如果只有一个ip:port 就只需要将对应的地址改成http请求地址即可
添加host
vim /etc/hosts
加入 ip servername
保存退出
测试yum update 成功: