一、配置带认证的代理服务

 默认时,Squid本身不带任何认证程序,但是可以通过外部认证程序来实现用户认证。一般有以下的认证程序:LDAP认证、SMB认证、基于mysql的认证、基于sock5的密码认证和基于Radius的认证。下面介绍常用的ncsa实现的认证,ncsa是Squid源代码包自带的认证程序

 ncsa模块  在squid解压的目录中能找到。
[root@localhost NCSA]# tar zxvf squid-3.2.3.tar.bz2
[root@localhost NCSA]# cd /root/squid-3.2.3/helpers/basic_auth/NCSA/
[root@localhost NCSA]# pwd
/root/squid-3.2.3/helpers/basic_auth/NCSA
[root@localhost NCSA]# ll
总用量 124
-rwxr-xr-x. 1 root root 21769 11月 17 00:33 basic_ncsa_auth
-rw-r--r--. 1 1020 1020  2763 10月 20 20:39 basic_ncsa_auth.8
-rw-r--r--. 1 1020 1020  4557 10月 20 20:39 basic_ncsa_auth.cc
-rw-r--r--. 1 root root  4360 11月 17 00:33 basic_ncsa_auth.o
-rwxr-xr-x. 1 1020 1020    17 10月 20 20:39 config.test
-rw-r--r--. 1 1020 1020  5618 10月 20 20:39 crypt_md5.cc
-rw-r--r--. 1 1020 1020   641 10月 20 20:39 crypt_md5.h
-rw-r--r--. 1 root root  4060 11月 17 00:33 crypt_md5.o
-rw-r--r--. 1 root root 27681 11月 17 00:31 Makefile
-rw-r--r--. 1 1020 1020   457 10月 20 20:39 Makefile.am
-rw-r--r--. 1 1020 1020 27636 10月 20 20:40 Makefile.in
[root@localhost NCSA]# make && make install

编译成功后,会生成basic_ncsa_auth的可执行文件 到/usr/local/squid/libexec/  这个目录

[root@localhost ~]# cd /usr/local/squid/libexec/
[root@localhost libexec]# ls
basic_db_auth                 basic_pop3_auth    ext_file_userip_acl     ntlm_smb_lm_auth
basic_fake_auth               basic_radius_auth  ext_unix_group_acl      pinger
basic_getpwnam_auth           basic_smb_auth     ext_wbinfo_group_acl    unlinkd
basic_msnt_auth               basic_smb_auth.sh  helper-mux.pl           url_fake_rewrite
basic_msnt_multi_domain_auth  cachemgr.cgi       log_file_daemon         url_fake_rewrite.sh
basic_ncsa_auth               digest_file_auth   negotiate_wrapper_auth
basic_nis_auth                diskd              ntlm_fake_auth

拷贝basic_msnt_auth 文件到/usr/bin目录下

利用Apache携带的工具软件htpasswd在/usr/locad/squid/etc下生成密码文件,并添加相应的用户信息。该密码文件每行包含一个用户的信息,即用户名和密码。例如,用htpasswd生成密码文件passwd并添加用户guest 密码 guest:
[root@localhost libexec]#  htpasswd -c /usr/local/squid/etc/passwd  guest

修改squid.conf文件的相关选项
[root@localhost libexec]# vi /usr/local/squid/etc/squid.conf
在第一个: http_access 前加上:

auth_param basic program /usr/local/squid/libexec/basic_ncsa_auth  /usr/local/squid/etc/passwd
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
acl normal proxy_auth REQUIRED
http_access allow normal

5 重新启动Squid,密码认证生效。

[root@localhost libexec]# /usr/local/squid/sbin/squid -k kill
[root@localhost libexec]# /usr/local/squid/sbin/squid stop
[root@localhost libexec]# /usr/local/squid/sbin/squid start
[root@localhost libexec]# /usr/local/squid/sbin/squid -s

验证:如图