줄기세포

[MongoDB] yum을 이용한 설치 (CentOS 7.9) 본문

DB/mongoDB

[MongoDB] yum을 이용한 설치 (CentOS 7.9)

줄기세포(Stem_Cell) 2023. 3. 30. 16:18

두가지 방법

  1. 설치파일(tar.gz) 이용한 설치
  2. yum 설치

나는 yum을 이용한 방법을 선택


환경

  • 클라우드
  • CentOS 7.9.2009
  • Memory: 4G

MongoDB YUM 설치 (참조 블로그)

1. ADD MongoDB Repository

[root@cloud-server ~]# vi /etc/yum.repos.d/mongodb-org-5.0.repo

[mongodb-org-5.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/5.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc

yum repolist로 repogitory 한번 업데이트 시켜준다

[root@cloud-server ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.riken.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
repo id                                                       repo name                                                                                   status
apprepo                                                       apprepo                                                                                          5
base/7/x86_64                                                 CentOS-7 - Base                                                                             10,072
epel/x86_64                                                   Extra Packages for Enterprise Linux 7 - x86_64                                              13,770
extras/7/x86_64                                               CentOS-7 - Extras                                                                              515
mongodb-org-5.0/7                                             MongoDB Repository                                                                             229
updates/7/x86_64                                              CentOS-7 - Updates                                                                           4,857
repolist: 29,448
  • 위 결과는 업데이트 과정을 거치고, 한번 더 yum repolist 명령어 수행하여 깔끔한 화면

2. yum 설치

[root@cloud-server ~]# yum install -y mongodb-org

 

패키지 Dependency 확인

확인

[root@cloud-server ~]# mongo -version
MongoDB shell version v5.0.15
Build Info: {
    "version": "5.0.15",
    "gitVersion": "935639beed3d0c19c2551c93854b831107c0b118",
    "openSSLVersion": "OpenSSL 1.0.1e-fips 11 Feb 2013",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "rhel70",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

[root@cloud-server ~]# which mongo
/usr/bin/mongo

3. Configuration File 수정 (공식문서 참조)

  • /etc/mongod.conf 수정 (yum 설치시 파일 바로 존재)
  • 파일의 포맷은 yaml 형식을 따른다고 한다
  • 참고로 yaml은 들여쓰기는 tab(들여쓰기)를 인식하지 않으니, 꼭 space를 이용하도록..
  • OS 별 Configuration File 경로

systemLog:
  destination: file
  logAppend: true
  path: /mongo/log/mongod.log

storage:
  dbPath: /mongo/data
  journal:
    enabled: true

processManagement:
    fork: true

net:
    bindIP: 127.0.0.1
    port: 27017
setParameter:
   enableLocalhostAuthBypass: false

Data 경로생성

  • Data 파일, Instance, Log 파일 등은 Disk를 분리 권장
  • root Partition 를 사용하지 않는 것을 권장
[root@cloud-server ~]# mkdir /mongo/data
[root@cloud-server ~]# mkdir /mongo/log

Virtr 벌처 클라우드 디스트 파티션 Disk Partition

4. mongo DB Start

실패

  • error: {"t":{"$date":"2023-03-29T17:26:16.791+09:00"},"s":"I", "c":"CONTROL", "id":20712, "ctx":"LogicalSessionCacheReap","msg":"Sessions collection is not set up; waiting until next sessions reap interval","attr":{"error":"NamespaceNotFound: config.system.sessions does not exist"}}
  • 원인은 간단했음: 오너십 문제
[root@cloud-server ~]# systemctl start mongod
[root@cloud-server ~]# systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2023-03-29 17:54:09 KST; 3s ago
     Docs: <https://docs.mongodb.org/manual>
  Process: 1938 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=100)
 Main PID: 1938 (code=exited, status=100)

Mar 29 17:54:09 cloud-server systemd[1]: Started MongoDB Database Server.
Mar 29 17:54:09 cloud-server csystemd[1]: mongod.service: main process exited, code=exited, status=100/n/a
Mar 29 17:54:09 cloud-server systemd[1]: Unit mongod.service entered failed state.
Mar 29 17:54:09 cloud-server systemd[1]: mongod.service failed.

mongod UID와 GID

[root@cloud-server ~]# tail -5 /etc/group
screen:x:84:
slocate:x:21:
dba:x:1024:
saslauth:x:76:
**mongod:x:994:**
[root@cloud-server ~]# tail -5 /etc/group
screen:x:84:
slocate:x:21:
dba:x:1024:
saslauth:x:76:
**mongod:x:994:**

권한 부여

[root@cloud-server ~]# chown -R mongod:mongod /mongo

권한 변경 후 Mongod 재시작

[root@cloud-server ~]# systemctl start mongod
[root@cloud-server ~]# systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (**/usr/lib/systemd/system/mongod.service**; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2023-03-29 17:57:08 KST; 15h ago
     Docs: <https://docs.mongodb.org/manual>
 Main PID: 2223 (mongod)
   CGroup: /system.slice/mongod.service
           └─2223 **/usr/bin/mongod -f /etc/mongod.conf**

Mar 29 17:57:08 cloud-server systemd[1]: Started MongoDB Database Server.

5. 확인

  • 27107 포트로 Listen 중
[root@cloud-server ~]# netstat -napl | grep mongo
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      2223/mongod         
unix  2      [ ACC ]     STREAM     LISTENING     19203    2223/mongod          /tmp/mongodb-27017.sock
unix  3      [ ]         STREAM     CONNECTED     19202    2223/mongod

5. 참고

[root@cloud-server ~]# cat /usr/lib/systemd/system/mongod.service
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target

[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# <https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings>

[Install]
WantedBy=multi-user.target

5. MongoDB 접속

[root@cloud-server ~]# mongo

두가지 방법

  1. 설치파일(tar.gz) 이용한 설치
  2. yum 설치

나는 yum을 이용한 방법을 선택


환경

  • 클라우드
  • CentOS 7.9.2009
  • Memory: 4G

MongoDB YUM 설치 (참조 블로그)

1. ADD MongoDB Repository

[root@cloud-server ~]# vi /etc/yum.repos.d/mongodb-org-5.0.repo

[mongodb-org-5.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/5.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc

yum repolist로 repogitory 한번 업데이트 시켜준다

[root@cloud-server ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.riken.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
repo id                                                       repo name                                                                                   status
apprepo                                                       apprepo                                                                                          5
base/7/x86_64                                                 CentOS-7 - Base                                                                             10,072
epel/x86_64                                                   Extra Packages for Enterprise Linux 7 - x86_64                                              13,770
extras/7/x86_64                                               CentOS-7 - Extras                                                                              515
mongodb-org-5.0/7                                             MongoDB Repository                                                                             229
updates/7/x86_64                                              CentOS-7 - Updates                                                                           4,857
repolist: 29,448
  • 위 결과는 업데이트 과정을 거치고, 한번 더 yum repolist 명령어 수행하여 깔끔한 화면

2. yum 설치

[root@cloud-server ~]# yum install -y mongodb-org

패키지 Dependency 확인

확인

[root@cloud-server ~]# mongo -version
MongoDB shell version v5.0.15
Build Info: {
    "version": "5.0.15",
    "gitVersion": "935639beed3d0c19c2551c93854b831107c0b118",
    "openSSLVersion": "OpenSSL 1.0.1e-fips 11 Feb 2013",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "rhel70",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

[root@cloud-server ~]# which mongo
/usr/bin/mongo

3. Configuration File 수정 (공식문서 참조)

  • /etc/mongod.conf 수정 (yum 설치시 파일 바로 존재)
  • 파일의 포맷은 yaml 형식을 따른다고 한다
  • 참고로 yaml은 들여쓰기는 tab(들여쓰기)를 인식하지 않으니, 꼭 space를 이용하도록..
  • OS 별 Configuration File 경로
systemLog:
  destination: file
  logAppend: true
  path: /mongo/log/mongod.log

storage:
  dbPath: /mongo/data
  journal:
    enabled: true

processManagement:
    fork: true

net:
    bindIP: 127.0.0.1
    port: 27017
setParameter:
   enableLocalhostAuthBypass: false

Data 경로생성

  • Data 파일, Instance, Log 파일 등은 Disk를 분리 권장
  • root Partition 를 사용하지 않는 것을 권장
[root@cloud-server ~]# mkdir /mongo/data
[root@cloud-server ~]# mkdir /mongo/log

Virtr 벌처 클라우드 디스트 파티션 Disk Partition

4. mongo DB Start

실패

  • error: {"t":{"$date":"2023-03-29T17:26:16.791+09:00"},"s":"I", "c":"CONTROL", "id":20712, "ctx":"LogicalSessionCacheReap","msg":"Sessions collection is not set up; waiting until next sessions reap interval","attr":{"error":"NamespaceNotFound: config.system.sessions does not exist"}}
  • 원인은 간단했음: 오너십 문제
[root@cloud-server ~]# systemctl start mongod
[root@cloud-server ~]# systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2023-03-29 17:54:09 KST; 3s ago
     Docs: <https://docs.mongodb.org/manual>
  Process: 1938 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=100)
 Main PID: 1938 (code=exited, status=100)

Mar 29 17:54:09 cloud-server systemd[1]: Started MongoDB Database Server.
Mar 29 17:54:09 cloud-server csystemd[1]: mongod.service: main process exited, code=exited, status=100/n/a
Mar 29 17:54:09 cloud-server systemd[1]: Unit mongod.service entered failed state.
Mar 29 17:54:09 cloud-server systemd[1]: mongod.service failed.

mongod UID와 GID

[root@cloud-server ~]# tail -5 /etc/group
screen:x:84:
slocate:x:21:
dba:x:1024:
saslauth:x:76:
**mongod:x:994:**
[root@cloud-server ~]# tail -5 /etc/group
screen:x:84:
slocate:x:21:
dba:x:1024:
saslauth:x:76:
**mongod:x:994:**

권한 부여

[root@cloud-server ~]# chown -R mongod:mongod /mongo

권한 변경 후 Mongod 재시작

[root@cloud-server ~]# systemctl start mongod
[root@cloud-server ~]# systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (**/usr/lib/systemd/system/mongod.service**; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2023-03-29 17:57:08 KST; 15h ago
     Docs: <https://docs.mongodb.org/manual>
 Main PID: 2223 (mongod)
   CGroup: /system.slice/mongod.service
           └─2223 **/usr/bin/mongod -f /etc/mongod.conf**

Mar 29 17:57:08 cloud-server systemd[1]: Started MongoDB Database Server.

5. 확인

  • 27107 포트로 Listen 중
[root@cloud-server ~]# netstat -napl | grep mongo
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      2223/mongod         
unix  2      [ ACC ]     STREAM     LISTENING     19203    2223/mongod          /tmp/mongodb-27017.sock
unix  3      [ ]         STREAM     CONNECTED     19202    2223/mongod

5. 참고

[root@cloud-server ~]# cat /usr/lib/systemd/system/mongod.service
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target

[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# <https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings>

[Install]
WantedBy=multi-user.target

5. MongoDB 접속

[root@cloud-server ~]# mongo

두가지 방법

  1. 설치파일(tar.gz) 이용한 설치
  2. yum 설치

나는 yum을 이용한 방법을 선택


환경

  • 클라우드
  • CentOS 7.9.2009
  • Memory: 4G

MongoDB YUM 설치 (참조 블로그)

1. ADD MongoDB Repository

[root@cloud-server ~]# vi /etc/yum.repos.d/mongodb-org-5.0.repo

[mongodb-org-5.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/5.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-5.0.asc

yum repolist로 repogitory 한번 업데이트 시켜준다

[root@cloud-server ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.riken.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
repo id                                                       repo name                                                                                   status
apprepo                                                       apprepo                                                                                          5
base/7/x86_64                                                 CentOS-7 - Base                                                                             10,072
epel/x86_64                                                   Extra Packages for Enterprise Linux 7 - x86_64                                              13,770
extras/7/x86_64                                               CentOS-7 - Extras                                                                              515
mongodb-org-5.0/7                                             MongoDB Repository                                                                             229
updates/7/x86_64                                              CentOS-7 - Updates                                                                           4,857
repolist: 29,448
  • 위 결과는 업데이트 과정을 거치고, 한번 더 yum repolist 명령어 수행하여 깔끔한 화면

2. yum 설치

[root@cloud-server ~]# yum install -y mongodb-org

패키지 Dependency 확인

확인

[root@cloud-server ~]# mongo -version
MongoDB shell version v5.0.15
Build Info: {
    "version": "5.0.15",
    "gitVersion": "935639beed3d0c19c2551c93854b831107c0b118",
    "openSSLVersion": "OpenSSL 1.0.1e-fips 11 Feb 2013",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "rhel70",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

[root@cloud-server ~]# which mongo
/usr/bin/mongo

3. Configuration File 수정 (공식문서 참조)

  • /etc/mongod.conf 수정 (yum 설치시 파일 바로 존재)
  • 파일의 포맷은 yaml 형식을 따른다고 한다
  • 참고로 yaml은 들여쓰기는 tab(들여쓰기)를 인식하지 않으니, 꼭 space를 이용하도록..
  • OS 별 Configuration File 경로
systemLog:
  destination: file
  logAppend: true
  path: /mongo/log/mongod.log

storage:
  dbPath: /mongo/data
  journal:
    enabled: true

processManagement:
    fork: true

net:
    bindIP: 127.0.0.1
    port: 27017
setParameter:
   enableLocalhostAuthBypass: false

Data 경로생성

  • Data 파일, Instance, Log 파일 등은 Disk를 분리 권장
  • root Partition 를 사용하지 않는 것을 권장
[root@cloud-server ~]# mkdir /mongo/data
[root@cloud-server ~]# mkdir /mongo/log

Virtr 벌처 클라우드 디스트 파티션 Disk Partition

4. mongo DB Start

실패

  • error: {"t":{"$date":"2023-03-29T17:26:16.791+09:00"},"s":"I", "c":"CONTROL", "id":20712, "ctx":"LogicalSessionCacheReap","msg":"Sessions collection is not set up; waiting until next sessions reap interval","attr":{"error":"NamespaceNotFound: config.system.sessions does not exist"}}
  • 원인은 간단했음: 오너십 문제
[root@cloud-server ~]# systemctl start mongod
[root@cloud-server ~]# systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2023-03-29 17:54:09 KST; 3s ago
     Docs: <https://docs.mongodb.org/manual>
  Process: 1938 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=100)
 Main PID: 1938 (code=exited, status=100)

Mar 29 17:54:09 cloud-server systemd[1]: Started MongoDB Database Server.
Mar 29 17:54:09 cloud-server csystemd[1]: mongod.service: main process exited, code=exited, status=100/n/a
Mar 29 17:54:09 cloud-server systemd[1]: Unit mongod.service entered failed state.
Mar 29 17:54:09 cloud-server systemd[1]: mongod.service failed.

mongod UID와 GID

[root@cloud-server ~]# tail -5 /etc/group
screen:x:84:
slocate:x:21:
dba:x:1024:
saslauth:x:76:
**mongod:x:994:**
[root@cloud-server ~]# tail -5 /etc/group
screen:x:84:
slocate:x:21:
dba:x:1024:
saslauth:x:76:
**mongod:x:994:**

권한 부여

[root@cloud-server ~]# chown -R mongod:mongod /mongo

권한 변경 후 Mongod 재시작

[root@cloud-server ~]# systemctl start mongod
[root@cloud-server ~]# systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (**/usr/lib/systemd/system/mongod.service**; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2023-03-29 17:57:08 KST; 15h ago
     Docs: <https://docs.mongodb.org/manual>
 Main PID: 2223 (mongod)
   CGroup: /system.slice/mongod.service
           └─2223 **/usr/bin/mongod -f /etc/mongod.conf**

Mar 29 17:57:08 cloud-server systemd[1]: Started MongoDB Database Server.

5. 확인

  • 27107 포트로 Listen 중
[root@cloud-server ~]# netstat -napl | grep mongo
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      2223/mongod         
unix  2      [ ACC ]     STREAM     LISTENING     19203    2223/mongod          /tmp/mongodb-27017.sock
unix  3      [ ]         STREAM     CONNECTED     19202    2223/mongod

5. 참고

[root@cloud-server ~]# cat /usr/lib/systemd/system/mongod.service
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network-online.target
Wants=network-online.target

[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# <https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings>

[Install]
WantedBy=multi-user.target

5. MongoDB 접속

[root@cloud-server ~]# mongo

Comments