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

一、前提条件

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

#两台机器公共配置

[[email protected] ~]# cat /etc/redhat-release

CentOS release 6.7 (Final)

[[email protected] ~]# uname -m

x86_64

[[email protected] ~]# uname -r

2.6.32-573.el6.x86_64

#服务端配置

[[email protected] ~]# ifconfig eth0|awk -F "[ :]+"‘NR==2{print $4}‘

10.0.0.61

[[email protected] ~]# hostname

m01

#客户端配置

[[email protected] ~]# ifconfig eth0|awk -F ‘[ :]+‘ ‘NR==2{print$4}‘

10.0.0.8

[[email protected] ~]# hostname

web01

#RPM介绍

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

二、定制化RPM包

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

2、1FPM安装

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

[[email protected] ~]# rpm -qa ruby rubygems ruby-devel

#安装ruby模块

[[email protected] ~]# yum -y install ruby rubygems ruby-devel

[[email protected] ~]# 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仓库,外国的源太慢

[[email protected] ~]# gem sources -ahttp://mirrors.aliyun.com/rubygems/

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

#移除原生的Ruby仓库

[[email protected] ~]# gem sources --remove http://rubygems.org/

http://rubygems.org/ removed from sources

#安装fpm

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

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

[[email protected] ~]# 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程序生成文档

[[email protected] ~]# fpm --help|wc -l

175

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

2、2定制nginx的RPM包

2、2、1准备操作

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

[[email protected] /]# mkdir -p /application/tools/

[[email protected] /]# cd /application/tools/

[[email protected] tools]# pwd

/application/tools

#上传或下载nginx安装包

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

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

[[email protected] tools]# wget -qhttp://nginx.org/download/nginx-1.6.3.tar.gz

[[email protected] 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

[[email protected] tools]# cp /etc/yum.conf/etc/yum.conf.ori.20160630

[[email protected] tools]# sed ‘s#keepcache=0#keepcache=1#g‘/etc/yum.conf

[main]

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

keepcache=1

#主要的是上面两条

[[email protected] tools]# sed -i ‘s#keepcache=0#keepcache=1#g‘ /etc/yum.conf

[[email protected] tools]# grep "keepcache=1"/etc/yum.conf

keepcache=1

#清空本机已有yum缓存

[[email protected] tools]# find /var/cache/ -type f -name"*rpm"

[[email protected] tools]# find /var/cache/ -type f -name"*rpm"|xargs rm -f

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

-----------------------------------------------------------

#设置yum源为阿里的配置

[[email protected] 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

[[email protected] tools]# cp /etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.ori.20160630

[[email protected] 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

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

[[email protected] 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过滤一下查看是否配置成功

[[email protected] 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

[[email protected] tools]# rpm -qa pcre-devel openssl-devel

[[email protected] tools]# yum -y install pcre-devel openssl-devel

[[email protected] 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文件千万不要删除,切记!

[[email protected] 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

[[email protected] ~]# ls /tmp/

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

[[email protected] ~]# 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包的时候会用到

[[email protected] ~]# cd /tmp/ && tar zcfnginx_yum.tar.gz *.rpm

[[email protected] tmp]# ls -l nginx_yum.tar.gz

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

[[email protected] tmp]# sz nginx_yum.tar.gz

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

-----------------------------------------------------------

[[email protected] nginx-1.6.3]# useradd nginx -M -s /sbin/nologin

[[email protected] nginx-1.6.3]# tail -1 /etc/passwd

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

[[email protected] tools]# pwd

/application/tools

[[email protected] tools]# ls -l nginx-1.6.3.tar.gz

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

[[email protected] tools]# tar zxf nginx-1.6.3.tar.gz

[[email protected] tools]# cd nginx-1.6.3

[[email protected] 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

[[email protected] nginx-1.6.3]# ./configure --user=nginx --group=nginx --prefix=/application/nginx-1.6.3/ --with-http_stub_status_module

[[email protected] nginx-1.6.3]# make && make install

[[email protected] nginx-1.6.3]# cd ..

[[email protected] 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

[[email protected] tools]# pwd

/application/tools

[[email protected] tools]# ln -s /application/nginx-1.6.3//application/nginx

-----------------------------------------------------------

#创建rpm包要执行的脚本

[[email protected] tmp]# mkdir -p /server/scripts/

[[email protected] tmp]# cd /server/scripts/

[[email protected] scripts]# cat nginx_rpm.sh

#!/bin/bash

useradd nginx -M -s /sbin/nologin

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

#做一次快照

#通过fpm命令打包rpm

[[email protected] 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"}

[[email protected] 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

[[email protected] tools]# sz nginx-1.6.3-1.x86_64.rpm

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

-----------------------------------------------------------

#查看rpm包信息

[[email protected] tools]# rpm -qpi nginx-1.6.3-1.x86_64.rpm

Name        :nginx                        Relocations:/

Version     :1.6.3                             Vendor:[email protected]

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    :<[email protected]>

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

Summary     : nodescription given

Description :

no description given

#查看rpm包内容

[[email protected] 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的包依赖

[[email protected] 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包中

[[email protected] 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包

[[email protected] tools]# yum localinstallnginx-1.6.3-1.x86_64.rpm

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

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

[[email protected] 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

[[email protected] ~]# rpm -ivh openssl-devel-1.0.1e-48.el6_8.1.x86_64.rpm

[[email protected] ~]# rpm -ivh pcre-devel-7.8-7.el6.x86_64.rpm

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

[[email protected] ~]# tar zxf nginx_yum.tar.gz

[[email protected] ~]#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参数,因为有些包本地有,需要更新。

[[email protected] ~]# rpm -Uvh --aid *rpm

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

3、3、1服务端配置

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

[[email protected] tools]# ls -ld /application/yum/centos6/x86_64

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

[[email protected] tools]# mkdir /application/yum/centos6/x86_64

mkdir: cannot create directory`/application/yum/centos6/x86_64‘: No such file or directory

[[email protected] tools]# mkdir -p /application/yum/centos6/x86_64

[[email protected] tools]# cd /application/yum/centos6/x86_64

[[email protected] x86_64]# pwd

/application/yum/centos6/x86_64

[[email protected] 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

[[email protected] x86_64]# cp/application/tools/nginx-1.6.3-1.x86_64.rpm /application/yum/centos6/x86_64/

[[email protected] 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

[[email protected] x86_64]# rpm -qa createrepo

[[email protected] x86_64]# yum -y install createrepo

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

[[email protected] 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服务是否开启

[[email protected] x86_64]# ps -ef|grep nginx

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

[[email protected] x86_64]# ps -ef|grep 80

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

[[email protected] x86_64]# netstat -lntup|grep nginx

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

[[email protected] x86_64]# /application/nginx/sbin/nginx -s stop

#检查防火墙是否开启

[[email protected] x86_64]# /etc/init.d/iptables status

iptables: Firewall is not running.

#如果开启,那么关闭即可

[[email protected] x86_64]# /etc/init.d/iptables stop

[[email protected] x86_64]# pwd

/application/yum/centos6/x86_64

[[email protected] x86_64]# python -m SimpleHTTPServer 80&>/dev/null &

[1] 8383

#此时可以通过浏览器输入本机IP查看

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

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

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

[[email protected] x86_64]# grep "keepcache=1"/etc/yum.conf

keepcache=1

#只下载软件不安装

[[email protected] x86_64]# yumdownloader pcre-devel openssl-devel

[[email protected] 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

[[email protected] x86_64]# pwd

/application/yum/centos6/x86_64

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

[[email protected] 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文件列表

[[email protected] 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创建脚本

[[email protected] ~]# cd /etc/yum.repos.d

[[email protected] yum.repos.d]# cat oldboy.repo

[oldboy]

name=Server

baseurl=http://10.0.0.61

enable=1

gpgcheck=0

3、3、2、2yum操作

[[email protected] 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

[[email protected] 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操作没有影响

[[email protected] yum.repos.d]# yum install nginx

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

[[email protected] 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/

[[email protected] yum.repos.d]# ls -ld /application/nginx/

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

[[email protected] 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

[[email protected] yum.repos.d]# netstat -lntup|grep nginx

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

[[email protected] 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 包。

时间: 2024-10-14 21:54:38

定制RPM包及yum仓库搭建(以安装nginx为例)的相关文章

一键自动化部署(定制rpm包,yum仓库)

部署--前篇 上午将MySQL多实例部署完成,由于有公司特定一些需求,需要源码安装,现在需要批量部署,如果一台台部署,就太过麻烦,而且浪费时间,这个时候自动化部署 就体现出价值了 我们将MySQL制作定制化rpm包,然后放到我们的yum仓库中,在将yum所有客户端,都指向yum源,之后就是喝喝茶,看看片,轻松批量部署了,废话不多说,开干. 如果MySQL多实例还没配置的,或不了解软件的安装方式 的 请参考:http://qiuyt.blog.51cto.com/1229789/1920686 一

定制rpm包、搭建yum仓库

一.定制rpm包 1.环境 [[email protected] ~]# cat /etc/redhat-release  CentOS release 6.9 (Final) [[email protected] ~]# uname -r2.6.32-696.el6.x86_64 [[email protected] ~]# /etc/init.d/iptables status iptables: Firewall is not running. [[email protected] ~]#

如何搭建yum仓库与定制rpm包

当我们自动仳部署集群的时候,想要快速的安装所有服务,搭建yum仓库与定制rpm包是我们首先要做的 原创作品,转载请注明出处.http://www.cnblogs.com/Csir/  本人导师---悠久之翼 #服务端1.#先保留平常下载下来的rpm包 sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf 这样当我们yum安装软件的时候,文件就是被保存下来: /var/cache/yum/ #部署nginx,提供80端口服务#安装依赖包 yum in

yum仓库+fpm定制rpm包

试验环境: ip:yum 10.0.0.201 yum仓库 web 10.0.0.8 web(未安装nginx) yum端安装: 第一个里程碑:创建定制的rpm包 1.开启rpm包的缓存 sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf 2.清空已有缓存 find /var/cache/ -type f -name '*rpm'|xargs rm -f 3.编译安装nginx wget -O /etc/yum.repos.d/epel.repo

定制rpm包及搭建yum仓库

定制rpm包及搭建yum仓库 第1章 定制rpm包 1.FPM打包工具 FPM的作者是jordansisselFPM的github:https://github.com/jordansissel/fpmFPM功能简单说就是将一种类型的包转换成另一种类型. 支持的源类型包: dir         将目录打包成所需要的类型,可以用于源码编译安装的软件包 rpm         对rpm进行转换 gem         对rubygem包进行转换 python      将python模块打包成相应

5周第1次课 安装软件包的三种方法 rpm包介绍 yum工具用法 yum搭建本地仓库

Linux 安装软件的三种方式 rpm 工具:此种安装方式即通过rpm 工具对介质上的rpm 包进行安装. yum 工具:核心依然是rpm,但不同的是它是基于网络的源,并会自动安装依赖组件. 源码包:源代码包,需要相应的编译器进行编译,然后才能安装.三种方式里最难的. 1.rpm 工具 rpm包的来源:光盘或其他地方拷贝本次实验,将Centos7虚拟光盘加载到虚拟机上 1.1 进入系统后执行挂载 [[email protected] ~]# mount /dev/cdrom /mntmount:

定制RPM包

目录 1. 安装软件的方式... 1 2. 定制RPM包... 1 2.1 RPM简介... 2 2.2 fpm工具介绍... 2 2.3 FPM安装  *****. 3 2.4 yum安装时如何解决依赖问题的... 4 3. 实战定制nginx的RPM包  *****. 4 3. 安装rpm包  *****. 7 4. 定制LNMP的RPM包思路... 8 1. 安装软件的方式 1 编译安装软件 优点:定制优化安装目录:按需开启功能:可定制(定制安装目录和软件功能),一般情况下不需要网络,可选

Linux 定制rpm包

 定制rpm包 说明:这些操作全部在管理服务器内操作. 定制rpm包,搭建内网yum仓库,通过kickstart批量系统安装,这是互联网企业运维自动化的必要技能,自动化运维的基石. 1.1 面试题 有100台服务器想安装系统.你有什么方案快速部署并优化吗?需要多少时间搞定? 1.1.1 解决方案 (1) tar打包:先编译安装.打包.批量分发.解包: (2) saltstack.puppet.ansible批量部署: (3) 定制rpm所.搭建yum仓库.yum安装: (4) openstack

自动化部署必备技能——定制RPM包

回顾下安装软件的三种方式: 1.编译安装软件,优点是可以定制化安装目录.按需开启功能等,缺点是需要查找并实验出适合的编译参数,诸如MySQL之类的软件编译耗时过长. 2.yum安装软件,优点是全自动化安装,不需要为依赖问题发愁了,缺点是自主性太差,软件的功能.存放位置都已经固定好了,不易变更. ===>如果你现在还为是使用编译安装软件还是使用yum安装软件发愁,那你就out了. 3.编译源码,根据自己的需求做成定制RPM包–>搭建内网yum仓库–yum安装.结合前两者的优点,暂未发现什么缺点.