Linux operation and maintenance tutorial-Linux package management

Linux package management


  • rpm package management

  • Yum package management

  • Dnf package management

  • Source code compilation and installation


Ready to work

Mount the iso image

image

image



Mount the optical drive to the system

[root@myserver dev]# mount /dev/sr0 /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@myserver dev]# df -h
Filesystem                   Size Used Avail Use% Mounted on
devtmpfs                     884M     0 884M   0% /dev
tmpfs                         901M     0 901M   0% /dev/shm
tmpfs                         901M 9.8M 891M   2% /run
tmpfs                         901M     0 901M   0% /sys/fs/cgroup
/dev/mapper/cl_myserver-root   17G 5.2G   12G 31% /
/dev/sdb1                     5.0G   68M 5.0G   2% /data/sdb1
/dev/sda1                     976M 194M 716M 22% /boot
tmpfs                         181M   16K 181M   1% /run/user/0
tmpfs                         181M 1.2M 179M   1% /run/user/42
/dev/sr0                     6.7G 6.7G     0 100% /mnt



Rpm package management

windows : exe ; mac OS : dmg ; Linux : rpm

When our application can be installed directly, it is recommended to use rpm to install directly. But when our application needs to depend on other packages, rpm will become uncomfortable.

How to use the rpm command

rpm -qa | grep xz: view all installed packages

rpm -ivh xxx.rpm: install xxx.rpm

rpm -e xxx: uninstall xxx

rpm -Uvh xxx.rpm: update xxx.rpm


cd /mnt/BaseOS/Packages 

## Find if the package has been installed
[root@myserver Packages]# rpm -qa | grep xz
xz-libs-5.2.4-3.el8.x86_64
xz-5.2.4-3.el8. x86_64


## Get related RPM packages
[root@myserver Packages]# ls | grep xz
xz-5.2.4-3.el8.x86_64.rpm
xz-devel-5.2.4-3.el8.i686.rpm
xz-devel -5.2.4-3.el8.x86_64.rpm
xz-libs-5.2.4-3.el8.i686.rpm
xz-libs-5.2.4-3.el8.x86_64.rpm

## Start installation
[root@myserver Packages]# rpm -ivh xz-devel-5.2.4-3.el8.x86_64.rpm
Verifying... ######################### ######## [100%]
Preparing... ################################ [ 100%]
Updating / installing...
  1:xz-devel-5.2.4-3.el8 ################################# [100%]

## Verify that the installation is successful
[root@myserver Packages]# rpm -qa | grep xz
xz-libs-5.2.4-3.el8.x86_64
xz-5.2.4-3.el8.x86_64
xz-devel-5.2.4 -3.el8.x86_64

## Uninstall
[root@myserver Packages]# rpm -e xz-devel-5.2.4-3.el8.x86_64
[root@myserver Packages]# rpm -qa | grep xz
xz-libs-5.2 .4-3.el8.x86_64
xz-5.2.4-3.el8.x86_64




Yum package management tool

Yum warehouse concept === Yum source

What the source configuration needs is a xxx.repo file, /etc/yum.repos.d/

yum remove xz-devel: 卸载xz-devel

yum -y install xz-devel: Install xz-devel -y without interactive mode.

yum update xz-devel:更新xz-devel

yum clean all: clean the cache


Preparation before operation: back up the original source

[root@myserver yum.repos.d]# mkdir bak
[root@myserver yum.repos.d]# ls
bak                     CentOS-Debuginfo.repo CentOS-Media.repo
CentOS-AppStream.repo   CentOS-Devel.repo     CentOS-PowerTools.repo
CentOS-Base.repo       CentOS-Extras.repo     CentOS-Sources.repo
CentOS-centosplus.repo CentOS-fasttrack.repo CentOS-Vault.repo
CentOS-CR.repo         CentOS-HA.repo
[root@myserver yum.repos.d]# mv *.repo bak/
[root@myserver yum.repos.d]# ls
bak


Yum source file format

[BaseOS] ## Warehouse name 
name=CentOS-$releasever-Base ## Warehouse description
baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/ ## Source address [online HTTP|FILE local file]
gpgcheck=1 ## Certificate verification
enabled=1 ## Whether to start
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial


Configure local YUM
[myrepo]
name=My first repo test.
baseurl=file:///mnt/BaseOS/
gpgcheck=0
enabled=1
[root@myserver ~]# cd /etc/yum.repos.d/
[root@myserver yum.repos.d]# ls
bak
[root@myserver yum.repos.d]# vim myrepo.repo
[root@myserver yum.repos.d]# ls
bak myrepo.repo


[root@myserver ~]# yum repolist
repo id                             repo name
myrepo                             My first repo test.


[root@myserver ~]# rpm -qa | grep xz
xz-libs-5.2.4-3.el8.x86_64
xz-5.2.4-3.el8.x86_64
[root@myserver ~]# yum install xz*
My first repo test.                                 24 MB/s | 2.2 MB     00:00    
Last metadata expiration check: 0:00:01 ago on Sun 21 Jun 2020 10:00:03 PM EDT.
Package xz-5.2.4-3.el8.x86_64 is already installed.
Package xz-libs-5.2.4-3.el8.x86_64 is already installed.
Dependencies resolved.
===================================================================================
Package           Architecture     Version               Repository       Size
===================================================================================
Installing:
xz-devel           x86_64           5.2.4-3.el8           myrepo           62 k

Transaction Summary
===================================================================================
Install 1 Package

Total size: 62 k
Installed size: 202 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing       :                                                                       1/1
Installing       : xz-devel-5.2.4-3.el8.x86_64                                           1/1
Running scriptlet: xz-devel-5.2.4-3.el8.x86_64                                           1/1
Verifying       : xz-devel-5.2.4-3.el8.x86_64                                           1/1
Installed products updated.

Installed:
xz-devel-5.2.4-3.el8.x86_64                                                                  

Complete!
[root@myserver ~]# rpm -qa | grep xz
xz-devel-5.2.4-3.el8.x86_64
xz-libs-5.2.4-3.el8.x86_64
xz-5.2.4-3.el8.x86_64


[root@myserver ~]# yum remove xz-devel
Dependencies resolved.
================================================================================================
 Package               Architecture        Version                   Repository            Size
================================================================================================
Removing:
 xz-devel              x86_64              5.2.4-3.el8               @myrepo              202 k

Transaction Summary
================================================================================================
Remove  1 Package

Freed space: 202 k
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                        1/1
  Erasing          : xz-devel-5.2.4-3.el8.x86_64                                            1/1
  Running scriptlet: xz-devel-5.2.4-3.el8.x86_64                                            1/1
  Verifying        : xz-devel-5.2.4-3.el8.x86_64                                            1/1
Installed products updated.

Removed:
  xz-devel-5.2.4-3.el8.x86_64

Complete!



Online YUM source

Back up local yum and create a new online yum source

[root@myserver ~]# cd /etc/yum.repos.d/
[root@myserver yum.repos.d]# ls
bak  myrepo.repo
[root@myserver yum.repos.d]# mv myrepo.repo myrepo.repo~
[root@myserver yum.repos.d]# ls
bak  myrepo.repo~
[root@myserver yum.repos.d]# vim myrepo.repo


[myrepo]
name=My first repo test.
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/8/BaseOS/x86_64/os/
gpgcheck=0
enabled=1


[root@myserver yum.repos.d]# yum -y install xz-devel
My first repo test.                                             537 kB/s | 2.2 MB     00:04
Last metadata expiration check: 0:00:01 ago on Sun 21 Jun 2020 10:09:55 PM EDT.
Dependencies resolved.
================================================================================================
 Package               Architecture        Version                    Repository           Size
================================================================================================
Installing:
 xz-devel              x86_64              5.2.4-3.el8                myrepo               62 k

Transaction Summary
================================================================================================
Install  1 Package

Total download size: 62 k
Installed size: 202 k
Downloading Packages:
xz-devel-5.2.4-3.el8.x86_64.rpm                                 105 kB/s |  62 kB     00:00
------------------------------------------------------------------------------------------------
Total                                                           104 kB/s |  62 kB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                        1/1
  Installing       : xz-devel-5.2.4-3.el8.x86_64                                            1/1
  Running scriptlet: xz-devel-5.2.4-3.el8.x86_64                                            1/1
  Verifying        : xz-devel-5.2.4-3.el8.x86_64                                            1/1
Installed products updated.

Installed:
  xz-devel-5.2.4-3.el8.x86_64

Complete!



FAQ

[root@myserver yum.repos.d]# yum -y install xz-devel
My first repo test.                                             0.0  B/s |   0  B     00:00
Errors during downloading metadata for repository 'myrepo':
  - Curl error (6): Couldn't resolve host name for https://mirrors.tuna.tsinghua.edu.cn/centos/8/BaseOS/x86_64/os/repodata/repomd.xml [Could not resolve host: mirrors.tuna.tsinghua.edu.cn]
Error: Failed to download metadata for repo 'myrepo': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
[root@myserver yum.repos.d]# ping www.baidu.com
ping: www.baidu.com: Name or service not known

## 重新获取地址信息
[root@myserver yum.repos.d]# dhclient
[root@myserver yum.repos.d]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.121) 56(84) bytes of data.
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=1 ttl=56 time=4.68 ms
64 bytes from 61.135.169.121 (61.135.169.121): icmp_seq=2 ttl=56 time=4.92 ms
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 2ms
rtt min/avg/max/mdev = 4.675/4.795/4.916/0.138 ms




Dnf package management tool

DNF is the abbreviation of Dandified yum. DNF is also a package management tool based on RPM, which first appeared in Fedora system and has become the default package management tool of Fedora system.

It is simpler than Yum, consumes less content, and relies on package parsing faster


xz-devel

dnf list installed: List all installed packages

dnf search: find packages

dnf install: installation command

dnf reinstall: reinstall

dnf download: download package

dnf check-update: check for updates

dnf update: update

dnf repolist all: view all available sources

dnf remove: uninstall software

dnf clean all: clear the cache



Source code compilation and installation




Create archive

tar cf archive name file

tar xf archive name -C specifies the unpacking path

[root@myserver ~]# tar cf mytestfile.tar a.txt b.txt c.txt
[root@myserver ~]# ls
a                b.txt    Documents             Music       Pictures   test
anaconda-ks.cfg  c.txt    Downloads             mytestfile  Public     Videos
a.txt            Desktop  initial-setup-ks.cfg  mytest.txt  Templates
[root@myserver ~]# file mytestfile.tar
mytestfile: POSIX tar archive (GNU)
[root@myserver ~]# tar xf mytestfile.tar -C /opt/
[root@myserver ~]# ls /opt/
a.txt  b.txt  c.txt

Compressed package tar.gz

[root@myserver ~]# tar zcf mytestfile.tar.gz a.txt b.txt c.txt
[root@myserver ~]# ls
a                c.txt      initial-setup-ks.cfg  mytest.txt  test
anaconda-ks.cfg  Desktop    Music                 Pictures    Videos
a.txt            Documents  mytestfile            Public
b.txt            Downloads  mytestfile.tar.gz     Templates
[root@myserver ~]# file mytestfile.tar.gz
mytestfile.tar.gz: gzip compressed data, last modified: Mon Jun 22 12:38:35 2020, from Unix, original size 10240
[root@myserver ~]# tar zxf mytestfile.tar.gz -C /mnt/
[root@myserver ~]# ls /mnt/
a.txt  b.txt  c.txt  hgfs



Source code compilation and installation process

  • Download the source code package of the application

    • wget download source package

  • Unzip the source package

    • Default decompression path: /usr/local/

    • tar zxf xxxx -C /usr/local

  • Execution configuration file

  • Execute compilation

  • Perform compile and install


[root@myserver ~]# wget http://zlib.net/zlib-1.2.11.tar.gz
--2020-06-22 08:44:02--  http://zlib.net/zlib-1.2.11.tar.gz
Resolving zlib.net (zlib.net)... 68.66.224.49
Connecting to zlib.net (zlib.net)|68.66.224.49|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 607698 (593K) [application/x-gzip]
Saving to: \u2018zlib-1.2.11.tar.gz\u2019

zlib-1.2.11.tar.gz    100%[=======================>] 593.46K  11.4KB/s    in 49s

2020-06-22 08:44:47 (12.2 KB/s) - \u2018zlib-1.2.11.tar.gz\u2019 saved [607698/607698]


[root@myserver ~]# ls
a                c.txt      initial-setup-ks.cfg  mytest.txt  test
anaconda-ks.cfg  Desktop    Music                 Pictures    Videos
a.txt            Documents  mytestfile            Public      zlib-1.2.11.tar.gz
b.txt            Downloads  mytestfile.tar.gz     Templates
[root@myserver ~]# tar zxf zlib-1.2.11.tar.gz  -C /usr/local/
[root@myserver ~]# ls /usr/local/
bin  etc  games  include  lib  lib64  libexec  sbin  share  src  zlib-1.2.11
[root@myserver ~]# cd /usr/local/zlib-1.2.11/
[root@myserver zlib-1.2.11]# ls
adler32.c       examples    inflate.c     README           zlib.3
amiga           FAQ         inflate.h     test             zlib.3.pdf
ChangeLog       gzclose.c   inftrees.c    treebuild.xml    zlib.h
CMakeLists.txt  gzguts.h    inftrees.h    trees.c          zlib.map
compress.c      gzlib.c     Makefile      trees.h          zlib.pc.cmakein
configure       gzread.c    Makefile.in   uncompr.c        zlib.pc.in
contrib         gzwrite.c   make_vms.com  watcom           zutil.c
crc32.c         INDEX       msdos         win32            zutil.h
crc32.h         infback.c   nintendods    zconf.h
deflate.c       inffast.c   old           zconf.h.cmakein
deflate.h       inffast.h   os400         zconf.h.in
doc             inffixed.h  qnx           zlib2ansi
[root@myserver zlib-1.2.11]#


开始编译  https://www.nginx.cn/install

编译之前首先需要安装gcc gcc-c++ 编译器


yum -y install gcc automake autoconf libtool make
yum install gcc gcc-c++`


[root@myserver zlib-1.2.11]# ./configure
Checking for gcc...
Checking for shared library support...
Building shared library libz.so.1.2.11 with gcc.
Checking for size_t... Yes.
Checking for off64_t... Yes.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.


[root@myserver zlib-1.2.11]# make
[root@myserver zlib-1.2.11]# make install
rm -f /usr/local/lib/libz.a
cp libz.a /usr/local/lib
chmod 644 /usr/local/lib/libz.a
cp libz.so.1.2.11 /usr/local/lib
chmod 755 /usr/local/lib/libz.so.1.2.11
rm -f /usr/local/share/man/man3/zlib.3
cp zlib.3 /usr/local/share/man/man3
chmod 644 /usr/local/share/man/man3/zlib.3
rm -f /usr/local/lib/pkgconfig/zlib.pc
cp zlib.pc /usr/local/lib/pkgconfig
chmod 644 /usr/local/lib/pkgconfig/zlib.pc
rm -f /usr/local/include/zlib.h /usr/local/include/zconf.h
cp zlib.h zconf.h /usr/local/include
chmod 644 /usr/local/include/zlib.h /usr/local/include/zconf.h


Guess you like

Origin blog.51cto.com/15127507/2656568