Ubuntu环境编译Squid 5

准备

注解

我的编译工作是在 私有云架构私有云KVM环境 进行的,采用 ref:libvirt_lvm_poolclone虚拟机 脚本构建的编译虚拟机。

编译Squid需要大量磁盘空间,默认clone出来虚拟机6G磁盘(实际空闲空间不足3G)因容量不足,首次编译失败。所以,采用 在libvirt LVM卷管理存储池中扩展虚拟机磁盘 将虚拟机磁盘扩展到 16GB 以完成编译工作。

  • 升级操作系统:

    sudo apt update && sudo apt upgrade -y && sudo reboot
    
  • 安装编译所需的工具:

    sudo apt -y install devscripts build-essential fakeroot debhelper dh-autoreconf dh-apparmor cdbs
    
  • 安装squid 5需要的的头文件包:

    sudo apt -y install \
        libcppunit-dev \
        libsasl2-dev \
        libxml2-dev \
        libkrb5-dev \
        libdb-dev \
        libnetfilter-conntrack-dev \
        libexpat1-dev \
        libcap-dev \
        libldap2-dev \
        libpam0g-dev \
        libgnutls28-dev \
        libssl-dev \
        libdbi-perl \
        libecap3 \
        libecap3-dev \
        libsystemd-dev \
        libtdb-dev
    

编译Squid 5

源代码包是从 http://http.debian.net/debian/pool/main/s/squid/ 获取,所以查看该目录下可以确定最新版本是 5.2

  • 创建配置文件 squid.ver :

编译squid 5脚本配置 squid.ver
#!/usr/bin/env bash

# set squid version
SQUID_VER="5.2"
SQUID_PKG="${SQUID_VER}-1"
  • 编译脚本 build_squid.sh :

编译squid 5脚本: build_squid.sh
#!/bin/bash

if [[ $EUID -eq 0  ]]; then
      echo "This script must NOT be run as root" 1>&2
        exit 1
fi

# drop squid build folder
rm -R build/squid

# we will be working in a subfolder make it
mkdir -p build/squid

# set squid version
source squid.ver

# decend into working directory
pushd build/squid

# get squid from debian experimental
wget http://http.debian.net/debian/pool/main/s/squid/squid_${SQUID_PKG}.dsc
wget http://http.debian.net/debian/pool/main/s/squid/squid_${SQUID_VER}.orig.tar.xz
wget http://http.debian.net/debian/pool/main/s/squid/squid_${SQUID_VER}.orig.tar.xz.asc
wget http://http.debian.net/debian/pool/main/s/squid/squid_${SQUID_PKG}.debian.tar.xz

# unpack the source package
dpkg-source -x squid_${SQUID_PKG}.dsc

# build the package
cd squid-${SQUID_VER} && dpkg-buildpackage -rfakeroot -b -us -uc

# and revert
popd
  • 执行编译:

    ./build_squid.sh
    
  • 安装脚本 install_squid.sh :

安装squid 5脚本: install_squid.sh
#!/bin/bash

if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

# set squid version
source squid.ver

# decend into working directory
pushd build/squid

# install squid packages
sudo apt-get install squid-langpack
dpkg --install squid-common_${SQUID_PKG}_all.deb
dpkg --install squid-openssl_${SQUID_PKG}_amd64.deb
dpkg --install squidclient_${SQUID_PKG}_amd64.deb

# and revert
popd

# verify the installed squid binary
systemctl stop squid && systemctl start squid && systemctl status squid && /usr/sbin/squid -v
  • 执行安装:

    ./install_squid.sh
    

参考