note_11.2_yum仓库

如何使用光盘当作本地yum仓库:

  1. 挂载光盘至某目录,例如/media/cdrom
    mount -r -t iso9660 /dev/cdrom /media/cdrom
  2. 创建配置文件/etc/yum.repos.d/*.repo
    [CentOS7]
    name=
    baseurl=
    gpgcheck=
    enabled=
    

yum的repo配置文件中可用的变量:

$releasever: 当前OS的发行版的主版本号;
$arch: 平台;
$basearch:基础平台;
$YUM0-$YUM9

e.g. http://mirrors.magedu.com/centos/$releasever/$basearch/os

  • 创建yum仓库:
    createrepo [options]

  • 程序包编译安装:
    testapp-VERSION-release.src.rpm --> 安装后,使用rpmbuild命令制作成二进制格式的rpm包,而后再安装;
    源代码 --> 预处理 --> 编译(gcc) --> 汇编 --> 链接 --> 执行

  • 源代码组织格式:
    多文件:文件中的代码之间,很可能存在跨文件依赖关系;

    • C、C++: make (configure --> Makefile.in --> makefile)
    • java: maven
  • C代码编译安装三步骤:

    • ./configure:
      (1) 通过选项传递参数,指定启用特性、安装路径等;执行时会参考用户的指定以及Makefile.in文件生成makefile;
      (2) 检查依赖到的外部环境;
    • make:
      根据makefile文件,构建应用程序;
    • make install

    开发工具:
     autoconf: 生成configure脚本
     automake:生成Makefile.in
    建议:安装前查看INSTALL,README

  • 开源程序源代码的获取:

    • 官方自建站点:
      apache.org (ASF)
      mariadb.org
      ...
    • 代码托管:
      SourceForge
      Github.com
      code.google.com

c/c++: gcc (GNU C Complier)

编译C源代码:

前提:提供开发工具及开发环境
  开发工具:make, gcc等
  开发环境:开发库,头文件
   glibc:标准库

通过“包组”提供开发组件
  CentOS 6: "Development Tools", "Server Platform Development",

  • 第一步:configure脚本
    选项:指定安装位置、指定启用的特性
    --help: 获取其支持使用的选项

    • 选项分类:
      安装路径设定:
        --prefix=/PATH/TO/SOMEWHERE: 指定默认安装位置;默认为/usr/local/
        --sysconfdir=/PATH/TO/SOMEWHERE:配置文件安装位置;

      System types:
        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]

  1. 导出头文件
    基于链接的方式实现:
      ln -sv

  2. 导出帮助手册
    编辑/etc/man.config文件
      添加一个MANPATH


练习:

1、yum的配置和使用;包括yum repository的创建;
2、编译安装apache;启动此服务;
下载httpd源码tar包

[root@localhost ~]# wget -P /tmp http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.38.tar.bz2
[root@localhost ~]# tar xjf /tmp/httpd-2.4.38.tar.bz2 
[root@localhost ~]# cd httpd-2.4.38/
[root@localhost httpd-2.4.38]# cat INSTALL 

  APACHE INSTALLATION OVERVIEW

  Quick Start - Unix
  ------------------

  For complete installation documentation, see [ht]docs/manual/install.html or
  http://httpd.apache.org/docs/2.4/install.html

     $ ./configure --prefix=PREFIX
     $ make
     $ make install
     $ PREFIX/bin/apachectl start

configure报错少APR

[root@localhost httpd-2.4.38]# ./configure \
>--prefix=/usr/local/apache2 \
> --sysconfdir=/etc/httpd2
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.

yum 安装APR

[root@localhost httpd-2.4.38]# yum -y install *apr*.x86_64*

./configure又报错少PCRE

[root@localhost httpd-2.4.38]# ./configure \
> --prefix=/usr/local/apache\
> --sysconfdir=/etc/httpd2
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... yes
  setting CC to "gcc"
  setting CPP to "gcc -E"
  setting CFLAGS to "  -pthread"
  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_SOURCE"
  setting LDFLAGS to " "
configure: 
configure: Configuring Apache Portable Runtime Utility library...
configure: 
checking for APR-util... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking for gcc option to accept ISO C99... -std=gnu99
checking for pcre-config... false
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

yum安装PCRE

[root@localhost httpd-2.4.38]# yum install *pcre*x86*

./configure完成

[root@localhost httpd-2.4.38]# ./configure \
> --prefix=/usr/local/apache \
> --sysconfdir=/etc/httpd2
....
configure: summary of build options:

    Server Version: 2.4.38
    Install prefix: /usr/local/apache
    C compiler:     gcc -std=gnu99
    CFLAGS:           -pthread  
    CPPFLAGS:        -DLINUX -D_REENTRANT -D_GNU_SOURCE  
    LDFLAGS:           
    LIBS:             
    C preprocessor: gcc -E
[root@localhost httpd-2.4.38]# make
[root@localhost httpd-2.4.38]# make install

启动服务

[root@localhost httpd-2.4.38]# /usr/local/apache/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
[root@localhost httpd-2.4.38]# netstat -tan
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp        0      0 192.168.223.129:22      192.168.223.1:4543      ESTABLISHED
tcp        0     52 192.168.223.131:22      192.168.223.1:12950     ESTABLISHED
tcp        0      0 192.168.223.131:22      192.168.223.1:13127     ESTABLISHED
tcp6       0      0 :::80                   :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN    

你可能感兴趣的:(note_11.2_yum仓库)