linux下安装mongodb脚本

#! /bin/bash

#download url file_name file_dir define
download_url=https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.18.tgz
file_name=${download_url##*/}
file_dir=${file_name%.tgz*}

dbpath=dbpath=/usr/local/mongodb/db
logpath=logpath=/usr/local/mongodb/logs/mongodb.log
fork=fork=true
port=port=27017


cd /usr/local/src

rm -rf /usr/local/mongodb
rm -rf mongo*

wget ${download_url}

tar -zxvf $file_name

mv $file_dir /usr/local/mongodb

cd /usr/local/mongodb

if [ ! -d "/usr/local/mongodb/db" ]; then
  mkdir /usr/local/mongodb/db
fi

if [ ! -d "/usr/local/mongodb/logs" ]; then
  mkdir /usr/local/mongodb/logs
fi

binpath=/usr/local/mongodb/bin
ip=0.0.0.0
rm -rf bin/mongodb.conf
echo $dbpath >> bin/mongodb.conf
echo $logpath >> bin/mongodb.conf
echo $fork >> bin/mongodb.conf
echo $port >> bin/mongodb.conf

bindpath=/usr/local/mongodb/bin

# kill previous mongodb process 
ps -ef|grep mongodb|grep -v grep|cut -c 9-15|xargs kill -9

${binpath}/mongod --bind_ip ${ip} -f ${binpath}/mongodb.conf

echo ${binpath}/mongod --bind_ip ${ip} -f ${binpath}/mongodb.conf >> /etc/rc.local
ln -s ${binpath}/mongo /usr/local/bin/mongo

  

保存文件为install.sh

 

chmod +x install.sh

./install.sh

 

如果wget太慢的也可以自己下载好后放到/usr/local/src下面 注释 下面这两行

rm -rf mongo*  // 防止多次下载不成功,下次下载的重命名为后缀1

wget ${download_url} 

linux下安装mongodb脚本

上一篇:SQL的基础语法


下一篇:Spring JDBC框架操作mysql数据库