Build Yum private warehouse in Centos7.3

method one,

Use the local iso image to create a local yum warehouse. This method is not recommended. It is only used in an environment where the yum server cannot be connected to the public network. After all, the packages in the iso image are very limited.

Use putty's upload tool to upload a complete centos operating system

G:\centos>pscp "CentOS-7.3-x86_64-DVD-1611 (1).iso" [email protected]:/root/

[email protected]'s password:

CentOS-7.3-x86_64-DVD-161 | 961092 kB | 11175.5 kB/s | ETA: 00:04:56 | 22%

mount -o loop CentOS-7.3-x86_64-DVD.iso /mnt

mkdir /centos7.3

cp -r /mnt/Packages/*.rpm /centos7.3/

yum install -y createrepo

Use createrepo to create an index

createrepo /centos7.3

Update index

createrepo --update /centos7.3

Clean yum cache data

yum clean all

yum makecache

Change the system default yum source

vi /etc/yum.repos.d/CentOS-Base.repo

[ base]

name=CentOS-$releasever - Base

mirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=basearch&repo=os&infra=$infra

baseurl=file:///centos7.3

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7.3

Test environment Centos7.3

For the fpm knowledge involved in this article, please refer to Making rpm package with FPM

method one,

Use the local iso image to create a local yum warehouse. This method is not recommended. It is only used in an environment where the yum server cannot be connected to the public network. After all, the packages in the iso image are very limited.

mount -o loop CentOS-7.3-x86_64-DVD.iso /mnt

mkdir /centos7

cp -r /mnt/Packages/*.rpm /centos7/

Use createrepo to create an index

createrepo /centos7

Update index

createrepo --update /centos7

Clean yum cache data

yum clean all

Then use yum makecache #update cache

Change the system default yum source

cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

vi /etc/yum.repos.d/CentOS-Base.repo

[ base]

name=CentOS-$releasever - Base

mirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=basearch&repo=os&infra=$infra

baseurl=file:///centos7

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Now we install a ntpdate package to test

yum install ntpdate, as shown below, it is found that the local yum source has been installed successfully

Method Two,

Use rsync to synchronize with the yum warehouse on the public network. This method is recommended to synchronize, especially when the network is unstable and easily interrupted. Because rsync is a fast incremental backup tool, it can continue to synchronize from the last interrupted file. The disadvantage is that many portal yum sources do not support rsync synchronization.

Because the repo file of the public network yum source is directly downloaded here, there is no need to use createrepo to create the index, and it can be used directly after synchronization.

Base package and related repo files

/usr/bin/rsync -avrtzH --delete--delay-updates rsync://rsync.mirrors.ustc.edu.cn/centos/7/os/x86_64/Packages//var/www/html/centos/7/os/x86_64/Packages/>/tmp/rsyncbase.log 2>&1/usr/bin/rsync -avrtzH --delete--delay-updates rsync://rsync.mirrors.ustc.edu.cn/centos/7/os/x86_64/repodata//var/www/html/centos/7/os/x86_64/repodata/>/tmp/rsyncbaserepo.log 2>&1

Update package and related repo files

/usr/bin/rsync -avrtzH --delete--delay-updates rsync://rsync.mirrors.ustc.edu.cn/centos/7/updates/x86_64/Packages//var/www/html/centos/7/updates/x86_64/Packages/>/tmp/rsyncupdate.log 2>&1/usr/bin/rsync -avrtzH --delete--delay-updates rsync://rsync.mirrors.ustc.edu.cn/centos/7/updates/x86_64/repodata//var/www/html/centos/7/updates/x86_64/repodata/>/tmp/rsyncupdaterepo.log 2>&1

epel expansion pack

/usr/bin/rsync -avrtzH --delete--delay-updates --exclude=SRPMS/--exclude=aarch64/--exclude=ppc64/--exclude=ppc64le/--exclude=x86_64/debug/ rsync://rsync.mirrors.ustc.edu.cn/epel/7//var/www/html/epel/7/>/tmp/rsyncepel.log 2>&1

Parameter description -a, --archive archive mode, which means to recursively transfer files and keep all file ownership

**Method three, **

Use reposync to synchronize with public network yum sources

Here is the epel source of Alibaba Cloud for testing

1、 Now the Alibaba Cloud image source repo file to the local:

wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo

2、 Install httpd service to provide storage yum source:

[ root@localhost~] yum install httpd -y

Use the default configuration, if you have special needs, you can modify the configuration file /etc/httpd/conf/httpd.conf

http default home directory/var/www/html

3、 Install yum-utils to provide reposync service

yum install yum-utils -y

4、 Select the specified warehouse ID as the local yum source:

Execute the yum repolist command to view the yum warehouse ID

Use epel as the local yum source and /var/www/html as the root directory of the yum warehouse

reposync -r epel -p /var/www/html

After the command is executed, the epel source in Alibaba Cloud will be synchronized to the local /var/www/html; the epel directory is automatically created in /var/www/html to store the rpm package; the first synchronization may take longer Long, about 1W multiple rpm packages.

5、 The createrepo command creates a local YUM warehouse for the rpm package under /var/www/html/epel, the purpose is to generate a repodata directory and automatically create index information

[ root@localhost ~]# createrepo -pdo /var/www/html/epel/ /var/www/html/epel/

The first directory is the repodata storage directory, and the second directory is the yum source warehouse directory that needs to generate index information

Log in to other servers in other intranets, and be able to communicate with the yum source server; write repo files:

vim /etc/yum.repos.d/epel-7.The repo content is as follows
[ epel]
name=local epel
baseurl=http://yum source server IP/epel
enabled=1
gpgcheck=0

Execute yum clean all, yum makecache to clear and update yum cache

6、 In order to ensure that the local yum source can be synchronized with the Alibaba Cloud mirror source, it can be achieved through script timing tasks:

vim /root/yum-update.sh
#! /bin/bash
datetime=`date +"%Y-%m-%d"`
exec >/var/log/epel.log  #Synchronization log output
reposync -d -r epel -p /var/www/html/    #Sync mirror source
if[ $?-eq 0];then
 createrepo --update  /var/www/html/epel   #Every time a new rpm is added,Epel index information must be updated
echo "SUCESS: $datetime epel update successful"else
echo "ERROR: $datetime epel update failed"
fi

Timed task: Synchronize yum source at three o'clock in the morning every Saturday

crontab -e

3 * * 6 /bin/bash/root/yum-update.sh

Create a customized yum warehouse that belongs to your own configuration requirements

What we talked about above is how to get from the public yum source to the local. Now we compile and install with the tar package according to the needs, then use the fpm tool to generate the rpm installation package, and finally put the generated rpm package into your own yum warehouse

Install fpm tool

yum install -y ruby rubygems ruby-devel rpm-build
gem sources --remove https://rubygems.org/
gem sources -a https://mirrors.aliyun.com/rubygems/
gem install fpm -v 1.4.0

You need to manually compile nginx first

groupadd nginx
useradd -g nginx -s /sbin/nologin nginx
mkdir /var/log/nginx&&chown -R nginx:nginx /var/log/nginx 
mkdir /usr/local/www&&chown -R nginx:nginx /usr/local/www

wget http://nginx.org/download/nginx-1.14.0.tar.gz
. /configure --prefix=/usr/local/nginx --user=nginx --group=nginx \
- - with-http_ssl_module \
- - with-http_stub_status_module \
 - - with-http_flv_module  \
- - with-http_gzip_static_module
make
make install DESTDIR=/tmp/nginx  #Generate a copy of the installation file and install it in/tmp/nginx
make install

4 scripts needed to generate rpm package

rpm package pre-installation script

[ root@localhost scripts]# cat install_nginx_before.sh 
#! /bin/bash
date=`date +%Y%m%d%H%M%S`[[-n `ps aux|grep sbin/nginx|grep -v grep`]]&& killall -9 nginx
if[-f /usr/local/nginx/conf/nginx.conf ];then
 mv -f /usr/local/nginx/conf/nginx.conf /tmp/nginx.conf-${date}
fi
if[-d /usr/local/nginx ];then
 rm -rf /usr/local/nginx
fi
[[- n `getent group nginx`]]|| groupadd  nginx
[[- n `getent passwd nginx`]]|| useradd nginx -g nginx -s /sbin/nologin
exit 0

rpm install script

[ root@localhost scripts]# cat install_nginx_after.sh 
#! /bin/bash
log="/var/log/nginx"
web="/usr/local/www"if[-d "$log"];then
 rm -rf "$log"
 mkdir "$log"else
 mkdir "$log"
fi

if[-d "$web"];then
 rm -rf "$web"
 mkdir "$web"else
 mkdir "$web"
fi
chown -R nginx.nginx /var/log/nginx
chown -R nginx.nginx /usr/local/www
exit 0

Script before rpm package uninstall

[ root@localhost scripts]# cat uninstall_nginx_before.sh 
#! /bin/bash
[[- n `ps aux|grep sbin/nginx|grep -v grep`]]&& killall -9 nginx
exit 0

Script after rpm package uninstallation

[ root@localhostscripts]# cat uninstall_nginx_after.sh 
#! /bin/bash
rm -rf/usr/local/nginx
rm -rf /usr/local/www
rm -rf /var/log/nginx
userdel -r nginx
exit 0

fpm command packaging

fpm -s dir -t rpm -n nginx_test -v 1.14.0-d "pcre-devel,openssl-devel >= 1:1.0.2k-8"--pre-install /tmp/scripts/install_nginx_before.sh --post-install /tmp/scripts/install_nginx_after.sh --pre-uninstall /tmp/scripts/uninstall_nginx_before.sh --post-uninstall /tmp/scripts/uninstall_nginx_after.sh -C /tmp/nginx/

Copy the generated rpm to your private warehouse

cp nginx_test12-1.14.0-1.x86_64.rpm /var/www/html/private

Use createrepo to create an index

createrepo /var/www/html/private/

Finally, let's look at the yum warehouse configuration file of the client machine. Here, 192.168.10.59 is the yum warehouse as an example

Base's local warehouse

[ root@localhost tmp]#cat /etc/yum.repos.d/CentOS-Base.repo

[ base]

name=CentOS-$releasever- Base

mirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=basearch&repo=os&infra=$infra

baseurl=http://192.168.10.59/centos/releasever/os/basearch/

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

released updates

[ updates]

name=CentOS-$releasever- Updates

mirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=basearch&repo=updates&infra=$infra

baseurl=http://192.168.10.59/centos/releasever/updates/basearch/

baseurl=http://mirror.centos.org/centos/releasever/updates/basearch/

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

epel's local warehouse

[ root@localhost tmp]#cat /etc/yum.repos.d/epel.repo

[ epel]

name=Extra Packagesfor Enterprise Linux $releasever - $basearch

baseurl=http://192.168.10.59/epel/7/x86_64/

failovermethod=priority

enabled=1

gpgcheck=0

gpgkey=http://mirrors.sohu.com/RPM-GPG-KEY-EPEL-$releasever

Finally, the private yum warehouse of the rpm package is generated through fpm

[ root@localhost tmp]#cat /etc/yum.repos.d/private.repo

[ private]

name=private - Base

mirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=basearch&repo=os&infra=$infra

baseurl=http://192.168.10.59/private/

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Execute yum clean all first and then yum makecache

Execute the yum repolist command to view the yum warehouse ID

Execute yum install nginx_test12

We see that the nginx_test12 test package can be successfully installed through yum.

https://blog.csdn.net/u013127762/article/details/54314550

http://blog.51cto.com/gdlwolf/1729020

http://www.mamicode.com/info-detail-1839438.html

Recommended Posts

Build Yum private warehouse in Centos7.3
CentOS build private git
Build Hadoop in CentOS
Build zabbix monitoring zabbix4.2 in CentOS7.6
Build zabbix monitoring zabbix4.2 in CentOS7.6
Install Docker CE in yum under CentOS 7
CentOS7 build jenkins
Centos build lnmp
Centos7 build python3.8.5+scrapy+gerapy
Build Discuz Forum in LNMP Environment under CentOS7
Build Dedecms website in LNMP environment under CentOS7
CentOS7.3 64 bit, build Zabbix3.4
Linux (centos7) build gitlab
Build k8s1.9.9 on centos7
Centos7 YUM install MariaDB 10.0
CentOS6.7 build LNMP environment
Install MySQL5.7 in centos7
Centos6.9 build rabbitmq 3.6.8 cluster
CentOS server deployment (YUM)
CentOS 7.2 Yum install MySQL 5.6
Jenkins build on centos
Install redis5.0 in CentOS7
Centos7 YUM install MariaDB 10.0
Centos7 build DNS service
KVM virtualization in centos
CentOS 5 to CentOS 5.8 YUM source
CentOS 7 build LNMP environment
Build docker environment under Centos6.5
CentOs7.3 build Solr stand-alone service
Build OpenV** Server under CentOS7
Build OpenLDAP server under CentOS7
Build MariaDB replication on CentOS
Centos 6.10 reinstall python and yum
CentOs7.3 build ZooKeeper-3.4.9 stand-alone service
CentOS deploys Harbor mirror warehouse
Debug Kernel Panic in Centos
ubuntu make local yum warehouse
CentOs7.3 build SolrCloud cluster service
Centos network settings in virtualbox
CentOS 7 yum install PHP7.3 tutorial
Update gcc to 6.4.0 in centos