金庸武功之“碧血剑法”----squid做透明代理

一.试验目的:公司阿里云环境要求之开放一个代理服务器,其他服务器不允许有外网IP

二.环境拓扑:

A:代理服务器:(利用squid做透明代理) (centos7.2)

[[email protected] squid]# ip a

eth0:10.30.204.122

eth1:116.62.XX.XX

B:客户端服务器:(centos7.2)

[[email protected] squid]# ip a

eth0:10.30.204.90

三.试验环境准备(A,B都执行)

  1. yum  -y update
  2. 关闭SEliunx

[[email protected]~]# vi /etc/sysconfig/selinux

SELINUX=disabled

3.关闭防火墙

[[email protected]~]#  systemctl  stop     firewalld

[[email protected]~]#  systemctl disable    firewalld

[[email protected]~]#  systemctl  status    firewalld

4.同步系统时间

[[email protected]~]# rm -rf  /etc/localtime

[[email protected] ~]# ln  -s   /usr/share/zoneinfo/Asia/Shanghai  /etc/localtime

[[email protected]~]#  yum  install  -y  ntpdate

[[email protected]~]# /usr/sbin/ntpdate -u202.120.2.101 && hwclock -w

systemctl enable ntpdate && systemctlstart ntpdate

[[email protected]~]#  crontab  -e

*/5 * * * * /usr/sbin/ntpdate -u 202.120.2.101 && hwclock -w

5.修改主机名

hostnamectl --static set-hostname XXX

6.打开路由转发

vi /etc/sysctl.conf

输入net.ipv4.ip_forward=1

四.A代理服务器配置

[[email protected] ~]# yum install -y gcc openssl openssl-devel #依赖软件要先提前安装

[[email protected] ~]#    yum install squid

[[email protected] ~] #   cd /etc/squid

[[email protected] ~] # openssl req -new > lidongbest5.csr

Generating a 2048 bit RSA private key

..........................................................................+++

.........................................................................................................+++

writing new private key to ‘privkey.pem‘

Enter PEM pass phrase:                                                                   #输入密码,后面会用到,比如这里输入123456

Verifying - Enter PEM pass phrase:

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter ‘.‘, the field will be left blank.

-----

Country Name (2 letter code) [XX]:cn                                                  #国家

State or Province Name (full name) []:beijing                                       #省份

Locality Name (eg, city) [Default City]:beijing                                      #地区名字

Organization Name (eg, company) [Default Company Ltd]:sjwl        #公司名

Organizational Unit Name (eg, section) []:Technology                            #部门

Common Name (eg, your name or your server‘s hostname) []:sjwl    #CA主机名

Email Address []:[email protected]                  #邮箱

Please enter the following ‘extra‘ attributes

to be sent with your certificate request

A challenge password []:123456      #证书请求密钥,CA读取证书的时候需要输入密码

An optional company name []:sjwl     #-公司名称,CA读取证书的时候需要输入名称

[[email protected] squid]# openssl rsa -in privkey.pem -out lidongbest5.key

Enter pass phrase for privkey.pem: #输入上面设置的密码123456

writing RSA key

[[email protected] squid]# openssl x509 -in lidongbest5.csr -out lidongbest5.crt -req -signkey lidongbest5.key -days 3650

Signature ok

subject=/C=cn/ST=beijing/L=beijing/O=huanqiu/OU=Technology/CN=huanqiu/[email protected]

Getting Private key

[[email protected] ~] #   cp squid.conf squidbackup.conf

[[email protected] ~]#    vi  squid.conf

http_access deny all     改成 http_access allow all

# Squid normally listens to port 3128

http_port 8086 transparent

https_port 443 cert=/etc/squid/lidongbest5.crt key=/etc/squid/lidongbest5.key

dns_nameservers 8.8.8.8

cache_mem 1600 MB

cache_log /var/log/squid/cache.log

visible_hostname captain

启动squid,启动前进行测试和初始化
[[email protected] squid]# squid -k parse                    #测试
2016/08/09 13:35:04| Processing Configuration File: /etc/squid/squid.conf (depth 0)
2016/08/09 13:35:04| Processing: acl manager proto cache_object
..............
..............
2016/08/09 13:35:04| Processing: refresh_pattern . 0 20% 4320
2016/08/09 13:35:04| Initializing https proxy context

[[email protected] squid]# squid -z                            #初始化
2016/08/09 13:35:12| Creating Swap Directories

[[email protected] squid]# systemctl start squid.service

[[email protected] squid]# systemctl enable squid.service

iptables配置安装:

[[email protected] squid]#  systemctl stop firewall.service

[[email protected] squid]#  systemctl disable firewalld.service
[[email protected] squid]#  yum install iptables-services

[[email protected] squid]#  cd /etc/sysconfig/

[[email protected] squid]#  vi iptables

# Generated by iptables-save v1.4.21 on Tue Mar 28 17:42:00 2017

*nat

:PREROUTING ACCEPT [0:0]

:INPUT ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

:POSTROUTING ACCEPT [0:0]

-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8086

-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8086

-A PREROUTING -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 443

COMMIT

# Completed on Tue Mar 28 17:42:00 2017

# Generated by iptables-save v1.4.21 on Tue Mar 28 17:42:00 2017

*filter

:INPUT ACCEPT [42:2941]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [1950:331902]

-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT

COMMIT

# Completed on Tue Mar 28 17:42:00 2017

[[email protected] squid]#   systemctl   restart   iptables.service

五.客户端服务器配置:

客户端安装配置stunnel

  1,安装

  [[email protected] squid]#  yum install stunnel -y  #这里虽是阿里云内网,但有它内部的yum源

  [[email protected] squid]#  vi /etc/stunnel/stunnel.conf

client = yes

[https]

accept = 127.0.0.1:8088

connect = 10.30.204.122:443

如果报,FIPS_mode_set: 2D06C06E: error:2D06C06E:FIPS routines:FIPS_module_mode_set:fingerprint does not match,

stunnel.conf配置文件中加上,fips = no

2.启动stunnel并查看

[[email protected] squid]#  stunnel   //启动,默认配置文件路径 /etc/stunnel/stunnel.conf

[[email protected] squid]#  ps -ef |grep stunnel //查看

root 15972 0.0 0.0 103256 848 pts/0 S+ 17:30 0:00 grep stunnel

  root 21099 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel

  root 21100 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel

  root 21101 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel

  root 21102 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel

  root 21103 0.0 0.0 41532 1060 pts/0 S 15:42 0:00 stunnel

  root 21104 0.0 0.0 2077984 6824 ? Ss 15:42 0:00 stunnel

3.配置/etc/profile系统环境变量
底部添加下面两行
[[email protected] stunnel]# vim /etc/profile

export http_proxy=http://10.30.204.122:8086

export https_proxy=http://127.0.0.1:8088

4.测试

curl https://www.baidu.com

curl www.baidu.com

5.额外的要求:

如果需要做访问控制(比如只允许某些IP的客户端才能连接代理服务器)

试验中是只允许

http://blog.chinaunix.net/uid-25266990-id-2722465.html

参考:http://www.linuxidc.com/Linux/2017-02/140398.htm

http://www.xuexila.com/diannao/xitong/linux/648947.html

http://www.centoscn.com/CentOS/config/2016/0708/7599.html

时间: 2024-08-11 01:23:18

金庸武功之“碧血剑法”----squid做透明代理的相关文章

centos7.3安装squid的透明代理

关于squid这个强大的代理软件,已不须多言,自己也测试了一把,不过,在centos7.3安装测试的过程,出现了问题, 在做透明代理的时候,用iptables是可以成功的,而用firewall默认防火墙怎么也不成功,但真正知道了firwall的原理后,其实firewall已经帮我们做好了!请看 安装 #yum install squid -y 禁用selinux #vi /etc/sysconfig/selinux SELINUX=disabled #setenforce 0 临时关闭 打开路由

squid配置透明代理

搞了半个月的squid普通代理和透明代理终于差不多了!! squid配置透明代理主要有两步,见图: 第一个主要的步骤:设置客户端默认网关,让默认网关指向squid代理服务器 第二个主要的步骤:设置防火墙转发规则,让所有来自局域网段(本测试环境为192.168.10.0/24)都转发到squid的3128端口上

使用squid配置透明代理并对上网行为进行控制

使用Squid配置透明代理 环境:CentOS 6.4 + squid-3.1.10-20.el6_5.3.x86_64 1.检查squid是否默认安装,没有安装先安装 rpm -qa squid 假如查找不到,就安装squid: yum install squid 2.配置虚拟机的网络,一个网卡是内网,另一个是外网 内网:eth0 ip:192.168.10.209 netmask:255.255.255.0 gateway:192.168.10.1 外网:eth1 ip:10.10.10.1

Squid做反向代理缓存

环境介绍: 主机名 角色 IP地址 squid.contoso.com squid代理服务器 192.168.49.135 image01.contoso.com 图片服务器(web) 192.168.49.139 一.准备工作 以其中一台为例: [[email protected] etc]# iptables -L Chain INPUT (policy ACCEPT) target     prot opt source               destination Chain FO

金庸武功之“黯然销魂掌”---zabbix实现微信报警

一.部署环境 系统:CentOS 6.5x64 最小化安装 Server:192.168.93.126 Client:192.168.93.125 二.基础软件包安装 在server安装基础软件包,这里的环境使用yum安装,如果使用源码安装也是可以的. yum -y install wget vim tree gcc gcc-c++ autoconf httpd php mysql mysql-server php-mysql httpd-manual mod_ssl mod_perl mod_

金庸武功之“九阳神功”--kubenetes集群的那些事儿

一.前言 首先,要解决的就是安装来源问题,由于长城防火墙的原因,我们要想办法自己找来源. Kubernetes 编译的各种发行版安装包来源于 Github 上的另一个叫 release 的项目,地址 点这里,把这个项目 clone 下来,由于本人是 Centos 用户,所以进入 rpm 目录,在安装好 docker 的机器上执行那个 docker-build.sh 脚本即可编译 rpm 包,最后会生成到当前目录的 output 目录下,截图如下 1.git clone https://githu

金庸武功之“”天山折梅手“”-elk5.2

ELK是Elasticsearch.Logstash.Kibana的简称,这三者是核心套件,但并非全部. Elasticsearch是实时全文搜索和分析引擎,提供搜集.分析.存储数据三大功能:是一套开放REST和JAVA API等结构提供高效搜索功能,可扩展的分布式系统.它构建于Apache Lucene搜索引擎库之上. Logstash是一个用来搜集.分析.过滤日志的工具.它支持几乎任何类型的日志,包括系统日志.错误日志和自定义应用程序日志.它可以从许多来源接收日志,这些来源包括 syslog

金庸武功之““兰花拂穴手””--elk5.5安装

ELK是Elasticsearch.Logstash.Kibana的简称,这三者是核心套件,但并非全部. Elasticsearch是实时全文搜索和分析引擎,提供搜集.分析.存储数据三大功能:是一套开放REST和JAVA API等结构提供高效搜索功能,可扩展的分布式系统.它构建于Apache Lucene搜索引擎库之上. Logstash是一个用来搜集.分析.过滤日志的工具.它支持几乎任何类型的日志,包括系统日志.错误日志和自定义应用程序日志.它可以从许多来源接收日志,这些来源包括 syslog

金庸武功之“无毒掌”---jenkins安装部署

一.环境准备 centos7.2mini  SELinux关闭 防火墙关闭 二.JDK安装 安装方式:rpm安装  软件:jdk-7u80-linux-x64.rpm 进一步查看JDK信息: [[email protected] ~]# rpm -qa | grep java tzdata-java-2012c-1.el6.noarch java-1.6.0-openjdk-1.6.0.0-1.45.1.11.1.el6.x86_64     卸载OpenJDK,执行以下操作: [[email