服务器之家:专注于服务器技术及软件下载分享
分类导航

云服务器|WEB服务器|FTP服务器|邮件服务器|虚拟主机|服务器安全|DNS服务器|服务器知识|Nginx|IIS|Tomcat|

服务器之家 - 服务器技术 - 服务器知识 - 用DNSPod和Squid打造自己的CDN (六) 编译并安装Squid

用DNSPod和Squid打造自己的CDN (六) 编译并安装Squid

2021-09-29 15:28服务器技术网 服务器知识

这篇文章主要介绍centos下编译并安装Squid的方法,需要的朋友可以参考下

第 6 章 编译并安装Squid
首先使用tar把源代码压缩包解压

tar zxvf squid-2.6.STABLE13.tar.gz

解压后,我们得到一个名为 squid-2.6.STABLE13 的目录。进入目录

cd squid-2.6.STABLE13

在configure前,我们必须要先设置cflags,这里我们假设CPU是intel core duo的,cpu family 6,model 14。通过 http://gentoo-wiki.com/Safe_Cflags#Intel_Core_Solo.2FDuo 可以找到对应的优化参数

CHOST="i686-pc-linux-gnu"
CFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer"
CXXFLAGS="${CFLAGS}"

然后通过export命令设置

export CHOST="i686-pc-linux-gnu"
export CFLAGS="-march=prescott -O2 -pipe -fomit-frame-pointer"
export CXXFLAGS="${CFLAGS}"

设置完成后,我们可以通过env命令来查看是否设置成功。

然后,我们开始configure源代码。使用下面的命令,把squid安装到/usr/local/squid目录中去。

./configure --prefix=/usr/local/squid --enable-follow-x-forwarded-for --enable-storeio=aufs,ufs --with-maxfd=65536 --with-pthreads --enable-dlmalloc --enable-poll --enable-stacktraces --enable-removal-policies=heap,lru --enable-delay-pools

对应参数的作用可以使用./configure --help得到。
这里大家要注意下,configure前面还有一个./,这个代表当前目录。意思是当前目录下面的configure文件。linux如果要执行当前目录的文件,必须要加上./。如果要执行当前目录下的下级目录里面的文件,可以不用加,比如bin/run。当然,./bin/run也是一样的效果。
接着我们会看到屏幕向下翻滚,出现一大堆checking for …的字样。一直等到下面的文字出现,并且停止,那么configure就算完成了。

config.status: creating tools/Makefile
config.status: creating include/autoconf.h
config.status: executing depfiles commands
[root@cnc squid-2.6.STABLE13]#

然后,我们输入make编译源代码,又是一行行的英文翻滚。是否有点感觉做黑客的味道?我们要做的还是继续等待下面的文字出现

make[2]: Leaving directory `/root/squid-2.6.STABLE13/tools'
make[1]: Leaving directory `/root/squid-2.6.STABLE13/tools'
make[1]: Entering directory `/root/squid-2.6.STABLE13'
make[1]: Nothing to be done for `all-am'.
make[1]: Leaving directory `/root/squid-2.6.STABLE13'
[root@cnc squid-2.6.STABLE13]#

这样源代码就算编译完成了。然后我们运行make install安装,等待下面的提示

make[2]: Leaving directory `/root/squid-2.6.STABLE13'
make[1]: Leaving directory `/root/squid-2.6.STABLE13'
[root@cnc squid-2.6.STABLE13]#

这里要注意:如果任何一个步骤出现带有error之类的警告,那么就是编译出错,需要检查到底是什么步骤出现问题并且改正。如果严格按照本文来编译,一般是不会出现错误的。另外,cflags参数使用不当同样会造成编译错误。
如果出现编译错误,必须要先make clean,然后重新make。(如果错误是在configure这步就不需要了)

到这里,squid就算是编译安装完毕了。我们可以到/usr/local/squid目录看看,里面已经躺着一大堆文件了。
[root@cnc squid-2.6.STABLE13]# cd /usr/local/squid
[root@cnc squid]# ls -lh
total 72K
drwxr-xr-x 2 root root 4.0K Jul  7 02:27 bin
drwxr-xr-x 2 root root 4.0K Jul  7 02:27 etc
drwxr-xr-x 2 root root 4.0K Jul  7 02:27 libexec
drwx------ 2 root root  16K Jun 15 08:09 lost+found
drwxr-xr-x 3 root root 4.0K Jul  7 02:27 man
drwxr-xr-x 2 root root 4.0K Jul  7 02:25 sbin
drwxr-xr-x 4 root root 4.0K Jul  7 02:25 share
drwxr-xr-x 3 root root 4.0K Jul  7 02:25 var
[root@cnc squid]#

接着我们要做的是配置squid。

延伸 · 阅读

精彩推荐