美文网首页
nginx反向代理内网yum

nginx反向代理内网yum

作者: 扎啤 | 来源:发表于2023-02-05 14:41 被阅读0次

目的:解决内网服务器无法访问yum服务,而搭建内网yum代理服务器
一、安装配置Nginx服务(Nginx服务器上建议先关闭iptables/firewalld服务,待实验完成后再根据实际情况配置)
yum install nginx -y
cd /etc/nginx/conf.d/
vim proxy.conf

server{
listen 80;
server_name mirrors.cxsw.com;  
location  /centos/ {         #yum  base源代理配置
   proxy_pass http://mirrors.aliyun.com/centos/ ;
  }
location  /epel/ {          #yum epel源代理设置
   proxy_pass http://mirrors.aliyun.com/epel/ ;
  }
}

nginx -t #检查语法并重启

二、客户端配置yum源访问地址
/etc/yum.repos.d/CentOS-Base.repo #配置base 源

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - mirrors.cxsw.com
failovermethod=priority
baseurl=http://mirrors.cxsw.com/centos/$releasever/os/$basearch/
              http://mirrors.cxswcs.com/centos/$releasever/os/$basearch/
              http://mirrors.cloud.cxswcs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.cxsw.com/centos/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.cxsw.com
failovermethod=priority
baseurl=http://mirrors.cxsw.com/centos/$releasever/updates/$basearch/
        http://mirrors.cxswcs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.cxswcs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.cxsw.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.cxsw.com
failovermethod=priority
baseurl=http://mirrors.cxsw.com/centos/$releasever/extras/$basearch/
        http://mirrors.cxswcs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.cxswcs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.cxsw.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.cxsw.com
failovermethod=priority
baseurl=http://mirrors.cxsw.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cxswcs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.cxswcs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.cxsw.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.cxsw.com
failovermethod=priority
baseurl=http://mirrors.cxsw.com/centos/$releasever/contrib/$basearch/
              http://mirrors.cxswcs.com/centos/$releasever/contrib/$basearch/
              http://mirrors.cloud.cxswcs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.cxsw.com/centos/RPM-GPG-KEY-CentOS-7

/etc/yum.repos.d/epel.repo #配置epel.repo源

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.cxsw.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.cxsw.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.cxsw.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0

三、设置本机hosts解析
vim /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.233.3 mirrors.cxsw.com

四、测试

[root@localhost yum.repos.d]# ping mirrors.cxsw.com
PING mirrors.cxsw.com (192.168.233.3) 56(84) bytes of data.
64 bytes from mirrors.cxsw.com (192.168.233.3): icmp_seq=1 ttl=64 time=0.316 ms
64 bytes from mirrors.cxsw.com (192.168.233.3): icmp_seq=2 ttl=64 time=0.763 ms
64 bytes from mirrors.cxsw.com (192.168.233.3): icmp_seq=3 ttl=64 time=0.788 ms
64 bytes from mirrors.cxsw.com (192.168.233.3): icmp_seq=4 ttl=64 time=0.313 ms
64 bytes from mirrors.cxsw.com (192.168.233.3): icmp_seq=5 ttl=64 time=0.322 ms
^C
--- mirrors.cxsw.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4010ms
rtt min/avg/max/mdev = 0.313/0.500/0.788/0.225 ms


yum clean all
yum makecache
[root@localhost nginx]# tail -f /var/log/nginx/access.log
192.168.233.4 - - [06/Feb/2023:14:20:10 +0800] "GET /epel/7/x86_64/repodata/a9c7a8cbffb5e5c07cbf31397bf11d9f7755e96c72ce897e04dba556dd4cc0eb-comps-Everything.x86_64.xml.gz HTTP/1.1" 200 100956 "-" "urlgrabber/3.10 yum/3.4.3" "-"
192.168.233.4 - - [06/Feb/2023:14:20:13 +0800] "GET /centos/7/os/x86_64/repodata/d6d94c7d406fe7ad4902a97104b39a0d8299451832a97f31d71653ba982c955b-filelists.sqlite.bz2 HTTP/1.1" 200 7508416 "-" "urlgrabber/3.10 yum/3.4.3" "-"
192.168.233.4 - - [06/Feb/2023:14:20:16 +0800] "GET /epel/7/x86_64/repodata/b8ab124ce8b2ecc0afaa1248f05f72f3d2a830decced09ca13bd58538a32d5ba-updateinfo.xml.bz2 HTTP/1.1" 200 1091701 "-" "urlgrabber/3.10 yum/3.4.3" "-"
192.168.233.4 - - [06/Feb/2023:14:20:17 +0800] "GET /epel/7/x86_64/repodata/d9dac75e0d44976e326df0b694bb515726ea2f32f9b207a0e6aadae66b1cdeea-prestodelta.xml.gz HTTP/1.1" 200 1821 "-" "urlgrabber/3.10 yum/3.4.3" "-"
192.168.233.4 - - [06/Feb/2023:14:20:24 +0800] "GET /centos/7/os/x86_64/repodata/ecaab5cc3b9c10fefe6be2ecbf6f9fcb437231dac3e82cab8d9d2cf70e99644d-other.sqlite.bz2 HTTP/1.1" 200 2676918 "-" "urlgrabber/3.10 yum/3.4.3" "-"
192.168.233.4 - - [06/Feb/2023:14:21:02 +0800] "GET /epel/7/x86_64/repodata/806ac38a1d133072220213748cab12566d1902a91f04e8b150bb2fea9c0c06eb-primary.sqlite.bz2 HTTP/1.1" 200 7332715 "-" "urlgrabber/3.10 yum/3.4.3" "-"
192.168.233.4 - - [06/Feb/2023:14:21:04 +0800] "GET /centos/7/extras/x86_64/repodata/511a574b4c3f907f9acfe5603566958fb6f09137292c5cd5d5d57c298864790f-primary.sqlite.bz2 HTTP/1.1" 200 255402 "-" "urlgrabber/3.10 yum/3.4.3" "-"

相关文章

网友评论

      本文标题:nginx反向代理内网yum

      本文链接:https://www.haomeiwen.com/subject/ltzahdtx.html