1. FreeBSD第二天 <构建内网DNS服务器及Squid代理服务器> 
  2.  
  3. 本系统主要是是为了学习FreeBSD这个系统,文中不少FREEBSD内容来自<构建高可用Linux服务器> 
  4. 在此,感谢抚琴煮酒. 
  5.  
  6. 上午把昨天的内容在一台真实服务器上重新操作一次!安装了vim,bash,sudo,alex. 
  7. 今天主要是内容是将其配置成DNS服务器及Squid代理服务器使用。 
  8.  
  9. 一、安装DNS. <发现portsnap里面的资源很多!光一个DNS服务器,就有不少可以选择。> 
  10. 在这里我使用的是bind96 
  11. # cd /usr/ports/dns/bind96 
  12. # make install clean 
  13.  
  14. 配置: 
  15. # vim /etc/namedb/named.conf  
  16. --------------------------->因为只是用于转发,所以里面没有建正反向解析 
  17. options { 
  18.   directory "/etc/namedb/working"; 
  19.   pid-file  "/var/run/named/pid"; 
  20.   dump-file "/var/dump/named_dump.db"; 
  21.   statistics-file "/var/stats/named.stats"; 
  22.   forward only; 
  23.   forwarders { 202.96.128.86; }; 
  24.   listen-on { 0.0.0.0; }; 
  25.  ............省略其他未修改内容 
  26. ------------------------------- 
  27.  
  28. # /etc/rc.d/named start 
  29. Cannot 'start' named. Set named_enable to YES in /etc/rc.conf or use 'onestart' instead of 'start'. 
  30. # echo "named_enable="YES" " >> /etc/rc.conf  
  31.  
  32. # /etc/rc.d/named restart 
  33. Stopping named. 
  34. Waiting for_ PIDS: 30182. 
  35. Starting named. 
  36.  
  37. 查看端口的侦听情况: 
  38. # netstat -an | grep .53 
  39. tcp6       0      0 ::1.953                *.*                    LISTEN 
  40. tcp4       0      0 127.0.0.1.953          *.*                    LISTEN 
  41. tcp4       0      0 127.0.0.1.53           *.*                    LISTEN 
  42. tcp4       0      0 192.168.10.29.53       *.*                    LISTEN 
  43. tcp4       0      0 192.168.1.29.53        *.*                    LISTEN 
  44.  
  45.  
  46. 找台客户机测试下: 
  47. # dig @192.168.10.29 www.51cto.com 
  48.  
  49. <<>> DiG 9.7.0-P1 <<>> @192.168.10.29 www.51cto.com 
  50. ; (1 server found) 
  51. ;; global options: +cmd 
  52. ;; Got answer: 
  53. ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30800 
  54. ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0 
  55.  
  56. ;; QUESTION SECTION: 
  57. ;www.51cto.com.         IN  A 
  58.  
  59. ;; ANSWER SECTION: 
  60. www.51cto.com.      464 IN  A   118.144.78.38 
  61.  
  62. ;; Query time: 574 msec 
  63. ;; SERVER: 192.168.10.29#53(192.168.10.29) 
  64. ;; WHEN: Thu Nov 17 13:13:28 2011 
  65. ;; MSG SIZE  rcvd: 47 
  66.  
  67.  
  68. 二、安装squid代理服务 
  69. 找到位置 
  70. # find /usr/ports/ -name "squid" 
  71. /usr/ports/www/squid 
  72. # cd /usr/ports/www/squid 
  73. # make install clean  
  74. 出现选项时,我选择了常规的选项,如SQUID_SNMP,SQUID_AUFS,SQUID_ARP_ACL等。 
  75.  
  76. 相关的提示内容: 
  77. ===> post-installation information for squid-2.7.9_1: 
  78.  
  79.      o You can find the configuration files for this package in the 
  80.        directory /usr/local/etc/squid. 
  81.  
  82.      o The default cache directory is /var/squid/cache. 
  83.        The default log directory is /var/squid/logs. 
  84.  
  85.        Note: 
  86.        You must initialize new cache directories before you can start 
  87.        squid.  Do this by running "squid -z" as 'root' or 'squid'. 
  88.        If your cache directories are already initialized (e.g. after an 
  89.        upgrade of squid) you do not need to initialize them again. 
  90.  
  91.      o The default configuration will deny everyone but local networks 
  92.        as defined in RFC 1918 access to the proxy service. 
  93.        Edit the "http_access allow/deny" directives in 
  94.        /usr/local/etc/squid/squid.conf to suit your needs. 
  95.  
  96.      To enable Squid, set squid_enable=yes in either 
  97.      /etc/rc.conf, /etc/rc.conf.local or /etc/rc.conf.d/squid 
  98.      Please see /usr/local/etc/rc.d/squid for_ further details. 
  99.  
  100.      Note: 
  101.      If you just updated your Squid installation from 2.6 or earlier, 
  102.      make sure to check your Squid configuration against the 2.7 default 
  103.      configuration file /usr/local/etc/squid/squid.conf.default. 
  104.  
  105.      Additionally, you should check your configuration by calling 
  106.      'squid -f /path/to/squid.conf -k parse' before starting Squid. 
  107.  
  108.  
  109. 开工,修改squid.conf的配置文件: 
  110.  
  111. # mkdir /usr/cache 
  112. # id squid 
  113. uid=100(squid) gid=100(squid) groups=100(squid) 
  114.  
  115. # chown -R squid.squid /usr/cache 
  116. # squid -z 
  117. 2011/11/17 22:12:50| Creating Swap Directories 
  118.  
  119. # ls -l /usr/cache/ 
  120. total 66 
  121. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 00 
  122. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 01 
  123. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 02 
  124. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 03 
  125. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 04 
  126. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 05 
  127. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 06 
  128. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 07 
  129. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 08 
  130. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 09 
  131. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 0A 
  132. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 0B 
  133. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 0C 
  134. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 0D 
  135. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 0E 
  136. drwxr-x---  258 squid  squid  3584 Nov 17 22:12 0F 
  137. -rw-r-----    1 squid  squid    48 Nov 17 22:13 swap.state 
  138. 配置文件: 
  139. # cat squid.conf   基础配置 
  140. acl all src all 
  141. acl manager proto cache_object 
  142. acl localhost src 127.0.0.1/32 
  143. acl localnet src 192.168.10.0/24 
  144. acl SSL_ports port 443 
  145. acl Safe_ports port 80      # http 
  146. acl Safe_ports port 21      # ftp 
  147. acl Safe_ports port 443     # https 
  148. acl Safe_ports port 70      # gopher 
  149. acl Safe_ports port 210     # wais 
  150. acl Safe_ports port 1025-65535  # unregistered ports 
  151. acl Safe_ports port 280     # http-mgmt 
  152. acl Safe_ports port 488     # gss-http 
  153. acl Safe_ports port 591     # filemaker 
  154. acl Safe_ports port 777     # multiling http 
  155. acl CONNECT method CONNECT 
  156. http_access allow manager localhost 
  157. http_access deny manager 
  158. http_access deny !Safe_ports 
  159. http_access deny CONNECT !SSL_ports 
  160. http_access allow localnet 
  161. http_access deny all 
  162.  
  163. http_port 3128 
  164. cache_mem 128 MB 
  165. cache_dir ufs /usr/cache 1000 16 256 
  166. minimum_object_size 0 KB 
  167. maximum_object_size 4096 KB 
  168. cache_swap_low 90 
  169. cache_swap_high 95 
  170. update_headers on 
  171. access_log /var/squid/logs/access.log squid 
  172. cache_store_log none 
  173. logfile_rotate 5 
  174. pid_filename /var/squid/logs/squid.pid 
  175. coredump_dir /var/squid/cache 
  176.  
  177. 启动squid 
  178. # squid -NdD1 &  
  179. # netstat -anl | grep .3128 
  180. tcp4       0      0 *.3128                 *.*                    LISTEN 
  181.  
  182. 看看自己装的是哪个版本? 
  183. # squid -v 
  184. Squid Cache: Version 2.7.STABLE9 
  185.  
  186. 将其放到rc.conf 里,开机自动启动
    echo "squid_enable="YES"" >> /etc/rc.conf
  187.  
  188. 现在找个客户机测试下!
  189.  
  190. 我已经在我的P3(512M)主机上跑起来了。