Single Node
| Server IP | Host Role |
|---|---|
| 192.168.10.4 | MongoDB Standalone |
Start Deployment
-
Download the MongoDB installation package and extract it to the installation directory
- RedHat / CentOS 7.0 x64
- RedHat / CentOS 8.0 x64
- Debian 10.0+ x64
- Others
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.31.tgztar -zxvf mongodb-linux-x86_64-rhel70-4.4.31.tgzmv mongodb-linux-x86_64-rhel70-4.4.31 /usr/local/mongodbwget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel80-4.4.31.tgztar -zxvf mongodb-linux-x86_64-rhel80-4.4.31.tgzmv mongodb-linux-x86_64-rhel80-4.4.31 /usr/local/mongodb- If the operating system is higher than Debian 10, install the libssl1.1 dependency first
wget https://pdpublic.mingdao.com/private-deployment/offline/common/libssl1.1_1.1.1w-0+deb11u1_amd64.debdpkg -i libssl1.1_1.1.1w-0+deb11u1_amd64.deb- Download the MongoDB installation package and extract it to the installation directory
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian10-4.4.31.tgztar -zxvf mongodb-linux-x86_64-debian10-4.4.31.tgzmv mongodb-linux-x86_64-debian10-4.4.31 /usr/local/mongodb-
Official Download: For packages targeting other operating systems, visit the MongoDB Community Edition Download Center.
-
Domestic System Compatibility: For systems like EulerOS, Kylin, and UOS, the corresponding CentOS 7/8 packages are generally compatible.
-
Example (Kylin V10): If using the Kylin V10 ARM version, you can download the CentOS 8 ARM 64 architecture package:
-
Create the MongoDB user
useradd -M -s /sbin/nologin mongodb -
Create data and log directories and grant permissions
mkdir -p /data/mongodb/ /data/logs/mongodbchown -R mongodb:mongodb /usr/local/mongodb/ /data/mongodb/ /data/logs/mongodb -
Disable Transparent Huge Pages (THP)
MongoDB may experience performance degradation and memory fragmentation when THP is enabled. It is recommended to disable it via a systemd service before starting MongoDB.
cat > /etc/systemd/system/disable-thp.service <<\EOF[Unit]Description=Disable Transparent Huge Pages (THP)DefaultDependencies=noAfter=sysinit.target local-fs.targetBefore=mongodb.service[Service]Type=oneshotExecStart=/bin/sh -c 'echo never > /sys/kernel/mm/transparent_hugepage/enabled'ExecStart=/bin/sh -c 'echo never > /sys/kernel/mm/transparent_hugepage/defrag'[Install]WantedBy=basic.targetEOFsystemctl daemon-reloadsystemctl enable disable-thpsystemctl start disable-thp -
Configure the systemd management file
cat > /etc/systemd/system/mongodb.service <<'EOF'[Unit]Description=MongoDBAfter=network-online.targetWants=network-online.target[Service]User=mongodbGroup=mongodbLimitNOFILE=1000000LimitNPROC=1000000LimitMEMLOCK=infinityExecStart=/usr/local/mongodb/bin/mongod --logpath /data/logs/mongodb/mongodb.log --dbpath /data/mongodb --auth --port 27017 --bind_ip 0.0.0.0ExecStop=/usr/bin/kill $MAINPIDRestart=on-failureRestartSec=5TimeoutStopSec=300[Install]WantedBy=multi-user.targetEOF -
Add to startup
# Do not start the service with systemctl start mongodb until the user has been createdsystemctl daemon-reloadsystemctl enable mongodb
Create Database Users
-
Temporarily start MongoDB without authentication
su -c '/usr/local/mongodb/bin/mongod --fork --logpath /data/logs/mongodb/mongodb.log --dbpath /data/mongodb --noauth --port 27017' -s /bin/bash mongodb -
Log in to MongoDB
Run in the system terminal:
/usr/local/mongodb/bin/mongo --host 127.0.0.1 --port 27017Run the following user creation statements in mongo.
-
Create the administrator user
db.getSiblingDB("admin").createUser({user: "root",pwd: "12345678",roles: [{role: "root", db: "admin"}]});- The example password for the root user in the MongoDB admin database is
12345678. Replace it with a strong password for your deployment.
- The example password for the root user in the MongoDB admin database is
-
Create business database users
var businessUser = "hap";var businessPassword = "123456";var databases = ["MDLicense","ClientLicense","commonbase","MDAlert","mdapproles","mdapprove","mdapps","mdattachment","mdcalendar","mdcategory","MDChatTop","mdcheck","mddossier","mdemail","mdform","MDGroup","mdgroups","MDHistory","mdIdentification","mdinbox","mdkc","mdmap","mdmobileaddress","MDNotification","mdpost","mdreportdata","mdroles","mdsearch","mdservicedata","mdsms","MDSso","mdtag","mdtransfer","MDUser","mdworkflow","mdworksheet","mdworkweixin","mdwsrows","pushlog","taskcenter","mdintegration","mdactionlog","mdworksheetlog","mdworksheetsearch","mddatapipeline","mdwfplugin","mdpayment","mdwfai","mdopenauth","mdaisearch","MDAgentInfra"];for (var i = 0; i < databases.length; i++) {var database = databases[i];db.getSiblingDB(database).createUser({user: businessUser,pwd: businessPassword,roles: [{role: "readWrite", db: database}]});}- The example password for the hap users in the MongoDB business databases is
123456. Replace it with a strong password for your deployment. - If the password contains special characters, use only
-or_. Do not use characters such as@ ! # &to avoid compatibility issues.
- The example password for the hap users in the MongoDB business databases is
-
Exit mongo
exit(); -
Stop the temporary MongoDB instance
Return to the system terminal and run:
kill $(pgrep -f 'mongod')
Start MongoDB
systemctl start mongodb
Verify Service Status
-
Check MongoDB status
systemctl status mongodb -
Test admin connection
Use the following command to test the connection of the admin account
/usr/local/mongodb/bin/mongo -u root -p 12345678 --authenticationDatabase admin -
Test business database connection
Use the following command to test the connection of a single business database user
/usr/local/mongodb/bin/mongo -u hap -p 123456 --authenticationDatabase mdwsrows