单实例mongodb 部署

配置文件

mkdir /data/mongopush/{log,data,conf,scripts,tmp}

systemLog:
  destination: file
  logAppend: true
  logRotate: reopen
  path: /data/mongopush/log/mongodb.log

storage:
  dbPath: /data/mongopush/data
  journal:
    enabled: true
  directoryPerDB: true
  syncPeriodSecs: 60
  engine: wiredTiger
  wiredTiger:
    engineConfig:
      cacheSizeGB: 88
      journalCompressor: snappy
      directoryForIndexes: true
    collectionConfig:
      blockCompressor: snappy
    indexConfig:
      prefixCompression: true

operationProfiling:
   slowOpThresholdMs: 50
   mode: "all"

processManagement:
  fork: true
  pidFilePath: /data/mongopush/tmp/mongodb.pid

net:
  port: 27017
  bindIp: 0.0.0.0
  maxIncomingConnections: 18500

security:
  authorization: enabled

#replication:
#  replSetName: picturebook
#  oplogSizeMB: 50240
#  secondaryIndexPrefetch: all

setParameter:
  enableLocalhostAuthBypass: true
  replWriterThreadCount: 32
  wiredTigerConcurrentReadTransactions: 1000
  wiredTigerConcurrentWriteTransactions: 1000

启动脚本

#!/bin/bash
#
# Explain: MongoDB start、stop scripts 
#
# Define variables
RETVAL=0
MonPort="push"
MonConf="/data/mongo${MonPort}/conf/mongodb.conf"
MonCommPath="/usr/local/mongodb-linux-x86_64-3.4.20/bin"

# Define functions
start(){
MonStatusCheck="$(ps -ef |grep [mo]ngo${MonPort}|wc -l)"
if [ "$MonStatusCheck" -eq 0 ];then
           $MonCommPath/mongod -f $MonConf >/dev/null 2>&1
           RETVAL=$?
           if [ $RETVAL -eq 0 ];then
              echo "Start mongodb service[$MonPort] success"
             else
              echo "Start mongodb service[$MonPort] fail"
   fi
          else
           echo "mongodb service[$MonPort] is running"
fi
return $RETVAL
}

stop(){
MonStatusCheck="$(ps -ef |grep [mo]ngo${MonPort}|wc -l)"
if [ "$MonStatusCheck" -ne 0 ];then
           $MonCommPath/mongod --shutdown -f $MonConf  >/dev/null 2>&1
           RETVAL=$?
   if [ $RETVAL -eq 0 ];then
      echo "Stop mongodb service[$MonPort] success"
     else
      echo "Stop mongodb service[$MonPort] fail"
   fi
  else
   echo "mongodb service[$MonPort] is not running"
fi
return $RETVAL
}

status(){
MonStatusCheck="$(ps -ef |grep [mo]ngo${MonPort}|wc -l)"
if [ "$MonStatusCheck" -ne 0 ];then
   echo "mongodb service[$MonPort] is running"
  else
   echo "mongodb service[$MonPort] is not running"
fi
return $RETVAL
}

# case call define functiosn
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
restart)
stop
sleep 5
start
RETVAL=$?
;;
status)
status
RETVAL=$?
;;
*)
echo "USAGE:$0{start|stop|restart|status}"
exit 1
esac

system

[Unit]
Description=MongoDB Database Service
Wants=network.target
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/mongodb-linux-x86_64-3.4.20/bin/mongod -f /data/mongopush/conf/mongodb.conf
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
RestartSec=20

[Install]
WantedBy=multi-user.target
posted @ 2024-01-23 20:26  萱乐庆foreverlove  阅读(5)  评论(0编辑  收藏  举报