Build your own CDN with dnspod and squid (v) pre-preparation of squid installation _linux

Source: Internet
Author: User
Tags install php memory usage cpu usage

5th Chapter Installation Squid Preparation

from this chapter, you will learn how to install under Linux, compile the program, but also learn how to compile the program optimization methods, and finally through the source code compiled way to install squid.

1.Linux The basic knowledge of the installation of the program

A. Classification of program installation packages
Usually you install the program under Windows, usually directly run the installation program, and then the installation program will compile a good binary files into the system, Finally completes the installation process.
under Linux, Setup has more freedom than Windows. Because most of the things under Linux are open source, the program is usually provided in binary packages or source code packages.
Binary packages also have different packaging and management styles (similar to zip, RAR, but more advanced). The two most common packages are the packages used by RPM (Redhat, SUSE, etc.) and Deb (Debian, Ubuntu). There are more packages installed on the machine, and a software is needed to manage and update it naturally. So there is the Yum (rpm), APT (deb) package management, upgrade software.
Source code package, such a simple package, usually directly to the source code into a compressed file, the suffix is generally tar.gz or TAR.BZ2
Package management software Installation software is relatively simple, set up a good 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 package you want to install, you can search by using the following method:
Yum search php (yum)
Apt-cache Search PHP (APT)
This article mainly discusses the installation of source code package.

B. Installing programs from source code packs
In general, the program from the source code to the normal use, need to go through three steps: 1. According to the system environment to the source code configuration (configure); 2. Compiler (make); 3. Setup (make install).
A. Source code configuration
By running the Configure script, you can automatically find some basic environments for the programs you need to compile, the commands you use, the libraries, and so on, and generate the makefile files you need to compile the files. Because Linux has too many distributions, each version of the environment is different, so need to use this script. You can also customize the program's modules by configure scripts, and you can disable or activate a feature.
B. Compiling programs
According to the Configure script generated makefile file, the source code to compile, link, generate binary files. But this time the binaries are generally not available.
C. Installation Procedures
By making install command, the compiled binaries are installed to the appropriate path, and the program is actually available.

C. Where is the program installed?
Programs that are normally compiled and installed are installed under/usr/local. For example, PHP will be installed to the/usr/local/bin/php,php.ini will be installed to/usr/local/lib/php.ini, and so on. If you need to specify the installation directory, specify the--prefix parameter when configure, and all files are installed into the prefix directory. Like,/configure--prefix=/usr/local/php. Then all the files will be installed into this directory, it will eventually appear to be/usr/local/php/bin/php and/usr/local/php/lib/php.ini

D. How do I get the Configure parameters?
The commonly used configure parameters are--prefix, which can be obtained by the./configure--help get more parameters. Typically with--enable-、--with-The beginning of a feature is enabled,--disable-、--without-The beginning of a feature is disabled.

E. How do I remove a installed program?
Linux removal programs are not quite the same as Windows. Windows recommends uninstalling a program with uninstall, and programs that are installed under Linux with package management software can also be removed directly by command, for example:
Yum remove PHP (YUM)
Apt-get remove php5 (APT)

If you install a program from a source code pack, you typically have make uninstall, which allows you to delete the files you have installed. If you do not have make uninstall, you can delete the program installation directory directly.
Note: If you are relying on libraries (such as PHP to use the functionality of MySQL, you must first install MySQL, and then configure PHP when you specify the path of the MySQL library, then PHP is dependent on MySQL), to remove the dependent programs, Then the use of the library-dependent programs will not be used (for example, after the removal of MySQL, PHP will not be normal use of the MySQL part of the function).

F. What's the use of make-clean?
Make clean is used to sweep the battlefield. Clean up all the temporary files left at compile time, the compiled binaries, and so on. It is generally recommended to make clean after make install to facilitate the next recompile and save space.

2. Source code compile-time optimization
With Windows friends know, usually the most headache thing is that the program CPU is too high, and consumes a particularly large memory. This is because Windows programs are "generic" programs that are not optimized for specific platforms and specific CPUs. In Linux, the problem will be effectively improved by compiling binaries from the source code. We can reduce file size, CPU usage, and memory usage by adding tuning parameters to optimize the program for a CPU model and a system.
However, programs that are compiled by specifying tuning parameters will no longer have cross-platform capabilities across the system. Even if the two machine system versions, as long as the CPU is not the same, the program can not run. The program can only run on the compiled machine.

Generally, the optimization parameters are set Cflags and cxxflags by the Export command, and then automatically read when configure, and the selected optimization parameters are automatically used when make.

For example, the CPU for normal Pentium 4 (the Display model is Intel (r) Pentium (r) 4 CPU xxxxmhz,cpu FAMILY:15,MODEL:0/1/2) can enter the following command
Export chost= "I686-pc-linux-gnu"
Export cflags= "-march=pentium4-o2-pipe-fomit-frame-pointer"
Export cxxflags= "${cflags}"


Information such as CPU model can be obtained by entering the following command
Cat/proc/cpuinfo
Will output information similar to the following

processor:0
Vendor_id:authenticamd
CPU Family:15
Model:47
Model NAME:AMD Athlon (tm) 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 syscal L NX mmxext fxsr_opt lm 3dnowext 3dnow up PNI lahf_lm ts FID vid TTP TM STC
bogomips:4002.57

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

CPU tuning parameters can be obtained from the following address (some CPU family and model not, can be replaced with the same model)

Http://gentoo-wiki.com/Safe_Cflags


3. Prepare squid in the prophase
We need to know something called a "file descriptor" first. We know that there is a limit to what people can do at the same time. A file descriptor is something that limits the maximum limit. The file descriptor is used to limit the number of files that a program can open at the same time, by default 1024. That is, if you do not modify the file descriptor, then a program can only open 1024 files at a time. 1024 this number, the general procedure is enough, but squid not. Squid will open thousands of files at the same time to ensure maximum efficiency and response speed.
Imagine the following two cases: a. Each time a user accesses the Squid,squid, it opens the file, reads the file content, and then returns it to the user. B.squid access to a high frequency file, the user access Squid,squid directly to the content returned to the user. In contrast, the following method can react more quickly to a user's request.

To change the size of a file descriptor, you must modify two files.
/usr/include/bits/typesizes.h
/usr/include/linux/posix_types.h
Use VI to open the above file (if you forget how to use, refer to the previous section), find
#define __FD_SETSIZE 1024
Change 1024 to 65536 and save.
Why is 65536, not bigger? Because this is the maximum number that Linux can accept.
The two files I just edited are the header files in C/s + + program, which are automatically referenced when compiling squid. In addition to these two files, we also need to set up the current environment.
Environment, which is when you use SSH to login to the system some settings. Each logon process can be set individually, and the environment settings are lost after the logon process is turned off without writing the settings to the Environment configuration file (. profile,.bash_rc).
For example, if you use Pietty to open two windows, use the same account password, log on 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 and not on another login process.

After we understand, let's talk about the Ulimit order. Ulimit is used to set some resource limits for the current environment. As I said earlier, this command is set up for the environment, so the command will expire after exiting the current logon process.

We enter the following command
ULIMIT-HS 65536
Ulimit-n 65536

The h parameter is a hard limit, S is the upper stack, and n is the upper limit of the file descriptor.

Finally, we use wget to download the squid source code back.
Wget Http://www.squid-cache.org/Versi ... 2.6.stable13.tar.gz

Wget is the next download tool for UNIX to support the continuation of breakpoints. There will be some more practical functions, such as the whole site of others to download back (like the usual use of thieves?) )。

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.