본문 바로가기
네이버클라우드/Linux

Linux 4일차 (2023-04-27) Linux System 관리 - 패키지 관리

by prometedor 2023. 4. 28.

패키지 관리

프로그램 설치/삭제

리눅스에서 프로그램을 설치하는 방법은 네 가지가 존재함


1. 소스를 다운 받아 직접 local에서 컴파일하여 설치

2. 컴파일된 binary의 압축파일을 다운 받아 바로 사용하는 방법

3. 다운 받아 직접 설치하는 방법

4. apt나 apt-get 이용한 자동설치 방법

 

명령어 복습

# enable  --> 내부 명령어 보기
# echo $SHELL
/bin/bash
echo ~  --> root 로 로그인 했으므로 홈은 /root
/root
# df -h  --> 용량 확인 가능 disk free
Filesystem               Size  Used Avail Use% Mounted on   
devtmpfs                 4.0M     0  4.0M   0% /dev
tmpfs                    982M     0  982M   0% /dev/shm
tmpfs                    393M  5.5M  388M   2% /run
/dev/mapper/rl_ysy-root   12G  2.4G  9.7G  20% /
/dev/sda1               1014M  184M  831M  19% /boot
/dev/mapper/rl_ysy-data   10G  104M  9.9G   2% /data
/dev/mapper/rl_ysy-home  5.0G   69M  5.0G   2% /home
tmpfs                    197M  4.0K  197M   1% /run/user/0

# du /etc -sh  --> 디스크 용량 인간이 보기 쉽게 나타냄(크기 단위)
21M     /etc

du -sh ~blue  --> blue 가 얼마나 용량 쓰고 있는지 알 수 있음
60K     /home/blue

# dc  --> dnf list --installed | wc -l
611

# dnf list | more  --> 큰 파일 끊어서 보기
# compgen -b | paste - - - - -     --> builtin (현재 시스템에서 사용 가능한 모든 내장 명령어를 한 줄에 5개씩 보기)
.       :       [       alias   bg
bind    break   builtin caller  cd
command compgen complete        compopt continue
declare dirs    disown  echo    enable
eval    exec    exit    export  false
fc      fg      getopts hash    help
history jobs    kill    let     local
logout  mapfile popd    printf  pushd
pwd     read    readarray       readonly        return
set     shift   shopt   source  suspend
test    times   trap    true    type
typeset ulimit  umask   unalias unset
wait

# .  --> . 도 명령어임
-bash: .: filename argument required
.: usage: . filename [arguments]  --> . 뒤에 file명을 입력하여 사용한다는 뜻

# k=500  --> k 변수에 500 넣음
# echo $k  --> duplicate 창 실행해서 해당 명령어 사용 시 실행 안 됨 (환경변수 이므로!!!)
500
# env  --> 현재 셸에 설정된 환경 변수를 표시
SHELL=/bin/bash
HISTCONTROL=ignoredups
HISTSIZE=1000
HOSTNAME=ysy.linux.kr
PWD=/root
LOGNAME=root
XDG_SESSION_TYPE=tty
MOTD_SHOWN=pam
HOME=/root
LANG=C.UTF-8
생략 ...

# useradd white  --> white 라는 사용자 생성
# passwd white  --> white 라는 사용자 비밀번호 변경
Changing password for user white.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
# ls /home/  --> 이전에 만들어 둔 blue 와 red 계정을 포함해 생성한 white 계정도 볼 수 있음
blue  red  white

# tail -3 /etc/passwd  --> 최근 만든 계정 보기 위해 끝에서 3라인만 보기
flatpak:x:988:988:User for flatpak system helper:/:/sbin/nologin
mysql:x:27:27:MySQL Server:/var/lib/mysql:/sbin/nologin
white:x:1002:1002::/home/white:/bin/bash
[root@ysy ~]# echo $PS1  --> 주 프롬프트
[\u@\h \w]\$
[root@ysy ~]# echo $PS2  --> 보조 프롬프트
>

 

tree 

# di tree  --> alias : dnf -y install
# dnf list --installed | grep tree  --> 설치된 모든 파일 중 tree 라는 문자열이 들어간 리스트 보기
ostree-libs.x86_64                        2022.5-1.el9                     @appstream
tree.x86_64                               1.8.0-10.el9                     @baseos

# dnf list --installed | grep ^tree  --> 설치된 모든 파일 중 tree 로 시작하는 파일 리스트 보기
tree.x86_64                               1.8.0-10.el9                     @baseos

# tree  --> 디렉터리 구조
.
├── anaconda-ks.cfg
└── d3
    └── httpd-2.4.57.tar.gz

1 directory, 2 files

ㄴ tree 관련 명령

# dnf info tree  --> tree 패키지의 정보를 제공
# yum info tree  --> tree 패키지의 정보를 제공
# dnf -3 info tree  --> tree 패키지의 정보를 제공

 

whereis, whatis, which

whereis  --> 지정된 명령어의 위치를 찾아줌
whatis  --> 지정된 명령어, 파일, 또는 커맨드의 간단한 설명을 출력
which  --> 지정된 명령어의 실행 파일 위치를 찾아줌


# whereis yum
yum: /usr/bin/yum /etc/yum /usr/share/man/man8/yum.8.gz

# which yum  --> yum 명령어의 위치
/usr/bin/yum

# whatis yum
yum (8)              - redirecting to DNF Command Reference  --> dnf 의 참조

# ll /usr/bin/yum  --> dnf 의 참조 (yum 명령어의 위치가 dnf-3 명령어를 참조)
lrwxrwxrwx. 1 root root 5 Nov 15 18:28 /usr/bin/yum -> dnf-3

# whatis dnf
dnf (8)              - DNF Command Reference

# which dnf  --> dnf 명령어의 위치는 dnf-3 를 참조
/usr/bin/dnf

# ll /usr/bin/dnf
lrwxrwxrwx. 1 root root 5 Nov 15 18:28 /usr/bin/dnf -> dnf-3

ㄴ yum 명령어는 dnf 명령어를 참조하고 있음

ㄴ dnf 명령어는 dnf-3 를 참조하고 있음

-->  yum, dnf, dnf-3 는 모두 같은 기능을 하는 명령어임

 

 

Rocky Linux package 관리

rpm 은 과거에 쓰던 툴
yum, dnf 는 dnf-3 의 symbolic link 임 (reference)

# dnf -y install tree --> 설치 (-y : 자동으로 yes 해주는 옵션)
# dnf -y remove tree  --> 설치 삭제 (-y : 자동으로 yes 해주는 옵션)
# dnf list -installed | grep tree  --> 조회
# dnf info  --> 정보 보기 (-y : 자동으로 yes 해주는 옵션)

# dnf upgrade  --> upgrade
# dnf update  --> update

 

 

sqlite

[root@ysy /var/www/html]# di sqlite  --> sqlite 설치 (di : dnf -y install)
[root@ysy /var/www/html]# sqlite  --> mysql 처럼 따로 켜지 않아도 됨
SQLite version 3.34.1 2021-01-20 14:10:07
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .open myDB
sqlite> .open myDB
sqlite> create table score(name, kor, mat, eng);
sqlite> insert into score values("kim", 40, 50, 60);
sqlite> insert into score values("choi", 50, 90, 30);
sqlite>
sqlite> .mode col
sqlite> .head on
sqlite> select * from score;
name  kor  mat  eng
----  ---  ---  ---
kim   40   50   60
choi  50   90   30
sqlite> .q  --> sqlite 나가는 방법

 

./configure --prefix=/디렉터리 

--> 실행 파일을 지정한 디렉토리에 설치

 

[root@ysy /var/www/html]# ls
index.html  myDB
[root@ysy /var/www/html]# di sqlite3
Last metadata expiration check: 1:23:03 ago on Thu Apr 27 09:48:11 2023.
No match for argument: sqlite3
Error: Unable to find a match: sqlite3

** sqlite.org -->> source code 복사 해두기
 
[root@ysy /var/www/html]# mkdir /down  --> /down 디렉터리 생성
[root@ysy /var/www/html]# cd /down  --> /down 디렉터리로 경로 이동
[root@ysy /down]# wget https://sqlite.org/2023/sqlite-autoconf-3410200.tar.gz  --> 소스코드 주소 복사
--2023-04-27 11:15:17--  https://sqlite.org/2023/sqlite-autoconf-3410200.tar.gz
Resolving sqlite.org (sqlite.org)... 45.33.6.223, 2600:3c00::f03c:91ff:fe96:b959
Connecting to sqlite.org (sqlite.org)|45.33.6.223|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3125545 (3.0M) [application/x-gzip]
Saving to: ‘sqlite-autoconf-3410200.tar.gz’

sqlite-autoconf-341020 100%[===========================>]   2.98M  2.21MB/s    in 1.4s

2023-04-27 11:15:19 (2.21 MB/s) - ‘sqlite-autoconf-3410200.tar.gz’ saved [3125545/3125545]

[root@ysy /down]# ll
total 3056
-rw-r--r--. 1 root root 3125545 Mar 23 01:33 sqlite-autoconf-3410200.tar.gz

** Precompiled Binaries for Windows > sqlite-tools-win32-x86-3410200.zip
(1.91 MiB)

압축 풀고 > sqlite3  > 추가적용 > 실행

[root@ysy /down]# tar xvf sqlite-autoconf-3410200.tar.gz
-bash: tar: command not found  --> tar 가 없음
[root@ysy /down]# di tar  --> tar 설치 (di : dnf -y install)
[root@ysy /down]# tar xf sqlite-autoconf-3410200.tar.gz  --> 압축 풀기
[root@ysy /down]# l
total 3056
-rw-r--r--. 1 root root 3125545 Mar 23 01:33 sqlite-autoconf-3410200.tar.gz

[root@ysy /down]# cd sqlite-autoconf-3410200  --> 디렉터리 안으로 경로 이동
[root@ysy /down/sqlite-autoconf-3410200]# ls
INSTALL            README.txt    config.sub    ltmain.sh  sqlite3.h      tea
Makefile.am        Replace.cs    configure     missing    sqlite3.pc.in
Makefile.fallback  aclocal.m4    configure.ac  shell.c    sqlite3.rc
Makefile.in        compile       depcomp       sqlite3.1  sqlite3ext.h
Makefile.msc       config.guess  install-sh    sqlite3.c  sqlite3rc.h

** configure 파일--> 실행 파일
[root@ysy /down/sqlite-autoconf-3410200]# ./configure --prefix=/sql  --> 설치 위치를 지정해서 환경을 만드는 것
[root@ysy /down/sqlite-autoconf-3410200]# make --> 소프트웨어 빌드 프로세스를 자동화하기 위한 유틸리티 도구 --> 에러 안 뜨면 됨
[root@ysy /down/sqlite-autoconf-3410200]# make install --> 실행 파일 설치

ㄴ sqlite.org 홈페이지에서 source code 주소 복사

ㄴ wget 입력 후 복사해온 주소(소스코드 주소) 붙여넣어 다운로드 받기

ㄴ tar xf 이용하여 압축 풀기

ㄴ 압축 푼 디렉터리로 경로 이동  --> ls(목록 보기) 리스트에서 configure 파일 확인

ㄴ ./configure --prefix=/sql  --> 설치 위치를 /sql 로 지정해서 환경을 만듦

ㄴ make  --> 소프트웨어 빌드 프로세스를 자동화하기 위함 => 에러 안 뜨면 됨

ㄴ make install --> 실행 파일을 지정한 디렉토리에 설치

 

--> "./configure" 명령어를 사용하여 소스 코드를 설치할 디렉토리를 지정. 그리고 "make" 명령어를 사용하여 소스 코드를 컴파일하여 실행 파일을 생성. 마지막으로 "make install" 명령어를 사용하여 실행 파일을 지정한 디렉토리에 설치.

[root@ysy /down/sqlite-autoconf-3410200]# make install