mongodb安装脚本

#!/bin/bash
bao_dir="/tmp"
bao_name="mongodb-linux-x86_64-rhel70-5.0.0.tgz"
#安装依赖
yum install libcurl openssl xz-libs wget -y
#下包
cd $bao_dir
[ -f $bao_name ] || wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.0.tgz
tar xvf $bao_name -C /opt
mv /opt/mongodb-linux-x86_64-rhel70-5.0.0 /opt/mongodb
#设置环境变量
echo 'export PATH=/opt/mongodb/bin:$PATH' >> /etc/profile
#增加mongodb启动用户
useradd mongod
#创建数据库文件夹,并给mongod权限
mkdir -p /data/mongo
chown -R mongod:mongod /data/mongo
#创建日志目录,并给mongod权限
mkdir -p /var/log/mongodb
chown -R mongod:mongod /var/log/mongodb
#创建进程管理目录,并给mongod权限
mkdir -p /var/run/mongodb
chown -R mongod:mongod /var/run/mongodb

#设置配置文件
echo "
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log
storage:
  dbPath: /data/mongo
  journal:
  enabled: true
processManagement:
  fork: true # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
net:
  port: 27017
  bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
" > /etc/mongod.conf

chown mongod:mongod /etc/mongod.conf

#设置启动脚本

echo '
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual
[Service]
User=mongod
Group=mongod
Environment="OPTIONS=--quiet -f /etc/mongod.conf"
ExecStart=/opt/mongodb/bin/mongod $OPTIONS run
PIDFile=/var/run/mongodb/mongod.pid
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings
[Install]
WantedBy=multi-user.target
' > /usr/lib/systemd/system/mongod.service

chmod 755 /usr/lib/systemd/system/mongod.service
source /etc/profile
systemctl daemon-reload
systemctl start mongod.service

posted @ 2021-07-21 16:13  渣渣中的战斗机  阅读(147)  评论(0)    收藏  举报