YAZONG 我的开源

定制RPM包及yum仓库搭建(以安装nginx为例)

  , ,
0 评论0 浏览

一、前提条件

下面通过虚拟机准备了一台服务端,一台客户端,基于外网IP测试,以安装nginx为例。

两台机器公共配置
[root@m01 ~]# cat /etc/redhat-release

CentOS release 6.7 (Final)

[root@m01 ~]# uname -m

x86_64

[root@m01 ~]# uname -r

2.6.32-573.el6.x86_64

服务端配置

[root@m01 ~]# ifconfig eth0|awk -F "[ :]+"'NR==2{print $4}'

10.0.0.61

[root@m01 ~]# hostname

m01

客户端配置

[root@web01 ~]# ifconfig eth0|awk -F '[ :]+' 'NR==2{print$4}'

10.0.0.8

[root@web01 ~]# hostname

web01

RPM介绍

http://www.ibm.com/developerworks/cn/linux/l-rpm/

二、定制化RPM包

下面是服务端的配置,只要没有标明都是服务端操作

2、1FPM安装

fpm是ruby写的,因此系统环境需要ruby,且ruby版本号大于1.8.5

[root@m01 ~]# rpm -qa ruby rubygems ruby-devel

安装ruby模块

[root@m01 ~]# yum -y install ruby rubygems ruby-devel

[root@m01 ~]# rpm -qa ruby rubygems ruby-devel

rubygems-1.3.7-5.el6.noarch

ruby-1.8.7.374-4.el6_6.x86_64

ruby-devel-1.8.7.374-4.el6_6.x86_64

添加阿里云的rubygems仓库,外国的源太慢

[root@m01 ~]# gem sources -ahttp://mirrors.aliyun.com/rubygems/

http://mirrors.aliyun.com/rubygems/ added to sources

移除原生的Ruby仓库

[root@m01 ~]# gem sources --remove http://rubygems.org/

http://rubygems.org/ removed from sources

安装fpm

指定安装fpm1.3.3版本的软件,fpm这个工具升级很频繁,而且在每次升级后会出现各种各样的问题。但是老版本的fpm工具能够满足我们的需求,因此就用这个版本了。

这里一定要指定fpm的版本,不然会报错,报错原因可追溯到版本频繁升级的问题导致。

[root@m01 ~]# gem install fpm -v 1.3.3

Building native extensions. This could take a while...

Building native extensions. This could take a while...

Successfully installed json-1.8.3

Successfully installed cabin-0.8.1

Successfully installed backports-3.6.8

Successfully installed arr-pm-0.0.10

Successfully installed clamp-0.6.5

Successfully installed ffi-1.9.10

Successfully installed childprocess-0.5.9

Successfully installed fpm-1.3.3

8 gems installed

Installing ri documentation for json-1.8.3...

Installing ri documentation for cabin-0.8.1...

Installing ri documentation for backports-3.6.8...

Installing ri documentation for arr-pm-0.0.10...

Installing ri documentation for clamp-0.6.5...

Installing ri documentation for ffi-1.9.10...

Installing ri documentation for childprocess-0.5.9...

Installing ri documentation for fpm-1.3.3...

Installing RDoc documentation for json-1.8.3...

Installing RDoc documentation for cabin-0.8.1...

Installing RDoc documentation for backports-3.6.8...

Installing RDoc documentation for arr-pm-0.0.10...

Installing RDoc documentation for clamp-0.6.5...

Installing RDoc documentation for ffi-1.9.10...

Installing RDoc documentation for childprocess-0.5.9...

Installing RDoc documentation for fpm-1.3.3...

rdoc和ri为ruby程序生成文档

[root@m01 ~]# fpm --help|wc -l

175

最好做下快照,方便还原和测试

2、2定制nginx的RPM包

2、2、1准备操作

准备好nginx安装包,统一放在/application/tools/目录下。

[root@m01 /]# mkdir -p /application/tools/

[root@m01 /]# cd /application/tools/

[root@m01 tools]# pwd

/application/tools

上传或下载nginx安装包

上传使用rz -y命令即可。

下面使用下载方式获取nginx安装包

[root@m01 tools]# wget -q http://nginx.org/download/nginx-1.6.3.tar.gz

[root@m01 tools]# ls -l nginx-1.6.3.tar.gz

-rw-r--r-- 1 root root 805253 Apr 8 2015nginx-1.6.3.tar.gz

开启yum缓存, /etc/yum.conf的解释在4、2

[root@m01 tools]# cp /etc/yum.conf/etc/yum.conf.ori.20160630

[root@m01 tools]# sed 's#keepcache=0#keepcache=1#g'/etc/yum.conf

[main]

cachedir=/var/cache/yum/$basearch/$releasever

keepcache=1

主要的是上面两条

[root@m01 tools]# sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf

[root@m01 tools]# grep "keepcache=1"/etc/yum.conf

keepcache=1

清空本机已有yum缓存

[root@m01 tools]# find /var/cache/ -type f -name"*rpm"

[root@m01 tools]# find /var/cache/ -type f -name"*rpm"|xargs rm -f

最好做下快照,方便还原和测试


设置yum源为阿里的配置

[root@m01 tools]# ls -l /etc/yum.repos.d/CentOS-Base.repo

-rw-r--r--. 1 root root 1991 Aug 4 2015/etc/yum.repos.d/CentOS-Base.repo

[root@m01 tools]# cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.ori.20160630

[root@m01 tools]# ls -l/etc/yum.repos.d/CentOS-Base.repo.ori.20160630

-rw-r--r-- 1 root root 1991 Jun 29 22:23/etc/yum.repos.d/CentOS-Base.repo.ori.20160630

[root@m01 tools]# wget -O /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-6.repo

[root@m01 tools]# ls -l /etc/yum.repos.d/CentOS-Base.repo

-rw-r--r--. 1 root root 2572 May 15 2015 /etc/yum.repos.d/CentOS-Base.repo

可以通过baseurl过滤一下查看是否配置成功

[root@m01 tools]# grep "baseurl"/etc/yum.repos.d/CentOS-Base.repo

#remarked out baseurl= line instead.

baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/

baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/

baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/

baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/

baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/


2、2、2安装nginx

[root@m01 tools]# rpm -qa pcre-devel openssl-devel

[root@m01 tools]# yum -y install pcre-devel openssl-devel

[root@m01 nginx-1.6.3]# rpm -qa pcre-developenssl-devel

openssl-devel-1.0.1e-48.el6_8.1.x86_64

pcre-devel-7.8-7.el6.x86_64


查看yum缓存文件,/var/cache/下的rpm文件千万不要删除,切记!

[root@m01 tools]# find /var/cache/ -type f -name"*rpm"

/var/cache/yum/x86_64/6/updates/packages/openssl-1.0.1e-48.el6_8.1.x86_64.rpm

/var/cache/yum/x86_64/6/updates/packages/openssl-devel-1.0.1e-48.el6_8.1.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/zlib-devel-1.2.3-29.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/libselinux-2.0.94-7.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/pcre-devel-7.8-7.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/libsepol-devel-2.0.41-4.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/libselinux-utils-2.0.94-7.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/libcom_err-devel-1.41.12-22.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/libselinux-devel-2.0.94-7.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/krb5-libs-1.10.3-57.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/krb5-devel-1.10.3-57.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/keyutils-libs-devel-1.4-5.el6.x86_64.rpm

[root@m01 ~]# ls /tmp/

[root@m01 ~]# find /var/cache/ -type f -name"*rpm"|xargs cp -t /tmp/

[root@m01 ~]# ls /tmp/

keyutils-libs-devel-1.4-5.el6.x86_64.rpm libselinux-2.0.94-7.el6.x86_64.rpm openssl-1.0.1e-48.el6_8.1.x86_64.rpm

krb5-devel-1.10.3-57.el6.x86_64.rpm libselinux-devel-2.0.94-7.el6.x86_64.rpm openssl-devel-1.0.1e-48.el6_8.1.x86_64.rpm

krb5-libs-1.10.3-57.el6.x86_64.rpm libselinux-utils-2.0.94-7.el6.x86_64.rpm pcre-devel-7.8-7.el6.x86_64.rpm

libcom_err-devel-1.41.12-22.el6.x86_64.rpm libsepol-devel-2.0.41-4.el6.x86_64.rpm zlib-devel-1.2.3-29.el6.x86_64.rpm

下述在安装rpm包的时候会用到

[root@m01 ~]# cd /tmp/ && tar zcfnginx_yum.tar.gz *.rpm

[root@m01 tmp]# ls -l nginx_yum.tar.gz

-rw-r--r-- 1 root root 4442080 Jun 29 22:31nginx_yum.tar.gz

[root@m01 tmp]# sz nginx_yum.tar.gz

#D:\Program\SecureCRT\download\ nginx_yum.tar.gz


[root@m01 nginx-1.6.3]# useradd nginx -M -s /sbin/nologin

[root@m01 nginx-1.6.3]# tail -1 /etc/passwd

nginx : x:502:502::/home/nginx:/sbin/nologin

[root@m01 tools]# pwd

/application/tools

[root@m01 tools]# ls -l nginx-1.6.3.tar.gz

-rw-r--r-- 1 root root 805253 Apr 8 2015nginx-1.6.3.tar.gz

[root@m01 tools]# tar zxf nginx-1.6.3.tar.gz

[root@m01 tools]# cd nginx-1.6.3

[root@m01 nginx-1.6.3]# ll

total 624

drwxr-xr-x 6 1001 1001 4096 Jun 29 22:26 auto

-rw-r--r-- 1 1001 1001 236608 Apr 7 2015CHANGES

-rw-r--r-- 1 1001 1001 360501 Apr 7 2015CHANGES.ru

drwxr-xr-x 2 1001 1001 4096 Jun 29 22:26 conf

-rwxr-xr-x 1 1001 1001 2369 Apr 7 2015 configure

drwxr-xr-x 4 1001 1001 4096 Jun 29 22:26 contrib

drwxr-xr-x 2 1001 1001 4096 Jun 29 22:26 html

-rw-r--r-- 1 1001 1001 1397 Apr 7 2015 LICENSE

drwxr-xr-x 2 1001 1001 4096 Jun 29 22:26 man

-rw-r--r-- 1 1001 1001 49 Apr 7 2015 README

drwxr-xr-x 8 1001 1001 4096 Jun 29 22:26 src

安装nginx

[root@m01 nginx-1.6.3]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.3/ --with-http_stub_status_module

[root@m01 nginx-1.6.3]# make && make install

[root@m01 nginx-1.6.3]# cd ..

[root@m01 tools]# ll

total 792

drwxr-xr-x 9 1001 1001 4096 Jun 29 22:33 nginx-1.6.3

-rw-r--r-- 1 root root 805253 Apr 8 2015nginx-1.6.3.tar.gz

[root@m01 tools]# pwd

/application/tools

[root@m01 tools]# ln -s /application/nginx-1.6.3//application/nginx


创建rpm包要执行的脚本

[root@m01 tmp]# mkdir -p /server/scripts/

[root@m01 tmp]# cd /server/scripts/

[root@m01 scripts]# cat nginx_rpm.sh

#!/bin/bash

useradd nginx -M -s /sbin/nologin

ln -s /application/nginx-1.6.3/ /application/nginx

做一次快照

通过fpm命令打包rpm

[root@m01 tools]# fpm-s dir -t rpm -n nginx -v 1.6.3 -d'pcre-devel,openssl-devel' --post-install /server/scripts/nginx_rpm.sh -f/application/nginx-1.6.3/

no value for epoch is set, defaulting to nil{:level=>:warn}

no value for epoch is set, defaulting to nil{:level=>:warn}

Created package {:path=>"nginx-1.6.3-1.x86_64.rpm"}

[root@m01 tools]# ls -l nginx-1.6.3-1.x86_64.rpm

-rw-r--r-- 1 root root 1046824 Jun 29 22:39nginx-1.6.3-1.x86_64.rpm

[root@m01 tools]# sz nginx-1.6.3-1.x86_64.rpm

#D:\Program\SecureCRT\download\nginx-1.6.3-1.x86_64.rpm


查看rpm包信息

[root@m01 tools]# rpm -qpi nginx-1.6.3-1.x86_64.rpm

Name :nginx Relocations:/

Version :1.6.3 Vendor:root@m01

Release :1 Build Date: Wed 29 Jun2016 10:39:39 PM CST

Install Date: (not installed) Build Host: m01

Group :default Source RPM:nginx-1.6.3-1.src.rpm

Size :3179846 License:unknown

Signature :(none)

Packager :root@m01

URL :http://example.com/no-uri-given

Summary : nodescription given

Description :

no description given

查看rpm包内容

[root@m01 tools]# rpm -qpl nginx-1.6.3-1.x86_64.rpm

/application/nginx-1.6.3/conf/fastcgi.conf

/application/nginx-1.6.3/conf/fastcgi.conf.default

/application/nginx-1.6.3/conf/fastcgi_params

/application/nginx-1.6.3/conf/fastcgi_params.default

/application/nginx-1.6.3/conf/koi-utf

/application/nginx-1.6.3/conf/koi-win

/application/nginx-1.6.3/conf/mime.types

/application/nginx-1.6.3/conf/mime.types.default

/application/nginx-1.6.3/conf/nginx.conf

/application/nginx-1.6.3/conf/nginx.conf.default

/application/nginx-1.6.3/conf/scgi_params

/application/nginx-1.6.3/conf/scgi_params.default

/application/nginx-1.6.3/conf/uwsgi_params

/application/nginx-1.6.3/conf/uwsgi_params.default

/application/nginx-1.6.3/conf/win-utf

/application/nginx-1.6.3/html/50x.html

/application/nginx-1.6.3/html/index.html

/application/nginx-1.6.3/logs

/application/nginx-1.6.3/sbin/nginx

查看rpm的包依赖

[root@m01 tools]# rpm -qpR nginx-1.6.3-1.x86_64.rpm

pcre-devel

openssl-devel

/bin/sh

rpmlib(PayloadFilesHavePrefix) <= 4.0-1

rpmlib(CompressedFileNames) <= 3.0.4-1

查看rpm自带的执行脚本,执行脚本不是以文件的形式存在rpm包中

[root@m01 tools]# rpm -qp --scriptsnginx-1.6.3-1.x86_64.rpm

postinstall scriptlet (using /bin/sh):

#!/bin/bash

useradd nginx -M -s /sbin/nologin

ln -s /application/nginx-1.6.3/ /application/nginx

三、安装rpm包的三种方法(重点是第三种yum仓库)

3、1第一种,yum命令安装rpm包

[root@m01 tools]# yum localinstallnginx-1.6.3-1.x86_64.rpm

这个命令会自动先从网络安装rpm包的依赖,然后再安装nginx的rpm包。

3、2第二种,rpm命令安装

[root@m01 tools]# rpm -ivh nginx-1.6.3-1.x86_64.rpm

error: Failed dependencies:

   pcre-develis needed by nginx-1.6.2-1.x86_64

  openssl-devel is needed by nginx-1.6.2-1.x86_64

但会报如上依赖错误,需要先yum安装依赖才能安装rpm包。

解决方案:

1、以第一种yum命令安装rpm包的方式**

2

[root@web01 ~]# rpm -ivh openssl-devel-1.0.1e-48.el6_8.1.x86_64.rpm

[root@web01 ~]# rpm -ivh pcre-devel-7.8-7.el6.x86_64.rpm

3、如果本机已有所有的依赖包(对应上述中的nginx_yum.tar.gz),那么执行以下操作:**

[root@web01 ~]# tar zxf nginx_yum.tar.gz

[root@web01 ~]#rpm -ivh --aid *rpm

#如果报下述错误

Preparing... ########################################### [100%]

    file/usr/lib64/libkadm5clnt_mit.so.8.0 from install ofkrb5-libs-1.10.3-42z1.el6_7.x86_64 conflicts with file from packagekrb5-libs-1.10.3-42.el6.x86_64

    file/usr/lib64/libkadm5srv_mit.so.8.0 from install of krb5-libs-1.10.3-42z1.el6_7.x86_64conflicts with file from package krb5-libs-1.10.3-42.el6.x86_64

    file/usr/bin/openssl from install of openssl-1.0.1e-42.el6_7.4.x86_64 conflictswith file from package openssl-1.0.1e-42.el6.x86_64

    file/usr/lib64/.libcrypto.so.1.0.1e.hmac from install ofopenssl-1.0.1e-42.el6_7.4.x86_64 conflicts with file from packageopenssl-1.0.1e-42.el6.x86_64

    file/usr/lib64/.libssl.so.1.0.1e.hmac from install ofopenssl-1.0.1e-42.el6_7.4.x86_64 conflicts with file from packageopenssl-1.0.1e-42.el6.x86_64

………………

报错原因:rpm包冲突,使用U参数,因为有些包本地有,需要更新。

[root@web01 ~]# rpm -Uvh --aid *rpm

3、3第三种方法,搭建yum仓库(重点)

3、3、1服务端配置

3、3、1、1创建yum仓库

[root@m01 tools]# ls -ld /application/yum/centos6/x86_64

ls: cannot access /application/yum/centos6/x86_64: Nosuch file or directory

[root@m01 tools]# mkdir -p /application/yum/centos6/x86_64

[root@m01 tools]# cd /application/yum/centos6/x86_64

[root@m01 x86_64]# pwd

/application/yum/centos6/x86_64

[root@m01 x86_64]# rz -y

上传rpm包到此目录,此目录下面还可以包括文件夹

#D:\Program\SecureCRT\download\nginx-1.6.3-1.x86_64.rpm**

也可以直接拿过来前面生成的nginx-1.6.3-1.x86_64.rpm

[root@m01 x86_64]# cp/application/tools/nginx-1.6.3-1.x86_64.rpm /application/yum/centos6/x86_64/

[root@m01 x86_64]# ls -l nginx-1.6.3-1.x86_64.rpm

-rw-r--r-- 1 root root 1046824 Jun 29 23:04nginx-1.6.3-1.x86_64.rpm

3、3、1、2安装createrepo

[root@m01 x86_64]# rpm -qa createrepo

[root@m01 x86_64]# yum -y install createrepo

3、3、1、3初始化repodata索引文件

[root@m01 x86_64]# createrepo -pdo /application/yum/centos6/x86_64/ /application/yum/centos6/x86_64/

Spawning worker 0 with 1 pkgs

Workers Finished

Gathering worker results

Saving Primary metadata

Saving file lists metadata

Saving other metadata

Generating sqlite DBs

Sqlite DBs complete

3、3、1、4提供yum服务

可以用Apache或nginx提供web服务,但用Python的http模块更简单,适用于内网环境

先检查nginx服务是否开启

[root@m01 x86_64]# ps -ef|grep nginx

root 8370 1969 0 23:08 pts/1 00:00:00 grep nginx

[root@m01 x86_64]# ps -ef|grep 80

root 8372 1969 0 23:08 pts/1 00:00:00 grep 80

[root@m01 x86_64]# netstat -lntup|grep nginx

如果开启,那么要先关闭,因为下面要使用80端口操作

[root@m01 x86_64]# /application/nginx/sbin/nginx -s stop

检查防火墙是否开启

[root@m01 x86_64]# /etc/init.d/iptables status

iptables: Firewall is not running.

如果开启,那么关闭即可

[root@m01 x86_64]# /etc/init.d/iptables stop

[root@m01 x86_64]# pwd

/application/yum/centos6/x86_64

[root@m01 x86_64]# python -m SimpleHTTPServer 80&>/dev/null &

[1] 8383

此时可以通过浏览器输入本机IP查看
Screenshot20200105定制RPM包及yum仓库搭建以安装nginx为例你可以选择不平凡51CTO博客.png

上述图中的文件列表对应/application/yum/centos6/x86_64中的内容。

3、3、1、5添加新的rpm包

再次验证yum缓存是否开启,使yum安装软件时不删除安装包

[root@m01 x86_64]# grep "keepcache=1"/etc/yum.conf

keepcache=1

只下载软件不安装

[root@m01 x86_64]# yumdownloader pcre-devel openssl-devel

[root@m01 x86_64]# ll

total 4076

-rw-r--r-- 1 root root 1046824 Jun 29 23:04nginx-1.6.3-1.x86_64.rpm

-rw-r--r-- 1 root root 1226136 May 13 19:30openssl-devel-1.0.1e-48.el6_8.1.i686.rpm

-rw-r--r-- 1 root root 1226260 May 13 19:30openssl-devel-1.0.1e-48.el6_8.1.x86_64.rpm

-rw-r--r-- 1 root root 327952 Jul 25 2015pcre-devel-7.8-7.el6.i686.rpm

-rw-r--r-- 1 root root 327960 Jul 25 2015pcre-devel-7.8-7.el6.x86_64.rpm

drwxr-xr-x 2 root root 4096 Jun 29 23:07 repodata

[root@m01 x86_64]# pwd

/application/yum/centos6/x86_64

每加入一个rpm包就要更新一下

[root@m01 x86_64]# createrepo --update /application/yum/centos6/x86_64

Spawning worker 0 with 4 pkgs

Workers Finished

Gathering worker results

Saving Primary metadata

Saving file lists metadata

Saving other metadata

Generating sqlite DBs

Sqlite DBs complete

再次检查一下/var/cache/下的rpm文件列表

[root@m01 x86_64]# find /var/cache/ -type f -name"*rpm"

/var/cache/yum/x86_64/6/updates/packages/openssl-1.0.1e-48.el6_8.1.x86_64.rpm

/var/cache/yum/x86_64/6/updates/packages/openssl-devel-1.0.1e-48.el6_8.1.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/createrepo-0.9.9-24.el6.noarch.rpm

/var/cache/yum/x86_64/6/base/packages/zlib-devel-1.2.3-29.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/libselinux-2.0.94-7.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/pcre-devel-7.8-7.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/libsepol-devel-2.0.41-4.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/libselinux-utils-2.0.94-7.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/libcom_err-devel-1.41.12-22.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/libselinux-devel-2.0.94-7.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/krb5-libs-1.10.3-57.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/krb5-devel-1.10.3-57.el6.x86_64.rpm

/var/cache/yum/x86_64/6/base/packages/keyutils-libs-devel-1.4-5.el6.x86_64.rpm

3、3、2客户端配置

3、3、2、1创建脚本

[root@web01 ~]# cd /etc/yum.repos.d

[root@web01 yum.repos.d]# cat oldboy.repo

[oldboy]

name=Server

baseurl=http://10.0.0.61

enable=1

gpgcheck=0

3、3、2、2yum操作

[root@web01 yum.repos.d]# yum clean all

Loaded plugins: fastestmirror, security

Cleaning repos: base extras oldboy updates

Cleaning up Everything

Cleaning up list of fastest mirrors

[root@web01 yum.repos.d]# yum --enablerepo=oldboy --disablerepo=base,extras,updates,epel list

这条命令中的oldboy名称一定要对应oldboy.repo中的[oldboy]!

注意最下面白色的文件列表

Available Packages

nginx.x86_641.6.3-1oldboy

openssl-devel.i6861.0.1e-48.el6_8.1oldboy

openssl-devel.x86_641.0.1e-48.el6_8.1oldboy

pcre-devel.i6867.8-7.el6oldboy

pcre-devel.x86_647.8-7.el6oldboy

#在哪个路径下执行yum操作没有影响

[root@web01 yum.repos.d]# yum install nginx

3、3、2、3检查nginx是否安装成功

[root@web01 yum.repos.d]# ls -ld/application/nginx-1.6.3/

drwxr-xr-x 6 root root 4096 Jun 30 21:51/application/nginx-1.6.3/

[root@web01 yum.repos.d]# ls -ld /application/nginx/

drwxr-xr-x 6 root root 4096 Jun 30 21:51/application/nginx/

[root@web01 yum.repos.d]# ls -l /application/nginx/

total 16

drwxr-xr-x 2 root root 4096 Jun 30 21:51 conf

drwxr-xr-x 2 root root 4096 Jun 30 21:51 html

drwxr-xr-x 2 root root 4096 Jun 29 22:39 logs

drwxr-xr-x 2 root root 4096 Jun 30 21:51 sbin

[root@web01 yum.repos.d]# netstat -lntup|grep nginx

tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2022/nginx

[root@web01 yum.repos.d]# ps -ef|grep nginx

root 2022 1 0 21:52 ? 00:00:00 nginx: master process/application/nginx/sbin/nginx

nginx 2023 2022 0 21:52 ? 00:00:00 nginx: worker process

root 2027 1947 0 21:52 pts/1 00:00:00 grep nginx

四、其他

4、1fpm参数

-s 指定源类型

-t 指定目标类型,即想要制作为什么包

-n 指定包的名字

-v 指定包的版本号

-C 指定打包的相对路径 Change directory to here before searchingforfiles

-d 指定依赖于哪些包

-f 第二次打包时目录下如果有同名安装包存在,则覆盖它

-p 输出的安装包的目录,不想放在当前目录下就需要指定

--post-install 软件包安装完成之后所要运行的脚本;同--after-install

--pre-install 软件包安装完成之前所要运行的脚本;同--before-install

--post-uninstall 软件包卸载完成之后所要运行的脚本;同--after-remove

--pre-uninstall 软件包卸载完成之前所要运行的脚本;同--before-remove

4、2 /etc/yum.conf参数

cachedir=/var/cache/yum

  //yum 缓存的目录,yum 在此存储下载的rpm 包和数据库,默认设置为/var/cache/yum

keepcache=0

  //安装完成后是否保留软件包,0为不保留(默认为0),1为保留

debuglevel=2

  //Debug 信息输出等级,范围为0-10,缺省为2

logfile=/var/log/yum.log

  //yum 日志文件位置。用户可以到/var/log/yum.log 文件去查询过去所做的更新。

exactarch=1

  //有1和0两个选项,设置为1,则yum 只会安装和系统架构匹配的软件包,例如,yum 不会将i686的软件包安装在适合i386的系统中。默认为1。

obsoletes=1

  //这是一个update 的参数,具体请参阅yum(8),简单的说就是相当于upgrade,允许更新陈旧的RPM包。

gpgcheck=1  // 有1和0两个选择,分别代表是否是否进行gpg(GNU Private Guard) 校验,以确定rpm 包的来源是有效和安全的。这个选项如果设置在[main]部分,则对每个repository 都有效。默认值为0。

plugins=1

  //是否启用插件,默认1为允许,0表示不允许。我们一般会用yum-fastestmirror这个插件。

installonly_limit=5 #允许保留多少个内核包。

distroverpkg=redhat-release

  //指定一个软件包,yum 会根据这个包判断你的发行版本,默认是redhat-release,也可以是安装的任何针对自己发行版的rpm 包。


标题:定制RPM包及yum仓库搭建(以安装nginx为例)
作者:yazong
地址:https://blog.llyweb.com/articles/2016/07/01/1578159429636.html