friht 发表于 2018-11-17 09:10:50

Apache二进制免编译安装和参数配置


[*]下载http相关二进制软件包  

cd /usr/local/src/  
wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.34.tar.gz
  
wget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz
  
wget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz
  

  说明:
  apr和apr-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便的从linux移植到windos

  2.解压安装包
  

tar zxvfhttpd-2.4.34.tar.gz  
tar zxvf apr-1.6.3.tar.gz
  
tar zxvfapr-util-1.6.1.tar.gz
  

  3.编译安装 apr-1.6.3
  

cd apr-1.6.3  
./configure --prefix=/usr/local/apr
  

  报错01:
  

# ./configure --prefix=/usr/local/apr  
checking build system type... x86_64-pc-linux-gnu
  
checking host system type... x86_64-pc-linux-gnu
  
checking target system type... x86_64-pc-linux-gnu
  
Configuring APR library
  
Platform: x86_64-pc-linux-gnu
  
checking for working mkdir -p... yes
  
APR Version: 1.6.3
  
checking for chosen layout... apr
  
checking for gcc... no
  
checking for cc... no
  
checking for cl.exe... no
  
configure: error: in `/usr/local/apr-1.6.3':
  
configure: error: no acceptable C compiler found in $PATH
  
See `config.log' for more details
  
# echo $?
  
1
  

  解决办法:安装gcc
  

yum install gcc -y  

  再次config编译成功
  

# ./configure --prefix=/usr/local/apr  


  

#make && make install  
# echo $?
  
0
  


  4.编译安装apr-util-1.6.1
  

cd /usr/local/src/apr-util-1.6.1  
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  
make && make install
  

  编译安装报错


  解决报错:安装expat库
  

yum install expat-devel -y  

  再次执行make && make install,报错解决

  5.编译安装httpd-2.4.29
  

cd /usr/local/src/httpd-2.4.29  
./configure \
  
--prefix=/usr/local/apache2.4 \
  
--with-apr=/usr/local/apr\
  
--with-apr-util=/usr/local/apr-util \
  
--enable-so \   ##支持动态扩展模块,apache支持以一个动态模块存在,Apache本身就是一个进程服务
  
--enable-mods-shared=most
  

  编译报错01:configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

  

解决办法:  
yum install pcre-devel -y
  

  再次执行./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most返回如下界面,表示configure编译成功

  

注:如果在编译过程中出现,缺少某个依赖包,解决思路  
yum list |grep 包
  
然后安装devel关键字的软件包
  
yum install -y 软件包
  

  make && make install 编译安装报错

  说明:缺少了xml相关的库,需要安装libxml2-devel包。直接安装并不能解决问题,因为httpd调用的apr-util已经安装好了,但是apr-util并没有libxml2-devel包支持
  解决办法:
  

参考https://blog.csdn.net/MrDing991124/article/details/78829184  

  重新安装libxml2-devel
  

yum install -y libxml2-devel  

  删除apr-util软件包
  

rm -rf /usr/local/src/apr-util-1.6.1  
cd /usr/local/src/
  

  重新编译安装apr-util
  

tar zxvf apr-util-1.6.1.tar.gz  
cd apr-util-1.6.1/
  ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
  
make && make install
  


  

# pwd  
/usr/local/src/apr-util-1.6.1
  
# cd ..
  
#
  
# cd httpd-2.4.34
  
#
  
# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
  
返回下面界面说明configure这步编译成功
  


  

make && make install  
返回下面界面说明make && make install 执行成功
  


  

  
root@server-1 httpd-2.4.29]# cd /usr/local/apache2.4/
  
# ls
  
binbuildcgi-binconferrorhtdocsiconsincludelogsmanmanualmodules
  
说明:
  
bin目录:命令执行
  
conf目录:配置文件所在目录
  
htdocs目录:默认网站访问的内容就存在这个目录下
  
logs日志目录:访问日志,服务报错日志
  
modules目录:存放apache需要的模块
  
# ls ./modules/
  


  

# ls ./htdocs/  
index.html
  
# ls ./bin/
  


  

# ls ./logs/  
# ls ./conf/
  
extrahttpd.confmagicmime.typesoriginal
  

  查看apache服务状态,执行/usr/local/apache2.4/bin/apachectl命令后返回如下提示
  

# /usr/local/apache2.4/bin/apachectl
  
AH00558: httpd: Could not>  

  解决办法:
  编译/usr/local/apache2.4/conf/httpd.conf文件,把参数 ServerName改为
  

ServerName localhost  

  注意:这里的localhost表示本机主机名,主机名可以自定义为其他
  然后重启apache服务
  

# /usr/local/apache2.4/bin/apachectl restart  
# /usr/local/apache2.4/bin/apachectl
  
httpd (pid 71429) already running
  

  查看apache加载的模块
  

/usr/local/apache2.4/bin/httpd -M  


  

说明: apache会加载两种类型的模块  
static:静态模块
  
shared:动态模块
  
两者的区别在于,static模块是已经编译安装到/usr/local/apache2.4/bin/httpd配置文件中,而shared表示apache动态加载的模块
  

  启动apache服务
  

/usr/local/apache2.4/bin/apachectl start  

  查看apache服务进程
  

# ps aux |grep httpd  
root       14633.00.2 2536008828 ?      Ss   04:19   0:00 /usr/local/apache2.4/bin/httpd -k start
  
daemon   14642.00.2 5404288916 ?      Sl   04:19   0:00 /usr/local/apache2.4/bin/httpd -k start
  
daemon   14652.00.2 5404288916 ?      Sl   04:19   0:00 /usr/local/apache2.4/bin/httpd -k start
  
daemon   14701.00.2 5404288912 ?      Sl   04:19   0:00 /usr/local/apache2.4/bin/httpd -k start
  
root       15490.00.0 112704   972 pts/1    R+   04:19   0:00 grep --color=auto httpd
  



页: [1]
查看完整版本: Apache二进制免编译安装和参数配置