Linux源代码编译安装详解(4)

系统版本与软件版本

[root@GNOME-C7 ~]# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) [root@GNOME-C7 ~]# uname -r 3.10.0-693.el7.x86_64 ------------------------------------------------------------------ apr-1.6.3 apr-util-1.6.1 httpd-2.4.6

提前安装开发环境
[root@GNOME-C7 ~]# yum groupinstall -y "Development tools" "Development and Creative Workstation"

3.2.1. 安装apr-1.6.3 [root@GNOME-C7 ~]# cd apr-1.6.3/ root@GNOME-C7 apr-1.6.3]# ./configure -prefix=/usr/local/apr-1.6.3 [root@GNOME-C7 apr-1.6.3]# make [root@GNOME-C7 apr-1.6.3]# make install 3.2.2. 安装apr-util-1.6.1 [root@GNOME-C7 apr-1.6.3]# cd ../apr-util-1.6.1/ [root@GNOME-C7 apr-util-1.6.1]# ./configure -prefix=/usr/local/apr-unil-1.6.1 --with-apr=/usr/local/apr-1.6.3 [root@GNOME-C7 apr-util-1.6.1]# make 遇到报错: xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory #include <expat.h> ^ compilation terminated. make[1]: *** [xml/apr_xml.lo] Error 1 make[1]: Leaving directory `/root/apr-util-1.6.1' make: *** [all-recursive] Error 1 解决方法:yum install -y expat-devel [root@GNOME-C7 apr-util-1.6.1]# make install 3.2.3. 安装httpd-2.4.6 [root@GNOME-C7 apr-util-1.6.1]# cd ../httpd-2.4.6/ [root@GNOME-C7 apr-util-1.6.1]# yum install -y openssl-devel ##如果想要直接编译成功ssl模块,需要提前安装该openssl-devel,否则编译过程中虽然不报错(因为不是是动态编译),但是编译结束后会发现没有ssl模块; [root@GNOME-C7 httpd-2.4.6]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr-1.6.3 --with-apr-util=/usr/local/apr-unil-1.6.1 --with-included-apr --sysconfdir=/etc/httpd --enable-so --enable-mpms-shared=all --enable-mods-shared=all --with-mpm=prefork 遇到报错:configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/. 解决方法:cp -r ../apr-1.6.3 ./srclib/apr ; cp -r ../apr-util-1.6.1 ./srclib/apr-util 遇到报错:configure: error: pcre-config for libpcre not found. PCRE is required and available from 解决方法:yum -y install pcre-devel [root@GNOME-C7 httpd-2.4.6]# make [root@GNOME-C7 httpd-2.4.6]# make install 本次使用的编译参数 --enable-so:表示启用DSO动态模块加载机制; --enable-mpms-shared=安装所有支持的MPM模块 --enable-mods-shared=all:动态的编译所有的模块 --with-mpm=prefork:指定默认MPM 3.2.4. 导出二进制程序目录至PATH变量 [root@centos7 ~]# export PATH=$PATH:/usr/local/apache2/bin [root@centos7 ~]# vim /etc/profile.d/apache2.sh export PATH=$PATH:/usr/local/apache2/bin 3.2.5. 导出man手册 [root@centos7 ~]# vim /etc/man_db.conf MANPATH_MAP /usr/local/apache2/bin /usr/local/apache2/man [root@GNOME-C7 ~]# manpath /usr/local/share/man:/usr/share/man/overrides:/usr/share/man:/usr/local/apache2/man 3.2.6. 导出头文件 [root@GNOME-C7 ~]# ln -sv /usr/local/apache2/include /usr/include/httpd ‘/usr/include/httpd’ -> ‘/usr/local/apache2/include’ 3.2.7. 导出库文件 [root@GNOME-C7 ~]# vim /etc/ld.so.conf.d/httpd.conf /usr/local/apache2/lib [root@GNOME-C7 ~]# ldconfig -v [root@GNOME-C7 ~]# ldconfig -p | grep apache libaprutil-1.so.0 (libc6,x86-64) => /usr/local/apache2/lib/libaprutil-1.so.0 libaprutil-1.so (libc6,x86-64) => /usr/local/apache2/lib/libaprutil-1.so libapr-1.so.0 (libc6,x86-64) => /usr/local/apache2/lib/libapr-1.so.0 libapr-1.so (libc6,x86-64) => /usr/local/apache2/lib/libapr-1.so 3.2.8. 创建服务管理脚本

这两个脚本是从其他机器上复制的,然后改了一下文件与目录的路径

[root@GNOME-C7 ~]# cat /etc/sysconfig/httpd # Configuration file for the httpd service. # # The default processing model (MPM) is the process-based # 'prefork' model. A thread-based model, 'worker', is also # available, but does not work with some modules (such as PHP). # The service must be stopped before changing this variable. # HTTPD=/usr/local/apache2/bin/httpd # # To pass additional options (for instance, -D definitions) to the # httpd binary at startup, set OPTIONS here. # #OPTIONS= # # By default, the httpd process is started in the C locale; to # change the locale in which the server runs, the HTTPD_LANG # variable can be set. # #HTTPD_LANG=C [root@GNOME-C7 ~]# cat /etc/rc.d/init.d/httpd #!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: The Apache HTTP Server is an efficient and extensible \ # server implementing the current HTTP standards. # processname: httpd # config: /etc/httpd/httpd.conf # config: /etc/sysconfig/httpd # pidfile: /usr/local/apache2/logs/httpd.pid # ### BEGIN INIT INFO # Provides: httpd # Required-Start: $local_fs $remote_fs $network $named # Required-Stop: $local_fs $remote_fs $network # Should-Start: distcache # Short-Description: start and stop Apache HTTP Server # Description: The Apache HTTP Server is an extensible server # implementing the current HTTP standards. ### END INIT INFO # Source function library. . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi # Start httpd in the C locale by default. HTTPD_LANG=${HTTPD_LANG-"C"} # This will prevent initlog from swallowing up a pass-phrase prompt if # mod_ssl needs a pass-phrase from the user. INITLOG_ARGS="" # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server # with the thread-based "worker" MPM; BE WARNED that some modules may not # work correctly with a thread-based MPM; notably PHP will refuse to start. # Path to the apachectl script, server binary, and short-form for messages. apachectl=/usr/local/apache2/bin/apachectl httpd=${HTTPD-/usr/local/apache2/bin/httpd} prog=httpd pidfile=${PIDFILE-/usr/local/apache2/logs/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 STOP_TIMEOUT=${STOP_TIMEOUT-10} # The semantics of these two functions differ from the way apachectl does # things -- attempting to start while running is a failure, and shutdown # when not running is also a failure. So we just do it the way init scripts # are expected to behave here. start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } # When stopping httpd, a delay (of default 10 second) is required # before SIGKILLing the httpd parent; this gives enough time for the # httpd parent to SIGKILL any errant children. stop() { status -p ${pidfile} $httpd > /dev/null if [[ $? = 0 ]]; then echo -n $"Stopping $prog: " killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd else echo -n $"Stopping $prog: " success fi RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: " if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then RETVAL=6 echo $"not reloading due to configuration syntax error" failure $"not reloading $httpd due to configuration syntax error" else # Force LSB behaviour from killproc LSB=1 killproc -p ${pidfile} $httpd -HUP RETVAL=$? if [ $RETVAL -eq 7 ]; then failure $"httpd shutdown" fi fi echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} $httpd RETVAL=$? ;; restart) stop start ;; condrestart|try-restart) if status -p ${pidfile} $httpd >&/dev/null; then stop start fi ;; force-reload|reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}" RETVAL=2 esac exit $RETVAL 3.2.9. 使用chkconfig管理 [root@GNOME-C7 ~]# chmod 755 /etc/init.d/httpd [root@GNOME-C7 ~]# chkconfig --add httpd [root@GNOME-C7 ~]# chkconfig --level 3 httpd on [root@GNOME-C7 ~]# chkconfig --list | grep httpd httpd 0:off 1:off 2:off 3:on 4:off 5:off 6:off 3.2.10. 启动服务 [root@GNOME-C7 ~]# service httpd start Starting httpd (via systemctl): [ OK ] [root@GNOME-C7 ~]# ss -ant | grep 80 LISTEN 0 128 *:80 *:* [root@GNOME-C7 ~]# ps aux | grep http[d] ##现在运行httpd的用户是daemon,可以在配置文件中更改 root 114229 0.0 0.0 97508 2536 ? Ss 18:34 0:00 /usr/local/apache2/bin/httpd daemon 114231 0.0 0.0 386420 4416 ? Sl 18:34 0:00 /usr/local/apache2/bin/httpd daemon 114232 0.0 0.0 386420 4416 ? Sl 18:34 0:00 /usr/local/apache2/bin/httpd daemon 114233 0.0 0.0 386420 4420 ? Sl 18:34 0:00 /usr/local/apache2/bin/httpd daemon 114234 0.0 0.0 386420 4420 ? Sl 18:34 0:00 /usr/local/apache2/bin/httpd 3.2.11. 访问测试

Linux源代码编译安装详解

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/44123ec20e806eb679beb0fe9a90c162.html