Centos7 下配置yum代理

1、应用场景
某些应用场景中,Linux服务器需要通过yum安装应用的包,但是这些Linux服务器可能不能连接到外网,但是内部也没有对应的yum服务器,这个时候,找一台内部能够访问外网的服务器配置一个代理,然后使用代理进行yum的动作。
2、案列
服务端: 172.16.5.154
客户端: 172.16.5.156
3、找一个公司可以上外网的服务器配置Squid代理

rpm -qa squid    # 确保本服务器没有配置Squid
yum -y install  openssl squid
cat /etc/squid/squid.conf

内容如下

#
#Recommended minimum configuration:
##Example rule allowing access from your local networks.
#Adapt to list your (internal) IP networks from where browsing
#should be allowed
acl localnet src 10.0.0.0/8     # RFC1918 possible internal network
acl localnet src 172.16.0.0/12  # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7       # RFC 4193 local private network range
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machinesacl SSL_ports port 443
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443         # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl CONNECT method CONNECT#
#Recommended minimum Access Permission configuration:
#
#Deny requests to certain unsafe ports
http_access deny !Safe_ports#Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports#Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager#We strongly recommend the following be uncommented to protect innocent
#web applications running on the proxy server who think the only
#one who can access services on "localhost" is a local user
#http_access deny to_localhost#
#INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
##Example rule allowing access from your local networks.
#Adapt localnet in the ACL section to list your (internal) IP networks
#from where browsing should be allowed
http_access allow localnet
http_access allow localhost#And finally deny all other access to this proxy
http_access deny all
http_access allow all
#Squid normally listens to port 3128
http_port 3128#Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256Leave coredumps in the first cache dir
coredump_dir /var/spool/squid#Add any of your own refresh_pattern entries above these.
#
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320

将此文件中的 http_access deny all改为 # http_access deny all
将此文件中注释的地方下面加一条内容
http_access allow all
4、启动代理

systemctl start squid
systemctl enable squid
systemctl status squid
netstat -ntlp

结果如下

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      2129/mongod
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      25748/nginx: master
tcp        0      0 0.0.0.0:81              0.0.0.0:*               LISTEN      25708/httpd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      2291/sshd
tcp        0      0 127.0.0.1:32000         0.0.0.0:*               LISTEN      1275/java
tcp6       0      0 :::80                   :::*                    LISTEN      25748/nginx: master
tcp6       0      0 :::3128                 :::*                    LISTEN      16820/(squid-1)
# 说明3128端口开启,说明代理是正常

5、在客户端服务器配置yum代理配置
(1)备份

 cd /etc/yum.repos.d/mkdir repo_bakmv *.repo repo_bak/

(2)下载新的Centos-Base.repo 到 /etc/yum.repos.d/

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repoyum clean allyum makecache

(3) 安装epel 源

yum list | grep epel-release
yum -y install epel-release
yum clean all
yum makecache
yum repolist enabled   # 查看启动的仓库
yum repolist all       # 查看所有的仓库

(4)在/etc/yum.conf中添加如下内容

proxy=http:172.16.5.154:3128
ping www.baidu.com   #执行此命令会看到如下错误
ping: www.baidu.com: Name or service not known
yum -y install squid


Centos7配置 yum代理相关推荐

  1. Centos7配置yum国内源(BaseOS+epel+ELRepo+SCL+IUS+REMI)

    Centos7配置yum国内源 配置必要源 配置base源 下载阿里云的base源 下载163的base源 刷新源 查看源是否添加成功 安装epel源 替换epel.repo文件 刷新源 查看源是否添 ...

  2. Centos7配置yum源(本地yum源和阿里网络yum源)

    一.centos7配置yum源 yum源分为本地yum源和网络yum源 1.配置本地yum源 步骤一:在centos虚拟机中挂载光盘 1.创建挂载点目录 [root@localhost ~]# mkd ...

  3. centos7配置squid代理(透明代理)

    squid透明代理 实验材料 这里只是先详细的阐述,后面实验环境配置我会详细讲 一台centos7配置squid服务 添加一块网卡 vm1 网卡IP 192.168.100.102 模拟内网 vm2 ...

  4. 虚拟机给Centos7配置yum源(本地yum和网络yum)

    文章目录 目录 文章目录 前言 一.本地yum源配置 二.配置网络yum源 (需要能连接外网) 总结 前言 yum简介: 1.Yum(全称为 Yellowdog Updater, Modified)是 ...

  5. centos7:配置yum源,阿里源和本地源,并配置中文

    将阿里源作为yum源 # 首先检测wget是否已安装,如果未安装通过 yum install -y wget安装wget# 接着将原始yum源环境文件替换,通过重命名/etc/yum.repos.d/ ...

  6. linux yum 安装dns,centos7配置YUM安装DNS服务

    1.配置DNS地址vim /etc/resolv.conf nameserver 192.168.1.100 #注:这里的地址是你DNS服务器本机的地址 2.安装dns服务yum install bi ...

  7. centos7配置yum为国内源

    问题: yum install libXm.so.4 报错:Cannot find a valid baseurl for repo: base/7/x86_64 因为yum源不是国内的,切换一下. ...

  8. CentOS7配置yum源

    目录 一.配置网络yum源 1.首先CentOS可以连接到外网 2.配置网络yum 3.清除缓存载入yum数据 二.配置本地yum 1.挂载镜像 2.写入yum 3.清除缓存,载入新yum数据 注: ...

  9. Centos7 配置Socks5代理

    一.安装依赖 yum install gcc openldap-devel pam-devel openssl-devel wget 二.下载ss5 wget http://jaist.dl.sour ...

最新文章

  1. python(19)编码问题
  2. golang 线程 Java线程_Golang 学习笔记(06)—— 多线程
  3. .NetCore(四) 在Nginx部署
  4. 如何向Spring Bean 中注入java.util.Properties?
  5. pageSet还没完count就执行了
  6. display属性_CSS之使用display:inline-block来布局
  7. leetcode面试题 04.02. 最小高度树(深度优先搜索)
  8. glassfish服务器默认的网页所在的位置
  9. math.pow int_Java Math类static int min(int i1,int i2)与示例
  10. 查找整数c语言编程,关于算法:查找整数的位数
  11. oracle错误 无监听程序,oracle_无监听程序_错误
  12. 搭建Cocos2d-js开发环境(Window)
  13. Vue学习(二):class与style绑定
  14. JAVA三大框架入门
  15. linux 驱动笔记(七)
  16. java -jar -xx_java 启动方式 java -jar xx.jar
  17. selenium+python爬取京东评论最多的计算机配置信息
  18. mac android 模拟器耗电,Android模拟器崩溃在Mac
  19. 寄存器 内存 磁盘 读取速度
  20. imazing是什么?为什么选择 iMazing?

热门文章

  1. 新浪校招php笔试题,新浪笔试题 PHP
  2. elk6.4.3安装部署指导手册
  3. VS2015生成的exe文件在其他电脑下运行
  4. php pdo的用法,php pdo函数库用法详解
  5. 高效清除电脑中的灰尘。。。。社会工程学真的很管用
  6. 黑客逆向破解基础-3:如何识别程序加的什么壳
  7. whm修改tmp目录空间大小为4096M
  8. 佛经经典名句300句
  9. 用计算机怎么管理小米路由器,怎样用手机设定小米路由器
  10. 小规模纳税人可以申请美元账户收款么?