Squid

在server上面安装squid的过程很简单。

yum install squid

然后启动squid:

service squid start

再查看是否运行:

$ service squid status
Redirecting to /bin/systemctl status squid.service
● squid.service - Squid caching proxyLoaded: loaded (/usr/lib/systemd/system/squid.service; disabled; vendor preset: disabled)Active: active (running) since Tue 2022-01-04 14:26:36 CST; 5s agoProcess: 10368 ExecStart=/usr/sbin/squid $SQUID_OPTS -f $SQUID_CONF (code=exited, status=0/SUCCESS)Process: 10362 ExecStartPre=/usr/libexec/squid/cache_swap.sh (code=exited, status=0/SUCCESS)Main PID: 10371 (squid)Tasks: 3Memory: 13.5MCGroup: /system.slice/squid.service├─10371 /usr/sbin/squid -f /etc/squid/squid.conf├─10373 (squid-1) -f /etc/squid/squid.conf└─10374 (logfile-daemon) /var/log/squid/access.logJan 04 14:26:36 iZj6c45po7f4v416r8l94nZ systemd[1]: Starting Squid caching proxy...
Jan 04 14:26:36 iZj6c45po7f4v416r8l94nZ squid[10371]: Squid Parent: will start 1 kids
Jan 04 14:26:36 iZj6c45po7f4v416r8l94nZ squid[10371]: Squid Parent: (squid-1) process 10373 started
Jan 04 14:26:36 iZj6c45po7f4v416r8l94nZ systemd[1]: Started Squid caching proxy.

再查看port是否在监听中:

$ netstat -lntpo | grep 312
tcp6       0      0 :::3128                 :::*                    LISTEN      9016/(squid-1)       off (0.00/0/0)

发现只有IPV6,没有IPV4的监听。这可怎么办?在网上搜索,发现需要修改squid的配置文件:

vim /etc/squid/squid.conf

找到http_port行,将http_port 3128改为如下:

# Squid normally listens to port 3128
http_port 0.0.0.0:3128

再重启squid并查看监听端口:

$ service squid restart
$ netstat -lntp | grep 3128
tcp        0      0 0.0.0.0:3128            0.0.0.0:*               LISTEN      10373/(squid-1)

使用curl试试是否可以通过代理访问google

$  curl -x localhost:3128 www.google.com
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="zh-HK"><head><meta content="text/html; charset=UTF-8"...

测试成功。

Stunnel

接下来安装stunnel:

yum install stunnel

生成自签名证书:

openssl req -new -x509 -days 3650 -nodes -out stunnel.pem -keyout stunnel.pem

将生成的证书,复制到/etc/stunnel文件夹下

cp -p stunnel.pem /etc/stunnel

修改stunnel的配置/etc/stunnle/stunnle.conf

; 设置工作目录,没有目录需要先创建
chroot = /var/run/stunnel/
; 设置stunnel的pid文件路径(在chroot下)
pid = /stunnel.pid
; 设置stunnel工作的用户(组)
setuid = root
setgid = root; 开启日志等级:emerg (0), alert (1), crit (2), err (3), warning (4), notice (5), info (6), or debug (7)
; 默认为5
debug = 7
; 日志文件路径(我的server的版本有个bug,这个文件也被放在chroot路径下了,client的版本则是独立的=。=#)
output = /stunnel.log; 证书文件,就是在本文2.2中用openssl生成的自签名证书(server端必须设置这两项)
cert = /etc/stunnel/stunnel.pem
; 私钥文件
key = /etc/stunnel/stunnel.pem; 设置stunnel服务,可以设置多个服务,监听同的端口,并发给不同的server。
; 自定义服务名squid-proxy
[squid-proxy]
; 服务监听的端口,client要连接这个端口与server通信
accept = 3129
; 服务要连接的端口,连接到squid的3128端口,将数据发给squid
connect = localhost:3128

启动stunnel:

$ /usr/bin/stunnel /etc/stunnel/stunnel.conf
Clients allowed=31999
stunnel 4.56 on x86_64-redhat-linux-gnu platform
Compiled/running with OpenSSL 1.0.1e-fips 11 Feb 2013
Threading:PTHREAD Sockets:POLL,IPv6 SSL:ENGINE,OCSP,FIPS Auth:LIBWRAP
Reading configuration from file /etc/stunnel/stunnel.conf
FIPS mode is enabled
Compression not enabled
Snagged 64 random bytes from /root/.rnd
Wrote 1024 new random bytes to /root/.rnd
PRNG seeded successfully
Initializing service [squid-proxy]
Insecure file permissions on /etc/stunnel/stunnel.pem
Certificate: /etc/stunnel/stunnel.pem
Certificate loaded
Key file: /etc/stunnel/stunnel.pem
Private key loaded
Could not load DH parameters from /etc/stunnel/stunnel.pem
Using hardcoded DH parameters
DH initialized with 2048-bit key
ECDH initialized with curve prime256v1
SSL options set: 0x01000004
Configuration successful
Service [squid-proxy] (FD=12) bound to 0.0.0.0:19908
chroot: No such file or directory (2)
Closing service [squid-proxy]
Service [squid-proxy] closed (FD=12)
Sessions cached before flush: 0
Sessions cached after flush: 0
Service [squid-proxy] closed
str_stats: 15 block(s), 1233 data byte(s), 870 control byte(s)

但是在查看stunnel进程时,发现stunnel进程结束了。这是怎么回事?

后来再查资料,发现有资料提到配置项client = no。于是修改配置文件如下:

$ cat /etc/stunnel/stunnel.conf
chroot = /var/run/stunnel/
pid = /stunnel.pid
setuid = root
setgid = root
debug = 7
;compression = zlib
output = stunnel.log
cert = /etc/stunnel/stunnel.pem
key = /etc/stunnel/stunnel.pem
CAfile = /etc/stunnel/stunnel.pem
client = no[squid-proxy]
accept = 19908
connect = localhost:3128

上面配置项也加了CAfile = /etc/stunnel/stunnel.pem。再启动stunnel,通过ps看起来运行起来了。

$ stunnel /etc/stunnel/stunnel.conf
$ ps -ef | grep stunnel
root      6813     1  0 10:01 pts/0    00:00:00 stunnel /etc/stunnel/stunnel.conf
root      6814     1  0 10:01 pts/0    00:00:00 stunnel /etc/stunnel/stunnel.conf
root      6815     1  0 10:01 pts/0    00:00:00 stunnel /etc/stunnel/stunnel.conf
root      6816     1  0 10:01 pts/0    00:00:00 stunnel /etc/stunnel/stunnel.conf
root      6817     1  0 10:01 pts/0    00:00:00 stunnel /etc/stunnel/stunnel.conf
root      6818     1  0 10:01 ?        00:00:00 stunnel /etc/stunnel/stunnel.conf
root      6825  4726  0 10:01 pts/0    00:00:00 grep --color=auto stunnel

Stunnel 客户端

服务端处理完了以后,开始部署客户端。

$ yum install stunnel

编辑/etc/stunnel/stunnel.conf

$ cat stunnel.conf
client = yes
pid = /tmp/stunnel.pid
debug = 7
foreground = no
verify = 0[proxy]
accept = 0.0.0.0:19908
connect = 192.168.0.154:19908

检查server是否可以连上:

$ telnet 192.168.0.154 19908
Trying 192.168.0.154...
Connected to 192.168.0.154.
Escape character is '^]'.
^]qtelnet> q
Connection closed.

启动客户端的stunnel

$ stunnel /etc/stunnel/stunnel.conf
$ ps -ef | grep stunnel
root      4872     1  0 10:09 pts/1    00:00:00 stunnel /etc/stunnel/stunnel.conf
root      4873     1  0 10:09 pts/1    00:00:00 stunnel /etc/stunnel/stunnel.conf
root      4874     1  0 10:09 pts/1    00:00:00 stunnel /etc/stunnel/stunnel.conf
root      4875     1  0 10:09 pts/1    00:00:00 stunnel /etc/stunnel/stunnel.conf
root      4876     1  0 10:09 pts/1    00:00:00 stunnel /etc/stunnel/stunnel.conf
root      4877     1  0 10:09 ?        00:00:00 stunnel /etc/stunnel/stunnel.conf
root      4879  4841  0 10:09 pts/1    00:00:00 grep --color=auto stunnel

Firefox 代理设置

在Firefox的菜单“设置”页面,最后是“网络设置”,点击“设置”按钮:


然后在Firefox中打开网页,测试OK。

CentOS 7安装Stunnel和Squid相关推荐

  1. CentOS 7安装squid代理服务器

    Squid,一个高性能的代理缓存服务器,支持FTP.gopher.HTTP协议. Squid,一个缓存Internet 数据的软件,其接收用户的下载申请(作为代理服务器),并自动处理所下载的数据,并返 ...

  2. CentOS 8 安装图解

    继 RHEL 8 发布之后,CentOS 社区也发布了让人期待已久的 CentOS 8,并发布了两种模式: CentOS stream:滚动发布的 Linux 发行版,适用于需要频繁更新的开发者 Ce ...

  3. CentOS 6 安装配置教程【完整版】

    [url]http://yp.oss.org.cn/blog/show_resource.php?resource_id=1069[/url] 一.准备安装CentOS 6 1.CentOS简介 Ce ...

  4. CentOS 8 安装笔记

    CentOS 8 安装笔记 第一部分 概述 初始版本:CentOS 8.0.1905 继 RHEL 8 发布之后,CentOS 社区也发布了让人期待已久的 CentOS 8,并发布了两种模式: Cen ...

  5. centOS 自动安装php

    centos下安装php #yum install -y php 这个只安装PHP 建议安装运行库及MySQL的支持 #yum install -y php php-devel php-mysql 如 ...

  6. Centos下安装mysql 总结

    一.MySQL安装 Centos下安装mysql 请点开:http://www.centoscn.com/CentosServer/sql/2013/0817/1285.html 二.MySQL的几个 ...

  7. linux卸载欧朋浏览器,如何在Centos下安装opera浏览器

    如何在Centos下安装opera浏览器 ,Opera目前是Linux平台上性能最优的浏览器,而且Opera中国团队本身即定位于Opera的研发中心,主要也是负责全球Linux平台项目的开发,这个版本 ...

  8. 如何在Ubuntu/CentOS上安装Linux内核4.0

    如何在Ubuntu/CentOS上安装Linux内核4.0 大家好,今天我们学习一下如何从Elrepo或者源代码来安装最新的Linux内核4.0.代号为'Hurr durr I'm a sheep'的 ...

  9. CentOS 7 安装 Jenkins

    CentOS 7 安装 Jenkins 准备工作 首选需要安装JAVA环境 这个简单不说了 如果你的系统没有自带git,那么也需要安装一个 yum install git 1.安装 第一种方法 sud ...

最新文章

  1. 比特币现金将出新招,推动比特币现金使用
  2. Java中MySQL事务处理举例
  3. 史上最拉风年货?苏宁门店私人飞机开售 网友:这个真香不了吧
  4. jmeter 及测试
  5. redis set 超时_redis分布式锁3种实现方式对比分析总结
  6. android-getTextSize返回值是以像素(px)为单位的,setTextSize()以sp为单位
  7. 如何对物联网数据进行大数据分析
  8. Linux课程第二十四天学习笔记
  9. 【Java万字笔记】重要基础知识点整理与汇总
  10. granfana 使用cdn模式加速页面加载
  11. 摄影——相机的成像原理
  12. 看看这模型!“桥梁建设国家队”是如何用CC来三维建模的?
  13. 夜神模拟器 Nox Player 雷电模拟器 掉线 连不上 运行不显示的解决方案
  14. 上海计算机5年制大专学校,上海五年一贯制大专学校有哪些
  15. Micro SD 卡(TF卡) spi 模式实现方法
  16. phpStudy配置站点解决各种不能访问问题(本地可www.xx.com访问)
  17. 数据结构 - 逻辑结构和存储结构
  18. linux服务器上装r,linux服务器安装R语言及Rstudio server
  19. 一个数据分析师,在公司里的主要职责是什么?
  20. Siri, Alexa, Cortana, 为什么所有的语音助手都是“她”?

热门文章

  1. 移位运算符<< >> >>>的使用
  2. 强化学习(Reinforcement Learning)入门知识
  3. CAD二次开发--系统找不到指定的文件/应用程序不支持实时(JIT)调试解决办法【即:C#调用外部exe文件在CAD内部执行失败处理办法】
  4. Excel一键将中文括号替换为英文括号
  5. 为什么银行卡收不到消息服务器,你为什么收不到银行短信?
  6. 考华为认证HCIA还有含金量吗?
  7. 移动端布局——Flex布局
  8. 单例模式懒汉单例实现
  9. linux 根据pid查看占用端口,根据端口查看pid
  10. 留在一线,逃离一线?我从上海举家回成都的生活经历告诉你。。。