【随手记录】mongoDB离线安装脚本

#校验依赖
num=`ldd /home/mongodb/bin/mongod|grep 'not found'|wc -l`
if [ $num -nt 0 ]; then
  echo 'mongo缺少必要依赖,请确认:'
  echo `ldd /home/mongodb/bin/mongod|grep 'not found'`
  exit 1
fi

# 数据存放目录
sudo mkdir -p "/home/mongodb/data/db"
# 日志目录
sudo mkdir -p "/home/mongodb/log/mongodb"
sudo touch -c "/home/mongodb/log/mongodb/mongod.log"
# 文件夹权限
sudo chmod 755 "/home/mongodb/log/mongodb" "/home/mongodb/data/db" 
sudo chmod 755 -R "/home/mongodb/bin"


# 设置配置文件
cat << EOF > /etc/mongodb.conf
storage:
    dbPath: /home/mongodb/data/db
systemLog:
    destination: file
    logAppend: true
    path: /home/mongodb/log/mongodb/mongod.log
net:
    port: 27019
    bindIp: 0.0.0.0
processManagement:
    fork: true
EOF

# 设置运行服务
cat << EOF > /etc/systemd/system/mongod.service
[Unit]
Description=MongoDB Database Service
After=network.target

[Service]
Type=forking
ExecStart=/home/mongodb/bin/mongod --config /etc/mongodb.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/home/mongodb/bin/mongod --shutdown --config /etc/mongodb.conf
Restart=always
LimitNOFILE=64000
LimitNPROC=64000

[Install]
WantedBy=multi-user.target

EOF

sudo systemctl daemon-reload
sudo systemctl enable mongod.service
sudo systemctl restart mongod.service

  

posted @ 2024-10-10 18:50  空知大仙人  阅读(5)  评论(0编辑  收藏  举报