当前位置 主页 > 服务器问题 > Linux/apache问题 >

    Centos定制rpm包、搭建yum仓库的教程

    栏目:Linux/apache问题 时间:2019-11-30 13:06

    1 保留yum安装软件时下载下来的rpm包

    只需修改yum配置文件即可。下载下来的rpm包会自动保存在/var/cache/yum/目录下

    [root@swag ~]# sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf
    [root@swag ~]# yum install sl -y
    [root@swag ~]# tree /var/cache/yum/x86_64/6/epel/
    /var/cache/yum/x86_64/6/epel/
    ├── 83f14a3d88054141092be5da12eb18cb1baabd7d52e1ae38bfc98d3d5005490c-primary.sqlite
    ├── cachecookie
    ├── packages
    │  └── sl-5.02-1.el6.x86_64.rpm
    └── repomd.xml
    
    1 directory, 4 files

    2 编译安装Nginx

    # Download tar.gz package
    cd /home/oldboy/tools
    wget -q http://nginx.org/download/nginx-1.6.3.tar.gz
    # Yum install Dependent package
    yum install openssl openssl-devel -y
    yum install pcre pcre-devel -y
    rpm -qa pcre pcre-devel
    # Useradd www
    useradd www -s /sbin/nologin -M
    # Compile and install
    tar -xf nginx-1.6.3.tar.gz
    cd nginx-1.6.3
    ./configure --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --prefix=/application/nginx-1.6.3/
    make && make install
    # Create a soft link
    ln -s /application/nginx-1.6.3/ /application/nginx
    # Start nginx
    /application/nginx/sbin/nginx
    # Check port 80
    lsof -i :80

    3 安装fpm工具

    首先安装依赖包

    yum -y install zlib-devel curl-devel openssl-devel httpd-devel apr-devel apr-util-devel mysql-devel

    下载ruby,fpm是ruby写的,因此系统环境需要ruby。不推荐yum安装ruby,在测试的时候会出现一些问题。

    [root@swag tools]# wget https://ruby.taobao.org/mirrors/ruby/ruby-2.3.0.tar.gz
    [root@swag tools]# tar -xf ruby-2.3.0.tar.gz
    [root@swag tools]# cd ruby-2.3.0
    [root@swag ruby-2.3.0]# ./configure
    [root@swag ruby-2.3.0]# make && make install
    [root@swag ruby-2.3.0]# ruby -v
    ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
    [root@swag ~]# whereis gem
    gem: /usr/local/bin/gem
    [root@swag ~]# /usr/local/bin/gem install fpm
    [root@swag ~]# fpm -v
    1.9.3
    # 添加阿里云的Rubygems仓库,默认的源为外国源,访问下载速度比较慢,在添加之前先移除原生的Ruby仓库
    [root@swag ~]# gem sources
    *** CURRENT SOURCES ***
    https://rubygems.org/ 
    [root@swag ~]# gem sources --remove https://rubygems.org/
    https://rubygems.org/ removed from sources
    # 添加阿里仓库
    [root@swag ~]# gem sources -a http://mirrors.aliyun.com/rubygems/
    http://mirrors.aliyun.com/rubygems/ added to sources
    [root@swag ~]# gem sources
    *** CURRENT SOURCES ***

    http://mirrors.aliyun.com/rubygems/

    fpm常用参数
    -s:指定源类型
    -t:指定目标类型,即想要制作为什么包
    -n:指定包的名字
    -v:指定包的版本号
    -C:指定打包的相对路径
    -d:指定依赖于哪些包
    -f:第二次打包时目录下如果有同名安装包存在,则覆盖它
    -p:输出的安装包的目录,不想放在当前目录下就需要指定
    --post-install:软件包安装完成之后所要运行的脚本;同--offer-install
    --pre-install:软件包安装完成之前所要运行的脚本;同--before-install
    --post-uninstall:软件包卸载完成之后所要运行的脚本;同--offer-remove
    --pre-uninstall:软件包卸载完成之前所要运行的脚本;同—before-remove