Chapter 2 Preparations for installing Squid
Starting from this chapter, you will learn how to install and compile programs under Linux, the optimization methods of program compilation, and the installation of Squid through source code compilation.
1. Basic program installation knowledge in Linux
A. Classification of program installation packages
In normal times, you usually run the installation program in Windows. Then, the installation program copies the compiled binary file to the system to complete the installation process.
In Linux, the freedom of the installer is higher than that of Windows. Because most of the content in Linux is open-source, the program is generally provided in binary or source code packages.
Binary packages also have different packaging and management methods (similar to zip and rar, but more advanced ). The two most common software packages are rpm (the packages used by systems such as redhat and suse) and deb (debian and ubuntu ). There are more software packages installed on the machine, and a software is required for management and update. Therefore, software packages such as yum (rpm) and apt (deb) are used to manage and upgrade software.
The source code package, which is relatively simple. Generally, the source code is directly packaged into a compressed file with the extension tar.gz?tar.bz2.
Installing software through the package management software is relatively simple. After setting the software installation source, you can use the following command to install the software:
Yum install php (yum)
Apt-get install php5 (apt)
If you do not know the exact name of the software package to be installed, you can search by using the following method:
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
Generally, the program can be used normally from the source code. Three steps are required: 1. configure the source code according to the system environment (configure); 2. compile the program (make); 3. make install ).
A. source code configuration
By running the configure script, you can automatically search for the basic environment, commands, libraries, and other files of the program to be compiled, generate the Makefile required for compiling the file. This script is required because there are too many release versions in Linux and the environment of each version is different. The configure script can also be used to customize the program modules. You can disable or activate a function.
B. Compile the program
Based on the Makefile file generated by the configure script, the source code is compiled and linked to generate a binary file. However, binary files cannot be used at this time.
C. Installer
Run the make install command to install the compiled binary file to the corresponding path. This is when the program can be used.
C. Where is the program installed?
Generally, programs compiled and installed are installed under/usr/local. For example, php will be installed in/usr/local/bin/php, php. ini will be installed in/usr/local/lib/php. ini, and so on. If you need to specify the installation directory and specify the -- prefix parameter during configure, all files will be installed in the prefix directory. For example,./configure -- prefix =/usr/local/php. All the files will be installed in this directory, and it looks like/usr/local/php/bin/php and/usr/local/php/lib/php. ini.
D. How to obtain the configure parameter?
Common configure parameters include -- prefix. You can use./configure -- help to get more parameters. Generally, parameters starting with -- enable-and -- with-are all enabled with a function. All parameters starting with -- disable-and -- without-are disabled with a function.
E. How to delete the installed program?
Linux programs are not the same as Windows programs. In Windows, we recommend that you use the uninstall function to uninstall a program. In Linux, programs installed using the package management software can also be deleted using commands. For example:
Yum remove php (yum)
Apt-get remove php5 (apt)
If you use the source code package to install a program, it usually carries make uninstall. You can use this command to delete the installed files. If make uninstall is not included, you can directly Delete the installation directory of the program.
Note: If you are using a dependent Library (for example, if you want to use the mysql function in php, you must first install mysql and then specify the path of the mysql database When configuring php, php depends on mysql). If you delete the dependent program, all the programs that use the dependent library will be unavailable (for example, after you delete mysql, php will not be able to use the functions of mysql normally ).
F. What is the use of make clean?
Make clean is used to clean the battlefield. Clear all temporary files and compiled binary files left during compilation. It is generally recommended that you make clean after make install to facilitate next re-compilation and save space.
2. source code compilation Optimization
Windows users know that the most common headache is that the CPU usage is too high and the memory consumption is extremely high. This is because Windows programs are all "generic" and are not optimized for specific platforms and CPUs. In Linux, the problem of compiling binary files through source code will be effectively improved. We can add optimization parameters so that the program can optimize a CPU model and a system to reduce the file size, CPU usage, and memory usage.
However, programs compiled by specifying optimization parameters do not have cross-system cross-platform capabilities. Even if the system versions of the two machines are the same, the program cannot run as long as the CPU is different. The program can only run on the compiled machine.
In general, the optimization parameters are set through the export command CFLAGS and CXXFLAGS, and will be automatically read during configure, and the selected optimization parameters will be automatically used during make.
For example, the general Pentium 4 CPU (display model is Intel (R) Pentium (R) 4 CPU XXXXMHz, cpu family: 15, model: 0/1/2) you can enter the following command
Export CHOST = "i686-pc-linux-gnu"
Export CFLAGS = "-march = pentium4-O2-pipe-fomit-frame-pointer"
Export CXXFLAGS = "$ {CFLAGS }"
Enter the following command to obtain the CPU model and other information:
Cat/proc/cpuinfo
The output is similar to the following information.
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 limit 36 clflush mmx fxsr sse sse2 syscall nx mmxext rjlm 3 limit 3 dnow up pni limit ts fid vid ttp tm stc
Bogomips: 4002.57
The above information 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 exist and can be replaced by the same model)
Http://gentoo-wiki.com/Safe_Cflags
3. Prepare for compiling Squid
We need to first understand something called "file descriptor. We know that what people can do at the same time is limited. The file descriptor is the maximum limit. The file descriptor is used to limit the number of files that a program can open at the same time. The default value is 1024. That is to say, if you do not modify the file descriptor, a program can open only 1024 files at the same time. The number 1024 is generally enough, but Squid is not enough. Squid opens thousands of files at the same time to ensure the highest efficiency and response speed.
Imagine the following two situations: a. Each time a user accesses squid, squid will open the file as needed, then read the file content and return it to the user. B. squid pre-opens files with High Access frequency. Users access squid, and squid directly returns the content to users. Relatively speaking, the following methods can respond to users' requests more quickly.
To change the file descriptor size, you must modify two files.
/Usr/include/bits/typesizes. h
/Usr/include/linux/posix_types.h
Open the above file with vi (if you forget how to use it, refer to the previous chapter), find
# Define _ FD_SETSIZE 1024
Change 1024 to 65536 and save the settings.
Why is it 65536, not bigger? This is the maximum value that Linux can accept.
The two files just edited are the header files in the C/C ++ program and will be automatically referenced during squid compilation. In addition to the two files, we also need to set the current environment.
Environment, that is, some settings when you log on to the system using ssh. Each logon process can be set separately. If the setting is not written to the Environment configuration file (. profile,. bash_rc), the environment settings will be lost after the logon process is disabled.
For example, you use pietty to open two windows, use the same account password, log on to the same server at the same time, and then use the export command in one of the login processes, it will only take effect in this login process and will not take effect for another login process.
After understanding this, let's talk about the ulimit command. Ulimit is used to set resource limits for the current environment. As mentioned above, this command is used to set the environment, so the command will expire after exiting the current logon process.
Run the following command:
Ulimit-hs65536
Ulimit-n 65536
The H parameter is a hard limit, the s parameter is the stack limit, and the n parameter is the file descriptor limit.
Finally, we use wget to download the squid source code.
Wget http://www.squid-cache.org/Versi... 2.6.STABLE13.tar.gz
Wget is the next download tool that supports resumable upload in unix. There will be some more practical functions, such as downloading the entire website of others (like thieves at ordinary times ?).