内网服务器无法连接外网yum源,所以找一台跳板机,利用nginx的http转发功能做内网yum源,例如
跳板机IP 192.168.0.45
内网机IP 192.168.0.41
在跳板机上部署nginx,在配置文件中添加
server {
listen 9180;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
#root html;
#index index.html index.htm;
#转发到北理工的yum源
proxy_pass http://mirror.bit.edu.cn:80;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
log_format yum_source_access_log '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#日志路径
access_log /app/nginxlogs/yum_source_access.log yum_source_access_log;
}
启动nginx后,会把http://192.168.0.45:9180 的请求转发到http://mirror.bit.edu.cn:80,接下来我们需要配置内网机IP 192.168.0.41 上的yum配置文件,
备份原来的配置文件
mv /etc/yum.repos.d /etc/yum.repos.d_bak
mkdir /etc/yum.repos.d
cp /etc/yum.repos.d_bak/CentOS-Base.repo /etc/yum.repos.d/
然后编辑 /etc/yum.repos.d/CentOS-Base.repo
把每一项的mirrorlist注释掉,baseurl改成跳板机IP端口
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://192.168.0.45:9180/centos/$releasever/os/$basearch/
完成后内网机yum就可以使用啦~