etgsd 发表于 2016-8-19 09:56:05

Apache源码编译安装

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/
#tar xzvf apr-util-1.5.4.tar.gz -C /opt/
#tar xjvf httpd-2.4.23.tar.bz2 -C /opt/                                 //将源码包解压#cd /opt/                                                                                 //切换到源码包解压目录
#cp -r apr-1.5.2/ httpd-2.4.23/srclib/apr
#cp -r apr-util-1.5.4/ httpd-2.4.23/srclib/apr-util            //将apr源码注入httpd-2.4.23/srclib/apr目录中# mount /dev/cdrom /mnt/                                                 //挂载光盘搭建yum仓库# vi /etc/yum.repos.d/rhel-source.repo                           //通过vi编辑器编辑yum仓库源
name=Red Hat Enterprise Linux $releasever – $basearch – Source
baseurl=file:///mnt
enabled=1
gpgcheck=0                                                                                                         //编辑完毕wq保存退出编辑#cd /mnt                                                                           //搭建yum仓库优化编译语言
# yum -y install \
gcc \
gcc-c++ \
make \
pcre-devel# cd /opt/httpd-2.4.23/
#./configure \                                                   //整合编译源码
–prefix=/usr/local/apache \
–enable-so \
–enable-rewrite \
–enable-mods-shared=most \
–with-mpm=worker \
–disable-cgid \
–disable-cgi# yum remove httpd                                        //编译安装之前将系统本身自带的web服务器卸载# make                                                             //编译# make install                                                //编译安装# ln -s /usr/local/apache/bin/* /usr/local/bin/                                              //建立软链接# grep -v “#” /usr/local/apache/bin/apachectl > /etc/init.d/httpd            //以apachectl脚本为模板生成Apache服务控制脚本#vi /etc/init.d/httpd
在文件最前面插入下面的行,使其支持chkconfig命令:
#!/bin/sh
# chkconfig: 2345 85 15
# description: Apache is a World Wide Web server.                                     //编辑完成wq保存退出编辑
# chmod +x /etc/init.d/httpd
# chkconfig –add httpd                                     //将httpd加入services管理器# vi /usr/local/apache/conf/httpd.conf            //编辑Apache主配置文件只需修改下面这两行配置ServerNamelocalhost.localdomain                                                                //设置成hostname显示的名称
Listen 192.168.10.20:80                                                                              //192.168.10.20为服务器ip地址#service httpd start                                           //启动服务查看httpd的80端口是否处于监听状态,如果没有处于监听状态,就是Linux防火墙的原因,可以清除防火墙规则重新启动服务即可# netstat -antp | grep httpd#service iptables stop#service httpd restart

宇之逸 发表于 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相关模块?
{:6_409:}

宇之逸 发表于 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/pcre/files/pcre/8.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]
查看完整版本: Apache源码编译安装