This article by show according to Lin Feng to provide friendship sponsorship, starting in the mud row world.
Recently to start learning nagios monitoring knowledge, but Nagios and Apache combination of relatively close, so this article will first the Apache source installation learning.
We now install Apache in the following steps:
1. Install the compilation environment
2, uninstall the original Apache
3. Download the extracted source package
4. Installing Apache
5. Test Apache
6. View the directory generated by Apache installation
7. View Apache configuration Files
8. Apache joins the system service
First, install the compilation environment
Before installing Apache, we need to install the relevant packages needed to compile Apache as follows:
Yum-y install gcc gcc++ zlib zlib-devel
Second, uninstall the original Apache
Before installing Apache in the source code, we need to uninstall the Apache installed in the system, which has already passed the RPM package. As follows:
Rpm-qa |grep httpd
RPM-E--nodeps httpd-2.2.15-29.el6.centos.x86_64
RPM-E--nodeps httpd-tools-2.2.15-29.el6.centos.x86_64
Third, download the decompression source package
Download the Apache source package, our experiment with Apache version 2.2.27 For example. Apache source package is recommended to go directly to the Apache official website to download, as follows:
Use the following command to download the Apache source package:
wget http://apache.fayea.com/httpd/httpd-2.2.27.tar.gz
Unzip the downloaded source package, because the download is tar.gz source package, so we have two methods of decompression.
Method One, the use of Gunzip decompression, as follows:
Gunzip-c Httpd-2.2.27.tar.gz>httpd-2.2.27.tar
-C parameter can not delete source file
TAR-XF Httpd-2.2.27.tar
Method Two, the direct use of tar decompression, as follows:
TAR-ZXF httpd-2.2.27.tar.gz
or TAR-XF httpd-2.2.27.tar.gz.
IV. installation of Apache
To install Apache, we first need to compile and then install.
We can use the Configure command to view compile-time related help, as follows:
./configure--help
The specific compilation is as follows:
./configure--prefix=/usr/local/apache2--enable-rewrite--enable-so--enable-headers--enable-expires--with-mpm= Worker--enable-modules=most--enable-deflate
--PREFIX=/USR/LOCAL/APACHE2 indicates the installation path for the specified Apache, the default installation path is/usr/local/apache2
--enable-rewrite provides a more tender rewrite of the URL rules, which translates to other desired URL addresses based on a known URL address
--ENABLE-SO activation of the Apache service DSO (dynamic shared objects), that is, in the future can be in the form of DSO to compile the installation of shared modules, the module itself can not be built in the DSO mode.
The--enable-headers provides control of the HTTP request header that is allowed.
--enable-expires Activation Xunyu Control http "Expires:" and "Cache-control:" header content through the configuration file, that is, the website image, JS, CSS and other content, provide the client browser cache settings. This is one of the important options for Apache tuning.
--with-mpm=worker Select the Apache MPM mode for worker mode. The principle of worker mode is that more threads are used to process requests, so more concurrent requests can be processed. While the overhead of system resources is little jade based on the process of MPM prefork. If you do not specify this parameter, the default mode is Prefork process mode. This is one of the important options for Apache tuning.
--enable-deflate provides compression transmission encoding support for content, usually HTML, JS, CSS and other content of the site. Using this parameter will increase the transfer speed and enhance the visitor's experience. in a production environment, this is one of the important options for Apache tuning.
Make
Make install
After installing Apache, view the installed directory as follows:
Tree-l 1/usr/local/apache2/
Five, Test Apache
Copy the Apache startup script to the/ETC/RC.D/INIT.D directory, as follows:
Cp/usr/local/apache2/bin/apachectl/etc/init.d/httpd
In fact, Apache boot is called/usr/local/apache2/bin/httpd this command, view the contents of the script, as follows:
Cat/etc/init.d/httpd|grep-v ^#|grep-v ^$
Start Apache as follows:
/ETC/INIT.D/HTTPD start
Netstat-lntp|grep 80
Lsof-i: 80
You can also use/USR/LOCAL/APACHE2/BIN/HTTPD to start. As follows:
/usr/local/apache2/bin/httpd–k start
After Apache boot is complete, let's take a look at the following commands:
wget http://192.168.1.213
Through, we can obviously see that Apache has started normally.
Vi. viewing the directory generated by Apache installation
After Apache starts normally, let's look at the directory that the Apache installation generates. As follows:
Bin Main Store program command directory,.
Conf primarily stores Apache configuration files.
Htdocs primarily stores the site directory.
The logs primarily stores the default log files.
Modules primarily stores Apache's operating modules. For example, PHP, memcache compiled modules are stored here.
VII. viewing the Apache configuration file
Apache configuration file httpd.conf is stored in the Conf directory, as follows:
View the httpd.conf configuration content as follows:
Egrep-v ' ^[]*#|^$ '/usr/local/apache2/conf/httpd.conf | nl
ServerRoot "/usr/local/apache2" represents the Apache root directory, which should be accessed only by the root user and generally does not need to be modified.
Listen 80 represents the Apache listening port, which defaults to 80. If you are monitoring port 81 at the same time, add one line: Listen 81.
AddType application/x-httpd-php. php LoadModule php5_module modules/libphp5.so is used when Apache integrates with PHP.
User Daemon Group Daemon represents the Apache runtime users and groups, the default is daemon, recommended modifications, such as Apache.
DocumentRoot "/usr/local/apache2/htdocs" means Apache Default Web site Directory, do not add a slash at the end of the path.
ServerAdmin [Email protected] represents the system administrator's mailbox, which is not an important option. When there is a problem with the site, the page address is displayed.
DirectoryIndex index.php index.html Configure the default Apache home page. If the virtual host is not configured, the configuration is applied here by default.
Errorlog "Logs/error_log" error log path.
LogLevel warn error log level.
scriptalias/cgi-bin/"/usr/local/apache2/cgi-bin/" to configure CGI aliases.
Eight, Apache join system Services
In order for Apache to boot, we can add the Apachectl boot script to the rc.local file, as follows:
echo "/usr/local/apache2/bin/apachectl start" >>/etc/rc.local
Cat/etc/rc.local
We can also launch Apache by adding Apache to the system service. There are two ways to add Apache as a system service, the first is to add it through Chkconfig, and the second is to add the system's individual boot levels directly.
Let us first introduce the first method, modify the startup httpd script to add the following two lines of command, as follows:
#chkconfig: 2345 70 60
#description: Apache
Description
chkconfig:2345 70 60 in 2345 refers to the running level of the script, that is, in 2345 of the 4 modes can be run, 234 is the text interface, 5 is the graphical interface x.
70 refers to the future startup sequence number of the script, if the start sequence number of other programs is smaller than 70 (such as 44, 45), the script needs to wait until these programs are started before starting. 60 refers to the stop order number of the script when the system shuts down.
Description:apache A short description of the script.
Use Chkconfig to add the following:
Chkconfig--add httpd
Chkconfig |grep httpd
chkconfig--add httpd The purpose of the command is to add the/etc/init.d/httpd to the/ETC/RC.D/RC0.D to the/ETC/RC.D/RC6.D directory. as follows:
Find/etc-name *httpd
To turn on Apache boot, use the following command:
Chkconfig httpd on
Chkconfig |grep httpd
After the above operation, Apache can boot up.
Slime: Source Installation Apache