클라우드 네이티브 애플리케이션 부트캠프 알림

티스토리 뷰

Redhat S/W설치와 업그레이드를 위한 명령어에 대해 설명합니다.

subscription-manager

redhat s/w의 repository에 접근하기 위한 subscription 권한을 현재 서버에 등록, 수정, 조회, 삭제하는 명령입니다.

전체 subscription 추가  
$ subscription-manager register --username [username] --password [password] --auto-attach

subscription별 추가: list에서 Pool ID확인하여 추가함    
$ subscription-manager register --username [username] --password [password]
$ subscription-manager list --available
$ subscription-manager attach --pool=<POOL ID>

참고: subscription refresh  
$ subscription-manager refresh

rpm

rpm은 Redhat Package Manager의 약자로 Redhat S/W의 설치를 간편하게 만들어주는 프로그램입니다.

rpm package파일 다운로드는 아래 redhat사이트에서 할 수 있습니다. 단, rpm download subscription이 있어야 합니다.

access.redhat.com/downloads/content/package-browser

주요 사용법은 아래와 같습니다.

rpm -qa는 query, all로서 모든 설치된 S/W리스트를 리턴합니다.

[root@bastion rhsm]# rpm -q dbus
dbus-1.10.24-13.el7_6.x86_64
[root@bastion rhsm]#
[root@bastion rhsm]# rpm -qa
binutils-2.27-43.base.el7_8.1.x86_64
authconfig-6.2.8-30.el7.x86_64
ncurses-base-5.9-14.20130511.el7_4.noarch
util-linux-2.23.2-63.el7.x86_64
...

특정 S/W가 설치되었는지 보려면 -q를 사용합니다. 그리고, 그 S/W의 상세정보까지 보려면 -qi 옵션을 이용합니다.

[root@bastion rhsm]# rpm -q dbus
dbus-1.10.24-13.el7_6.x86_64


[root@bastion rhsm]# rpm -qi dbus
Name        : dbus
Epoch       : 1
Version     : 1.10.24
Release     : 13.el7_6
Architecture: x86_64
Install Date: Tue Dec 10 23:35:36 2019
Group       : System Environment/Libraries
Size        : 595216
License     : (GPLv2+ or AFL) and GPLv2+
Signature   : RSA/SHA256, Wed Mar 20 04:51:06 2019, Key ID 24c6a8a7f4a80eb5
Source RPM  : dbus-1.10.24-13.el7_6.src.rpm
Build Date  : Thu Mar 14 19:18:13 2019
Build Host  : x86-02.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.freedesktop.org/Software/dbus/
Summary     : D-BUS message bus
Description :
D-BUS is a system for sending messages between applications. It is
used both for the system-wide message bus service, and as a
per-user-login-session messaging facility.

package내의 파일들 목록은 -ql 옵션으로 봅니다.

[root@bastion rhsm]# rpm -ql dbus
/etc/dbus-1
/etc/dbus-1/session.conf
/etc/dbus-1/session.d
/etc/dbus-1/system.conf
/etc/dbus-1/system.d
/lib64/dbus-1
/lib64/dbus-1/dbus-daemon-launch-helper
/run/dbus
/usr/bin/dbus-cleanup-sockets
...

configuration file 목록만 보려면 -qc를 이용합니다.

[root@bastion rhsm]# rpm -qc dbus
/etc/dbus-1/session.conf
/etc/dbus-1/system.conf

document file 목록은 -qd를 사용합니다.

[root@bastion rhsm]# rpm -qd dbus
/usr/share/doc/dbus-1.10.24/AUTHORS
/usr/share/doc/dbus-1.10.24/ChangeLog
/usr/share/doc/dbus-1.10.24/HACKING
/usr/share/doc/dbus-1.10.24/NEWS
/usr/share/doc/dbus-1.10.24/README
/usr/share/doc/dbus-1.10.24/examples/GetAllMatchRules.py
/usr/share/doc/dbus-1.10.24/examples/GetAllMatchRules.pyc
/usr/share/doc/dbus-1.10.24/examples/GetAllMatchRules.pyo
/usr/share/doc/dbus-1.10.24/examples/example-session-disable-stats.conf
...

패키지를 설치하려면 -i옵션을 주십시오.

- v: verbose. 결과UI를 좀 더 보기 좋게 하는 옵션

- h: hash. 진행상태를 '#'으로 표시하는 옵션

[root@bastion tmp]# rpm -ivh ./mariadb-5.5.65-1.el7.src.rpm
Updating / installing...
   1:mariadb-1:5.5.65-1.el7           ################################# [100%]

어떤 특정 파일이 어떤 rpm에 속해있는지를 알려면 -qf를 사용합니다.

아래는 sshd_config파일이 어떤 rpm에 속해 있는지 보여줍니다. -ql 또는 -qc로 진짜 속해 있는지 검증할 수 있습니다.

[root@bastion tmp]# rpm -qf /etc/ssh/sshd_config
openssh-server-7.4p1-21.el7.x86_64

[root@bastion tmp]# rpm -ql openssh-server-7.4p1-21.el7.x86_64 | grep sshd_config
/etc/ssh/sshd_config
/usr/share/man/man5/sshd_config.5.gz
[root@bastion tmp]# rpm -qc openssh-server-7.4p1-21.el7.x86_64
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd

rpm package를 download하는 방법은 아래 redhat사이트에서 직접 다운로드하거나, yumdownloader를 이용할 수 있습니다.

yum repolist: repository 목록을 표시합니다. repository는 /etc/yum.repos.d 디렉토리에 정의합니다.

yumdownloader : 각 repository에서 package keyword로 시작하는 rpm 패키지가 있는지 검색하고 다운로드합니다.

[root@bastion tmp]# yumdownloader openssh-server
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, product-id, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Loading mirror speeds from cached hostfile
 * epel: ftp.riken.jp
openssh-server-7.4p1-21.el7.x86_64.rpm                                                                                  | 459 kB  00:00:01

rpm파일내 목록을 보려면 -qpl, -qpc, -qpd를 사용하십시오. 'p'는 package라는 뜻입니다.

이는 설치된 rpm의 파일 목록을 보는 -ql, -qc, -qd와 동일합니다.

[root@bastion tmp]# rpm -qpl openssh-server-7.4p1-21.el7.x86_64.rpm
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd
/usr/lib/systemd/system/sshd-keygen.service
/usr/lib/systemd/system/sshd.service

[root@bastion tmp]# rpm -qpc openssh-server-7.4p1-21.el7.x86_64.rpm
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd


[root@bastion tmp]# rpm -qpd openssh-server-7.4p1-21.el7.x86_64.rpm
/usr/share/man/man5/moduli.5.gz
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sftp-server.8.gz
/usr/share/man/man8/sshd.8.gz

또한, -q --scripts명령을 rpm파일에 대해서 하려면 -qp --scripts를 이용하십시오.

[root@bastion tmp]# rpm -qp --scripts openssh-server-7.4p1-21.el7.x86_64.rpm
preinstall scriptlet (using /bin/sh):
getent group sshd >/dev/null || groupadd -g 74 -r sshd || :
getent passwd sshd >/dev/null || \
  useradd -c "Privilege-separated SSH" -u 74 -g sshd \
  -s /sbin/nologin -r -d /var/empty/sshd sshd 2> /dev/null || :
postinstall scriptlet (using /bin/sh):

if [ $1 -eq 1 ] ; then
        # Initial installation
        systemctl preset sshd.service sshd.socket >/dev/null 2>&1 || :
fi
preuninstall scriptlet (using /bin/sh):

if [ $1 -eq 0 ] ; then
        # Package removal, not upgrade
        systemctl --no-reload disable sshd.service sshd.socket > /dev/null 2>&1 || :
        systemctl stop sshd.service sshd.socket > /dev/null 2>&1 || :
fi
postuninstall scriptlet (using /bin/sh):

systemctl daemon-reload >/dev/null 2>&1 || :
if [ $1 -ge 1 ] ; then
        # Package upgrade, not uninstall
        systemctl try-restart sshd.service >/dev/null 2>&1 || :
fi

rpm패키지를 rpm2cpio라는 명령으로 extract할 수 있습니다.

[root@bastion scratch]# rpm2cpio openssh-server-7.4p1-21.el7.x86_64.rpm | cpio -duim
1946 blocks
[root@bastion scratch]# ls -l
total 480
drwxr-xr-x. 5 root root   4096 Jun 15 11:24 etc
-rw-r--r--. 1 root root 470036 Aug 23  2019 openssh-server-7.4p1-21.el7.x86_64.rpm
drwxr-xr-x. 7 root root   4096 Jun 15 11:24 usr
drwxr-xr-x. 3 root root   4096 Jun 15 11:24 var

yum

yum search로 원하는 프로그램을 찾습니다.

[root@bastion tmp]# yum search nmap
Loading mirror speeds from cached hostfile
 * epel: ftp.riken.jp
============================================================== N/S matched: nmap ==============================================================
nmap-frontend.noarch : The GTK+ front end for nmap
nmap-ncat.x86_64 : Nmap's Netcat replacement
perl-Nmap-Parser.noarch : Parse nmap scan data with perl
nmap.x86_64 : Network exploration tool and security scanner

  Name and summary matches only, use "search all" for everything.
[root@bastion tmp]#

 

yum info로 프로그램의 세부정보를 볼 수도 있습니다.

[root@bastion ~]# yum info nmap

Loading mirror speeds from cached hostfile
 * epel: ftp.riken.jp
Installed Packages
Name        : nmap
Arch        : x86_64
Epoch       : 2
Version     : 6.40
Release     : 19.el7
Size        : 16 M
Repo        : installed
From repo   : base
Summary     : Network exploration tool and security scanner
URL         : http://nmap.org/
License     : GPLv2 and LGPLv2+ and GPLv2+ and BSD
Description : Nmap is a utility for network exploration or security auditing.  It supports
            : ping scanning (determine which hosts are up), many port scanning techniques
            : (determine what services the hosts are offering), and TCP/IP fingerprinting
            : (remote host operating system identification). Nmap also offers flexible target
            : and port specification, decoy scanning, determination of TCP sequence
            : predictability characteristics, reverse-identd scanning, and more. In addition
            : to the classic command-line nmap executable, the Nmap suite includes a flexible
            : data transfer, redirection, and debugging tool (netcat utility ncat), a utility
            : for comparing scan results (ndiff), and a packet generation and response analysis
            : tool (nping).

repoquery명령으로 yum패키지 설치 전에 내부의 파일 목록을 볼 수 있습니다.

[root@bastion ~]# repoquery -l nmap

/usr/bin/ndiff
/usr/bin/nmap
/usr/bin/nping
/usr/share/doc/nmap-6.40
/usr/share/doc/nmap-6.40/COPYING
/usr/share/doc/nmap-6.40/README
/usr/share/doc/nmap-6.40/nmap.usage.txt
/usr/share/man/de/man1/nmap.1.gz
/usr/share/man/es/man1/nmap.1.gz
/usr/share/man/fr/man1/nmap.1.gz
...

 

특정 파일이 어떤 yum 패키지에 있는지 알려면 yum provides <파일>를 이용하십시오.

[root@bastion ~]# yum provides /etc/fstab

Loading mirror speeds from cached hostfile
 * epel: ftp.riken.jp
setup-2.8.71-11.el7.noarch : A set of system configuration and setup files
Repo        : base
Matched from:
Filename    : /etc/fstab



setup-2.8.71-11.el7.noarch : A set of system configuration and setup files
Repo        : @base
Matched from:
Filename    : /etc/fstab

yum provides는 wildcard를 이용하여 검색할 수도 있습니다. 아래 예는 netstat라는 실행파일이 어떤 yum package에 있는지 찾습니다.

[root@bastion ~]# yum provides *bin/netstat

Loading mirror speeds from cached hostfile
 * epel: ftp.riken.jp
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
Repo        : base
Matched from:
Filename    : /bin/netstat



net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
Repo        : @base
Matched from:
Filename    : /bin/netstat

 

yum package설치 명령은 yum install <package명>입니다.

[root@bastion ~]# yum install -y nmap

Loading mirror speeds from cached hostfile
 * epel: ftp.riken.jp
Resolving Dependencies
--> Running transaction check
---> Package nmap.x86_64 2:6.40-19.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================
 Package                        Arch                             Version                                  Repository                      Size
===============================================================================================================================================
Installing:
 nmap                           x86_64                           2:6.40-19.el7                            base                           3.9 M

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

Total download size: 3.9 M
Installed size: 16 M
Downloading packages:
nmap-6.40-19.el7.x86_64.rpm                                                                                             | 3.9 MB  00:00:04
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2:nmap-6.40-19.el7.x86_64                                                                                                   1/1
  Verifying  : 2:nmap-6.40-19.el7.x86_64                                                                                                   1/1

Installed:
  nmap.x86_64 2:6.40-19.el7

Complete!

만약, rpm파일을 다운로드 하였다면 yum localinstall명령을 이용하여 다운로드한 rpm파일을 이용하여 설치할수 있습니다.

 

업그레이드는 yum update입니다.

[root@bastion ~]# yum update nmap

Loading mirror speeds from cached hostfile
 * epel: ftp.riken.jp
No packages marked for update

삭제는 yum remove입니다.

[root@bastion ~]# yum remove -y nmap

Resolving Dependencies
--> Running transaction check
---> Package nmap.x86_64 2:6.40-19.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================
 Package                        Arch                             Version                                 Repository                       Size
===============================================================================================================================================
Removing:
 nmap                           x86_64                           2:6.40-19.el7                           @base                            16 M

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

Installed size: 16 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 2:nmap-6.40-19.el7.x86_64                                                                                                   1/1
  Verifying  : 2:nmap-6.40-19.el7.x86_64                                                                                                   1/1

Removed:
  nmap.x86_64 2:6.40-19.el7

Complete!

 

yum package를 category group별로 볼 수 있습니다.

먼저 yum package group의 목록을 확인합니다.

[root@bastion ~]# yum group list

There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * epel: ftp.riken.jp
Available Environment Groups:
   Minimal Install
   Compute Node
   ...
Available Groups:
   Cinnamon
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Educational Software
   ...
Done

각 group내의 yum package는 yum group info <그룹명>을 이용합니다.

[root@bastion ~]# yum group info "Development Tools"

There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
 * epel: ftp.riken.jp

Group: Development Tools
 Group-Id: development
 Description: A basic development environment.
 Mandatory Packages:
   +autoconf
   +automake
   ...
 Default Packages:
   +byacc
   +cscope
   +ctags
   +diffstat
   ...
 Optional Packages:
   ElectricFence
   ant
   ...
 

 

yum 사용 history를 볼 수 있습니다.

[root@bastion ~]# yum history

ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    32 | remove autoconf          | 2020-06-17 12:02 | Erase          |    1
    31 | install autoconf         | 2020-06-17 12:01 | Install        |    3
    30 | remove -y nmap           | 2020-06-17 11:49 | Erase          |    1
    29 | install -y nmap          | 2020-06-17 11:47 | Install        |    1
    

history,의 특정 transaction 상세정보를 볼 수 있습니다.

[root@bastion ~]# yum history info 35

Transaction ID : 35
Begin time     : Wed Jun 17 12:33:01 2020
Begin rpmdb    : 441:948ae879b5f0beb9dfaf00466058372b72a239bc
End time       :            12:33:02 2020 (1 seconds)
End rpmdb      : 442:aea465938682bd126d7c4ee166d6ff85bdfe8b5d
User           : root <root>
Return-Code    : Success
Command Line   : install -y bash-completion
Transaction performed with:
    Installed     rpm-4.11.3-43.el7.x86_64                         @base
    Installed     subscription-manager-1.24.26-3.el7.centos.x86_64 @updates
    Installed     yum-3.4.3-167.el7.centos.noarch                  @base
    Installed     yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch  @updates
Packages Altered:
    Install bash-completion-1:2.1-8.el7.noarch @base
history info

 

또한, history상의 특정 transaction을 취소할 수도 있습니다.

[root@bastion ~]# yum history undo 32

Undoing transaction 32, from Wed Jun 17 12:02:36 2020
    Erase autoconf-2.69-11.el7.noarch @base
Loading mirror speeds from cached hostfile
 * epel: ftp.riken.jp
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.69-11.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved
...
Is this ok [y/d/N]: y
Downloading packages:
autoconf-2.69-11.el7.noarch.rpm                                                                                         | 701 kB  00:00:07
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : autoconf-2.69-11.el7.noarch                                                                                                 1/1
  Verifying  : autoconf-2.69-11.el7.noarch                                                                                                 1/1

Installed:
  autoconf.noarch 0:2.69-11.el7

Complete!

 

yum repository

yum repository를 관리하는 방법을 학습합니다.

 

현재 추가된 yum repository목록은 yum repolist 명령으로 확인합니다.

[root@bastion ~]# yum repolist

Loading mirror speeds from cached hostfile
 * epel: ftp.riken.jp
repo id                                                  repo name                                                                       status
base/7/x86_64                                            CentOS-7 - Base                                                                 10070
docker-ce-stable/x86_64                                  Docker CE Stable - x86_64                                                          77
epel/x86_64                                              Extra Packages for Enterprise Linux 7 - x86_64                                  13323
extras/7/x86_64                                          CentOS-7 - Extras                                                                 397
updates/7/x86_64                                         CentOS-7 - Updates                                                                759
repolist: 24626

모든 repository목록은 yum repolist all 명령으로 볼 수 있습니다.

[root@bastion yum.repos.d]# yum repolist all

Loading mirror speeds from cached hostfile
 * epel: ftp.riken.jp
repo id                                          repo name                                                                       status
C7.0.1406-base/x86_64                            CentOS-7.0.1406 - Base                                                          disabled
C7.0.1406-centosplus/x86_64                      CentOS-7.0.1406 - CentOSPlus                                                    disabled
C7.0.1406-extras/x86_64                          CentOS-7.0.1406 - Extras                                                        disabled
C7.0.1406-fasttrack/x86_64                       CentOS-7.0.1406 - Fasttrack                                                     disabled
C7.0.1406-updates/x86_64                         CentOS-7.0.1406 - Updates                                                       disabled
C7.1.1503-base/x86_64                            CentOS-7.1.1503 - Base                                                          disabled
C7.1.1503-centosplus/x86_64                      CentOS-7.1.1503 - CentOSPlus                                                    disabled
C7.1.1503-extras/x86_64                          CentOS-7.1.1503 - Extras                                                        disabled
...

repository정보 설정파일들은 /etc/yum.repos.d 디렉토리에 있습니다.

[root@bastion yum.repos.d]# ls -l /etc/yum.repos.d/
total 52
-rw-r--r--. 1 root root 1708 Oct 28  2014 CentOS-Base.repo
-rw-r--r--. 1 root root 1618 Oct 28  2014 CentOS-Base.repo.orig
-rw-r--r--. 1 root root 1309 Apr  8 07:01 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Apr  8 07:01 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  630 Apr  8 07:01 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Apr  8 07:01 CentOS-Sources.repo
-rw-r--r--. 1 root root 7577 Apr  8 07:01 CentOS-Vault.repo
-rw-r--r--. 1 root root  314 Apr  8 07:01 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  616 Apr  8 07:01 CentOS-x86_64-kernel.repo
-rw-r--r--. 1 root root 2424 Oct 19  2019 docker-ce.repo
-rw-r--r--. 1 root root 1050 Oct  3  2017 epel-testing.repo
-rw-r--r--. 1 root root  951 Oct  3  2017 epel.repo

각 repository정보에는 url, name, gpgkey 등이 있습니다.

[cr]
name=CentOS-$releasever - cr
baseurl=http://mirror.centos.org/centos/$releasever/cr/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=0

참고) gpg(Gnu private Guard) key란 ?

gpg key는 repository에서 내려 받은 소프트웨어가 위변조 되지 않았는지 검증하기 위한 repository의 public key입니다.

먼저 암호화와 전자서명에 대한 이해를 먼저 하시고 이 사이트에서 직접 gpg key를 만들어 사용해 볼 수 있습니다.

 

reposiroty추가는 yum-config-manager --add-repo="<url>"을 이용합니다.

[root@bastion yum.repos.d]# yum-config-manager --add-repo="http://dl.fedoraproject.org/pub/epel/7/x86_64"

adding repo from: http://dl.fedoraproject.org/pub/epel/7/x86_64

[dl.fedoraproject.org_pub_epel_7_x86_64]
name=added from: http://dl.fedoraproject.org/pub/epel/7/x86_64
baseurl=http://dl.fedoraproject.org/pub/epel/7/x86_64
enabled=1

 

 

module관리

module은 rpm을 그룹핑한것입니다. module의 각 버전을 Streams라고 합니다. rpm package는 각 Streams 하위에 존재합니다.

 

* centos의 yum에는 module명령이 지원되지 않습니다. rhel에서만 지원되는것 같습니다.

module의 Stream목록은 yum module list <module명>으로 확인합니다.

module 설치는 yum module install <module명>으로 합니다.  또는 yum install @<module명>도 동일한 명령입니다.

 

module 삭제는 yum module remove <module명>으로 합니다.

삭제 후에는 Profiles 컬럼에 (i)가 없어진걸 볼 수 있습니다.

 

댓글

클라우드 네이티브 애플리케이션 부트캠프 알림