设为首页 收藏本站
查看: 1909|回复: 2

[经验分享] Apache源码编译安装

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-8-19 09:56:05 | 显示全部楼层 |阅读模式

Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。

Apache 的安装无外乎两种方式:源代码安装和二进制包安装。这两种安装类型各有特色,二进制包安装不需要编译,而源代码安装则需要先配置编译再安装,二进制包安装在一个固定的位置下,选择固定的模块,而源代码安装则可以让你选择安装路径,选择你想要的模块。本文主要介绍源代码安装。

系统环境:Red Hat Enterprise Linux 6.5        主要配置文件:httpd.conf

获取源代码包 http://httpd.apache.org/   httpd-2.4.23.tar.bz2    http://apr.apache.org/  apr-1.5.2.tar.gz     apr-util-1.5.4.tar.gz

安装之前需要将以上三个源代码包导入Linux系统内

Apache服务源码安装开始

root@localhost ~]#tar xzvf apr-1.5.2.tar.gz -C /opt/
[iyunv@localhost ~]#tar xzvf apr-util-1.5.4.tar.gz -C /opt/
[iyunv@localhost ~]#tar xjvf httpd-2.4.23.tar.bz2 -C /opt/                                   //将源码包解压

[iyunv@localhost ~]#cd /opt/                                                                                 //切换到源码包解压目录
[iyunv@localhost opt]#cp -r apr-1.5.2/ httpd-2.4.23/srclib/apr
[iyunv@localhost opt]#cp -r apr-util-1.5.4/ httpd-2.4.23/srclib/apr-util              //将apr源码注入httpd-2.4.23/srclib/apr目录中

[iyunv@localhost opt]# mount /dev/cdrom /mnt/                                                 //挂载光盘搭建yum仓库

[iyunv@localhost opt]# vi /etc/yum.repos.d/rhel-source.repo                           //通过vi编辑器编辑yum仓库源

[rhel-source]
name=Red Hat Enterprise Linux $releasever – $basearch – Source
baseurl=file:///mnt
enabled=1
gpgcheck=0                                                                                                         //编辑完毕wq保存退出编辑

[iyunv@localhost opt]#cd /mnt                                                                             //搭建yum仓库优化编译语言
[iyunv@localhost mnt]# yum -y install \
gcc \
gcc-c++ \
make \
pcre-devel

[iyunv@localhost mnt]# cd /opt/httpd-2.4.23/
[iyunv@localhost httpd-2.4.23]#./configure \                                                     //整合编译源码
–prefix=/usr/local/apache \
–enable-so \
–enable-rewrite \
–enable-mods-shared=most \
–with-mpm=worker \
–disable-cgid \
–disable-cgi

[iyunv@localhost httpd-2.4.23]# yum remove httpd                                        //编译安装之前将系统本身自带的web服务器卸载

[iyunv@localhost httpd-2.4.23]# make                                                             //编译

[iyunv@localhost httpd-2.4.23]# make install                                                  //编译安装

[iyunv@localhost httpd-2.4.23]# ln -s /usr/local/apache/bin/* /usr/local/bin/                                              //建立软链接

[iyunv@localhost httpd-2.4.23]# grep -v “#” /usr/local/apache/bin/apachectl > /etc/init.d/httpd              //以apachectl脚本为模板生成Apache服务控制脚本

[iyunv@localhost httpd-2.4.23]#vi /etc/init.d/httpd
在文件最前面插入下面的行,使其支持chkconfig命令:
#!/bin/sh
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web server.                                     //编辑完成wq保存退出编辑


[iyunv@localhost httpd-2.4.23]# chmod +x /etc/init.d/httpd
[iyunv@localhost httpd-2.4.23]# chkconfig –add httpd                                     //将httpd加入services管理器

[iyunv@localhost httpd-2.4.23]# vi /usr/local/apache/conf/httpd.conf              //编辑Apache主配置文件

只需修改下面这两行配置

ServerName  localhost.localdomain                                                                //设置成hostname显示的名称
Listen 192.168.10.20:80                                                                                //192.168.10.20为服务器ip地址

[iyunv@localhost httpd-2.4.23]#service httpd start                                           //启动服务

查看httpd的80端口是否处于监听状态,如果没有处于监听状态,就是Linux防火墙的原因,可以清除防火墙规则重新启动服务即可

[iyunv@localhost httpd-2.4.23]# netstat -antp | grep httpd

[iyunv@localhost httpd-2.4.23]#service iptables stop

[iyunv@localhost httpd-2.4.23]#service httpd restart



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-259918-1-1.html 上篇帖子: Apache与Nginx比较 下篇帖子: 源码安装http2.2.29
累计签到:9 天
连续签到:1 天
发表于 2016-8-22 13:10:39 | 显示全部楼层
我的操作系统是:
# cat /etc/issue
CentOS release 6.4 (Final)
我的安装过程:
编译apr
# vim configure 修改apr编译文件
将RM='$RM'替换成RM='$RM -f'
# CC="gcc -m64" CFLAGS="-march=native -O2 -pipe" ./configure --prefix=/usr/local/apr --enable-profile --enable-threads
编译apr-util
# yum install openldap-devel openssl-devel
# CC="gcc -m64" CFLAGS="-march=native -O2 -pipe" ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr  --with-crypto --with-openssl=/usr/lib64 --with-ldap-include=/usr/lib64
编译pcre
# CC="gcc -m64" CFLAGS="-march=native -O2 -pipe" ./configure --prefix=/usr/local/pcre --enable-utf8 --enable-jit --enable-pcregrep-libz
编译httpd
# CC="gcc -m64" CFLAGS="-march=native -O2 -pipe" ./configure --prefix=/usr/local/apache2 --enable-load-all-modules --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --with-mpm=worker
编译安装后能正常启动,但是编译httpd的时候有警告:
# grep WARNING /usr/src/httpd-2.4.23/config.log
configure:10743: WARNING: apr/apr-util is compiled without ldap support
configure:18704: WARNING: apr/apr-util is compiled without ldap support
configure:29185: WARNING: nghttp2 version is too old
编译安装apr-util并无警告或错误:
# grep WARNING /usr/src/apr-util-1.5.4/config.log  没有结果
http.conf配置里面没有加载ldap相关模块:
# grep ldap /usr/local/apache2/conf/httpd.conf 没有结果
求问:如何才能加载上ldap相关模块?



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

累计签到:9 天
连续签到:1 天
发表于 2016-8-22 15:43:08 | 显示全部楼层
问题已解决:
apr-util编译时加载ldap模块方式应为--with-ldap --with-ldap-include=/usr/include/ --with-ldap-lib=/usr/lib64/
httpd编译安装完成后也加载了ldap相关模块,结果如下:
# grep ldap /usr/local/apache2/conf/httpd.conf
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule ldap_module modules/mod_ldap.so

我安装的详细步骤如下,可以对比一下:
# wget http://apache.fayea.com//apr/apr-1.5.2.tar.gz http://apache.fayea.com//apr/apr-util-1.5.4.tar.gz https://sourceforge.net/projects ... 39/pcre-8.39.tar.gz http://apache.fayea.com/httpd/httpd-2.4.23.tar.gz
系统自带perl-5.10.1-141.el6_7.1.x86_64,高于版本5,满足要求
# yum install gcc gcc-c++ libtool make
config.layout 定义各种安装目录
config.nice 记录最后执行的./configure参数,升级软件包时需使用同样的参数
config.log 记录./configure执行的详细日志
安装步骤:
编译apr
# vim configure 修改apr编译文件
将RM='$RM'替换成RM='$RM -f'
注:修改一下,不然编译apr-util时一直重复出现libtool错误。
# CC="gcc -m64" CFLAGS="-march=native -O2 -pipe" ./configure --prefix=/usr/local/apr --enable-profile --enable-threads
注:--enable-profile --enable-threads 最好加上这两个参数,否则编译安装apr-util时会出现threads不支持错误
编译apr-util
# yum install openldap-devel openssl-devel
# CC="gcc -m64" CFLAGS="-march=native -O2 -pipe" ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr  --with-crypto --with-openssl=/usr/lib64 --with-ldap --with-ldap-include=/usr/include/ --with-ldap-lib=/usr/lib64/
编译pcre
# CC="gcc -m64" CFLAGS="-march=native -O2 -pipe" CXX="g++ -m64" ./configure --prefix=/usr/local/pcre --enable-utf8 --enable-jit --enable-pcregrep-libz
注:
--enable-utf8 --enable-jit --enable-pcregrep-libz 这几个参数可以不接,个人习惯,对做实验没有他打影响
make install时警告:
libtool: warning: relinking 'libpcreposix.la'
libtool: warning: relinking 'libpcrecpp.la'
nginx不支持pcre2,这里不影响
编译httpd
# CC="gcc -m64" CFLAGS="-march=native -O2 -pipe" ./configure --prefix=/usr/local/apache2 --enable-load-all-modules --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --with-mpm=event
这种编译方式所加载的模块有:
# /usr/local/apache2/bin/apachectl -M
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_event_module (static)
authn_file_module (shared)
authn_dbm_module (shared)
authn_anon_module (shared)
authn_dbd_module (shared)
authn_socache_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_dbm_module (shared)
authz_owner_module (shared)
authz_dbd_module (shared)
authz_core_module (shared)
authnz_ldap_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
auth_form_module (shared)
auth_digest_module (shared)
allowmethods_module (shared)
file_cache_module (shared)
cache_module (shared)
cache_disk_module (shared)
cache_socache_module (shared)
socache_shmcb_module (shared)
socache_dbm_module (shared)
socache_memcache_module (shared)
watchdog_module (shared)
macro_module (shared)
dbd_module (shared)
dumpio_module (shared)
buffer_module (shared)
ratelimit_module (shared)
reqtimeout_module (shared)
ext_filter_module (shared)
request_module (shared)
include_module (shared)
filter_module (shared)
substitute_module (shared)
sed_module (shared)
deflate_module (shared)
mime_module (shared)
ldap_module (shared)
log_config_module (shared)
log_debug_module (shared)
logio_module (shared)
env_module (shared)
expires_module (shared)
headers_module (shared)
unique_id_module (shared)
setenvif_module (shared)
version_module (shared)
remoteip_module (shared)
proxy_module (shared)
proxy_connect_module (shared)
proxy_ftp_module (shared)
proxy_http_module (shared)
proxy_fcgi_module (shared)
proxy_scgi_module (shared)
proxy_wstunnel_module (shared)
proxy_ajp_module (shared)
proxy_balancer_module (shared)
proxy_express_module (shared)
proxy_hcheck_module (shared)
session_module (shared)
session_cookie_module (shared)
session_crypto_module (shared)
session_dbd_module (shared)
slotmem_shm_module (shared)
ssl_module (shared)
lbmethod_byrequests_module (shared)
lbmethod_bytraffic_module (shared)
lbmethod_bybusyness_module (shared)
lbmethod_heartbeat_module (shared)
unixd_module (shared)
dav_module (shared)
status_module (shared)
autoindex_module (shared)
info_module (shared)
cgid_module (shared)
dav_fs_module (shared)
vhost_alias_module (shared)
negotiation_module (shared)
dir_module (shared)
actions_module (shared)
speling_module (shared)
userdir_module (shared)
alias_module (shared)
rewrite_module (shared)


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表