编译安装apache

简介: 编译安装apache

检查是否已经rpm安装httpd服务,已安装则卸载服务。

[root@localhost ~]# rpm -e `rpm -qa | grep httpd` --nodeps
  • 开发工具安装

如果编译安装无法执行,可能是开发工具没有安装,执行下面命令即可安装。(如已安装则跳过即可)。

[root@localhost ~]# yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel
  • httpd安装

1. 挂载rpm包的iso镜像。

查看虚拟机使用ISO镜像,设备状态勾选已连接和启动时连接后确定即可。

 

2. 通过脚本解压tar包并编译安装。

1.  [root@localhost ~]# mkdir /sh
2. 
3.  [root@localhost ~]#  cd /sh
4. 
5.  [root@localhost sh]# vim add.sh
6. 
7. #!/bin/bash
8. 
9. mount /dev/cdrom /media/
10. 
11. tar zxf /media/apr-1.5.2.tar.gz -C /usr/src
12. 
13. cd /usr/src/apr-1.5.2
14. 
15. ./configure --prefix=/usr/local/apr && make && make install
16. 
17. tar zxf /media/apr-util-1.5.4.tar.gz -C /usr/src
18. 
19. cd /usr/src/apr-util-1.5.4
20. 
21. ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install
22. 
23. yum -y install zlib-*
24. 
25. tar zxf /media/pcre-8.39.tar.gz -C /usr/src
26. 
27. cd /usr/src/pcre-8.39
28. 
29. ./configure --prefix=/usr/local/pcre && make && make install
30. 
31. tar zxf /media/openssl-1.0.1u.tar.gz -C /usr/src
32. 
33. cd /usr/src/openssl-1.0.1u
34. 
35. ./config -fPIC --prefix=/usr/local/openssl enable-shared && make && make install

保存退出脚本并执行脚本文件,等待脚本执行完成并确认成功。

[root@localhost sh]# sh add.sh

3. 安装Apache主程序。

下面也通过脚本来安装主程序。

1. [root@localhost sh]# vim httpd.sh
2. 
3. #!/bin/bash
4. 
5. tar zxf /media/httpd-2.4.25.tar.gz -C /usr/src
6. 
7. cd /usr/src/httpd-2.4.25
8. 
9. ./configure --prefix=/usr/local/httpd --enable-so --enable-cgi --enable-cgid --enable-ssl --with-ssl=/usr/local/openssl --enable-rewrite --with-pcre=/usr/local/pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=event --enable-proxy --enable-proxy-fcgi --enable-expires --enable-deflate && make && make install

保存退出脚本并执行脚本文件,等待脚本执行完成并确认成功。

4. 优化链接和添加系统服务。

1. [root@localhost sh]# ln -s /usr/local/httpd/bin/* /usr/local/bin //链接优化
2. 
3. [root@localhost sh]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd //添加服务
4. 
5. [root@localhost sh]# vim /etc/init.d/httpd
6. 第二行添加下面两行命令
7. 
8. # chkconfig: 35 85 15     \\声明服务启动级别,开机启动顺序,关机关闭顺序
9. 
10. # description: apache 2.4.25 \\服务声明,简要信息
11. 
12. 
13. 
14. [root@localhost sh]# chkconfig --add httpd //添加到系统服务
15. 
16. [root@localhost sh]# chkconfig httpd on //设置开机自启
17. 
18. [root@localhost sh]# systemctl start httpd //开启服务

5. 查看httpd模块

安装后可以通过下面三行命令查看各项模块。

1. httpd -V \\查看版本和已装模块
2. 
3. httpd -l \\只查看静态编译模块
4. 
5. httpd -M \\查看所有模块

6. 查看mpm配置文件

vim /usr/local/httpd/conf/extra/httpd-mpm.conf

<IfModule mpm_event_module>

StartServers 3 #apache 启动时候默认开始的子进程数

MinSpareThreads 75 #最小空闲数量的工作线程

MaxSpareThreads 250 #最大空闲数量的工作线程

ThreadsPerChild 25 #每个子进程产生的线程数量

MaxRequestWorkers 400 #允许同时的最大接入请求数量

MaxConnectionsPerChild 0 #每个子进程可处理的请求数

</IfModule>

#企业推荐参数

<IfModule mpm_worker_module>

StartServers          2 #推荐设置:小=默认 中=3~5 大=5~10

MaxClients          150 #推荐设置:小=500 中=500~1500 大型=1500~3000

MinSpareThreads      25 #推荐设置:小=默认 中=50~100 大=100~200

MaxSpareThreads      75 #推荐设置:小=默认 中=80~160 大=200~400 ThreadsPerChild      25 #推荐设置:小=默认 中=50~100 大型=100~200

MaxRequestsPerChild   0 #推荐设置:小=10000 中或大=10000~50000(此外,如果MaxClients/ThreadsPerChild大于16,还需额外设置ServerLimit参数,ServerLimit必须大于等于 MaxClients/ThreadsPerChild 的值。)

</IfModule>

7. 查看apache主页

通过访问http://192.168.1.2可以看到apache默认网站。

8. 使用ab命令进行压力测试

通过上面命令已经启动httpd服务,通过ab工具测试httpd服务,如未安装通过下面命令安装ab命令工具(打开第二台服务器对第一台httpd服务器进行测试)。

[root@localhost ~]# yum -y install httpd-tools

安装完毕后执行下面命令对服务器进行200人并发访问,发出10000个请求。

1. [root@localhost ~]# ab -c 200 -n 10000 http://192.168.1.2/index.html
2. 
3. This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
4. 
5. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
6. 
7. Licensed to The Apache Software Foundation, http://www.apache.org/
8. 
9. 
10. 
11. Benchmarking 192.168.1.2 (be patient)
12. 
13. Completed 1000 requests
14. 
15. Completed 2000 requests
16. 
17. Completed 3000 requests
18. 
19. Completed 4000 requests
20. 
21. Completed 5000 requests
22. 
23. Completed 6000 requests
24. 
25. Completed 7000 requests
26. 
27. Completed 8000 requests
28. 
29. Completed 9000 requests
30. 
31. Completed 10000 requests
32. 
33. Finished 10000 requests
34. 
35. 
36. 
37. 
38. 
39. Server Software:        Apache/2.4.25
40. 
41. Server Hostname:        192.168.1.2
42. 
43. Server Port:            80
44. 
45. 
46. 
47. Document Path:          /index.html
48. 
49. Document Length:        45 bytes
50. 
51. 
52. 
53. Concurrency Level:      200
54. 
55. Time taken for tests:   3.803 seconds
56. 
57. Complete requests:      10000
58. 
59. Failed requests:        0
60. 
61. Write errors:           0
62. 
63. Total transferred:      2890000 bytes
64. 
65. HTML transferred:       450000 bytes
66. 
67. Requests per second:    2629.29 [#/sec] (mean)
68. 
69. Time per request:       76.066 [ms] (mean)
70. 
71. Time per request:       0.380 [ms] (mean, across all concurrent requests)
72. 
73. Transfer rate:          742.06 [Kbytes/sec] received
74. 
75. 
76. 
77. Connection Times (ms)
78. 
79.               min  mean[+/-sd] median   max
80. 
81. Connect:        0   22 153.7      2    3008
82. 
83. Processing:     8   47  34.1     44     451
84. 
85. Waiting:        4   44  33.0     43     435
86. 
87. Total:         28   69 157.9     46    3057
88. 
89. 
90. 
91. Percentage of the requests served within a certain time (ms)
92. 
93.   50%     46
94. 
95.   66%     49
96. 
97.   75%     51
98. 
99.   80%     54
100. 
101.   90%     62
102. 
103.   95%     80
104. 
105.   98%    267
106. 
107.   99%   1048
108. 
109.  100%   3057 (longest request)


相关文章
|
9月前
|
Linux Apache
百度搜索:蓝易云【Cnetos7编译安装Apache教程。】
现在,您已经成功在CentOS 7上通过编译安装了Apache。请注意,以上步骤提供了基本的指导,实际操作可能会有所差异。如有需要,您可以参考Apache官方文档或社区资源获取更详细的信息和帮助。
62 0
|
9月前
|
Linux Apache 开发工具
百度搜索:蓝易云【Centos8 stream系统编译安装Apache教程。】
以上是在CentOS 8 Stream系统上编译安装Apache的基本教程。请注意,具体的配置和参数可能因您的需求而有所不同,您可以根据自己的情况进行调整。同时,请确保在执行任何操作之前备份重要的文件和配置。
389 0
|
9月前
|
Ubuntu Apache
百度搜索:蓝易云【Ubuntu 18.04系统编译安装Apache教程。】
现在,您已经成功地在Ubuntu 18.04上编译和安装了Apache。您可以通过在浏览器中访问服务器的IP地址来验证Apache是否正常运行。请确保在实际操作中根据您的需求进行适当的配置和调整。请注意,通过编译安装方式安装的Apache不会自动更新,您需要手动更新版本或进行维护。
96 1
|
9月前
|
Ubuntu Apache
百度搜索:蓝易云【Ubuntu 20.04系统编译安装Apache教程。】
请注意,以上是一个基本的编译安装Apache的示例,您可能需要根据您的特定需求进行进一步配置和调整。
66 0
|
9月前
|
Apache
百度搜索:蓝易云【Debian11系统编译安装Apache教程。】
以上是在Debian 11系统上编译安装Apache的基本步骤。请根据实际情况进行相应的调整和配置。
64 0
|
Java 应用服务中间件 Linux
Apache HTTP服务器(Linux离线编译安装)
Apache HTTP服务器(Linux离线编译安装)
Apache HTTP服务器(Linux离线编译安装)
|
SQL 分布式计算 资源调度
apache tez 编译安装与验证
本文介绍apache tez 编译安装与验证
apache tez 编译安装与验证
|
Web App开发 关系型数据库 Shell

推荐镜像

更多