Install and configure squid2.7
CleverCode has recently studied the installation and configuration of squid. To sum up. Share with you.
1 Overview
The Proxy Server stands for Proxy Server. Its function is to obtain network information from the Proxy network user.
Squid is a software used to cache Internet data. It receives user download requests and automatically processes the downloaded data. When a user wants to download a home page, he/she can send an application to Squid to download the page instead of Squid. Then, Squid connects to the requested website and requests the home page, the home page is sent to the user and a backup is retained at the same time. When other users apply for the same page, Squid immediately transmits the saved backup to the user, making the user feel that the speed is quite fast. Squid can act as a proxy for HTTP, FTP, GOPHER, SSL, WAIS, and other protocols. Squid can be automatically processed and Squid can be set as needed to filter out unwanted items.
1.1 workflow when the current server has the data required by the client:
A. the client sends a data request to the proxy server;
B. the proxy server checks its own data cache;
C. The proxy server finds the data you want in the cache and retrieves the data;
D. the proxy server returns the data obtained from the cache to the client.
When the current server does not have the data required by the client:
1. The client sends a data request to the proxy server;
2. the proxy server checks its own data cache;
3. the proxy server does not find the data the user wants in the cache;
4. the proxy server sends data requests to the remote server on the Internet;
5. The remote server returns the response data;
6. the proxy server retrieves data from the remote server, returns the data to the client, and keeps a copy of the data in its own cache.
The Squid Proxy Server works on the TCP/IP application layer.
1.2 Squid classification based on different proxy types, Squid proxy can be divided into forward proxy and reverse proxy. Forward proxy can be divided into common proxy and transparent proxy according to different implementation methods.
Common Proxy: the client needs to specify the address and port of the proxy server in the browser;
Transparent Proxy: Applicable to enterprise gateway hosts (shared access to the Internet). The client does not need to specify the proxy server address, port, and other information, the proxy server needs to set a firewall policy to forward the client's Web access data to the proxy service program for processing;
Reverse Proxy: the proxy server is used to receive connection requests from the internet and then forward the requests to servers on the internal network, return the result obtained from the server to the Client Requesting connection from the internet. The proxy server is displayed as a server.
2. system environment operating system: CentOS release 6.5 (Final)
Squid version: squid-2.7.STABLE9-20101125.tar.gz
This installation of squid software:
Http://download.csdn.net/detail/clevercode/9337437.
3. Before installation, make sure to install the Linux support database. Otherwise, various errors may occur! For installation details of common supported libraries in Linux: http://blog.csdn.net/clevercode/article/details/45438401.
1)decompress squid-2.7.stable9-20101125.tar.gz
# Cd/usr/local/src/squid
# Tar zxvf squid-2.7.STABLE9-20101125.tar.gz
2) enter the decompressed directory
# Cd squid-2.7.STABLE9-20101125
3) Configuration
#./Configure -- prefix =/usr/local/squid \
-- Enable-gnuregex -- disable-carp -- enable-async-io = 240 \
-- With-pthreads -- enable-storeio = ufs, aufs, diskd \
-- Disable-wccp -- enable-icmp -- enable-kill-parent-hack \
-- Enable-cachemgr-hostname = localhost \
-- Enable-default-err-language = Simplify_Chinese \
-- With-maxfd = 65535 -- enable-epoll \
-- Enable-linux-netfilter -- enable-large-cache-files \
-- Enable-default-hostsfile =/etc/hosts -- with-dl \
-- With-large-files -- enable-delay-pools -- enable-snmp \
-- Enable-arp-acl -- prefix =/usr/local/squid
4) Compile
# Make
5) Installation
# Make install
6) configure the User Group Creation and initialization directory:
# Groupadd www # Add a www Group
# Useradd-g www-s/bin/false # create an nginx Running Account www and add it to the www group. www users are not allowed to log on to the system directly.
# Mkdir-p/data0/cache/logs/
# Chmod 755/data0/cache/-R
# Chown www. www/data0/cache-R
4. Practical Application
4.1 common proxy services are standard and traditional proxy services. The client needs to specify the address and port of the proxy server in the browser.
See http://www.cnblogs.com/mchina/p/3812190.html.
4.2 transparent proxy service is applicable to Gateway hosts of enterprises. The client does not need to specify the proxy server address, port, and other information, and forwards the Web access data of the client to the proxy service program for processing through iptables.
See http://www.cnblogs.com/mchina/p/3812190.html.
4.3 reverse proxy service provides cache acceleration for Internet users to access enterprise Web sites.
4.3.1 requirement Background The following experiment will simulate accessing different machines through different domain names, and simply implement load balancing in enterprise applications.
The client enters pic.domain.com and pic2.domain.com in the address bar of the browser to access the machine 192.168.142.130,
Access res.domain.com res2.domain.com and access 192.168.142.131.
Squid server: 192.168.142.133.
Web server: 192.168.142.130 and 192.168.142.131.
4.3.2 configure squid. conf
# Cd/usr/local/squid/etc/
# Mv squid. conf squid. conf. bak
# Vi/usr/local/squid/etc/squid. conf
# Host name visible_hostname static. squid-133 # Set the listening IP address and port number http_port 80 vhost vport # provide additional memory for squid. The total memory usage of squid is X * 10 + 15 + "cache_mem ", where X is the size occupied by squid cache (in GB) # For example, the following cache size is 100 M, that is, 0.1 GB, the total memory usage is 0.1*10 + 15 + 64 = 80 M. We recommend that you set the memory size to 1/3-1/2 of the physical memory size or more. Cache_mem 4096 MB # sets the maximum size of files cached on the squid disk. Files larger than 2 MB are not saved to the hard disk maximum_object_size_in_memory 2048 KB # Use lru for representation: it only replaces the memory_replacement_policy lru object that has not been accessed for a long time # This record file is used to record the addition and deletion of the buffer object (generally set to cache_store_log none, # To reduce the disk space occupied by log files, please note this .) Cache_store_log none # log File log format logformat combined %> a % ui % un [% tl] "% rm % ru HTTP/% rv" % Hs %
4.3.3 initial configuration #/usr/local/squid/sbin/squid-z
The following message indicates that the initialization is normal.
04:03:34 | Creating Swap Directories
4.3.4 start
# Background startup
#/Usr/local/squid/sbin/squid-s4.3.5 access
1) access http://res.domain.com/comm.js. As you can see, res.domain.com points to 192.168.142.133. However, the actual js file is retrieved from the 192.168.142.131 server.
2) Modify comm. js to the following content. However, the access to comm. js remains unchanged.
# Vi comm. js
This is from 192.168.142.131 js! I am change!
3) Clear the 133 cache and then access the data.
#/Usr/local/squid/bin/squidclient-m PURGE-p 80 "http://res.domain.com/comm.js"
4) Changing the URL also changes data. The key cached by squid can be interpreted as the md5 of the url. As long as the url changes, the data will be numbered.
Visit: http://res.domain.com/comm.js? R = 123456.
5) access images
5 common squid management commands
#/Usr/local/squid/sbin/squid-z initialize the cache space
#/Usr/local/squid/sbin/squid frontend startup (for output debugging)
#/Usr/local/squid/sbin/squid-s background startup
#/Usr/local/squid/sbin/squid-k shutdown stop
#/Usr/local/squid/sbin/squid-k reconfigure re-load the configuration file
#/Usr/local/squid/sbin/squid-k parse check conf
#/Usr/local/squid/sbin/squid-k rotate optimized fragments
#/Usr/local/squid/bin/squidclient-p 80 mgr: info view squid hits
#/Usr/local/squid/bin/squidclient-m PURGE-p 80 "http://res.domain.com/comm.js" delete specified URL Cache