向已安装好的Apache添加模块
背景故事
最近L同学单位搞了机房,搞了服务器,搞了新网站,然而L同学跟大D说网站慢的一笔。
又赶上春节期间偶感小病连躺好几天,也没腾出时间做事情,今天利用午休时间给L同学看了一下。
然而,大D都快瞎了啊~
大概列出几条罪状:
- GZIP压缩没开
- 没有Pagespeed模块
- 网页资源文件(JS,CSS未合并)
php.ini
中配置了memcached
但没有正确安装并开启memcached
由于不熟悉L同学单位网站的源码情况,资源合并这事儿大D就不做了,把memcached
正确配置上,GZIP开了速度也可以有很明显的提升。
于是习惯性的根据以前大D自己写在Blog上的博文来配置给Apache开启GZIP,然而。。
1 2 3 4 |
[root@localhost bin]# ./apachectl -t httpd: Syntax error on line 453 of /usr/local/apache/conf/httpd.conf: Cannot load /usr/local/apache/modules/mod_headers.so into server: /usr/local/apache/modules/mod_headers.so: cannot open shared object file: No such file or directory httpd: Syntax error on line 454 of /usr/local/apache/conf/httpd.conf: Cannot load /usr/local/apache/modules/mod_deflate.so into server: /usr/local/apache/modules/mod_deflate.so: cannot open shared object file: No such file or directory |
真是一口老血啊。。。。
于是又看一眼Apache安装的时候到底开了哪些模块?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
[root@localhost bin]# ./apachectl -l Compiled in modules: core.c mod_authn_file.c mod_authn_default.c mod_authz_host.c mod_authz_groupfile.c mod_authz_user.c mod_authz_default.c mod_auth_basic.c mod_include.c mod_filter.c mod_log_config.c mod_env.c mod_setenvif.c mod_version.c mod_proxy.c mod_proxy_connect.c mod_proxy_ftp.c mod_proxy_http.c mod_proxy_scgi.c mod_proxy_ajp.c mod_proxy_balancer.c prefork.c http_core.c mod_mime.c mod_status.c mod_autoindex.c mod_asis.c mod_cgi.c mod_negotiation.c mod_dir.c mod_actions.c mod_userdir.c mod_alias.c mod_so.c |
我X,我不想说什么了。。。。
正文
在目睹了各种No such file or directory
之后,只好向Apache添加模块了,这里就记录一下添加mod_headers.so
和mod_deflate.so
两个模块的过程。
首先查看一下安装的Apache是什么版本的。
1 2 |
[root@localhost bin]# ./apachectl -v Server version: Apache/2.2.29 (Unix) |
ok,Apache 2.2.29,上网搜索一份Apache 2.2.29的源码并解压。
使用Apache自带的apxs
进行模块安装。
apxs命令参数说明:
-i 此选项表示需要执行安装操作,以安装一个或多个动态共享对象到服务器的modules目录中。
-a 此选项自动增加一个LoadModule行到httpd.conf文件中,以激活此模块,或者,如果此行已经存在,则启用之。
-A 与 -a 选项类似,但是它增加的LoadModule命令有一个井号前缀(#),即此模块已经准备就绪但尚未启用。
-c 此选项表示需要执行编译操作。它首先会编译C源程序(.c)files为对应的目标代码文件(.o),然后连接这些目标代码和files中其余的目标代码文件(.o和.a),以生成动态共享对象dsofile 。如果没有指定 -o 选项,则此输出文件名由files中的第一个文件名推测得到,也就是默认为mod_name.so 。
使用apxs安装mod_header模块
mod_headers.so
模块的源码文件存储在/modules/metadata/
目录下
1 2 3 |
[root@localhost metadata]# pwd /root/httpd-2.2.29/modules/metadata |
ok,开始安装。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
[root@localhost metadata]# /usr/local/apache/bin/apxs -i -a -c mod_headers.c /usr/local/apache/build/libtool --silent --mode=compile gcc -prefer-pic -DLINUX -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I/usr/local/apache/include -I/usr/local/apache/include -I/usr/local/apache/include -c -o mod_headers.lo mod_headers.c && touch mod_headers.slo /usr/local/apache/build/libtool --silent --mode=link gcc -o mod_headers.la -rpath /usr/local/apache/modules -module -avoid-version mod_headers.lo /usr/local/apache/build/instdso.sh SH_LIBTOOL='/usr/local/apache/build/libtool' mod_headers.la /usr/local/apache/modules /usr/local/apache/build/libtool --mode=install cp mod_headers.la /usr/local/apache/modules/ cp .libs/mod_headers.so /usr/local/apache/modules/mod_headers.so cp .libs/mod_headers.lai /usr/local/apache/modules/mod_headers.la cp .libs/mod_headers.a /usr/local/apache/modules/mod_headers.a chmod 644 /usr/local/apache/modules/mod_headers.a ranlib /usr/local/apache/modules/mod_headers.a PATH="$PATH:/sbin" ldconfig -n /usr/local/apache/modules ---------------------------------------------------------------------- Libraries have been installed in: /usr/local/apache/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- chmod 755 /usr/local/apache/modules/mod_headers.so [activating module `headers' in /usr/local/apache/conf/httpd.conf] |
使用apxs安装mod_deflate模块
mod_deflate.so
模块的源码文件存储在:
1 2 3 |
[root@localhost filters]# pwd /root/httpd-2.2.29/modules/filters |
这两个文件存储在不同的地方,还是需要留意的。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
[root@localhost filters]# /usr/local/apache/bin/apxs -i -a -c mod_deflate.c /usr/local/apache/build/libtool --silent --mode=compile gcc -prefer-pic -DLINUX -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I/usr/local/apache/include -I/usr/local/apache/include -I/usr/local/apache/include -c -o mod_deflate.lo mod_deflate.c && touch mod_deflate.slo /usr/local/apache/build/libtool --silent --mode=link gcc -o mod_deflate.la -rpath /usr/local/apache/modules -module -avoid-version mod_deflate.lo /usr/local/apache/build/instdso.sh SH_LIBTOOL='/usr/local/apache/build/libtool' mod_deflate.la /usr/local/apache/modules /usr/local/apache/build/libtool --mode=install cp mod_deflate.la /usr/local/apache/modules/ cp .libs/mod_deflate.so /usr/local/apache/modules/mod_deflate.so cp .libs/mod_deflate.lai /usr/local/apache/modules/mod_deflate.la cp .libs/mod_deflate.a /usr/local/apache/modules/mod_deflate.a chmod 644 /usr/local/apache/modules/mod_deflate.a ranlib /usr/local/apache/modules/mod_deflate.a PATH="$PATH:/sbin" ldconfig -n /usr/local/apache/modules ---------------------------------------------------------------------- Libraries have been installed in: /usr/local/apache/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the `-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the `LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the `LD_RUN_PATH' environment variable during linking - use the `-Wl,--rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to `/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- chmod 755 /usr/local/apache/modules/mod_deflate.so [activating module `deflate' in /usr/local/apache/conf/httpd.conf] |
剩下的工作就是修改httpd.conf
,添加开启GZIP的相关配置代码。
后记
网站开发商把服务器部署成这个德行我也是醉了。