Build your own CDN of 5 with DNSPod and Squid to prepare for the installation of Squid

  • 2020-05-09 19:40:33
  • OfStack

Chapter 5 preliminary preparation for installing Squid

Starting with this chapter, you will learn how to install and compile the program under Linux, how to optimize the program compilation, and finally how to install Squid by means of source code compilation.

1. Basic knowledge of the following program installation for Linux

A. Classification of program installation packages
Usually everyone in Windows under the installation program, 1 is directly run the installation program, and then the installation program will compile the good binary files into the system, the final completion of the installation process.
Below Linux, the installer has more freedom than Windows. Because most of the following Linux stuff is open source, the program is usually provided as a base 2 package or source code package.
Base 2 packages will also have different packaging and management methods (similar to zip and rar, but more advanced). The two most common software packages are rpm (packages for systems like redhat, suse, etc.) and deb (debian, ubuntu). The software package installed on the machine is much, natural need 1 software to manage, update. Therefore, there are package management and upgrade software like yum (rpm) and apt (deb).
Source code package, this package is relatively simple, 1 is directly packaged into a compressed source code file, suffix 1 is tar.gz or tar.bz2
It is easy to install the software through the package management software. After setting up the installation source of the software, you can install the software using the following command:
yum install php (yum)
apt-get install php5(apt)
If you don't know the exact name of the package you want to install, you can search using the following methods:
yum search php(yum)
apt-cache search php(apt)
This article focuses on the installation of source code packages.

B. Install the program through the source code package
In general, the program from the source code to normal use, need to go through three steps: 1. According to the system environment to configure the source code (configure); 2. 2. Compiler (make); 3. Installation procedure (make install).
a. Source code configuration
By running the configure script, you can automatically find the basic environment, commands and libraries of the program you need to compile, and generate the Makefile files you need to compile the files. This script is needed because there are so many distributions of Linux that each version has a different environment. The configure script also allows you to customize the program's modules, disabling or enabling certain functions.
b. compiler
According to the Makefile file generated by configure script, compile and link the source code to generate a binary file. But at this point the base 2 file 1 is generally not available.
c. Setup program
With the make install command, the compiled binary files are installed into the corresponding path, and the program is then ready to use.

C. Where is the program installed?
1 compile and install the program will be installed under /usr/local. Such as php will be installed to/usr local/bin/php, php. ini will be installed to/usr local/lib/php ini, and so on. If you need to specify an installation directory, specify the --prefix parameter at configure, and all the files will be installed in the prefix directory. For example, /configure --prefix=/usr/local/php. Then will to install all files in this directory, the final look will be/usr local/php bin/php and/usr local/php/lib/php ini

D. How to get the parameters of configure?
The commonly used configure parameters are --prefix, which can be obtained through./configure --help. 1 normally, all arguments beginning with --enable-, --with- enable a feature, and --disable-, --without- disable a feature.

E. How do I delete an installed program?
The Linux delete program is not quite the same as Windows. Windows suggests using the uninstall function to uninstall the program. Programs installed by the package management software under Linux can also be removed by direct command, for example:
yum remove php(yum)
apt-get remove php5(apt)

If the program is installed through the source code package, 1 will generally come with make uninstall, which allows you to delete the installed files. If you do not have make uninstall with you, you can simply delete the program installation directory.
Note: if the dependent libraries (such as php if you want to use to mysql function, must want to install mysql first, then the specified in the configuration when php mysql library paths, then php is dependent on the mysql), delete the dependent program, then use dependent libraries application will not be able to use (such as delete after mysql php part will not be able to normal use mysql function).

F. And what is make for?
make clean is used to clean up the battlefield. Clean up all temporary files left behind at compile time, compiled binary files, etc. It is generally recommended that make clean be recompiled after make install to save space next time.

2. Optimization of source code at compile time
As anyone who USES Windows knows, the biggest headache is that the program takes up too much CPU and consumes too much memory. This is because Windows's applications are "generic" and are not optimized for a particular platform or CPU. Under Linux, compiling base 2 files from source code will effectively improve this problem. We can optimize the program for a certain CPU model and a certain system by adding optimization parameters to minimize file size, CPU utilization, and memory utilization.
However, programs that are compiled by specifying optimization parameters will no longer have the ability to cross systems and platforms. Even if both machine systems are version 1, as long as CPU is not version 1, the program will not work. Programs can only be run on the compiled machine.

In general, the optimization parameters are set to CFLAGS and CXXFLAGS by export command, and then configure will be read automatically, and make will automatically use the selected optimization parameters.

For example, CPU (Intel(R) Pentium(R) 4 CPU XXXXMHz, cpu family: 15, model: 0/1/2) of normal Pentium 4 can be entered as follows
export CHOST="i686-pc-linux-gnu"
export CFLAGS="-march=pentium4 -O2 -pipe -fomit-frame-pointer"
export CXXFLAGS="${CFLAGS}"


Information such as the CPU model can be obtained by entering the following command
cat /proc/cpuinfo
Something like the following will be output

processor             : 0
vendor_id             : AuthenticAMD
cpu family           : 15
model                     : 47
model name           : AMD Athlon(tm) 64 Processor 3200+
stepping               : 2
cpu MHz                 : 2000.336
cache size           : 512 KB
fdiv_bug               : no
hlt_bug                 : no
f00f_bug               : no
coma_bug               : no
fpu                         : yes
fpu_exception     : yes
cpuid level         : 1
wp                           : yes
flags                     : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt lm 3dnowext 3dnow up pni lahf_lm ts fid vid ttp tm stc
bogomips               : 4002.57

The information above shows that this is an AMD Athlon 64 3200+ CPU.

The CPU optimization parameters can be obtained from the following address (some cpu family and model do not have cpu and model, which can be replaced by the same model)

http://gentoo-wiki.com/Safe_Cflags


3. Preliminary preparation for compiling Squid
We need to understand something called a file descriptor. We know that there is a limit to what one can do at the same time. The file descriptor is the one thing that limits the maximum. The file descriptor is used to limit the number of files a program can open at the same time. The default is 1024. That is, a program can only open 1024 files at a time without modifying the file descriptor. The number 1024 is enough for 1 general program, but Squid is not. Squid opens thousands of files simultaneously for maximum efficiency and responsiveness.
Imagine 1: a. Each time a user accesses squid, squid opens the file as needed, reads the file and returns it to the user. b.squid opens the frequently accessed files in advance, the user accesses squid, and squid returns the content directly to the user. The latter approach is relatively quick to respond to user requests.

To change the size of the file descriptor, you must modify two files.
/usr/include/bits/typesizes.h
/usr/include/linux/posix_types.h
Open the above file with vi (refer to the previous section if you forget how to use it) and look it up
#define __FD_SETSIZE 1024
Change 1024 to 65536, and save.
Why is it 65536, not larger? Because this is the maximum value that Linux can accept.
The two files just edited are the header files in the C/C++ program, which will be automatically referenced when compiling squid. In addition to these two files, we also need to set up the current environment.
The environment, which is what you have when you log on to the system with ssh. Each login process can be set separately, and environment Settings are lost when the login process is turned off without writing the Settings to the environment profile (.profile,.bash_rc).
For example, if you open two Windows using pietty, use the same account password, log in to the same server, and then use the export command in one of the login processes, it will only take effect in this login process, not the other login process.

Once understood, we say 1 ulimit command. ulimit is used to set some resource limits for the current environment. As mentioned earlier, this command sets the environment, so it will be invalidated when you log out of the current login process.

We enter the following command
ulimit -Hs 65536
ulimit -n 65536

The H parameter is the hard limit, s is the stack limit, and n is the file descriptor limit.

Finally, we use wget to download the source code for squid back.
wget http://www.squid-cache.org/Versi ... 2.6.STABLE13.tar.gz

wget is the next download tool for unix that supports breakpoint continuation. Will have 1 some more practical functions, such as the entire website to download others back (like the usual use of thieves?) .


Related articles: