为何要编译

#编译安装可以选择定制化的环境,用yum和rpm是无法实现定制化的安装的
#编译安装的步骤:
 1  下载源码包解压
 2   进入解压的目录,./configure   传递参数,启用特性。指定安装的目录,如果不指定就是默认在/usr/local,生成makefile文件
                    Makefile  
                    make  根据Makefile文件构建缓存(make要提前安装)
                    makefile  复制文件到相应的路径

编译安装最新版本的tree

1.安装 gcc
2 [root11:02 AMcentos7 ]#tar xf  tree-1.8.0.tgz  解压
3. [root11:02 AMcentos7 ]#cd tree-1.8.0
4. [root11:03 AMcentos7 ]#sed -i 's#v1\.8\.0#v8.8.8#'  tree.c
5.vim Makefile   
    prefix = /apps/tree    #该目录在make以后会自动生成,自定义的目录
    CC=gcc 
    VERSION=1.8.0
    TREE_DEST=tree
    BINDIR=${prefix}/bin   #应用变量,以后tree文件就放在/apps/tree/bin 下面了
    MAN=tree.1
    MANDIR=${prefix}/man/man1
    OBJS=tree.o unix.o html.o xml.o json.o hash.o color.o file.o
6   [root11:17 AMcentos7 ]#make
    [root11:17 AMcentos7 ]#make install
7   发现了个不同的版本tree
    [root11:18 AMcentos7 ]#cd /apps/tree/bin/
    [root11:18 AMcentos7 ]#./tree --version
    tree v8.8.8 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke           Tokoro 
    [root11:18 AMcentos7 ]#tree --version
    tree v1.6.0 (c) 1996 - 2011 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro 
方法一: 修改环境变量,提高优先级,使用新版tree
    [root11:18 AMcentos7 ]#echo 'PATH=/apps/tree/bin:$PATH' > /etc/profile.d/tree.sh
    [root11:21 AMcentos7 ]#. /etc/profile.d/tree.sh 
     #老版本的tree的路径
    [root11:21 AMcentos7 ]#whereis tree
    tree: /usr/bin/tree /apps/tree/bin/tree /usr/share/man/man1/tree.1.gz
    [root11:22 AMcentos7 ]#echo $PATH  优先级提到第一了
    /apps/tree/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    [root11:21 AMcentos7 ]#tree --version
    tree v8.8.8 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke           Tokoro 
方法二 添加软链接,提高优先级
rm -rf /etc/profile.d/tree.sh 
[root11:30 AMcentos7 ]#tree  --version
tree v1.6.0 (c) 1996 - 2011 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro 
#给源文件指一条软链接
[root11:31 AMcentos7 ]#ln -s  /apps/tree/bin/tree /usr/local/bin
[root11:33 AMcentos7 ]#ll /usr/local/bin/
total 0
lrwxrwxrwx 1 root root 19 Apr 30 11:33 tree -> /apps/tree/bin/tree
[root11:33 AMcentos7 ]#cd /usr/local/bin/
[root11:34 AMcentos7 ]#ls
tree
#没有成功。依然缓存的就路径
[root11:34 AMcentos7 ]#tree --version
tree v1.6.0 (c) 1996 - 2011 by Steve Baker, Thomas Moore, Francesc Rocher, Kyosuke Tokoro 
[root11:36 AMcentos7 ]#hash
hits    command
   1    /usr/bin/ln
   2    /usr/bin/ls
   4    /usr/bin/tree  #缓存里面保存的是就路径
   [root11:39 AMcentos7 ]#hash -d tree   #清除一条缓存
    [root11:39 AMcentos7 ]#hash
    hits    command
       1    /usr/bin/ln
       2    /usr/bin/ls
    [root11:39 AMcentos7 ]#tree  --version
    tree v8.8.8 (c) 1996 - 2018 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke          Tokoro 

#删除旧的tree
[root11:41 AMcentos7 ]#yum -y remove tree
[root11:42 AMcentos7 ]#man tree
No manual entry for tree
[root11:42 AMcentos7 ]#whereis tree
tree: /usr/local/bin/tree    没有列出man的帮助文件,默认是找不到man帮助文件的
[root11:44 AMcentos7 ]#whereis bash
bash: /usr/bin/bash /usr/share/man/man1/bash.1.gz

#修改man 帮助
[root11:44 AMcentos7 ]#tree /apps/tree/
/apps/tree/
├── bin
│   └── tree
└── man
    └── man1
        └── tree.1

3 directories, 2 files
#文件里面增加增加新的一行
[root11:45 AMcentos7 ]#vim /etc/man_db.conf
MANDATORY_MANPATH                       /apps/tree/man

centos8安装cmatrix

  1.安装包 yum  install ncurses-devel -y
  2.下载安装包,解压缩,进入目录
  ./configure --prefix=/apps/cmatrix
[root04:40 PMcentos8 /usr/local/src/cmatrix]#make -j 2  
make  all-am
make[1]: Entering directory '/usr/local/src/cmatrix'
gcc -DHAVE_CONFIG_H -I.     -g -O2 -MT cmatrix.o -MD -MP -MF .deps/cmatrix.Tpo -c -o cmatrix.o cmatrix.c
cmatrix.c:43:10: fatal error: curses.h: No such file or directory
 #include <curses.h>
          ^~~~~~~~~~
报错的解决方法:
[root04:47 PMcentos8 /usr/local/src/cmatrix]#yum search curses   (搜索一下)
[root04:48 PMcentos8 /usr/local/src/cmatrix]#yum  install ncurses-devel -y  安装开发包
#创建软链接(因为就只有一个文件,就直接写条软链接就好)
[root04:53 PMcentos8 /usr/local/src/cmatrix]#ln -sv /apps/cmatrix/bin/cmatrix  /usr/local/bin/
'/usr/local/bin/cmatrix' -> '/apps/cmatrix/bin/cmatrix'

#修改man帮助
[root04:52 PMcentos8 /usr/local/src/cmatrix]#tree  /apps/cmatrix/
/apps/cmatrix/
├── bin
│   └── cmatrix
└── share
    └── man
        └── man1
            └── cmatrix.1

[root05:00 PMcentos8 /usr/local/src/cmatrix]#vim /etc/man_db.conf    (#添加一行)
MANDATORY_MANPATH                       /apps/cmatrix/share/man/

# 编译安装的拷贝到别的机器上,直接使用,在一台机器上弄好了直接拷贝别的机器上
#跨版本会产生问题
[root05:28 PMcentos8 /apps/cmatrix]#scp -r /apps/  10.0.0.81:/    
root01:24 PMcentos8 ~]#ln  -sv /apps/cmatrix/bin/cmatrix  /usr/local/bin/
'/usr/local/bin/cmatrix' -> '/apps/cmatrix/bin/cmatrix'
[root05:37 PMcentos8 ~]#cmatrix 

编译安装httpd-2.4.46

[root06:14 PMcentos8 ~/httpd-2.4.46]#yum install gcc apr-devel apr-util-devel pcre-devel openssl-devel redhat-rpm-config -y
[root06:11 PMcentos8 ~/httpd-2.4.46]#./configure --prefix=/apps/httpd --sysconfdir=/etc/httpd  --enable-ssl
 Server Version: 2.4.46
    Install prefix: /apps/httpd
    C compiler:     gcc
    CFLAGS:           -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E  
[root06:17 PMcentos8 ~/httpd-2.4.46]#make 
[root06:17 PMcentos8 ~/httpd-2.4.46]#make  install

#进入页面开启httpd服务
[root06:22 PMcentos8 /apps/httpd/bin]#pwd
/apps/httpd/bin
[root06:22 PMcentos8 /apps/httpd/bin]#ls
ab         apxs      dbmmanage  envvars-std  htcacheclean  htdigest  httpd      logresolve
apachectl  checkgid  envvars    fcgistarter  htdbm         htpasswd  httxt2dbm  rotatelogs
[root06:22 PMcentos8 /apps/httpd/bin]#./apachectl start

[root06:38 PMcentos8 /apps/httpd/bin]#useradd -r -s /sbin/nologin -d /var/www/ -c APACHE -u 49 apache
                                               -r 系统用户 
                                                -s  指定shell  
                                               -d家目录 
                                               -c 描述
                                               -u UID
[root06:44 PMcentos8 /apps/httpd/bin]#getent passwd apache
apache:x:49:49:APACHE:/var/www/:/sbin/nologin
用他来作为服务的启动账号

#进入到编译安装的指定的路径修改配置文件
[root06:47 PMcentos8 /apps/httpd/bin]#cd /etc/httpd/
[root06:47 PMcentos8 /etc/httpd]#ls
conf.modules.d  extra  httpd.conf  magic  mime.types  original
[root06:48 PMcentos8 /etc/httpd]#vim httpd.conf  #配置账户的信息
User apache
Group apache  #修改属主和属组

[root06:52 PMcentos8 /apps/httpd/bin]#echo 'PATH=/apps/httpd/bin:$PATH' >/etc/profile.d/httpd.sh
[root06:54 PMcentos8 /apps/httpd/bin]#. /etc/profile.d/httpd.sh 
[root06:54 PMcentos8 /apps/httpd/bin]#apachectl -h
[root06:56 PMcentos8 /apps/httpd/bin]#apachectl restart
[root06:56 PMcentos8 /apps/httpd/bin]#man  apachectl 
[root06:57 PMcentos8 ~]#apachectl stop
[root06:57 PMcentos8 ~]#apachectl start

[root06:58 PMcentos8 ~]#ps  aux |tail -5
apache     27836  0.0  0.7 878308  7748 ?        Sl   18:57   0:00 /apps/httpd/bin/httpd -k start
apache     27837  0.0  0.7 878308  7748 ?        Sl   18:57   0:00 /apps/httpd/bin/httpd -k start
apache     27838  0.0  0.7 878308  7748 ?        Sl   18:57   0:00 /apps/httpd/bin/httpd -k start
root       27922  0.0  0.4  57816  3976 pts/0    R+   18:58   0:00 ps aux
root       27923  0.0  0.0    204     4 pts/0    R+   18:58   0:00 [tail]

#编译安装的所在目录可以直接拷贝到别的机器上使用