免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2036 | 回复: 1
打印 上一主题 下一主题

[proxy] 基于NCSA的squid论证安装小结 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-08-31 18:30 |只看该作者 |倒序浏览
环境:red hat linux8.0+gcc
双网卡:eth0对外、eth1对内
安装时选route/firewall模式;系统默认没有安装squid与GCC.
GCC安装不必说了吧!
rpm -aq|grep squid  #查一下系统是否有squid包如果有rpm -e squid先移除它。嘿嘿,我没有用系统自带的做认证呀!:)

squid从http://www.squid-cache.org/下载:
wget http://www.squid-cache.org/Versions/v2/2.3/squid-2.3.STABLE2-src.tar.gz
tar zxvf squid-2.3.STABLE2-src.tar.gz  #先解
cd squid-2.3.STABLE2
./configure --prefix=/etc/squid/       #再编译
make
make install                           #再安装
cd auth_modules/NCSA
make
make install(系统自动在/etc/squid/bin下创建ncsa_auth可执行文件)

到这步已经完成大部分的安装工作了!
接下来进行配置工作:
首先编辑/etc/squid/etc/squid.conf这个文件
要让代理最基本的能跑起来(工作)只要改如下指下地方也就行了。
http_port 3128 (指定代理端口)
cache_dir ufs /var/spool/squid 100 16 256 (创建缓存目录,把前面的#号删除掉就行)
cache_access_log /var/log/squid/access.log (指定日志存放位置)

下面很重要:

authenticate_program /etc/squid/bin/ncsa_auth /etc/squid/etc/passwd  #指定鉴别程序,/etc/squid/bin/ncsa_auth为鉴别方法,/etc/squid/etc/passwd为相应的用户信息,此文件每行包含一个用户
信息,即用户名与密码。
acl auth_user proxy_auth REQUIRED  #配置访问表
#也可以改配置文件中的语句:
#acl password proxy_auth REQUIRED  #把前面的#号删除。当然前面的那一句就可以不要的其实是一样的只是列表名子不一样而已:)
acl all src 0.0.0.0/0.0.0.0        #定义一个包含全部的子网这样说对不对呀:)这是系统本身就有的

#下面是对访问表做策略。
http_access allow auth_user   #允许列表名为auth_user通过代理出去访问
http_access deny all          #默认拒绝所有

存盘!

生存客户端用户与相应口令:
添加一个用户名为user1用户:

/usr/bin/htpasswd -c /etc/squid/etc/passwd user1 #回车
系统提示输入密码与再次确认密码无误后系统会提示:
Adding password for user user1

当然也可以看htpasswd的所有执行功能与相关参数,可以直接运行/usr/bin/htpasswd回车
也能看明白的,嘿嘿外文要好的呢!:(

[root@test bin]# /usr/bin/htpasswd   
Usage:
        htpasswd [-cmdps] passwordfile username
        htpasswd -b[cmdps] passwordfile username password

        htpasswd -n[mdps] username
        htpasswd -nb[mdps] username password
-c  Create a new file.
-n  Don't update file; display results on stdout.
-m  Force MD5 encryption of the password.
-d  Force CRYPT encryption of the password (default).
-p  Do not encrypt the password (plaintext).
-s  Force SHA encryption of the password.
-b  Use the password from the command line rather than prompting for it.
On Windows, NetWare and TPF systems the '-m' flag is used by default.
On all other systems, the '-p' flag will probably not work.

注意下面这一点很重要:
改变/etc/squid/etc/passwd的属主,系统默认的root:root。
chown squid:squid /etc/squid/etc/passwd #回车

到这一步在代理服务上差不多就完成了:)
下面启动squid进程吧:
/etc/rc.d/init.d/squid -z    #创建缓存cache
/etc/rc.d/init.d/squid restart #重启squid进程

查看一下进程是否启动:
ps -ef|grep squid
如果能看到如下的信息表明带认证功能的squid已经起动了!
[root@test bin]# ps -ef|grep squid
root      1369     1  0 08:10 ?        00:00:00 squid -D
squid     1372  1369  0 08:10 ?        00:00:00 (squid) -D
squid     1373  1372  0 08:10 ?        00:00:00 (ncsa_auth) /etc/squid/etc/passw
squid     1374  1372  0 08:10 ?        00:00:00 (ncsa_auth) /etc/squid/etc/passw
squid     1375  1372  0 08:10 ?        00:00:00 (ncsa_auth) /etc/squid/etc/passw
squid     1376  1372  0 08:10 ?        00:00:00 (ncsa_auth) /etc/squid/etc/passw
squid     1377  1372  0 08:10 ?        00:00:00 (ncsa_auth) /etc/squid/etc/passw
squid     1378  1372  0 08:10 ?        00:00:00 (unlinkd)

如果没有看到,记住一定要查看相关的系统日志/var/log/message,一般来说如有问题,系统日志里都会有所反映记录的。

在手工执行如下语句吧!也可以把它们写到/etc/rc.d/rc.local文件中,让它们随机启动。
echo 1 >; /proc/sys/net/ipv4/ip_forward      #启动IP转发
iptables -t nat -A POSTROUTING -s 192.168.1.0/24  -j MASQUERADE  #指定可以进行NAT的段
iptables -t nat -A PREROUTING -s 0/0 -i eth1 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3128
#指定端口转发内网所以对80的请求转到代理服务器的相应端口


到目前完成了所以的配置了。接下来,找一台W2K的机器测试一下吧!
改IP与代理的eth1在一个段。网关添代理的eth1的地址。DNS为公网的好了。
改IE-》属性-》连接-》局域网设置-》在代理服务器下面选中"使用代理服务"地址(E)添上代理服务器eth1地址。端口(T)3128(你的/etc/squid/squid.conf里http_port 后的值)-》确定-》确定。
打开IE上网吧!
噢。会跳出一个对话框了吧!
防火墙:代理服务器的eth1地址
领域:Ssquid proxy-caching web server
用户名(u):
密码(p):

嘿嘿。赶快输入你/etc/squid/etc/passwd里所进行授过权的用户,进行上网冲浪吧!!!

如果这时候出现如下提示:
ERROR
Cache Access Denied

--------------------------------------------------------------------------------

While trying to retrieve the URL: http://www.linuxaid.com.cn/forum/

The following error was encountered:

Cache Access Denied.

Sorry, you are not currently allowed to request:

    http://www.linuxaid.com.cn/forum/
from this cache until you have authenticated yourself.

You need to use Netscape version 2.0 or greater, or Microsoft Internet Explorer 3.0, or an

HTTP/1.1 compliant browser for this to work. Please contact the cache administrator if you have

difficulties authenticating yourself or change your default password.

改变一下/etc/squid/etc/passwd的属主,嘿嘿,上面我重点提过呀!。

当然squid的很强大的代理功能,性能优化方面,这里我没有提及。着重说一种最最基本的认证方式:)请指教

论坛徽章:
0
2 [报告]
发表于 2004-09-01 19:58 |只看该作者

基于NCSA的squid论证安装小结

不错,我回头试试。

不过这么多用户名和密码太麻烦,能否就使用系统的用户名和密码呢?我添加用户名和密码麻烦,用户自己记密码也麻烦。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP