单节点
服务器IP | 主机角色 |
---|---|
192.168.10.4 | MongoDB Rtandalone |
开始部署
-
下载 mongodb 安装包
- 服务器支持访问互联网
- 服务器不支持访问互联网
wget http://pdpublic.mingdao.com/private-deployment/offline/common/mongodb-linux-x86_64-3.4.24.tgz
# mongodb 安装包文件下载链接,下载完成后上传到部署服务器
http://pdpublic.mingdao.com/private-deployment/offline/common/mongodb-linux-x86_64-3.4.24.tgz -
解压至安装目录
tar -zxvf mongodb-linux-x86_64-3.4.24.tgz
mv mongodb-linux-x86_64-3.4.24 /usr/local/mongodb -
创建 mongodb 用户
useradd -M -s /sbin/nologin mongodb
-
创建数据、日志目录并授予权限
mkdir -p /data/mongodb/ /data/logs/mongodb
chown -R mongodb:mongodb /usr/local/mongodb/ /data/mongodb/ /data/logs -
配置 systemd 管理文件
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
ExecStop=/usr/bin/kill \$MAINPID
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF -
加入开机自启动
# 安装后还没创建用户,所以先不用 systemctl start mongodb 启动服务
systemctl daemon-reload
systemctl enable mongodb
创建数据库用户
在 MongoDB Node01 节点上操作
-
临时启动一个未开启连接认证的 mongodb 服务
su -c '/usr/local/mongodb/bin/mongod --fork --logpath /data/logs/mongodb/mongodb.log --dbpath /data/mongodb --noauth --port 27017' -s /bin/bash mongodb
-
创建用户
/usr/local/mongodb/bin/mongo <<<'use admin
db.createUser({user:"root",pwd:"123456",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"}]})'- 命令中指定的 mongodb admin 库权限 root 用户密码为
123456
,实际部署时注意替换 - 命令中指定的 mongodb 业务库权限 mingdao 用户密码为
123456
,实际部署时注意替换
- 命令中指定的 mongodb admin 库权限 root 用户密码为
-
关闭临时启动的 MongoDB
kill $(pgrep -f 'mongod')
启动 MongoDB
systemctl start mongodb