源代码编译安装

    技术2022-07-11  100

    源代码编译

    使用源代码安装软件的优点

    获得最新的软件版本,计时修复bug根据用户需要,灵活定制软件功能

    应用场景举例

    安装较新版本的应用时当前安装的程序无法满足需要时需要为应用程序添加新的功能时

    Tarball封包

    .tar.gz和.tar.bz2格式居多软件素材参考:http://sourceforge.net

    完整性校验

    md5sum校验工具

    [root@localhost opt]# md5sum httpd-2.4.25.tar.gz 24fb8b9e36cf131d78caae864fea0f6a httpd-2.4.25.tar.gz

    确认源代码编译环境

    需要安装支持C/C++程序语言的编译器,如:

    gcc、gcc-c++、make、……

    [root@localhost apr]# yum -y install gcc gcc-c++ make pcre pcre-devel

    (pcre:一个Perl库,支持正则表达式)

    编译安装的基本步骤

    示例:手动编译安装Apache

    1.下载源代码安装文件 把源码包移动到/opt目录下 (apr是支持Apache上层应用跨平台,提供底层接口库apr-util是apr工具包)

    2.解压httpd、apr、apr-util

    [root@localhost opt]# tar xzvf httpd-2.4.25.tar.gz -C /opt

    [root@localhost opt]# tar xzvf apr-1.7.0.tar.gz -C /opt

    [root@localhost opt]# tar xzvf apr-util-1.6.1.tar.gz -C /opt

    把apr、apr-util放入到源码函数库中(否则在./configure配置时会报错)

    [root@localhost opt]# cp -R apr-1.7.0/ /opt/httpd-2.4.25/srclib/apr [root@localhost opt]# cp -R apr-util-1.6.1 /opt/httpd-2.4.25/srclib/apr-util

    3.进行./configure配置

    [root@localhost opt]# cd /opt/httpd-2.4.25/

    [root@localhost httpd-2.4.25]# ./configure \ --prefix=/usr/local/apache \ //指定安装位置 --enable-so \ //开启核心功能模块 --enable-rewrite \ //开启重写功能(防盗链所使用的) --enable-mods-shared=most \ --with-mpm=worker \ --disable-cgid \ --disable-cgi

    4.make编译

    [root@localhost httpd-2.4.25]# make

    (编译时出现以下报错 yum install expat-devel -y)

    5.make install安装

    [root@localhost httpd-2.4.25]# make install

    6.测试及应用维护软件 生成服务启动文件(生成启动脚本便于service管理) 【服务管理: systemctl管理 /usr/lib/systemd/system(7.0版本之后) 语法:systemctl 操作(start、stop、restart、reload……) 示例:systemctl start network.service service管理 /etc/init.d(6.0版本之前) 语法:服务名称 操作 示例:service network start 】

    [root@localhost httpd-2.4.25]# grep -v "#" /usr/local/apache/bin/apachectl > /etc/init.d/httpd //过略掉注释,重新生成到/etc/init.d目录下

    [root@localhost httpd-2.4.25]# vi /etc/init.d/httpd

    在文件最前面插入下面的行 #!/bin/sh # chkconfig:2345 85 15 # description:Apache is a World Wide Web server.

    [root@localhost httpd-2.4.25]# chmod +x /etc/init.d/httpd //添加执行权限 [root@localhost httpd-2.4.25]# chkconfig --add httpd [root@localhost httpd-2.4.25]# chkconfig --list httpd [root@localhost httpd-2.4.25]# chkconfig --level 35 httpd on

    建立软连接便于管理(配置文件)

    [root@localhost httpd-2.4.25]# ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf [root@localhost httpd-2.4.25]# vi /etc/httpd.conf

    开启IPV4,注释掉IPV6,进入监听状态 开启域名 开启服务

    [root@localhost httpd-2.4.25]# service httpd start [root@localhost httpd-2.4.25]# netstat -ntap |grep 80

    [root@localhost httpd-2.4.25]# systemctl stop firewalld //关闭防火墙

    [root@localhost opt]# iptables -F //清空防火墙 [root@localhost opt]# setenforce 0

    网站的站点在/usr/local/apache/htdocs/中

    [root@localhost httpd-2.4.25]# cd /usr/local/apache/htdocs/ [root@localhost htdocs]# ls [root@localhost ~]# vim index.html

    Processed: 0.021, SQL: 9