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.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 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.deb
dpkg -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.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- For other operating systems, installation packages can be selected and downloaded from the MongoDB official download page.
- Operating systems like EulerOS, Kylin, and UOS generally can use the same installation package as CentOS 7.0.
-
Create the MongoDB user
useradd -M -s /sbin/nologin mongodb -
Create data and log directories and grant permissions
mkdir -p /data/mongodb/ /data/logs/mongodb
chown -R mongodb:mongodb /usr/local/mongodb/ /data/mongodb/ /data/logs/mongodb -
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 -
Add to startup
# Do not start the service with systemctl start mongodb until the user has been created
systemctl daemon-reload
systemctl enable mongodb
Create Database Users
-
Temporarily start a MongoDB service without authentication enabled
su -c '/usr/local/mongodb/bin/mongod --fork --logpath /data/logs/mongodb/mongodb.log --dbpath /data/mongodb --noauth --port 27017' -s /bin/bash mongodb -
Create users
/usr/local/mongodb/bin/mongo <<<'use admin
db.createUser({user:"root",pwd:"12345678",roles:[{role:"root",db:"admin"}]})
use MDLicense
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"MDLicense"}]})
use ClientLicense
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"ClientLicense"}]})
use commonbase
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"commonbase"}]})
use MDAlert
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"MDAlert"}]})
use mdapproles
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdapproles"}]})
use mdapprove
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdapprove"}]})
use mdapps
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdapps"}]})
use mdattachment
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdattachment"}]})
use mdcalendar
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdcalendar"}]})
use mdcategory
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdcategory"}]})
use MDChatTop
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"MDChatTop"}]})
use mdcheck
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdcheck"}]})
use mddossier
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mddossier"}]})
use mdemail
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdemail"}]})
use mdform
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdform"}]})
use MDGroup
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"MDGroup"}]})
use mdgroups
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdgroups"}]})
use MDHistory
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"MDHistory"}]})
use mdIdentification
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdIdentification"}]})
use mdinbox
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdinbox"}]})
use mdkc
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdkc"}]})
use mdmap
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdmap"}]})
use mdmobileaddress
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdmobileaddress"}]})
use MDNotification
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"MDNotification"}]})
use mdpost
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdpost"}]})
use mdreportdata
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdreportdata"}]})
use mdroles
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdroles"}]})
use mdsearch
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdsearch"}]})
use mdservicedata
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdservicedata"}]})
use mdsms
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdsms"}]})
use MDSso
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"MDSso"}]})
use mdtag
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdtag"}]})
use mdtransfer
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdtransfer"}]})
use MDUser
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"MDUser"}]})
use mdworkflow
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdworkflow"}]})
use mdworksheet
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdworksheet"}]})
use mdworkweixin
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdworkweixin"}]})
use mdwsrows
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdwsrows"}]})
use pushlog
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"pushlog"}]})
use taskcenter
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"taskcenter"}]})
use mdintegration
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdintegration"}]})
use mdactionlog
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdactionlog"}]})
use mdworksheetlog
db.createUser({user:"hap",pwd:"123456",roles:[{role:"readWrite",db:"mdworksheetlog"}]})
use mdworksheetsearch
db.createUser({user: "hap",pwd: "123456",roles: [{role: "readWrite",db: "mdworksheetsearch"}]})
use mddatapipeline
db.createUser({user: "hap",pwd: "123456",roles: [{role: "readWrite",db: "mddatapipeline"}]})
use mdwfplugin
db.createUser({user: "hap",pwd: "123456",roles: [{role: "readWrite",db: "mdwfplugin"}]})
use mdpayment
db.createUser({user: "hap",pwd: "123456",roles: [{role: "readWrite",db: "mdpayment"}]})'- The password for the MongoDB admin database root user specified in the command is
12345678, but it must be changed to a strong password in actual deployment. - The password for the MongoDB business database user hap specified in the command is
123456, but it must be changed to a strong password in actual deployment. - If the password contains special characters, only
-or_are allowed. Characters like@ ! # &are forbidden to avoid compatibility issues.
- The password for the MongoDB admin database root user specified in the command is
-
Shut down the temporarily started MongoDB
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