Replica Set
Server IP | Host Role |
---|---|
192.168.10.4 | MongoDB Replica Set Node01 |
192.168.10.5 | MongoDB Replica Set Node02 |
192.168.10.6 | MongoDB Replica Set Node03 |
Begin Deployment
MongoDB Replica Set Node01
-
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 above Debian 10, first install the libssl1.1 dependency.
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, download the installation package from the MongoDB official download page.
- For trusted operating systems like EulerOS, Kylin, and UOS, CentOS 7.0 installation packages are generally compatible.
-
Create a MongoDB user.
useradd -M -s /sbin/nologin mongodb
-
Create data and log directories and grant permissions.
mkdir -p /data/mongodb/ /data/logs/mongodb
echo '1/3GWm7LjfCX/K2NOhv0evgBWan+KNX' > /data/mongodb/keyfile
chmod 400 /data/mongodb/keyfile
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 --keyFile /data/mongodb/keyfile --port 27017 --replSet local-mongodb-one --bind_ip 0.0.0.0
ExecStop=/usr/bin/kill \$MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF -
Add to startup applications.
# Since the user has not been created yet after installation, do not start the service with systemctl start mongodb
systemctl daemon-reload
systemctl enable mongodb
MongoDB Replica Set Node02
-
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 above Debian 10, first install the libssl1.1 dependency.
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, download the installation package from the MongoDB official download page.
- For trusted operating systems like EulerOS, Kylin, and UOS, CentOS 7.0 installation packages are generally compatible.
-
Create a MongoDB user.
useradd -M -s /sbin/nologin mongodb
-
Create data and log directories and grant permissions.
mkdir -p /data/mongodb/ /data/logs/mongodb
echo '1/3GWm7LjfCX/K2NOhv0evgBWan+KNX' > /data/mongodb/keyfile
chmod 400 /data/mongodb/keyfile
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 --keyFile /data/mongodb/keyfile --port 27017 --replSet local-mongodb-one --bind_ip 0.0.0.0
ExecStop=/usr/bin/kill \$MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF -
Add to startup applications.
# Since the user has not been created yet after installation, do not start the service with systemctl start mongodb
systemctl daemon-reload
systemctl enable mongodb
MongoDB Replica Set Node03
-
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 above Debian 10, first install the libssl1.1 dependency.
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, download the installation package from the MongoDB official download page.
- For trusted operating systems like EulerOS, Kylin, and UOS, CentOS 7.0 installation packages are generally compatible.
-
Create a MongoDB user.
useradd -M -s /sbin/nologin mongodb
-
Create data and log directories and grant permissions.
mkdir -p /data/mongodb/ /data/logs/mongodb
echo '1/3GWm7LjfCX/K2NOhv0evgBWan+KNX' > /data/mongodb/keyfile
chmod 400 /data/mongodb/keyfile
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 --keyFile /data/mongodb/keyfile --port 27017 --replSet local-mongodb-one --bind_ip 0.0.0.0
ExecStop=/usr/bin/kill \$MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF -
Add to startup applications.
# Since the user has not been created yet after installation, do not start the service with systemctl start mongodb
systemctl daemon-reload
systemctl enable mongodb
Create Database Users
Perform this step on MongoDB Replica Set Node01
-
Temporarily start a MongoDB service 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
-
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:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"MDLicense"}]})
use ClientLicense
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"ClientLicense"}]})
use commonbase
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"commonbase"}]})
use MDAlert
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"MDAlert"}]})
use mdapproles
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdapproles"}]})
use mdapprove
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdapprove"}]})
use mdapps
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdapps"}]})
use mdattachment
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdattachment"}]})
use mdcalendar
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdcalendar"}]})
use mdcategory
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdcategory"}]})
use MDChatTop
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"MDChatTop"}]})
use mdcheck
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdcheck"}]})
use mddossier
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mddossier"}]})
use mdemail
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdemail"}]})
use mdform
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdform"}]})
use MDGroup
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"MDGroup"}]})
use mdgroups
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdgroups"}]})
use MDHistory
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"MDHistory"}]})
use mdIdentification
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdIdentification"}]})
use mdinbox
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdinbox"}]})
use mdkc
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdkc"}]})
use mdmap
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdmap"}]})
use mdmobileaddress
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdmobileaddress"}]})
use MDNotification
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"MDNotification"}]})
use mdpost
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdpost"}]})
use mdreportdata
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdreportdata"}]})
use mdroles
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdroles"}]})
use mdsearch
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdsearch"}]})
use mdservicedata
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdservicedata"}]})
use mdsms
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdsms"}]})
use MDSso
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"MDSso"}]})
use mdtag
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdtag"}]})
use mdtransfer
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdtransfer"}]})
use MDUser
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"MDUser"}]})
use mdworkflow
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdworkflow"}]})
use mdworksheet
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdworksheet"}]})
use mdworkweixin
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdworkweixin"}]})
use mdwsrows
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdwsrows"}]})
use pushlog
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"pushlog"}]})
use taskcenter
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"taskcenter"}]})
use mdintegration
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdintegration"}]})
use mdactionlog
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdactionlog"}]})
use mdworksheetlog
db.createUser({user:"mingdao",pwd:"123456",roles:[{role:"readWrite",db:"mdworksheetlog"}]})
use mdworksheetsearch
db.createUser({user: "mingdao",pwd: "123456",roles: [{role: "readWrite",db: "mdworksheetsearch"}]})
use mddatapipeline
db.createUser({user: "mingdao",pwd: "123456",roles: [{role: "readWrite",db: "mddatapipeline"}]})
use mdwfplugin
db.createUser({user: "mingdao",pwd: "123456",roles: [{role: "readWrite",db: "mdwfplugin"}]})
use mdpayment
db.createUser({user: "mingdao",pwd: "123456",roles: [{role: "readWrite",db: "mdpayment"}]})'- The password for the MongoDB admin database user with root privileges specified in the command is
12345678
. Replace it during actual deployment. - The password for the MongoDB business database user with mingdao privileges specified in the command is
123456
. Replace it during actual deployment.
- The password for the MongoDB admin database user with root privileges specified in the command is
-
Shut down the temporarily started MongoDB.
kill $(pgrep -f 'mongod')
Start MongoDB
Perform this step on all three servers with MongoDB installed.
systemctl start mongodb
Configure the Replica Set
Perform this step on MongoDB Replica Set Node01
-
Log in to MongoDB.
/usr/local/mongodb/bin/mongo -u root -p 12345678 --authenticationDatabase admin
-
Configure the replica set.
rs.initiate({_id: "local-mongodb-one",members:[ {_id : 1, host : "192.168.10.4:27017"},{_id : 2, host : "192.168.10.5:27017"},{_id : 3, host : "192.168.10.6:27017"} ]})
- Replace the IPs of each node specified in the rs.initiate statement during actual deployment.
-
Confirm the replica set status.
rs.status()
# The output should show one PRIMARY node and two SECONDARY nodes.