[컴] mongodb 를 tgz 를 이용해서 설치

 mongdb 설치하기 / tgz 로 설치하는 법

mongodb 를 tgz 를 이용해서 설치

절차

  1. tarball download
  2. untar
  3. /usr/local/bin 에 link 만들기
  4. mongodb shell 설치

Dockerfile

# Dockerfile
FROM centos:centos8
LABEL maintainer="coosal@duck.com"

RUN groupadd mongod
RUN useradd -g mongod mongod

RUN groupadd mydeploy
RUN useradd -g mydeploy mydeploy

# ----------------------------
# mongod
# ----------------------------
# --------------------
# .tar download
# --------------------
WORKDIR /home/mydeploy/
USER mydeploy
RUN mkdir apps

WORKDIR /home/mydeploy/apps
RUN curl https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-5.0.6.tgz --output mongodb-linux-x86_64-rhel80-5.0.6.tgz
RUN tar -zxvf mongodb-linux-x86_64-rhel80-5.0.6.tgz
RUN mv mongodb-linux-x86_64-rhel80-5.0.6 mongodb-5.0.6
# --------------------
# data, log dir
# --------------------
RUN mkdir -p mongodb-5.0.6/data
RUN mkdir -p mongodb-5.0.6/log

USER root
RUN chmod o+rx /home/mydeploy
RUN chown -R mongod:mongod mongodb-5.0.6/data
RUN chown -R mongod:mongod mongodb-5.0.6/log
# --------------------
# /usr/local/bin path
# --------------------
RUN ln -s /home/mydeploy/apps/mongodb-5.0.6/bin/* /usr/local/bin/
# --------------------
# .conf
# --------------------
COPY --chown=mydeploy:mydeploy mongod.conf ./mongodb-5.0.6

# ----------------------------
# mongosh
# ----------------------------
# --------------------
# .tar download
# --------------------
WORKDIR /home/mydeploy/apps
USER mydeploy
RUN curl https://downloads.mongodb.com/compass/mongosh-1.1.9-linux-x64.tgz --output mongosh-1.1.9-linux-x64.tgz
RUN tar -zxvf mongosh-1.1.9-linux-x64.tgz
RUN mv mongosh-1.1.9-linux-x64 mongosh-1.1.9
# --------------------
# /usr/local/bin path
# --------------------
USER root
RUN ln -s $(pwd)/mongosh-1.1.9/bin/* /usr/local/bin/
# --------------------
# root 암호 설정
# --------------------
RUN echo 'root:mypassword' | chpasswd

USER mongod
ENTRYPOINT [ "/usr/local/bin/mongod", "-f", "/home/mydeploy/apps/mongodb-5.0.6/mongod.conf"].conf ./mongodb-5.0.6

# mongod.conf

# Where and how to store data.
storage:
  dbPath: /home/mydeploy/apps/mongodb-5.0.6/data
  journal:
    enabled: true

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  logRotate: reopen # 이렇게 하면 mongod 를 새로실행할 때마다 rotate 해준다. ref.3 을 보자.
  path: /home/mydeploy/apps/mongodb-5.0.6/log/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

replication:
   replSetName: "rs0"

기타

혹시 root 등을 이용해서 test 를 하게 되면, dbPath/ 내에 file 들과 /tmp/*.lock file 의 owner 가 root 이 된다. 이렇게 되면 다른 일반 계정으로 실행하게 될 때 error 가 발생한다.

See Also

  1. MongoDB Log Rotation Automation | dasbotask.com : 주기적으로 log 를 rotate 하는 법
  2. 쿠…sal: [컴][db] mongodb 를 production 에서 배포시 확인할 사항
  3. 쿠…sal: [컴][DB] Windows7 64 bit 에서 MongoDB 설치하기
  4. 쿠…sal: [컴] wsl2 에서 mongodb 접근

Reference

  1. Install MongoDB Community on Red Hat or CentOS using .tgz Tarball — MongoDB Manual
  2. Install mongosh — MongoDB Shell
  3. Rotate Log Files — MongoDB Manual

댓글 없음:

댓글 쓰기