编译安装——吐血经验,内附脚本

程序包编译安装:

源码包:name-VERSION-release.src.rpm

        rpm由源码包安装后,使用rpmbuild命令制作成二进制格式的rpm包,而后再安装

        源代码–> 预处理–> 编译(gcc)–> 汇编–> 链接–> 执行

源代码组织格式:

        多文件:文件中的代码之间,很可能存在跨文件依赖关系

C 、C++ :make ( 项目管理器,configure –> Makefile.in –> makefile)

java: maven

 

 

C代码编译安装三步骤:

1、./configure:

         (1)通过选项传递参数,指定启用特性、安装路径等;执行时会参考用户的指定以及makefile.in 文件生成makefile

         (2)检查依赖到的外部环境

2、make:

    根据makefile文件,构建应用程序

3、make install:

    复制文件到相应路径

 

开发工具:

         autoconf:生成configure 脚本

         automake:生成Makefile.in

 

注意:安装前查看INSTALL,README

 

开源程序源代码的获取:

官方自建站点:

         apache.org (ASF)

         mariadb.org

        

代码托管:

         SourceForge.net

         Github.com

         code.google.com

         c/c++ 编译器: gcc (GNU C Complier)

 

编译C源代码:

前提:提供开发工具及开发环境

         开发工具:make, gcc等

         开发环境:开发库,头文件

                 glibc:标准库

通过“包组”提供开发组件

         CentOS:

         "Development Tools",

         "Server Platform Development"

 

第一步:configure 脚本

选项:指定安装位置、指定启用的特性

–help:获取其支持使用的选项(进入到解压的文件中执行命令)

选项分类:

         安装路径设定:

         –prefix=/PATH:指定默认安装位置, 默认为/usr/local/

         –sysconfdir=/PATH:配置文件安装位置

        

         Optional Features:可选特性

         –disable-FEATURE

         –enable-FEATURE[=ARG]

        

         Optional Packages:可选包,

         –with-PACKAGE[=ARG], 依赖包

         –without-PACKAGE, 禁用依赖关系

 

第二步:make

 

第三步:make install

 

安装后的配置:

(1)  二进制程序目录导入至PATH 环境变量中;

         编辑文件/etc/profile.d/NAME.sh

         export PATH=/PATH/TO/BIN:$PATH

(2)  导入库文件路径

         编辑/etc/ld.so.conf.d/NAME.conf

                 添加新的库文件所在目录至此文件中;

         让系统重新生成缓存:

                 ldconfig [-v]

(3)导入头文件

         基于链接的方式导出头文件至/usr/include文件中

         2种实现方式,导出整个目录为1个符号链接,导出每个文件为符号链接

                 ln -sv

(4)导入帮助手册

         编辑/etc/man.config|man_db.conf 文件

         添加一个MANPATH

 

注以下shell脚本问自己手动编写,如若出现任何问题,本人概不负责

编译安装后自动配置脚本:(自动完成上述4步操作)

 

 

#!/bin/bash
#desricptino auto make dir of configue make make install
#version 0.1
#author gaomeng
#date 20160822
#
read -p "Please input service dir path: " dir

//检测该目录是否存在,不存在则报错,退出
if [ -e $dir ];then
    echo "dir is exist."
else
    echo "dir is not exist."
    exit
fi

bindir=$dir/bin
libdir=$dir/lib
includedir=$dir/include
mandir=$dir/man

//检测该目录下的bin,lib,include,man目录是否存在,不存在则报错,退出
if [ -e $bindir ];then
    echo "bin dir is exist."
else
    echo "bin dir is not exist."
    exit
fi

if [ -e $libdir ];then
    echo "lib dir is exist."
else
    echo "lib dir is not exist."
    exit
fi

if [ -e $includedir ];then
    echo "include dir is exist."
else
    echo "include dir is not exist."
    exit
fi

if [ -e $mandir ];then
    echo "man dir is exist."
else
    echo "man dir is not exist."
    exit
fi

name=`basename $dir`

//检测对应目录下(/etc/profile.d/ ,/etc/ld.so.conf.d/ ,/usr/include/)的以路径基名为文件名的文件是否存在,存在则报错,退出
if [ -e /etc/profile.d/$name.sh ]; then
    echo "/etc/profile.d/${name}.sh is exist."
    exit
else
    touch /etc/profile.d/${name}.sh
    echo "PATH=$bindir:$PATH" >> /etc/profile.d/${name}.sh
    echo "/etc/profile.d/${name}.sh add success."
    echo -e "\033[42;31mplease execute: source /etc/profile.d/http.sh\033[0m"
fi

if [ -e /etc/ld.so.conf.d/${name}.conf ]; then
    echo "/etc/ld.so.conf.d/${name}.conf is exist."
    exit
else
    echo "$libdir" >> /etc/ld.so.conf.d/${name}.conf
    ldconfig
    echo "/etc/ld.so.conf.d/${name}.conf add success."
fi

if [ -e /usr/include/${name} ]; then
    echo "/usr/include/${name} is exist."
    exit
else
    ln -sv $includedir /usr/include/${name}
    echo "/usr/include/${name} add success."
fi

//向/etc/man.config文件中最近一条man帮助文件路径
echo "MANPATH $mandir" >> /etc/man.config
echo "$mandir add in /etc/man.config."

自动卸载脚本:(自动删除上述4步所建目录和安装文件目录)

#!/bin/bash
#description auto del service configue file and service file
#version 0.1
#auther gaomeng
#date 20160823
#
read -p "Please input service dir path: " dir

//检测该目录是否存在,不存在则报错
if [ -e $dir ];then
    echo "dir is exist."
else
    echo "dir is not exist."
    read -p "you want go or exit,please input <y|n>" ans
    case $ans in
        [yY]|[yY][sS][eE])
            ;;
        [nN]|[nN][oO])
            exit;;
        *)
            exit;;
    esac
fi

name=`basename $dir`

//检测对应目录下(/etc/profile.d/ ,/etc/ld.so.conf.d/ ,/usr/include/)的以路径基名为文件名的文件是否存在,存在则删除文件,不存在则退出
if [ -e /etc/profile.d/$name.sh ]; then
    rm -f /etc/profile.d/${name}.sh
    echo "/etc/profile.d/${name}.sh is deleted."
else
    echo "/etc/profile.d/${name}.sh is not exist."
fi

if [ -e /etc/ld.so.conf.d/${name}.conf ]; then
    rm -f /etc/ld.so.conf.d/${name}.conf
    echo "/etc/ld.so.conf.d/${name}.conf is deletes."
else
    echo "/etc/ld.so.conf.d/${name}.conf is not exist."
fi

if [ -e /usr/include/${name} ]; then
    rm -f /usr/include/${name}
    echo "/usr/include/${name} is deletes."
else
    echo "/usr/include/${name} is exist."
fi

//删除/etc/man.config文件中的该服务的man帮助路径
sed -i "s@MANPATH /usr/local/${name}/man@@" /etc/man.config
fgrep "s@MANPATH /usr/local/${name}/man@@" /etc/man.config
echo "${name}/man delete from /etc/man.config." 

//删除该服务文件
rm -rf $dir

 

作业:源码安装http2.2.29

 

 

[root@CentOS6 ~]# lftp 10.1.0.1/pub          //下载源码包
cd ok, cwd=/pub
lftp 10.1.0.1:/pub> cd Sources/sources/httpd/
lftp 10.1.0.1:/pub/Sources/sources/httpd> get httpd-2.2.29.tar.bz2
5625498 bytes transferred
lftp 10.1.0.1:/pub/Sources/sources/httpd> bye
[root@CentOS6 ~]# tar xf httpd-2.2.29.tar.bz2            //解压源码包
[root@CentOS6 ~]# cd httpd-2.2.29
[root@CentOS6 httpd-2.2.29]# ./configure prefix=/usr/local/apache2             //安装3步骤
[root@CentOS6 httpd-2.2.29]# make
[root@CentOS6 httpd-2.2.29]# make install
[root@CentOS6 httpd-2.2.29]# which apachectl    //apachectl的二进制程序路径
/usr/sbin/apachectl
[root@CentOS6 httpd-2.2.29]# /root/makeautoadd.sh             //执行编译安装后自动配置脚本
Please input service dir path: /usr/local/apache2
dir is exist.
bin dir is exist.
lib dir is exist.
include dir is exist.
man dir is exist.
please execute: source /etc/profile.d/http.sh
/etc/profile.d/apache2.sh add success.
/etc/ld.so.conf.d/apache2.conf add success.
`/usr/include/apache2' -> `/usr/local/apache2/include'
/usr/include/apache2 add success.
/usr/local/apache2/man add in /etc/man.config.
[root@CentOS6 httpd-2.2.29]# source /etc/profile.d/apache2.sh
[root@CentOS6 httpd-2.2.29]# which apachectl   //apachectl的二进制程序路径改变了
/usr/local/apache2/bin/apachectl
[root@CentOS6 httpd-2.2.29]# echo "ServerName localhost:80" >> /usr/local/apache2/conf/httpd.conf 
[root@CentOS6 httpd-2.2.29]# apachectl start                 //启动服务
[root@CentOS6 httpd-2.2.29]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:dd:9f:c8 brd ff:ff:ff:ff:ff:ff
    inet 10.1.143.1/8 brd 10.255.255.255 scope global eth0              //ip地址
    inet6 fe80::20c:29ff:fedd:9fc8/64 scope link 
       valid_lft forever preferred_lft forever

QQ截图20160823200001.png

服务启动成功

 

 

 

 

 

原创文章,作者:megedugao,如若转载,请注明出处:http://www.178linux.com/39210

(0)
megedugaomegedugao
上一篇 2016-08-24 10:12
下一篇 2016-08-24 10:12

相关推荐

  • Linux百科

    百度百科摘

    Linux干货 2018-03-26
  • linux流程控制if,for,case,while

     Shell编程中循环命令用于特定条件下决定某些语句重复执行的控制方式,有三种常用的循环语句:for、while和until。while循环和for循环属于“当型循环”,而until属于“直到型循环”。循环控制符:break和continue控制流程转向。 选择执行:           …

    Linux干货 2017-03-25
  • 网络接口bonding的设置、网卡别名的设置

    网络接口bonding的设置、网卡别名的设置 网络接口bonding的设置 1.bonding的原理 Bonding就是将多块网卡绑定同一IP 地址对外提供服务,可以实现高可用或者负载均衡。当然,直接给两块网卡设置同一IP 地址是不可能的。通过bonding ,虚拟一块网卡对外提供连接,物理网卡的被修改为相同的MAC 地址。 2.Bonding 的工作模式 …

    Linux干货 2016-09-05
  • Linux的主要发行版及区别

    Linux的主要发行版介绍 主流的发行版 Linux至上世纪90年代基于Unix而诞生,至今其发行版有几百种之多,但其主流的发行版有三个系列。 Debian系 Ubuntu属于Debinan系。 Redhat系CentOS属于Redhat系。Slackware系SUSE Linux即属于Slackware系。 主要区别 软件包管…

    Linux干货 2016-10-29
  • 文件管理相关

     rename:对文件重命名     rename [options] expression replacement file        示例:          # rename -v cut.exe cut.exe3 cut.exe…

    Linux干货 2017-02-25
  • 第一周博客作业

       本文介紹計算机的组成及其功能 、Linux各版本的联系与区别、Linux的哲学思想、Linux系统上命令的使用格式及介绍部分命令、如何在Linux系统上获取帮助信息以及Linux发行版的基础目录名称以及规定。 一、计算机的组成及其功能 1)什么是计算机? 想了解计算机的组成,首先得了解计算机的含义。计算机其实是:接收用户输入指令与数…

    Linux干货 2016-12-04