Centos customize rpm package build yum warehouse tutorial

  • 2021-07-10 21:26:55
  • OfStack

1 Keep the rpm package downloaded when yum installed the software

Just modify the yum configuration file. Downloaded rpm packages are automatically saved in the/var/cache/yum/ directory


[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
 The    Off-  sl-5.02-1.el6.x86_64.rpm
 Off-  repomd.xml

1 directory, 4 files

2 compile and install 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 Installing fpm Tools

Install the dependency package first

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

Download ruby, fpm is written by ruby, so ruby is required for the system environment. It is not recommended to install ruby on yum, and there will be some problems during testing.


[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
#  Add Alibaba Cloud's Rubygems Warehouse, the default source is foreign source, and the access download speed is slow. Remove the native before adding it Ruby Warehouse 
[root@swag ~]# gem sources
*** CURRENT SOURCES ***
https://rubygems.org/ 
[root@swag ~]# gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
#  Add Ali Warehouse 
[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/

Common parameters of fpm
-s: Specifies source type
-t: Specify the target type, that is, what package do you want to make
-n: Specifies the name of the package
-v: Specifies the version number of the package
-C: Specifies the relative path of the package
-d: Specify which packages to rely on
-f: If there is an installation package with the same name in the directory during the second packaging, overwrite it
-p: The directory of the output installation package, which needs to be specified if you don't want to put it in the current directory
--post-install: The script to run after the package is installed; Same as--offer-install
--pre-install: The script to run before the package is installed; Same as--before-install
--post-uninstall: The script to run after the package is uninstalled; Same as--offer-remove
--pre-uninstall: Scripts to run before package uninstall completes; Same as-before-remove

Source type packages supported by fpm
dir: Package directories into the required types that can be used for source compilation and installation of software packages
rpm: Converting rpm
gem: Transforming rubygem packets
python: Package Python modules into appropriate types

Target type packages supported by fpm
rpm: Convert to rpm package
deb: Convert to deb packet
solaris: Convert to solaris package
puppet: Convert to puppet packet

4 Package Nginx


[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
#  Add Alibaba Cloud's Rubygems Warehouse, the default source is foreign source, and the access download speed is slow. Remove the native before adding it Ruby Warehouse 
[root@swag ~]# gem sources
*** CURRENT SOURCES ***
https://rubygems.org/ 
[root@swag ~]# gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
#  Add Ali Warehouse 
[root@swag ~]# gem sources -a http://mirrors.aliyun.com/rubygems/
http://mirrors.aliyun.com/rubygems/ added to sources
[root@swag ~]# gem sources
*** CURRENT SOURCES ***

[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
#  Add Alibaba Cloud's Rubygems Warehouse, the default source is foreign source, and the access download speed is slow. Remove the native before adding it Ruby Warehouse 
[root@swag ~]# gem sources
*** CURRENT SOURCES ***
https://rubygems.org/ 
[root@swag ~]# gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
#  Add Ali Warehouse 
[root@swag ~]# gem sources -a http://mirrors.aliyun.com/rubygems/
http://mirrors.aliyun.com/rubygems/ added to sources
[root@swag ~]# gem sources
*** CURRENT SOURCES ***

5 Other machine tests


# scp Put rpm The packet is transmitted 
[root@swag ~]# scp nginx-1.6.3-1.x86_64.rpm root@10.0.0.5:/home/oldboy/tools

#  Test 
[root@swag3 tools]# yum localinstall nginx-1.6.3-1.x86_64.rpm -y

6 yum warehouse construction

Install createrepo


[root@swag2 ~]# yum install createrepo -y

Create the yum repository directory and initialize the repodata index file


[root@swag2 ~]# mkdir -p /application/yum/centos6.9/x86_64/
[root@swag2 ~]# cd /application/yum/centos6.9/x86_64/  #  Copy custom rpm Package to this directory 
[root@swag2 x86_64]# createrepo -pdo /application/yum/centos6.9/x86_64/ /application/yum/centos6.9/x86_64/

Provide yum service


#  Used here python To provide web Service, also available apache Or nginx To provide web Services 
[root@swag2 x86_64]# python -m SimpleHTTPServer 80 &>/dev/null &  # python Adj. httpd Module 
[root@swag2 x86_64]# lsof -i :80
COMMAND  PID USER  FD  TYPE DEVICE SIZE/OFF NODE NAME
python 24680 root  3u IPv4 32493   0t0 TCP *:http (LISTEN)

If there is a new rpm package, it must be updated


[root@swag2 x86_64]# createrepo --update /application/yum/centos6.9/x86_64/

Client modifies yum source


cat >>/etc/yum.repo.d/<<EOF
[only]
name=Server
baseurl=http://10.0.0.7    
# baseurl Specify yum Warehouse IP If not 80 Port needs to be added 
enabled=1
gpgcheck=0
EOF
#  Client to install nginx For example 
#  Clear the local cache 
[root@swag4 ~]# yum clean all
#  Show local yum Source list 
[root@swag4 ~]# yum --enablerepo=only --disablerepo=base,extras,updates,epel list  
#  Attention should be paid here --enablerepo For local.repo Object defined in the file only
#  Installation nginx For example #
yum --enablerepo=local --disablerepo=base,extras,updates,epel install nginx -y

Some Uses of yum

# Download packages without installing packages
1. yumdownloader pcre-devel openssl-devel
2. yum--downloadonly pcre-devel openssl-devel


# 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
0

Error troubleshooting

# If the following error is reported when the client installs nginx because of the lack of dependency package, download it and update the yum repository.
yum Warehouse: createrepo--update/application/yum/centos6.9/x86_64/
Client: yum clean all

Error: Package: nginx-1.6.3-1.x86_64 (only)
Requires: pcre-devel
Error: Package: nginx-1.6.3-1.x86_64 (only)
Requires: openssl-devel

# Pay attention to whether the configuration file is written incorrectly

7 mirror synchronous public network yum source

Above, just put your own rpm package into yum source. However, there is another requirement. Usually, the installation software is downloaded from the public network, which occupies bandwidth. Therefore, repodata from the public network yum source can be directly used.

The upstream yum source must support the rsync protocol, otherwise rsync cannot be used for synchronization. http://mirrors.ustc.edu.cn/status/


# 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
1

Summarize


Related articles: