Packstack #1 사전 작업 및 패키지 설치

※ 이 포스트는 실제 설치및 설정을 수행하면서 작성하고 있습니다. 계속 업데이트 됩니다.

Openstack #1 개요

CentOS 7 에 install 하는것으로 가정한다.
CentOS 8 Linux 설치를 참고하여 최소설치 모드로 리눅스를 설치한다.
네트워크 설정을 변경한다. (NIC는 2개 이상이 필요하다. 외부 연결용, 노드간 통신 용)
root 권한으로 해야 하는 작업이 많다. root 패스워드를 설정하거나, SuDo : SuperUser Do를 참고하여 sudo 사용 설정을 한다.
클러스터간 설치 및 통신 용의성 확보를 위해 SSH설정을 참고하여 키를 등록한다.
openstack train 기준으로 진행한다.



네트워크설정, ssh 키 설정 등이 완료 됐으면 서비스 설정을 변경한다.
openstack 클러스터의 구성 노드 모두에서 작업 해줘야 한다.

 # 노드간 통신의 용의성을 위해 방화벽 서비스를 종료한다.
[HOSTNAME:/haedong]$ sudo systemctl disable firewalld
[HOSTNAME:/haedong]$ sudo service firewalld stop

 # Network 관리 서비스인데 개인적으로 아주 고약한 녀석이다. 
 # 아무리 설정을 바꿔도 제 멋대로 설정을 덮어 써버리는 경우가 허다하므로 종료한다.
 # 어차피 네트워크는 별도로 관리해야 한다. 
[HOSTNAME:/haedong]$ sudo systemctl disable NetworkManager
[HOSTNAME:/haedong]$ sudo service NetworkManager stop

 # 만약을 위해 서비스를 재시작하고, 항상 서비스가 구동도록 설정한다.
[HOSTNAME:/haedong]$ sudo systemctl enable network
[HOSTNAME:/haedong]$ sudo service network restart

packstack1RDO project의 puppet module을 이용한 CentOS 및 Redhat linux 용 openstack 자동 배포 유틸리티이다. 관련 리포지터리 및 패키지 설치

 # 만약 epel-release 리포지터리가 추가되어있다면 삭제한다.(혹은 disable로 변경해도 된다.)
[HOSTNAME:/home/haedong]$ sudo rm /etc/yum.repos.d/epel
rm: remove 일반 파일 `epel-testing.repo'? y
rm: remove 일반 파일 `epel.repo'? y
 # packstack repo 설치
[HOSTNAME:/home/haedong:]$ sudo yum install -y https://www.rdoproject.org/repos/rdo-release.rpm
[sudo] haedong의 암호:
Loaded plugins: fastestmirror, langpacks
rdo-release.rpm                                                                                                                                               | 6.7 kB  00:00:00
Examining /var/tmp/yum-root-URQvAZ/rdo-release.rpm: rdo-release-train-1.noarch
Marking /var/tmp/yum-root-URQvAZ/rdo-release.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package rdo-release.noarch 0:train-1 will be installed
--> Finished Dependency Resolution
base/7/x86_64                                                                                                                                                 | 3.6 kB  00:00:00
Dependencies Resolved
=====================================================================================================================================================================================
 Package                                      Arch                                    Version                                    Repository                                     Size
=====================================================================================================================================================================================
Installing:
 rdo-release                                  noarch                                  train-1                                    /rdo-release                                  3.1 k
Transaction Summary
=====================================================================================================================================================================================
Install  1 Package

Total size: 3.1 k
Installed size: 3.1 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : rdo-release-train-1.noarch                                                                                                                                        1/1
  Verifying  : rdo-release-train-1.noarch                                                                                                                                        1/1
Installed:
  rdo-release.noarch 0:train-1
Complete!
 # openstack train 패키지 설치
[HOSTNAME:/home/haedong:]$ sudo yum install -y centos-release-openstack-train
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
 * base: mirror.kakao.com
 * extras: mirror.kakao.com
 * openstack-train: mirror.kakao.com
 * rdo-qemu-ev: mirror.kakao.com
 * updates: mirror.kakao.com
openstack-train                                                                                                                                               | 3.0 kB  00:00:00
rdo-qemu-ev                                                                                                                                                   | 3.0 kB  00:00:00
(1/2): rdo-qemu-ev/x86_64/primary_db                                                                                                                          |  57 kB  00:00:00
(2/2): openstack-train/x86_64/primary_db                                                                                                                      | 1.1 MB  00:00:00
Resolving Dependencies
--> Running transaction check
---> Package centos-release-openstack-train.noarch 0:1-1.el7.centos will be installed
--> Processing Dependency: centos-release-qemu-ev for package: centos-release-openstack-train-1-1.el7.centos.noarch
--> Processing Dependency: centos-release-ceph-nautilus for package: centos-release-openstack-train-1-1.el7.centos.noarch
--> Running transaction check
---> Package centos-release-ceph-nautilus.noarch 0:1.2-2.el7.centos will be installed
--> Processing Dependency: centos-release >= 7-5.1804.el7.centos.2 for package: centos-release-ceph-nautilus-1.2-2.el7.centos.noarch
--> Processing Dependency: centos-release-storage-common for package: centos-release-ceph-nautilus-1.2-2.el7.centos.noarch
--> Processing Dependency: centos-release-nfs-ganesha28 for package: centos-release-ceph-nautilus-1.2-2.el7.centos.noarch
---> Package centos-release-qemu-ev.noarch 0:1.0-4.el7.centos will be installed
--> Processing Dependency: centos-release-virt-common for package: centos-release-qemu-ev-1.0-4.el7.centos.noarch
--> Running transaction check
---> Package centos-release.x86_64 0:7-5.1804.el7.centos will be updated
---> Package centos-release.x86_64 0:7-9.2009.1.el7.centos will be an update
---> Package centos-release-nfs-ganesha28.noarch 0:1.0-3.el7.centos will be installed
---> Package centos-release-storage-common.noarch 0:2-2.el7.centos will be installed
---> Package centos-release-virt-common.noarch 0:1-1.el7.centos will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================================================================
 Package                                                  Arch                             Version                                           Repository                         Size
=====================================================================================================================================================================================
Installing:
 centos-release-openstack-train                           noarch                           1-1.el7.centos                                    extras                            5.3 k
Installing for dependencies:
 centos-release-ceph-nautilus                             noarch                           1.2-2.el7.centos                                  extras                            5.1 k
 centos-release-nfs-ganesha28                             noarch                           1.0-3.el7.centos                                  extras                            4.3 k
 centos-release-qemu-ev                                   noarch                           1.0-4.el7.centos                                  extras                             11 k
 centos-release-storage-common                            noarch                           2-2.el7.centos                                    extras                            5.1 k
 centos-release-virt-common                               noarch                           1-1.el7.centos                                    extras                            4.5 k
Updating for dependencies:
 centos-release                                           x86_64                           7-9.2009.1.el7.centos                             updates                            27 k
Transaction Summary
=====================================================================================================================================================================================
Install  1 Package  (+5 Dependent packages)
Upgrade             ( 1 Dependent package)
Total download size: 62 k
Downloading packages:
No Presto metadata available for updates
(1/7): centos-release-7-9.2009.1.el7.centos.x86_64.rpm                                                                                                        |  27 kB  00:00:00
(2/7): centos-release-ceph-nautilus-1.2-2.el7.centos.noarch.rpm                                                                                               | 5.1 kB  00:00:00
(3/7): centos-release-nfs-ganesha28-1.0-3.el7.centos.noarch.rpm                                                                                               | 4.3 kB  00:00:00
(4/7): centos-release-qemu-ev-1.0-4.el7.centos.noarch.rpm                                                                                                     |  11 kB  00:00:00
(5/7): centos-release-storage-common-2-2.el7.centos.noarch.rpm                                                                                                | 5.1 kB  00:00:00
(6/7): centos-release-openstack-train-1-1.el7.centos.noarch.rpm                                                                                               | 5.3 kB  00:00:00
(7/7): centos-release-virt-common-1-1.el7.centos.noarch.rpm                                                                                                   | 4.5 kB  00:00:00
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                650 kB/s |  62 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : centos-release-7-9.2009.1.el7.centos.x86_64                                                                                                                       1/8
warning: /etc/yum/vars/contentdir created as /etc/yum/vars/contentdir.rpmnew
  Installing : centos-release-storage-common-2-2.el7.centos.noarch                                                                                                               2/8
  Installing : centos-release-nfs-ganesha28-1.0-3.el7.centos.noarch                                                                                                              3/8
  Installing : centos-release-ceph-nautilus-1.2-2.el7.centos.noarch                                                                                                              4/8
  Installing : centos-release-virt-common-1-1.el7.centos.noarch                                                                                                                  5/8
  Installing : centos-release-qemu-ev-1.0-4.el7.centos.noarch                                                                                                                    6/8
  Installing : centos-release-openstack-train-1-1.el7.centos.noarch                                                                                                              7/8
  Cleanup    : centos-release-7-5.1804.el7.centos.x86_64                                                                                                                         8/8
  Verifying  : centos-release-openstack-train-1-1.el7.centos.noarch                                                                                                              1/8
  Verifying  : centos-release-nfs-ganesha28-1.0-3.el7.centos.noarch                                                                                                              2/8
  Verifying  : centos-release-7-9.2009.1.el7.centos.x86_64                                                                                                                       3/8
  Verifying  : centos-release-ceph-nautilus-1.2-2.el7.centos.noarch                                                                                                              4/8
  Verifying  : centos-release-virt-common-1-1.el7.centos.noarch                                                                                                                  5/8
  Verifying  : centos-release-storage-common-2-2.el7.centos.noarch                                                                                                               6/8
  Verifying  : centos-release-qemu-ev-1.0-4.el7.centos.noarch                                                                                                                    7/8
  Verifying  : centos-release-7-5.1804.el7.centos.x86_64                                                                                                                         8/8
Installed:
  centos-release-openstack-train.noarch 0:1-1.el7.centos
Dependency Installed:
  centos-release-ceph-nautilus.noarch 0:1.2-2.el7.centos        centos-release-nfs-ganesha28.noarch 0:1.0-3.el7.centos        centos-release-qemu-ev.noarch 0:1.0-4.el7.centos
  centos-release-storage-common.noarch 0:2-2.el7.centos         centos-release-virt-common.noarch 0:1-1.el7.centos
Dependency Updated:
  centos-release.x86_64 0:7-9.2009.1.el7.centos

Complete!
 # 설치 된 패키지 업데이트.
[HOSTNAME:/home/haedong:]$ sudo yum -y update
Loaded plugins: fastestmirror, langpacks
Repository rdo-trunk-train-tested is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirror.kakao.com
 * centos-ceph-nautilus: mirror.kakao.com
 * centos-nfs-ganesha28: mirror.kakao.com
 * centos-openstack-train: mirror.kakao.com
 * centos-qemu-ev: mirror.kakao.com
 * extras: mirror.kakao.com
 * openstack-train: mirror.kakao.com
 * rdo-qemu-ev: mirror.kakao.com
 * updates: mirror.kakao.com
Resolving Dependencies
--> Running transaction check
---> Package GeoIP.x86_64 0:1.5.0-11.el7 will be updated
---> Package GeoIP.x86_64 0:1.5.0-14.el7 will be an update
--> Processing Dependency: geoipupdate for package: GeoIP-1.5.0-14.el7.x86_64
---> Package LibRaw.x86_64 0:0.14.8-5.el7.20120830git98d925 will be updated
---> Package LibRaw.x86_64 0:0.19.4-1.el7 will be an update
---> Package ModemManager.x86_64 0:1.6.10-1.el7 will be updated
---> Package ModemManager.x86_64 0:1.6.10-4.el7 will be an update
---> Package ModemManager-glib.x86_64 0:1.6.10-1.el7 will be updated
---> Package ModemManager-glib.x86_64 0:1.6.10-4.el7 will be an update
---> Package NetworkManager.x86_64 1:1.10.2-13.el7 will be updated
---> Package NetworkManager.x86_64 1:1.18.8-2.el7_9 will be an update
---> Package NetworkManager-adsl.x86_64 1:1.10.2-13.el7 will be updated
---> Package NetworkManager-adsl.x86_64 1:1.18.8-2.el7_9 will be an update
---> Package NetworkManager-glib.x86_64 1:1.10.2-13.el7 will be updated
---> Package NetworkManager-glib.x86_64 1:1.18.8-2.el7_9 will be an update
---> Package NetworkManager-libnm.x86_64 1:1.10.2-13.el7 will be updated
---> Package NetworkManager-libnm.x86_64 1:1.18.8-2.el7_9 will be an update
---> Package NetworkManager-ppp.x86_64 1:1.10.2-13.el7 will be updated
---> Package NetworkManager-ppp.x86_64 1:1.18.8-2.el7_9 will be an update
--> Running transaction check
...중략...
---> Package mokutil.x86_64 0:15-8.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================================================================================================
 Package                                                 Arch                     Version                                             Repository                                Size
=====================================================================================================================================================================================
Installing:
 freerdp-libs                                            x86_64                   2.1.1-2.el7                                         base                                     851 k
     replacing  freerdp-plugins.x86_64 1.0.2-15.el7
 gnome-dictionary                                        x86_64                   3.26.1-2.el7                                        base                                     642 k
     replacing  gnome-dictionary-libs.x86_64 3.20.0-1.el7
 gnome-shell                                             x86_64                   3.28.3-32.el7                                       updates                                  2.1 M
     replacing  caribou.x86_64 0.4.21-1.el7
     replacing  caribou-gtk2-module.x86_64 0.4.21-1.el7
     replacing  caribou-gtk3-module.x86_64 0.4.21-1.el7
     replacing  python2-caribou.noarch 0.4.21-1.el7
 xorg-x11-xauth                                          x86_64                   1:1.0.9-1.el7                                       base                                      30 k
 xorg-x11-xinit                                          x86_64                   1.3.4-2.el7                                         base                                      58 k
 xorg-x11-xkb-utils                                      x86_64                   7.7-14.el7                                          base                                     103 k
...중략...
Transaction Summary
=====================================================================================================================================================================================
Install   36 Packages (+95 Dependent packages)
Upgrade  940 Packages

Total download size: 1.1 G
Downloading packages:
No Presto metadata available for centos-openstack-train
No Presto metadata available for openstack-train
No Presto metadata available for base
No Presto metadata available for updates
No Presto metadata available for centos-ceph-nautilus
(1/1071): GeoIP-1.5.0-14.el7.x86_64.rpm                                                                                                                       | 1.5 MB  00:00:00
(2/1071): LibRaw-0.19.4-1.el7.x86_64.rpm                                                                                                                      | 308 kB  00:00:00
(3/1071): ModemManager-1.6.10-4.el7.x86_64.rpm                                                                                                                | 738 kB  00:00:00
(4/1071): ModemManager-glib-1.6.10-4.el7.x86_64.rpm                                                                                                           | 232 kB  00:00:00
(5/1071): NetworkManager-adsl-1.18.8-2.el7_9.x86_64.rpm                                                                                                       | 163 kB  00:00:00
(6/1071): NetworkManager-glib-1.18.8-2.el7_9.x86_64.rpm                                                                                                       | 1.5 MB  00:00:00
(7/1071): NetworkManager-libnm-1.18.8-2.el7_9.x86_64.rpm                                                                                                      | 1.7 MB  00:00:00
...중략...
(1068/1071): yum-utils-1.1.31-54.el7_8.noarch.rpm                                                                                                             | 122 kB  00:00:00
(1069/1071): zlib-1.2.7-18.el7.x86_64.rpm                                                                                                                     |  90 kB  00:00:00
(1070/1071): zlib-devel-1.2.7-18.el7.x86_64.rpm                                                                                                               |  50 kB  00:00:00
(1071/1071): zenity-3.28.1-1.el7.x86_64.rpm                                                                                                                   | 4.0 MB  00:00:00
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                 46 MB/s | 1.1 GB  00:00:25
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Storage
Importing GPG key 0xE451E5B5:
 Userid     : "CentOS Storage SIG (http://wiki.centos.org/SpecialInterestGroup/Storage) <security@centos.org>"
 Fingerprint: 7412 9c0b 173b 071a 3775 951a d4a2 e50b e451 e5b5
 Package    : centos-release-storage-common-2-2.el7.centos.noarch (@extras)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-Storage
...중략...
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : libgcc-4.8.5-44.el7.x86_64                                                                                                                                     1/2055
  Installing : urw-base35-fonts-common-20170801-10.el7.noarch                                                                                                                 2/2055
  Installing : xorg-x11-proto-devel-2018.4-1.el7.noarch                                                                                                                       3/2055
...중략...
  Verifying  : 10:qemu-kvm-1.5.3-156.el7.x86_64                                                                                                                            2053/2055
  Verifying  : python-dmidecode-3.12.2-2.el7.x86_64                                                                                                                        2054/2055
  Verifying  : freerdp-1.0.2-15.el7.x86_64                                                                                                                                 2055/2055
Installed:
  freerdp-libs.x86_64 0:2.1.1-2.el7                             gnome-dictionary.x86_64 0:3.26.1-2.el7                  gnome-shell.x86_64 0:3.28.3-32.el7
  grub2.x86_64 1:2.02-0.86.el7.centos                           grub2-tools.x86_64 1:2.02-0.86.el7.centos               grub2-tools-extra.x86_64 1:2.02-0.86.el7.centos
...중략...
  qemu-img.x86_64 10:1.5.3-156.el7                         qemu-kvm.x86_64 10:1.5.3-156.el7                               qemu-kvm-common.x86_64 10:1.5.3-156.el7
  sip-macros.x86_64 0:4.14.6-4.el7                         urw-fonts.noarch 0:2.4-16.el7                                  webkitgtk4-plugin-process-gtk2.x86_64 0:2.16.6-6.el7

Complete!
[HOSTNAME:/home/haedong:]$ sudo yum install -y openstack-packstack
Loaded plugins: fastestmirror, langpacks
Repository rdo-trunk-train-tested is listed more than once in the configuration
Loading mirror speeds from cached hostfile
 * base: mirror.kakao.com
Resolving Dependencies
--> Running transaction check
---> Package openstack-packstack.noarch 1:15.0.1-1.el7 will be installed
--> Processing Dependency: openstack-packstack-puppet = 1:15.0.1-1.el7 for package: 1:openstack-packstack-15.0.1-1.el7.noarch
--> Processing Dependency: python-docutils for package: 1:openstack-packstack-15.0.1-1.el7.noarch
--> Processing Dependency: python2-pbr for package: 1:openstack-packstack-15.0.1-1.el7.noarch
--> Running transaction check
---> Package openstack-packstack-puppet.noarch 1:15.0.1-1.el7 will be installed
--> Processing Dependency: puppet-aodh for package: 1:openstack-packstack-puppet-15.0.1-1.el7.noarch
--> Processing Dependency: puppet-apache for package: 1:openstack-packstack-puppet-15.0.1-1.el7.noarch
...중략...
  Verifying  : 1:openstack-packstack-15.0.1-1.el7.noarch                                                                                                                       76/78
  Verifying  : python2-pbr-5.1.2-2.el7.noarch                                                                                                                                  77/78
  Verifying  : puppet-cinder-15.4.0-1.el7.noarch                                                                                                                               78/78
Installed:
  openstack-packstack.noarch 1:15.0.1-1.el7
Dependency Installed:
  boost159-atomic.x86_64 0:1.59.0-2.el7.1                 boost159-chrono.x86_64 0:1.59.0-2.el7.1                      boost159-date-time.x86_64 0:1.59.0-2.el7.1
...중략...
  ruby-facter.x86_64 1:3.9.3-7.el7                        ruby-shadow.x86_64 0:1.4.1-23.el7                            rubygem-pathspec.noarch 0:0.2.1-3.el7
  rubygem-rgen.noarch 0:0.6.6-2.el7                       yaml-cpp.x86_64 0:0.5.1-6.el7
Complete!










SSH 설정

개요

시큐어 셸(Secure SHellSSH)은 네트워크 상의 다른 컴퓨터에 로그인하거나 원격 시스템에서 명령을 실행하고 다른 시스템으로 파일을 복사할 수 있도록 해 주는 응용 프로그램 또는 그 프로토콜을 가리킨다. 기존의 rshrlogin텔넷 등을 대체하기 위해 설계되었으며, 강력한 인증 방법 및 안전하지 못한 네트워크에서 안전하게 통신을 할 수 있는 기능을 제공한다. 기본적으로는 22번 포트를 사용한다.

SSH는 암호화 기법을 사용하기 때문에, 통신이 노출된다고 하더라도 이해할 수 없는 암호화된 문자로 보인다.

SSL 그리고 HTTPS 의 암호화 통신방식을 이용한 쉘이다.
비대칭키 암호화 알고리즘으로 대칭키를 암호화 하여 주고받은 뒤 대칭키로 암호화 된 메시지를 주고 받는 프로토골이다.

대부분의 리눅스 시스템에 기본으로 포함되어있고, 설치된다.
ssh 서버에 접속하기 위한 클라이언트는 대부분의 linux 배포본에는 기본적으로 포함되어있고, Windows Powershell에도 포함되어있다.




사용법

linux shell / powershell 모두
ssh 계정명@hostname_또는_IP 명령으로 다른 호스트에 연결할 수 있다.
대개의 경우 Windows 에서는 putty 라는 공개 툴을 많이 사용한다.

[haedong@openstack2:~]$ssh
usage: ssh [-1246AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-E log_file] [-e escape_char]
           [-F configfile] [-I pkcs11] [-i identity_file]
           [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]
           [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
           [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
           [user@]hostname [command]
 # 일반적인 연결방법
 # ssh account@server_HOSTNAME_or_server_IP
[haedong@openstack2:~]$ssh haedong@192.168.113.172
haedong@192.168.113.172's password:
Last login: Thu Dec 17 13:26:54 2020 from 192.168.4.199
[haedong@openstack2:~]$
 # 저장된 ssh key를 사용하는 경우
 # ssh account@server_HOSTNAME_or_server_IP -i KEY_FILE_NAME
[haedong@openstack2:~]$ssh root@192.168.113.171 -i ~/.ssh/id_rsa
Last login: Wed Dec 16 09:31:02 2020 from openstack3
[root@openstack1:~]#
 # 접속 로그 확인을 원할 경우
[haedong@openstack2:~]$ssh root@192.168.113.171 -i ~/.ssh/id_rsa -v
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug1: Connecting to 192.168.113.171 [192.168.113.171] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/haedong/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/haedong/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.113.171:22 as 'root'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit                               > compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit                               > compression: none
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: kex: curve25519-sha256 need=64 dh_need=64
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:mLoKmt/MNoY/Il1LahMDflXKfT/c                               KSpI80vbl2m5EFM
debug1: Host '192.168.113.171' is known and matches the ECDSA host key.
debug1: Found key in /etc/ssh/ssh_known_hosts:4
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mi                               c,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:1000)

debug1: Unspecified GSS failure.  Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:1000)

debug1: Next authentication method: publickey
debug1: Trying private key: /home/haedong/.ssh/id_rsa
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.113.171 ([192.168.113.171]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: pledge: network
debug1: client_input_global_request: rtype hostkeys-00@openssh.com want_reply 0
debug1: Sending environment.
debug1: Sending env LANG = ko_KR.UTF-8
Last login: Thu Dec 17 13:38:57 2020 from openstack2
[root@openstack1:~]#



sshd (SSH daemon : a.k.a ssh server) 설정

기본적으로 ssh 데몬의 설정파일은 /etc/ssh/sshd_config
ssh 클라이언트 설정 파일은 /etc/ssh/ssh_config
파일이다. 보통은 windows클라이언트에서 linux 서버로 접속을 하는 경우가 많다보니 ssh_config 파일을 수정하는경우는 많지 않(은것 같)다.

자주 사용하거나, 중요한 옵션만 기억하자.

 # ssh 서버 설정을 위한 값. 주석처리가 되어있는 경우 기본값으로 설정된다.
#Port 22
#ListenAddress 0.0.0.0


 # root로 로그인을 허용할 것인지 설정. no로 설정하고 sudo을 이용하는 것을 권장한다.
#PermitRootLogin yes
PermitRootLogin no

 # 로그인을 시도하는 계정/.ssh/authorized_keys 파일을 의미한다.
 # 허용할 공개키를 저장하는 파일을 가리킨다.
AuthorizedKeysFile      .ssh/authorized_keys

 # 빈 패스워드 로그인을 허용할 것인지 설정한다. 당연히 no로 설정하는 것이 '옳다'
PermitEmptyPasswords no

 # password를 이용한 로그인을 허용할 것인지 설정한다.
PasswordAuthentication yes

 # GSSAPI 사용 여부
 # 간혹 폐쇄망에서 접속 지연(ID 입력 후 지연)이 발생하년 경우 no로 변경
# GSSAPI options
GSSAPIAuthentication no
GSSAPICleanupCredentials no

 # 역시 폐쇄망 혹은 DNS 연결이 안되는 환경에서 접속 지연이 발생화면 no로 변경
UseDNS no

서비스 구동 / 재시작 / 종료

 # 서비스 구동
 # service sshd start
[haedong@openstack2:~]$ sudo systemctl start sshd.service

 # 서비스 재시작
 # service sshd restart
[haedong@openstack2:~]$ sudo systemctl restart sshd.service

 # 서비스 구동
 # service sshd stop
[haedong@openstack2:~]$ sudo systemctl stop sshd.service

사실 service sshd stop 또는 systemctl stop sshd.service 명령은 평생 내릴 일 없는 명령일지도 모른다.

ssh 키 쌍을 이용한 로그인 설정

SSL 그리고 HTTPS 포스트에서 설명한 공개키를 미리 서버에 저장해 두고 인증하는 방식이다.
이해를 위해 개념적인 절차를 기재해보면(실제 절차와는 차이가 있음)
1. 사용자가 비대칭 키 쌍 K1(공개키), K2(비밀키)를 생성.
2. 서버에 K1 을 저장
3. 사용자가 서버에 접속 시도
4. 서버는 대칭키 KS 생성
5. K1로 KS를 암호화하여 KK 생성
6. KK를 사용자에게 전달
7. 사용자는 KK를 K2를 복호화하여 KS 획득
8. KS를 KS로 암호화하여 SS 생성
9. 서버로 SS 전송
10. 서버는 KS로 SS를 복호화 하여 KS 획득.
11. 서버가 가지고 있는 KS와 사용자가 전송한 KS가 같은지 비교
가 되겠다.

보통은 보안상의 이유로 ssh key를 이용한 로그인을 강제하지만 반대로 편리한 것도 있다. 모든 서버의 키를 하나로 통일하고 passphrase를 비워두면 패스워드 입력 없이 모든 서버에 접속이 가능해 진다.(당연히 보안상 지양해야 하는 행위다)

서버에서 키를 생성하고 등록하는 과정은 다음과 같다.

 # 키를 등록할 서버에 로그인
[haedong@openstack3:~]$ssh-keygen
Generating public/private rsa key pair.
 # 키쌍이 저장될 경로 기본값은 /home/계정명/.ssh/
Enter file in which to save the key (/home/haedong/.ssh/id_rsa):
Enter passphrase (empty for no passphrase): 비워두거나 최소5자 이상의 암호구
Enter same passphrase again: 비워두거나 최소5자 이상의 암호구
Your identification has been saved in /home/haedong/.ssh/id_rsa.
Your public key has been saved in /home/haedong/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:+rZt72JUHSrIuqEeI07ey/5MQm1pYmFxFmBukuegj8s haedong@openstack3
The key's randomart image is:
+---[RSA 2048]----+
|    +.+.         |
|   + +        .  |
|  + *  . .   o . |
| . B o .o . o .  |
|.   = =.S  o     |
| o o +o.  .      |
|. + +.oo .       |
|.= +.*....+      |
|.Eoo*oo.o+.+o    |
+----[SHA256]-----+
[haedong@openstack3:~/.ssh]$ls -lah /home/haedong/.ssh/
합계 12K
drwx------. 2 haedong haedong   57 12월 17 14:33 .
drwx------. 3 haedong haedong   95 12월 16 09:30 ..
-rw-------. 1 haedong haedong 1.8K 12월 17 14:33 id_rsa
-rw-r--r--. 1 haedong haedong  400 12월 17 14:33 id_rsa.pub
-rw-r--r--. 1 haedong haedong  188 12월 16 09:30 known_hosts
[haedong@openstack3:~/.ssh]$ls -lah /home/haedong/
합계 16K
drwx------. 3 haedong haedong  95 12월 16 09:30 .
drwxr-xr-x. 3 root    root     21 12월 14 14:27 ..
-rw-------. 1 haedong haedong  31 12월 16 10:36 .bash_history
-rw-r--r--. 1 haedong haedong  18  4월  1  2020 .bash_logout
-rw-r--r--. 1 haedong haedong 193  4월  1  2020 .bash_profile
-rw-r--r--. 1 haedong haedong 231  4월  1  2020 .bashrc
drwx------. 2 haedong haedong  57 12월 17 14:33 .ssh
# 파일 권한ㅇ르 주목하자.
 # 공개키 등록
 # 다른 곳에서 만든 키를 넣어도 된다.
 # sshd_config 파일에 설정한 파일명과 일치해야 한다.
[haedong@openstack3:~/.ssh] cp ~/.ssh/id_rsa.pub    ~/.ssh/authorized_keys

 # 또는
[haedong@openstack3:~/.ssh] cat ~/.ssh/id_rsa.pub    >>  ~/.ssh/authorized_keys
 # >를 하나만 넣게 되면 authorized_key 파일의 내용을 모두 지운다음 id_rsa.pub의 내용이 들어가게 된다.
 # >>는 읽으려는 파일의 내용을 대상 파일의 맨 끝에 붙여넣는다.
 # .ssh 디렉토리는 700 
 # .ssh 디렉토리 아래 파일들은 600 권한이어야 한다.
 # 당연한 이야기지만 소유자는 해당 키를 사용할 계정이어야 한다.
[haedong@openstack3:~/.ssh]$chmod 600 ~/.ssh/*
[haedong@openstack3:~/.ssh]$ll ~/.ssh/
합계 16
-rw-------. 1 haedong haedong  400 12월 17 14:41 authorized_keys
-rw-------. 1 haedong haedong 1766 12월 17 14:33 id_rsa
-rw-------. 1 haedong haedong  400 12월 17 14:33 id_rsa.pub
-rw-------. 1 haedong haedong  188 12월 16 09:30 known_hosts

id_rsa 파일을 클라이언트에 저장한다.
다운로드 해도 되고, 내용을 복사한뒤 일반 텍스트 파일 형식으로 저장해도 된다.
앞서 설명한 것처럼 ” ssh account@hostname -i id_rsa ” 와 같이 키 파일을 지정해주면 된다.

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,C820352F5512D184F9C6887101DBE9F2

TFynB3AwsiFRoPUxJRg3Y9vv34lOsimQB3yNEyKMP2jvt5XbJFNT6Qw9BAD1xIkl
MfL27ADniRM73OgB+4E6OxzMgDXRE88Gor6CifWUZcASMPPOn55HrontgNE+fv7F
RL1TZ285IX73N/GDifAu9rchc3mIOL2i9D8t/TWUVMNjV+jL+jmSrWI70YlMArPE
I8qVUWc39SFn7NmQYuyo/7LBMNLdSBSMr4WpavM7WbbZAAcRZIYgT51gLWmgGEJv
LrCOcjdzHbSekxIp/8kejKj3ZbJZo6cwGsTKgT9RfLvamU38f21XeBp1bxXazuGF
jiqE9zZ4on69/nNzDRw9BKxuSbiO2rD4hwfSZyH0yJO0TUFaNPr2ejQ8uvbhVIxN
WNQ8+TNX84sm2Mjs8USN8UkAq9uzCLCBeKXJVbmrQAyGvIaU4Y8p9hXjwDgg4oKv
ohiW1VtoqMEigpgpRo2xF6Ft3E6O6yuuh48QauFVNwen2FPGLmRrx2ZkD5htBjjM
mgaZv/E2wP21EmEf6/3tmMOyR4mVxnn1Am4O6zMnOjCtA4OZxv2a2jWBSIZl7/SB
8Zu6yDaHycv0SLKBMtwm3cTXYwpD4StDgX7XBUv0tpyfYh/okT/YRVCx+HP723L+
FLSuwMs9bnvYvLqRbF2GBPJSUQSG1REyoxL//gSqBTdiUSYb2275vAVxYg72Oh28
MgH4tAGhTlk6rxp5ZMflFF0GeMQAoTqjfcs1n+LjFztLZY/L/nZfk6jQEZIbDyEA
IYrZ9zL4XQhsILI0RjCpYei//8rMtf3+w2QiyOFyIcKH0PDRDJegQyFUs5CWiOIX
0j+5ZOMr1igNHbotCR8JhGsPnm2XWx0rs5+nY/Y198Re9waebE7zCKHRjC2jbRnK
mM14mngyIVsaKkKlJz1OMkN1rEnHd6Hu0t52JRTDxI+DWed+ZbUsxpUsmPq9Y68l
jH7R7b5g0emb0sqcyMvjYOEbWD9hk7VBFuKL5CnLGraW4Ag+FcZSGg0DM5nL+Iwr
OHKslt6xFMHVRr7aSJxslw9zGGUb2LG0lBEp+SKLquCFevcv2rQp0Vzprb5UAzum
pVE/TYKXXVjeQA+rQlqefDY43HjJxWA+Oai8dLUNVMt/LuSge5D9mmwK3Nkkj98d
eVDZp1AKBw1vjom1w0LS4J9kKk8FJmUPjb/nb1nbkGYMc+QGQZGvOVYOmfb3bjbI
8M8EUHTs6Sg3WVPEALWZU99yqvemeVx1/A/gf3cqP/kuEYphFN7zRchMV9lXNs7m
pE1DtAYLcAEaLK5MZDgQ6Oo9jCVLlleiYXj3kBCijJ2zK0iXh08PsiggAoaYvlgk
l21oXTS1tPl1Cpe3QaIb98LMdTPZk+Qkbq4N+9YPQbRwBgiDF2ApXJQhSTdKmVES
B9E3mYCf5OqtiYw/V9xOKA7RB/RR2vCGxXAa1pem5ntzqPLYhBLaUZ2CShOOUPFh
/oL1exNCATeOgpSLypx0ZoHqU+TJLI9IhD15HlA6IAcZmyBp+jVMayTNYjvAmWgT
br8tBxaGuTyIVO00auUJQeud84Lq85pS0mGQMM7fORHsk9B4PuZT2zjkIpiGay30
-----END RSA PRIVATE KEY-----

putty 클라이언트를 사용하는 경우

puttygen 을 실행한 다음 아래 절차를 따라 키 포맷을 변경하고 putty에서 로드하면 된다.

CentOS 8 Linux 설치

SuDO : SuperUser DO

CentOS 7 네트워크설정

이전 포스트 CentOS 설치 미디어(ISO) 다운로드 를 참고하여 CentOS 설치 이미지를 다운로드 하고 설치 미디어를 만들어 부팅한다.

정상적으로 설치 미디어로 부팅이 된다면 다음 절차들을 참고하여 설치를 진행한다.
※ 예시는 CentOS8을 기준으로 하였지만 CentOS7도 다르지 않다.

설치가 완료되면 재부팅한다.
root 패스워드를 설정하지 않았으므로 root 계정으로는 로그인할 수 없다.
sudo 명령을 이용해 권한을 바꿔가면서 작업 하는 것을 권장하지만 꼭 root 로 로그인 해야 한다면 아래를 참고하여 password를 변경하면 된다.

login as: haedong
haedong@192.168.103.176's password:
Last login: Wed Dec  9 15:08:34 2020 from 192.168.4.199
[centos7:/home/haedong:]$ sudo -i
[sudo] haedong의 암호:
[centos7:/root:]# passwd root
root 사용자의 비밀 번호 변경 중
새  암호:
새  암호 재입력:
passwd: 모든 인증 토큰이 성공적으로 업데이트 되었습니다.
[centos7:/root:]#

CentOS 설치 미디어(ISO) 다운로드

센트OS(영어: CentOS)는 센트OS 프로젝트에서 레드햇 제휴로 개발한 컴퓨터 운영 체제이다. 업스트림 소스인 레드햇 엔터프라이즈 리눅스와 완벽하게 호환되는 무료 기업용 컴퓨팅 플랫폼을 제공할 목적으로 만들어진 리눅스계 운영 체제 가운데 하나다. 6.4 버전부터 베타 버전은 파워PC에서 사용가능할 것으로 예상되지만, 공식적으로 물리 주소 확장 기능을 가진 x86과 x86-64 아키텍처를 지원한다.

레드햇 엔터프라이즈 리눅스의 소스 코드를 그대로 가져와 빌드해 내놓으며 이 과정에서 이루어지는 변형은 레드햇의 상표가 잘리고 그 자리에 CentOS의 상표가 붙는(상표권 분쟁을 피하기 위해) 정도뿐이다. 판수 또한 레드햇 엔터프라이즈 리눅스의 판수를 그대로 가져오며(소수점 아래 숫자는 업데이트 차수를 가리킨다) 오늘날에는 레드햇 엔터프라이즈 리눅스의 행보를 가장 잘 따라가는 운영 체제라고 알려져 있다. 사용하는 꾸러미 형식은 RPM이다. 1위키백과에서 발췌

즉, RedHat Enterprise Linux 와 같다.

미러 사이트 등을 통해서 iso 파일과, torrent 파일을 이용해 배포하고 있다.

정보와 설치 미디어는 CentOS 홈페이지에서 다운로드 할 수 있다.

또는

 

 

 

SuDo : SuperUser DO

개요

sudo 명령어는 유닉스 및 유닉스 계열 운영 체제에서, 다른 사용자의 보안 권한, 보통 슈퍼유저로서 프로그램을 구동할 수 있도록 하는 프로그램이다. 명칭은 본래 슈퍼유저로서의 실행에 사용되던 것에서 “superuser do”에서 유래하였으나, 후에 프로그램의 기능이 확장되며 “substitute user do”(다른 사용자의 권한으로 실행)의 줄임말로 해석되게 되었다. 기본적으로 Sudo는 사용자 비밀번호를 요구하지만 루트 비밀번호(root password)가 필요할 수도 있고, 한 터미널에 한번만 입력하고 그 다음부터는 비밀번호가 필요 없다. Sudo는 각 명령줄에 사용할 수 있으며 일부 상황에서는 관리자 권한을 위한 슈퍼유저 로그인(superuser login)을 완벽히 대신하며, 주로 우분투, 리눅스와 애플의 OS X 에서 볼 수 있다. 1위키백과에서 발췌

Windows 시스템의 경우 이것과 같다.

이 명령(기능)이 필요한 이유는 이렇게 생각해 볼 수있겠다.
– 시스템 관리자 A가 있다. root 패스워드는 A만 알고 있다.
– DBA B B는 ‘가’서버의 DB만 관리한다. 서비스의 재 시작등이 필요할 때엔 A에게 요청해야 한다.
– A가 휴가를 갔다.
– A가 휴가를 간 사이 DBMS 서비스에 이상이 생겼고 서비스를 재시작해야 하는 상황이 발생했다.
– 서비스 재시작에는 root 권한이 필요하다.
이 때 A가 취할 수 있는 조치는 B에게 root의 패스워드를 알려주는 방법이 있다.
하지만 A는 A가 관리하는 ‘가’,’나’,’다’모든 서버의 패스워드를 동일하게 설정해서 관리 하고 있었다.
B는 A가 관리하는 모든 서버의 패스워드를 획득한 것과 다름이 없다.

이런 상황이 예가 될 수 있겠다.
사실 B는 신뢰할 수 있는 사람이겠지만, 위 상황은 이미 권한 없는 사용자가 모든 권한을 획득한 보안 사고라 할 수 있겠다. 여기서 sudo는 아래와 같이 동작한다.
– 시스템 관리자 A는 ‘가’서버에신뢰할 수 있는 사용자 B를 sudo 명령 허용 목록에 추가하였다.
– A가 휴가를 갔다.
– B는 ‘가’ 서버에서 sudo 명령을 사용한다.
sudo 명령은 B의 패스워드를 묻는다.
B의 패스워드가 정상적으로 입력 되었을 경우 권한을 상승시킨다.

여기서 B가 B로 로그인 해 있는데 B의 패스워드를 왜 확인해? 이게 무슨 소용이야? 하고 질문할 수 있겠지만 B의 계정은 이미 신뢰하는 계정이라 했으니, 작업을 하는 시점에 다시 B가 맞는지 확인 하는 것이다.
즉, B가 로그인 후 자리를 비웠다거나 하는 등 B를 대체 하더라도 B의 패스워드는 B만 알고 있으니 패스워드를 한번 더 입력 받고 B가 맞는지 확인한 뒤 권한을 상승 시킨다는 말이다.

설정

/etc/sudoers 파일에 권한을 부여할 사용자를 넣으면 된다.
※만약 설정파일의 문법을 틀리거나 하면 아런 에러를 만날 수 있다. (sudo가 동작하지 않는다!!!!)

[centos7:/home/haedong:]$ sudo -i
>>> /etc/sudoers: 문법 오류 near line 94 <<<
sudo: /etc/sudoers 94번째 줄에서 해석 오류
sudo: 올바른 sudoers 설정 원본이 없습니다. 나갑니다.
sudo: 정책 플러그인을 초기화할 수 없습니다

사용자 추가

 ## 기본적으로 root는 포함되어있다. root ALL=(ALL) ALL 을 찾아서 아래에 사용자를 추가한다.
 ## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL

 # 여기부터 선택적으로 추가한다.
 # 기본. 
 # haedong 계정으로 sudo 명령 사용 시 패스워드 확인 후 권한을 부여한다. 
 # 모든 명령 사용이 가능하다.
haedong ALL=(ALL)       ALL

 # haedong 계정으로 sudo 명령 사용 시 패스워드 확인 후 권한을 부여한다. /usr/bin/vi,/usr/bin/vim 만 사용 가능하다.
haedong ALL=            /usr/bin/vi,/usr/bin/vim      


 # haedong 계정으로 모든 명령 사용 시 패스워드 확인을 하지 않는다.
haedong ALL=(ALL)       NOPASSWD:   ALL

 # vi, vim 커맨드 사용 시 패스워드 확인을 하지 않고 권한을 상승시킨다.
haedong ALL=NOPASSWD:   /usr/bin/vi,/usr/bin/vim

환경변수 설정
현재 사용자의 환경변수를 sudo 명령 사용 시 승계 하고자 하는경우

 # "" 안에 추가하고자 하는 환경 변수를 추가한다.
Defaults    env_keep += "LD_LIBRARY_PATH"

PATH 변수 설정

 # : 로 구분하여 경로를 추가한다.
Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin

옵션 및 사용법
자세한 옵션은 man 을 참조하자

 # 일반적인 사용 예
[centos7:/home/haedong:]$ sudo vi
[sudo] haedong의 암호:
 # sudo를 이용한 로그인
[centos7:/home/haedong:]$ sudo -i
[sudo] haedong의 암호:
[centos7:/root:]#
[centos7:/root:]# sudo -h
sudo - 다른 사용자 권한으로 명령을 실행합니다

usage: sudo -h | -K | -k | -V
usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command]
usage: sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt] [-u user] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt] [-u user] file ...

옵션:
  -A, --askpass               암호 질문에 보조 프로그램 활용
  -b, --background            백그라운드에서 명령 실행
  -C, --close-from=num        num 보다 크거나 같은 모든 파일 서술자를 닫습니다
  -E, --preserve-env          명령을 실행할 때 사용자 환경을 유지합니다
  -e, --edit                  명령을 실행하는 대신 파일을 편집합니다
  -g, --group=group           지정 그룹 이름 또는 ID로 명령을 실행합니다
  -H, --set-home              대상 사용자의 내 폴더에 HOME 변수를 지정합니다
  -h, --help                  도움말을 보여주고 빠져나갑니다
  -h, --host=host             (플러그인에서 지원한다면)호스트에서 명령을 실행합니다
  -i, --login                 대상 사용자 자격으로 셸에 로그인합니다. 명령도 지정할 수 있습니다.
  -K, --remove-timestamp      타임스탬프 파일을 완전히 제거합니다
  -k, --reset-timestamp       타임스탬프 파일을 초기화합니다
  -l, --list                  사용자 권한을 보여주거나 지정 명령을 확인합니다. 긴 형식으로 보려면 옵션을 두 번 사용하십시오
  -n, --non-interactive       비대화형 모드. 프롬프트를 사용하지 않습니다
  -P, --preserve-groups       대상을 설정하는 대신 그룹 벡터를 유지합니다
  -p, --prompt=prompt         지정 암호 프롬프트를 활용합니다
  -r, --role=role             지정 역할을 지닌 SELinux 보안 컨텍스트를 만듭니다
  -S, --stdin                 표준 입력으로 암호를 입력 받습니다
  -s, --shell                 셸을 대상 사용자 명의로 실행합니다. 명령도 지정합니다.
  -t, --type=type             지정 유형의 SELinux 보안 컨텍스트를 만듭니다
  -U, --other-user=user       목록 모드에서 사용자 권한을 보여줍니다
  -u, --user=user             지정한 사용자 이름 또는 ID로 명령을 실행(또는 파일 편집)
  -V, --version               버전 정보를 보여주고 나갑니다
  -v, --validate              명령을 실행하지 않고 사용자 타임스탬프를 업데이트합니다
  --                          명령행 인자 처리를 멈춥니다

PostgresQL #.2 설정

인터페이스 변경

이전 포스트에서 구동 한 PostgresQL서버는 기본 값 loopbak(127.0.0.1) 인터페이스로 구동 되었다. 외부 연결을 위해서는 서비스 리슨 인터페이스를 변경 해 줘야 한다.
Listen 인터페이스 관련 설정은 postgresql.conf 파일에 정의 돼 있다. 이전 포스트의 내용대로 설치 했을 경우 설정 파일은 /var/lib/pgsql/12/data 아래에 존재한다. 1설치 할 때의 조건에 따라 /etc/postgresql/version 디렉토리 아래에 존재할 수 도 있다.

[postgres@centos7:/home/]$  vi /var/lib/pgsql/12/data/postgresql.conf
 
 # 아래 "listen_addresses"와 "port" 값을 변경해 주면 되는데 주석처리가 돼 있으므로 파일 끝에 새 값을 삽입한다.
      ... 중략...
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
#listen_addresses = 'localhost'         # what IP address(es) to listen on;
                                        # comma-separated list of addresses;
                                        # defaults to 'localhost'; use '*' for all
                                        # (change requires restart)
#port = 5432                            # (change requires restart)
max_connections = 100                   # (change requires restart)
#superuser_reserved_connections = 3     # (change requires restart)
#unix_socket_directories = '/var/run/postgresql, /tmp'  # comma-separated list of directories
                                        # (change requires restart)
#unix_socket_group = ''                 # (change requires restart)
#unix_socket_permissions = 0777         # begin with 0 to use octal notation
                                        # (change requires restart)
#bonjour = off                          # advertise server via Bonjour
                                        # (change requires restart)
#bonjour_name = ''                      # defaults to the computer name
                                        # (change requires restart)

# - TCP settings -
# see "man 7 tcp" for details

#tcp_keepalives_idle = 0                # TCP_KEEPIDLE, in seconds;
                                        # 0 selects the system default
#tcp_keepalives_interval = 0            # TCP_KEEPINTVL, in seconds;
                                        # 0 selects the system default
#tcp_keepalives_count = 0               # TCP_KEEPCNT;
                                        # 0 selects the system default
    ....중략...

 # 여기부터 파일 끝에 삽입한다.
listen_addresses = '0.0.0.0'
 # 인터페이스가 여러개일 경우 0.0.0.0을 입력하면 모든 인터페이스가 연결을 받아들이고
 # 특정 IP를 입력하면 지정한 IP로만 연결이 가능한다.
port = 5432                         

인증 방법 설정

 # 패스워드 인증을을 통한 접속 허용을 위한 설정
[postgres@centos7:/home/]$  vi /var/lib/pgsql/12/data/pg_hba.conf
 # 파일의 끝에 아래를 붙여넣기 한다.

host    all             all             0.0.0.0/0               md5
#호스트를 기준으로 모든 계정을 이용해 모든 IP에서 들어오는 연결에 대해 패스워드 인증을 허용하는 설정이다.
 #인터페이스 관련 설정을 변경할 경우 재기동이 필요하다.
[postgres@centos7:/home/]$  /usr/pgsql-12/bin/pg_ctl -D /var/lib/pgsql/12/data -l /var/lib/pgsql/12/data/pgsql.log stop
[postgres@centos7:/home/]$  /usr/pgsql-12/bin/pg_ctl -D /var/lib/pgsql/12/data -l /var/lib/pgsql/12/data/pgsql.log start

계정 생성

 # 생성하는 계정에 관리자 권한을 부여할 때
[postgres@centos7:/home/]$   /usr/pgsql-12/bin/createuser psqluser --interactive
createuser dataware --interactive
새 롤을 superuser 권한으로 지정할까요? (y/n) y
 # 관리자 권한을 부여하지 않을 때.
[postgres@centos7:/home/]$   /usr/pgsql-12/bin/createuser psqluser --interactive
새 롤을 superuser 권한으로 지정할까요? (y/n) n
이 새 롤에게 데이터베이스를 만들 수 있는 권할을 줄까요? (y/n) y
이 새 롤에게 또 다른 롤을 만들 수 있는 권한을 줄까요? (y/n) y
 # SQL을 이용한 사용자 생성
[postgres@centos7:/home/]$   /usr/pgsql-12/bin/psql
psql (12.4)
도움말을 보려면 "help"를 입력하십시오.

postgres=# CREATE USER datauser WITH ENCRYPTED PASSWORD 'password';
CREATE ROLE
postgres=#

데이터 베이스 생성

[postgres@centos7:/home/]$   /usr/pgsql-12/bin/psql
psql (12.4)
도움말을 보려면 "help"를 입력하십시오.

postgres=# CREATE DATABASE data OWNER data ENCODING 'utf-8';
CREATE ROLE
postgres=#

접속 확인

 # postgres 가 아닌 다른 계정으로 시도해본다. 원격지에서도 가능하다.
root@centos7:/home/]#   psql -U dataware -W -h localhost

다음과 같이 입력을 쉘이 변하면 정상 구동 중인 상태

암호:
psql (12.4)
도움말을 보려면 "help"를 입력하십시오.

postgres=# select * from pg_tables;
     schemaname     |        tablename        | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity
--------------------+-------------------------+------------+------------+------------+----------+-------------+-------------
 pg_catalog         | pg_statistic            | postgres   |            | t          | f        | f           | f
 pg_catalog         | pg_type                 | postgres   |            | t          | f        | f           | f
 pg_catalog         | pg_foreign_server       | postgres   |            | t          | f        | f           | f
 pg_catalog         | pg_authid               | postgres   | pg_global  | t          | f        | f           | f
 pg_catalog         | pg_statistic_ext_data   | postgres   |            | t          | f        | f           | f
 pg_catalog         | pg_user_mapping         | postgres   |            | t          | f        | f           | f
 pg_catalog         | pg_subscription         | postgres   | pg_global  | t          | f        | f           | f
 pg_catalog         | pg_attribute            | postgres   |            | t          | f        | f           | f
 pg_catalog         | pg_proc                 | postgres   |            | t          | f        | f           | f
 pg_catalog         | pg_class                | postgres   |            | t          | f        | f           | f
... 중략...
 information_schema | sql_sizing_profiles     | postgres   |            | f          | f        | f           | f
(70개 행)

PostgresQL #.1 설치 및 구동

개요

PostgreSQL은 확장 가능성 및 표준 준수를 강조하는 객체-관계형 데이터베이스 관리 시스템(ORDBMS)의 하나이다. BSD 허가권으로 배포되며 오픈소스 개발자 및 관련 회사들이 개발에 참여하고 있다. 데이터베이스 서버로서 주요 기능은 데이터를 안전하게 저장하고 다른 응용 소프트웨어로부터의 요청에 응답할 때 데이터를 반환하는 것이이다. 소규모의 단일 머신 애플리케이션에서부터 수많은 동시 접속 사용자가 있는 대형의 인터넷 애플리케이션(또는 데이터 웨어하우스용)에 이르기까지 여러 부하를 관리할 수 있으며 macOS 서버의 경우 PostgreSQL은 기본 데이터베이스이다. 마이크로소프트 윈도우, 리눅스(대부분의 배포판에서 제공됨)용으로도 이용 가능하다. PostgresQL의 전신은 Ingres DB로 실제 프로젝트의 공식 명칭은 “post-Ingres” 데이터베이스이다.

설치

Postgresql 사이트에서 yum 리포지터리 RPM을 다운로드 받을 수 있다.

이렇게 제공된다. 아래 텍스트를 복사-붙여넣기 하여 설치하면 된다.
 # repository RPM 설치
 # 설치하면 postgresql repo 파일이 /etc/yum.repos.d 아래 생성된다.
[root@centos7:/root/]# yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
 # PostgresQL 설치
[root@centos7:/root/]# yum install -y postgresql12-server
 
 # 이렇게 설치 해도 된다.
[root@centos7:/root/]# yum install -y postgresql12-*

초기화
initdb를 이용해 데이터 디렉토리 생성 및 지정이 필요하다.
postgresql 서버를 설치하면 postgres 계정이 자동으로 생성되고 DBMS의 최고 권한은 이 postgres 계정이 가지게 된다. 서버 프로세스의 구동부터 모든 작업이 postgres 계정으로 진행되어야 하므로 디렉토리 생성등을 할 경우 postgres 계정에 모든 권한을 부여해야 한다.

 # DB 초기화 등 작업

 # 초기화 :  /var/lib/pgsql/12/data 가 데이터 디렉토리로 '자동'지정된다.
[postgres@centos7:/home/]$ /usr/pgsql-12/bin/initdb 
이 데이터베이스 시스템에서 만들어지는 파일들은 그 소유주가 "postgres" id로
지정될 것입니다. 또한 이 사용자는 서버 프로세스의 소유주가 됩니다.

데이터베이스 클러스터는 "ko_KR.UTF-8" 로케일으로 초기화될 것입니다.
기본 데이터베이스 인코딩은 "UTF8" 인코딩으로 설정되었습니다.
initdb: "ko_KR.UTF-8" 로케일에 알맞은 전문검색 설정을 찾을 수 없음
기본 텍스트 검색 구성이 "simple"(으)로 설정됩니다.

자료 페이지 체크섬 기능 사용 하지 않음

이미 있는 /var/lib/pgsql/12/data 디렉터리의 액세스 권한을 고치는 중 ...완료
하위 디렉터리 만드는 중 ...완료
사용할 동적 공유 메모리 관리방식을 선택하는 중 ... posix
max_connections 초기값을 선택하는 중 ...100
기본 shared_buffers를 선택하는 중... 128MB
기본 지역 시간대를 선택 중 ... Asia/Seoul
환경설정 파일을 만드는 중 ...완료
부트스트랩 스크립트 실행 중 ... 완료
부트스트랩 다음 초기화 작업 중 ... 완료
자료를 디스크에 동기화 하는 중 ... 완료

initdb: 경고: 로컬 접속용 "trust" 인증을 설정 함
이 값을 바꾸려면, pg_hba.conf 파일을 수정하든지,
다음번 initdb 명령을 사용할 때, -A 옵션 또는 --auth-local,
--auth-host 옵션을 사용해서 인증 방법을 지정할 수 있습니다.

작업완료. 이제 다음 명령을 이용해서 서버를 가동 할 수 있습니다:

    ./pg_ctl -D /var/lib/pgsql/12/data -l 로그파일 start
# 초기화 : -pgdata= 로 지정한 디렉토리가 지정된다. 
 # 이경우 지정한 디렉토리의 소유자는 postgres이어야 하고 모든 권한을 가져야 한다.
[root@centos7:/home/]# mkdir /home/postgres
[root@centos7:/home/]# chown -R postgres /home/postgres
 # 쉘에 주의하자 여기까지는 root 이다.
[postgres@centos7:/home/]$ mkdir /home/postgres/data
[postgres@centos7:/home/]$ /usr/pgsql-12/bin/initdb  --pgdata=/home/postgres/data

/usr/pgsql-12/bin/postgresql-12-setup initdb
systemctl enable postgresql-12
systemctl start postgresql-12

구동
initdb 작업 결과의 명령대로 구동하면 된다.

[postgres@centos7:/home/]$ /usr/pgsql-12/bin//pg_ctl -D /var/lib/pgsql/12/data -l /var/lib/pgsql/12/data/pgsql.log start
서버를 시작하기 위해 기다리는 중.... 완료
서버 시작됨

확인

[root@host0 bin]# netstat -nltp |grep postgres
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      96383/postgres