MongoDB Deployment (Single Node)
Start Deployment
-
Download the MongoDB installation package and unzip it to the installation directory
- RedHat / CentOS 7.0 x64
- RedHat / CentOS 8.0 x64
- Debian 10.0+ x64
- Other
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.29.tgz
tar -zxvf mongodb-linux-x86_64-rhel70-4.4.29.tgz
mv mongodb-linux-x86_64-rhel70-4.4.29 /usr/local/mongodbwget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-4.4.29.tgz
tar -zxvf mongodb-linux-x86_64-rhel80-4.4.29.tgz
mv mongodb-linux-x86_64-rhel80-4.4.29 /usr/local/mongodb- If the operating system is above Debian 10, first install the libssl1.1 dependency
wget http://pdpublic.mingdao.com/private-deployment/offline/common/libssl1.1_1.1.1w-0+deb11u1_amd64.deb
dpkg -i libssl1.1_1.1.1w-0+deb11u1_amd64.deb- Download the MongoDB installation package and unzip it to the installation directory
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian10-4.4.29.tgz
tar -zxvf mongodb-linux-x86_64-debian10-4.4.29.tgz
mv mongodb-linux-x86_64-debian10-4.4.29 /usr/local/mongodb-
Installation packages for other operating systems can be downloaded from the MongoDB official download center
-
EulerOS, KylinOS, UOS can usually use the same installation package as RedHat 8.0
-
Create MongoDB user
useradd -M -s /sbin/nologin mongodb
-
Create data and log directories and assign permissions
mkdir -p /data/mongodb/ /data/logs/mongodb
chown -R mongodb:mongodb /usr/local/mongodb/ /data/mongodb/ /data/logs -
Configure the systemd management file
cat > /etc/systemd/system/mongodb.service <<EOF
[Unit]
Description=MongoDB
[Service]
User=mongodb
Group=mongodb
LimitNOFILE=1000000
LimitNPROC=1000000
ExecStart=/usr/local/mongodb/bin/mongod --logpath /data/logs/mongodb/mongodb.log --dbpath /data/mongodb --auth --port 27017 --bind_ip 0.0.0.0
ExecStop=/usr/bin/kill \$MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF -
Auto-start on boot
# After installation, no user has been created yet, so don't use systemctl start mongodb to start the service first
systemctl daemon-reload
systemctl enable mongodb
Create Database User
-
Temporarily start a mongodb service without connection authentication enabled
su -c '/usr/local/mongodb/bin/mongod --fork --logpath /usr/local/mongodb/mongodb.log --dbpath /data/mongodb --noauth --port 27017' -s /bin/bash mongodb
-
Create a user
/usr/local/mongodb/bin/mongo <<<'use admin
db.createUser({user:"root",pwd:"bxfC5J3HuYaY",roles:[{role:"root",db:"admin"}]})'- The root user specified in the command is the administrator of MongoDB, with the password
bxfC5J3HuYaY
. Please replace it with the actual password during deployment.
- The root user specified in the command is the administrator of MongoDB, with the password
-
Shut down the temporarily started MongoDB
kill $(pgrep -f 'mongod')
Start MongoDB
systemctl start mongodb