Centos7系统下实现httpd-2.2的安装,并分别实现pr
2018-06-05 本文已影响0人
华龙007
一、httpd介绍
- httpd是Apache组织的超文本传输协议HTTP服务器的主程序。它是Apache组织中的一个顶级项目。
- httpd的运行机制
- 高度模块化(Core+Modules):采用核心模块+扩展模块的机制
- DSO(Dynamic Shared Object)机制:可以按需动态的装载模块来实现相应的功能
- 采用MPM(Multipath Processing Moules):使用多路处理模块,有三种工作模型
- prefork模型:是两级进程模型,由父进程负责生成和管理多个子进程,每个子进程负责响应一个用户的请求。
- worker模型:是三级进程模型,由父进程生成和管理多个子进程,每个子进程又生成多个线程,由每一个线程来响应一个用户的请求。
- event模型:是二级进程模型,由父进程生成和管理多个子进程,每个子进程又通过事务(event-driven)机制直接响应多个用户请求。
二、CentOS7下安装httpd-2.2
CentOS7中yum源默认安装的是httpd-2.4版本。而这里用httpd-2.2版本来编译安装。
1.Centos7编译httpd-2.2,默认以perfork方式工作
[root@localhost ~]# yum -y install gcc gcc-c++ #安装编译器和编译环境
[root@localhost ~]# tar -zxvf httpd-2.2.32.tar.gz #解压并展开文档
[root@localhost ~]# cd httpd-2.2.32
[root@localhost httpd-2.2.32]# ./configure --prefix=/sw/pkg/apache
#编译此文档,默认是以perfork方式工作
[root@localhost httpd-2.2.32]# make && make install
#编译无问题后安装
[root@localhost httpd-2.2.32]# cd /sw/pkg/apache/
[root@localhost apache]# ls
bin build cgi-bin conf error htdocs icons include lib logs man manual modules
[root@localhost apache]# vim /etc/profile.d/httpd.sh
export PATH=/sw/pkg/apache/bin:$PATH
[root@localhost apache]# . /etc/profile.d/httpd.sh
#把httpd的命令添加到系统环境中
[root@localhost apache]# vim /usr/lib/systemd/system/httpd.service
[unit]
Description=httpd
After=network.target
[Service]
Type=forking
ExecStart=/sw/pkg/apache/bin/apachectl start
ExecReload=/sw/pkg/apache/bin/apachectl restart
ExecStop=/sw/pkg/apache/bin/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
#配置httpd的unit
[root@localhost apache]# systemctl daemon-reload
[root@localhost apache]# systemctl start httpd.service
[root@localhost apache]# ps aux | grep httpd
root 26292 0.0 0.3 27820 1676 ? Ss 10:16 0:00 /sw/pkg/apache/bin/httpd -k start
daemon 26293 0.0 0.2 27820 1136 ? S 10:16 0:00 /sw/pkg/apache/bin/httpd -k start
daemon 26294 0.0 0.2 27820 1136 ? S 10:16 0:00 /sw/pkg/apache/bin/httpd -k start
daemon 26295 0.0 0.2 27820 1136 ? S 10:16 0:00 /sw/pkg/apache/bin/httpd -k start
daemon 26296 0.0 0.2 27820 1136 ? S 10:16 0:00 /sw/pkg/apache/bin/httpd -k start
daemon 26297 0.0 0.2 27820 1136 ? S 10:16 0:00 /sw/pkg/apache/bin/httpd -k start
root 26299 0.0 0.1 112704 964 pts/0 S+ 10:16 0:00 grep --color=auto httpd
[root@localhost apache]# httpd -M | grep mpm
Syntax OK
mpm_prefork_module (static)
图片.png
2.Centos7重新编译http2.2,实现worker工作方式
[root@localhost ~]# yum -y install gcc gcc-c++
[root@localhost ~]# tar -zxvf httpd-2.2.32.tar.gz
[root@localhost ~]# cd httpd-2.2.32
[root@localhost httpd-2.2.32]# ./configure --prefix=/sw/pkg/apache --with-mpm=worker
#只在此命令末尾添加指定worker工作方式,其他安装过程和prefork一样
[root@localhost httpd-2.2.32]# make && make install
[root@localhost httpd-2.2.32]# vim /etc/profile.d/httpd.sh
export PATH=/sw/pkg/apache/bin:$PATH
[root@localhost httpd-2.2.32]# . /etc/profile.d/httpd.sh
[root@localhost httpd-2.2.32]# vim /usr/lib/systemd/system/httpd.service
[unit]
Description=httpd
After=network.target
[Service]
Type=forking
ExecStart=/sw/pkg/apache/bin/apachectl start
ExecReload=/sw/pkg/apache/bin/apachectl restart
ExecStop=/sw/pkg/apache/bin/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
[root@localhost httpd-2.2.32]# systemctl daemon-reload
[root@localhost httpd-2.2.32]# systemctl start httpd.service
[root@localhost httpd-2.2.32]# ps aux | grep httpd
root 26404 0.0 0.3 28028 1796 ? Ss 10:56 0:00 /sw/pkg/apache/bin/httpd -k start
daemon 26405 0.0 0.2 27760 1232 ? S 10:56 0:00 /sw/pkg/apache/bin/httpd -k start
daemon 26406 0.0 0.3 316992 1544 ? Sl 10:56 0:00 /sw/pkg/apache/bin/httpd -k start
daemon 26407 0.0 0.3 316992 1544 ? Sl 10:56 0:00 /sw/pkg/apache/bin/httpd -k start
daemon 26408 0.0 0.3 316992 1544 ? Sl 10:56 0:00 /sw/pkg/apache/bin/httpd -k start
root 26491 0.0 0.1 112704 964 pts/0 S+ 10:56 0:00 grep --color=auto httpd
[root@localhost httpd-2.2.32]# httpd -M | grep mpm
Syntax OK
mpm_worker_module (static)
图片.png
3.Centos7编译httpd-2.2以event方式工作,2.2中此方式还在试验阶段
[root@localhost httpd-2.2.32]# systemctl stop httpd
[root@localhost httpd-2.2.32]# rm -rf /sw
[root@localhost httpd-2.2.32]# make clean
[root@localhost httpd-2.2.32]# ./configure --prefix=/sw/pkg/apache --with-mpm=event
#末尾添加指定event工作方式,之后安装过程和其他工作方式一样
......
============================================================
WARNING: THE 'event' MPM IS EXPERIMENTAL
============================================================
The selected MPM might not be fully functional!
Development of this MPM is not complete. Do not use this
MPM unless you are a programmer willing to help fix it.
If you are looking for a stable server, you should not use
the 'event' MPM until it is moved out of experimental.
============================================================
#警告:在http-2.2中,event工作方式还在试验开发阶段,不能应用到生产中
[root@localhost httpd-2.2.32]# make && make install
[root@localhost httpd-2.2.32]# systemctl start httpd.service
[root@localhost httpd-2.2.32]# ps aux | grep httpd
root 59800 0.0 0.3 28028 1888 ? Ss 11:17 0:00 /sw/pkg/apache/bin/httpd -k start
daemon 59801 0.0 0.2 27760 1240 ? S 11:17 0:00 /sw/pkg/apache/bin/httpd -k start
daemon 59802 0.0 0.3 316992 1548 ? Sl 11:17 0:00 /sw/pkg/apache/bin/httpd -k start
daemon 59803 0.0 0.3 316992 1548 ? Sl 11:17 0:00 /sw/pkg/apache/bin/httpd -k start
daemon 59804 0.0 0.3 316992 1548 ? Sl 11:17 0:00 /sw/pkg/apache/bin/httpd -k start
root 59887 0.0 0.1 112704 960 pts/0 S+ 11:17 0:00 grep --color=auto httpd
[root@localhost httpd-2.2.32]# httpd -M | grep mpm
Syntax OK
mpm_event_module (static)
图片.png
补充:
[root@localhost httpd-2.2.32]# httpd -M | grep mpm
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
#使用命令时,出现错误提示
[root@localhost httpd-2.2.32]# vim /sw/pkg/apache/conf/httpd.conf
ServerName localhost:80
#在配置中添加这行即可解决
参考文档:http://man.chinaunix.net/newsoft/Apache2.2_chinese_manual/install.html