版本說明
- CentOS版本:
CentOS release 6.8 (Final) - 安裝包版本:
httpd-2.4.29.tar.gz
apr-1.6.3.tar.gz
apr-util-1.6.1
pcre-8.41.tar.gz
安裝過程
路徑說明
安裝包一般放在:/usr/local/src
安裝路徑一般為:/usr/local
安裝(用root使用者)
-
安裝必要應用
# yum install -y gcc gcc-c++
# yum install -y expat-devel //錯誤1
# yum install -y pcre-devel //錯誤2
# yum install -y openssl-devel //錯誤3
# yum install -y libxml2-devel //錯誤4 -
apr安裝
# tar zvxf apr-1.6.3.tar.gz
# cd apr-1.6.3
# ./configure –prefix=/usr/local/apr/
# make
# make install -
apr-util安裝
# tar zvxf 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 -
pcre安裝
# tar zvxf pcre-8.41.tar.gz
# cd pcre-8.41
# ./configure –prefix=/usr/local/pcre/
# make
# make install -
apache安裝
# ./configure
–prefix=/usr/local/apache2.4
–sbindir=/usr/local/apache2.4/sbin
–with-apr=/usr/local/apr/
–with-apr-util=/usr/local/apr-util
–with-pcre=/usr/local/pcre/
–enable-ssl
–with-ssl=shared
–enable-proxy=shared
–enable-so
–enable-mods-shared=all
# make
# make install
啟動及檢視
-
複製命令到service級別
# cp /usr/local/apache2.4/sbin/httpd /etc/rc.d/init.d -
啟動
# service httpd -k start -
停止
# service httpd -k stop -
重啟
# service httpd -k restart -
檢視狀態
# service httpd -T -
- 通過80埠狀態檢視
# sudo netstat -antp|grep 80 - 通過程式檢視
# ps -ef|grep httpd
- 通過80埠狀態檢視
-
訪問檢視是否啟動成功
訪問:http://ip:80
出現It works! 恭喜你就成功啦。
開通https訪問
-
生成證書
# cd /usr/local/apache2.4/conf # openssl req -new -x509 -nodes -out server.crt -keyout server.key
-
編輯httpd.conf,開啟以下注釋
Include conf/extra/httpd-ssl.conf LoadModule ssl_module modules/mod_ssl.so LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
- 重啟apache
-
檢視&訪問
- 檢視443埠:# sudo netstat -antp|grep 443
- 訪問:https://ip:443 , 如果出現It works! 恭喜你就成功啦。
實現與tomcat整合
-
編輯httpd.conf,開啟以下注釋
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
-
通過443埠跳轉
-
編輯/conf/extra/httpd-ssl.conf(在443虛擬機器中加入跳轉的tomcat)
<VirtualHost *:443> <Location /apache_tomcat_test> ProxyPass ajp://127.0.0.1:#tomcat的ajp埠#/apache_tomcat_test </Location> </VirtualHost>
- 重啟apache
- 訪問: https://ip:443/apache_tomcat_test
-
-
通過80埠跳轉(用https,關閉http訪問)
-
編輯/conf/extra/httpd-ssl.conf(在80虛擬機器中加入跳轉的tomcat)
<VirtualHost *:80> SSLEngine on SSLCertificateFile "/usr/local/apache2/conf/server.crt" SSLCertificateKeyFile "/usr/local/apache2/conf/server.key" <Location /apache_tomcat_test> ProxyPass ajp://127.0.0.1:#tomcat的ajp埠#/apache_tomcat_test </Location> </VirtualHost>
- 重啟apache
- 訪問: https://ip:80/apache_tomcat_test
-
安裝中的錯誤及解決
錯誤1
-
apr-util-1.6.1編譯時的錯誤
make[1]: Entering directory `/usr/local/apr-util-1.6.1`
/bin/sh /usr/local/apr//build-1/libtool –silent –mode=compile gcc -g -O2 -pthread -DHAVE_CONFIG_H -DLINUX -D_REENTRANT -D_GNU_SOURCE -I/usr/local/apr-util-1.6.1/include -I/usr/local/apr-util-1.6.1/include/private -I/usr/local/apr//include/apr-1 -o xml/apr_xml.lo -c xml/apr_xml.c && touch xml/apr_xml.lo
xml/apr_xml.c:35:19: error: expat.h: No such file or directory
xml/apr_xml.c:66: error: expected specifier-qualifier-list before ‘XML_Parser’
xml/apr_xml.c: In function ‘cleanup_parser’:
xml/apr_xml.c:364: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:365: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c: トップレベル:
xml/apr_xml.c:384: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
xml/apr_xml.c: In function ‘apr_xml_parser_create’:
xml/apr_xml.c:401: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:402: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:410: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:411: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:412: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:424: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:424: error: ‘default_handler’ undeclared (first use in this function)
xml/apr_xml.c:424: error: (Each undeclared identifier is reported only once
xml/apr_xml.c:424: error: for each function it appears in.)
xml/apr_xml.c: In function ‘do_parse’:
xml/apr_xml.c:434: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:438: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:442: error: ‘apr_xml_parser’ has no member named ‘xp_err’
xml/apr_xml.c:442: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c: In function ‘apr_xml_parser_geterror’:
xml/apr_xml.c:500: error: ‘apr_xml_parser’ has no member named ‘xp_err’
xml/apr_xml.c:500: error: ‘apr_xml_parser’ has no member named ‘xp_err’
make[1]: * [xml/apr_xml.lo] Error 1
make[1]: Leaving directory `/usr/local/apr-util-1.6.1`
make: * [all-recursive] Error 1 - 原因:缺少expat庫,估計是apr-util-1.6不提供了,apr-util-1.5就沒這個錯誤
- 解決:# yum install -y expat-devel
錯誤2
-
apache ./configure時的錯誤
checking for pcre-config… false - 原因:缺少pcre庫
- 解決:# yum -y install pcre-devel
錯誤3
-
apache ./configure時的錯誤
checking for OpenSSL version >= 0.9.8a… FAILED
configure: WARNING: OpenSSL version is too old - 原因:OpenSSL版本舊
- 解決:# yum install -y openssl-devel
錯誤4
-
apache make時出錯
/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_ParserCreate`
/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_GetErrorCode`
/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_SetUserData`
/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_ErrorString`
/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_SetEntityDeclHandler`
/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_ParserFree`
/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_SetElementHandler`
/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_StopParser`
/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_Parse`
/usr/local/apr-util//lib/libaprutil-1.so: undefined reference to `XML_SetCharacterDataHandler`
collect2: ld returned 1 exit status
make[2]: * [htpasswd] Error 1
make[2]: Leaving directory `/usr/local/httpd-2.4.29/support`
make[1]: * [all-recursive] Error 1
make[1]: Leaving directory `/usr/local/httpd-2.4.29/support`
make: * [all-recursive] Error 1 - 原因:缺少了xml相關的庫,導致reference無效
- 解決:# yum install -y libxml2-devel
- 注意:安裝libxml2-devel後,需要刪掉apr-util,重新安裝
其他說明
apache依賴包可以降低到1.5。就不會出上述錯誤了。
apr-1.5.2
apr-util-1.5.2
pcre-8.41