jiay 发表于 2015-11-19 12:48:02

一个简单的Squid服务器

  本文参考http://blog.s135.com/book/squid/chap07.html#a13,基本上是一步步照做
  
  一、服务器主机: CentOS5.3   159.226.3.209   
  局域网环境: 网络设置:172.16.2.*/24   网关:172.16.2.254
  
  说明:由于局域网所用网关已另行设置好,故服务器主机与局域网事先已经连通,那么服务器主机也就不必设置双IP,网关,甚至DNS等。如果你的局域网除了服务器主机外没有其它对外(外网,其它局域网)接口,就需要在服务器主机上设置双IP,风头,DNS等。
  
  二、安装squid,或者yum install squid,或者下载源代码,编译安装
  
  三、配置squid:
##显式指定主机名,这应该是squid的一个bugvisible_hostname xcch##代理服务器监听的端口http_port 4444##缓存目录 大小(兆) 第一级子目录个数 第二级子目录个数cache_mem 512 MBcache_dir       ufs   /mnt/server209/squid/logs 40960 16 256##日志文件路径cache_access_log      /mnt/server209/squid/logs/access.logcache_log               /mnt/server209/squid/logs/cache.logcache_store_log         /mnt/server209/squid/logs/store.log####访问控制,分两部分:########################本机的访问控制acl all         src   0.0.0.0/0.0.0.0acl localhost   src   127.0.0.1/32#######客户端访问控制acl safe_portsport    80 21 443 563 70 210 280 488 591 777 1025-65535acl ssl_ports   port    443 563acl normal      src   172.16.2.90-172.16.2.99http_access allow localhosthttp_access deny !safe_portshttp_access allow normalhttp_access denyall

说明:这里把日志文件重新设置了,默认的是/var/spool/log/下,
  四、运行
  
  运行前,先检查配置文件是否有效:
  $   squid   -k   parse
  如果没有任何输出,说明有效
  
  生成Cache目录:
  $   squid   -zX
  
  运行:
  $   squid   -Ndl   #前台运行
  或者:
  $   squid   -s         #后台运行
  
  五、配置客户端

1. firefox代理设置

       菜单:编辑->首选项->高级->网络->设置->手动配置代理
          把http代理,端口号填好,选上为所有协议使用相同代理,最后点确定即可。

2.   wget 代理设置

    打开/etc/wgetrc,找到如下行:
# You can set the default proxies for Wget to use for http and ftp.# They will override the value in the environment.# http_proxy = 159.226.3.209:4444/# ftp_proxy = 159.226.3.209:4444/

   将后两行前面的注释去掉,把你的代理地址、端口敲进去即可。

3. yum代理设置

    要设置所有 yum 操作都使用代理服务器,可以在 /etc/yum.conf 中设置代理服务器的信息。proxy 配置项必须设定为完整的代理服务器的 URL,包含 TCP 端口号在内。如果您的代理服务器要求用户名和密码,可以用 proxy_username 和 proxy_password 配置项来指定它们。示例如下:
#代理服务器 - proxy server:port numberproxy=http://159.226.3.209:4444#proxy=http://mycache.mydomain.com:port#用于 yum 连接的帐户细节proxy_username=yum-userproxy_password=qwerty

   上面的是为所有用户配置,如果为单用户配置,配置是在 ~/.bash_profile 中:

   # 这个帐号使用的代理服务器和用户名/密码
http_proxy="http://username:passwd@159.226.3.209:3128"
export http_proxy
             版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: 一个简单的Squid服务器