Build your own CDN of eight with DNSPod and Squid to test and run SQUID
- 2020-05-09 19:40:20
- OfStack
1. Preparation
To test whether SQUID works, you must first resolve the www.naizhao.com domain name to the IP domain name of 2.2.2.2. As in chapter 1, if you are a netcom user and you don't need to do anything, DNSPod will return you the IP of 2.2.2.2. If you are a telecom user, or if IP is not 2.2.2.2, then you need to modify the hosts table of the system and add the corresponding records. Unlike the previous chapter, which modified the hosts table of the SQUID server, you now need to modify the hosts table of the system you used to test SQUID.
In addition to modifying the hosts table, we need a small tool called curl. The 1-like Linux/Unix system comes with this tool. If you use Windows, you need to download one from the following address and put it in D :(or wherever you like).
http: / / curl. haxx. se/latest cgi? curl= win32-nossl (32-bit system)
http: / / curl. haxx. se/latest cgi? curl= win64-nossl (64-bit system)
After downloading and unzip, we only need 1 curl.exe.
2. Run SQUID
Let's continue with chapter 1 and start SQUID in debug mode
cd usr/local/SQUID/sbin
. / SQUID - Nd 1
Then open the browser, input http: / / www naizhao. com, look at the output page is correct.
If a normal page is displayed, then SQUID is up and running. But we still need to confirm 1, whether the required page has been cached by SQUID.
3. Test SQUID
We use curl and enter the following command (Windows user please use the command line to run curl)
curl - I http: / / www naizhao. com /
200 OK HTTP / 1.0
Date: Sun, 08 Jul 2007 12:16:27 GMT
Server: NaiZhao Web Server / 1.0.0
Last-Modified: Wed, 13 Dec 2006 06:11:14 GMT
ETag: "e480 b 7665-1983-4417"
Accept - Ranges: bytes
Content - Length: 6531
Vary: Accept - Encoding
Content - Type: text/css
Age: 29155
X - Cache: MISS from cnc. naizhao. com
Via: 1.0 cnc naizhao. com: 80 (SQUID / 2.6 STABLE13)
Connection: close
Notice the output. The following line indicates that the cache was not hit. That is, the required files are not read from the cache. It is normal for MISS to appear on the first access to a file because the file does not exist in the cache.
X - Cache: MISS from cnc. naizhao. com
Then, we rerun the command once and continue to see the output
curl - I http: / / www naizhao. com /
200 OK HTTP / 1.0
Date: Sun, 08 Jul 2007 12:16:27 GMT
Server: NaiZhao Web Server / 1.0.0
Last-Modified: Wed, 13 Dec 2006 06:11:14 GMT
ETag: "e480 b 7665-1983-4417"
Accept - Ranges: bytes
Content - Length: 6531
Vary: Accept - Encoding
Content - Type: text/css
Age: 29155
X - Cache: HIT from cnc. naizhao. com
Via: 1.0 cnc naizhao. com: 80 (SQUID / 2.6 STABLE13)
Connection: close
As you can see, the output this time is already HIT. That is, the content is read from the cache.
If the second visit is still MISS, check to see if the page is cached. We can start from the following aspects:
Last-Modified: Wed, 13 Dec 2006 06:11:14 GMT checks whether the row changes with each visit. If the 1 changes, the page is dynamic and does not fit the SQUID cache. SQUID checks this line at each request to see if the page has expired and retrieves the expired page.
Cache-Control: no-store, no-cache, must-revalidate, post-check =0, pre-check =0 this line is responsible for controlling the cache. no-store, no-cache, must-revalidate, etc., all require SQUID to disable the caching of content and verify whether the page is expired at each request.
Expires: Thu, 19 Nov 1981 08:52:00 GMT expiration time is also considered to have expired and needs to be retrieved if it is greater than the current time. Such pages will not be cached.
Pragma: no-cache is also disabled.
You can check and correct yourself according to the above content, according to the actual needs of the site can be modified.
After making sure there are no problems, we can officially get SQUID running.
4. Official operation of SQUID
ulimit Hs - 65536
ulimit n - 65536
. / SQUID
Just use the command above to get SQUID running.
Run after input http: / / www naizhao. com see if access to normal.
5. Have SQUID boot with the system
CentOS makes SQUID follow the system to boot simply by editing /etc/ rc.local and adding the following at the end
ulimit Hs - 65536
ulimit n - 65536
/ usr/local/SQUID/sbin/SQUID