Cnit09
2023-10-21 13:39:52
Bước 1: Download source
mkdir -p /opt/mongodb && cd /opt/mongodb
wget "https://fastdl.mongodb.org/tools/db/mongodb-database-tools-rhel70-x86_64-100.9.0.tgz"
wget "https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-7.0.2.tgz"
wget "https://downloads.mongodb.com/compass/mongosh-2.0.2-linux-x64.tgz"
Bước 2: giải nén source và copy binary vào path /opt/mongodb/bin/
mkdir -p /opt/mongodb/bin/
cd /opt/mongodb/
tar -xvf mongodb-database-tools-rhel70-x86_64-100.9.0.tgz
tar -xvf mongodb-linux-x86_64-rhel70-7.0.2.tgz
tar -xvf mongosh-2.0.2-linux-x64.tgz
rsync -avr mongodb-database-tools-rhel70-x86_64-100.9.0/bin/* /opt/mongodb/bin/
rsync -avr mongodb-linux-x86_64-rhel70-7.0.2/bin/* /opt/mongodb/bin/
rsync -avr mongosh-2.0.2-linux-x64/bin/* /opt/mongodb/bin/
Bước 3: tạo file config mongodb (/opt/mongodb/mongo_27017.conf)
net:
port: 27017
net:
bindIp: 0.0.0.0
storage:
dbPath: /data/mongodb
systemLog:
destination: file
path: /data/mongodb/mongod.log
logAppend: true
security:
authorization: enabled
port: MongoDB listens cho client connect. Mặc định là 27017.
bindIp: listent trên card netword nào của server. Dùng 0.0.0.0 sẽ listent tất cả trên card network của server.
dbPath: Folder chứa dữ liệu.
systemLog: Folder chứa file log
security: Có 2 option disabled,enabled. Kết nối có user và pass và kết nối ko cần user,pass
Bước 4: Start mongodb
/opt/mongodb/bin/mongod -f /opt/mongodb/mongo_27017.conf --fork
Bước 5: connect mongodb
#connect mongodb khi option security là disabled
/opt/mongodb/bin/mongosh mongodb://localhost:27017
#connect mongodb khi option security là enable
/opt/mongodb/bin/mongosh mongodb://localhost:27017 --username username --authenticationDatabase admin