您想了解如何在Ubuntu Linux上安装Squid吗? 在本教程中,我们将向您展示如何在Ubuntu Linux版本17上安装和配置代理服务器Squid。

硬件清单:

以下部分介绍了用于创建此Squid教程的设备列表。

上面列出的每一件硬件都可以在亚马逊网站上找到。

鱿鱼相关教程:

在此页面上,我们提供了与Squid相关的教程列表的快速访问。

教程 – Ubuntu Linux上的Squid

在Linux控制台上,使用以下命令设置正确的时区。

# dpkg-reconfigure tzdata

安装Ntpdate包并立即设置正确的日期和时间。

# apt-get install ntpdate
# ntpdate pool.ntp.br

在我们的示例中,Ntpdate命令用于使用巴西服务器pool.ntp.br设置正确的日期和时间

我们来安装NTP服务。

# apt-get install ntp

NTP是保持我们的服务器更新的服务。

使用命令日期检查Ubuntu Linux上配置的日期和时间。

# date

如果系统显示正确的日期和时间,则表示您已正确执行所有步骤。

使用以下命令安装所需的包。

# apt-get update
# apt-get install build-essential openssl libssl-dev

下载,编译和安装Squid包。

# mkdir /downloads
# cd /downloads
# wget http://www.squid-cache.org/Versions/v3/3.5/squid-3.5.27.tar.gz
# tar -zxvf squid-3.5.27.tar.gz
# cd squid-3.5.27
# ./configure –with-default-user=proxy
# make
# make install

这是Squid Package安装的原始squid配置文件。

# vi /usr/local/squid/etc/squid.conf

acl localnet src 10.0.0.0/8
acl localnet src 172.16.0.0/12
acl localnet src 192.168.0.0/16
acl localnet src fc00::/7
acl localnet src fe80::/10

acl SSL_ports port 443
acl Safe_ports port 80
acl Safe_ports port 21
acl Safe_ports port 443
acl Safe_ports port 70
acl Safe_ports port 210
acl Safe_ports port 1025-65535
acl Safe_ports port 280
acl Safe_ports port 488
acl Safe_ports port 591
acl Safe_ports port 777
acl CONNECT method CONNECT

http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localnet
http_access allow localhost
http_access deny all

http_port 3128

coredump_dir /usr/local/squid/var/cache/squid

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

这是我们配置的新文件。

更改的指令以粗体突出显示。

# vi /usr/local/squid/etc/squid.conf

acl localnet src 192.168.0.0/24  # My internal Network

acl SSL_ports port 443
acl Safe_ports port 80
acl Safe_ports port 21
acl Safe_ports port 443
acl Safe_ports port 70
acl Safe_ports port 210
acl Safe_ports port 1025-65535
acl Safe_ports port 280
acl Safe_ports port 488
acl Safe_ports port 591
acl Safe_ports port 777
acl CONNECT method CONNECT

http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localnet
http_access allow localhost
http_access deny all

http_port 3128

coredump_dir /usr/local/squid/var/cache/squid
cache_dir ufs /usr/local/squid/var/cache/squid 1000 16 256  # 1GB as Cache

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

我的配置只是基本的。

强烈建议您研究此配置文件以改进配置。

使用以下命令创建必要的缓存文件夹。

# chown -R proxy:proxy /usr/local/squid -R
# /usr/local/squid/sbin/squid -z

使用以下命令启动Squid服务。

# /usr/local/squid/sbin/squid -d 10

如果一切正常,您应该在屏幕上看到以下消息:

Starting Squid Cache version 3.5.27 for x86_64-pc-linux-gnu…
Service Name: squid
Process ID 19569
Process Roles: worker
With 1024 file descriptors available
Initializing IP Cache…
DNS Socket created at [::], FD 6
DNS Socket created at 0.0.0.0, FD 8
Adding nameserver 172.31.0.2 from /etc/resolv.conf
Adding domain us-west-2.compute.internal from /etc/resolv.conf
Logfile: opening log daemon:/usr/local/squid/var/logs/access.log
Logfile Daemon: opening log /usr/local/squid/var/logs/access.log
Unlinkd pipe opened on FD 14
Store logging disabled
Swap maxSize 1024000 + 262144 KB, estimated 98934 objects
Target number of buckets: 4946
Using 8192 Store buckets
Max Mem size: 262144 KB
Max Swap size: 1024000 KB
Rebuilding storage in /usr/local/squid/var/cache/squid (no log)
Using Least Load store dir selection
Set Current Directory to /usr/local/squid/var/cache/squid
Finished loading MIME types and icons.
HTCP Disabled.
Squid plugin modules loaded: 0
Adaptation support is off.
Accepting HTTP Socket connections at local=[::]:3128 remote=[::] FD 16 flags=9
Done scanning /usr/local/squid/var/cache/squid dir (0 entries)
Finished rebuilding storage from disk.
0 Entries scanned
0 Invalid entries.
0 With invalid flags.
0 Objects loaded.
0 Objects expired.
0 Objects cancelled.
0 Duplicate URLs purged.
0 Swapfile clashes avoided.
Took 0.04 seconds ( 0.00 objects/sec).
Beginning Validation Procedure
Completed Validation Procedure
Validated 0 Entries
store_swap_size = 0.00 KB
storeLateRelease: released 0 objects

要测试安装,请转到位于内部网络上的计算机,并将其浏览器配置为使用Squid服务器的IP地址和TCP端口3128作为代理服务器。