#! /bin/bash yum -y update echo -e "开始安装mongodb " 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 echo -e "进入 /usr/local/src目录 " cd /usr/local/src echo -e "删除/usr/local/mongodb " rm -rf /usr/local/mongodb rm -rf /usr/local/src/${file_dir} echo -e "检测是否存在包" if [ ! -f "/usr/local/src/${file_name}" ];then echo -e "下载: "${download_url} wget ${download_url} fi 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 echo -e "启动 " ${binpath}/mongod --bind_ip ${ip} -f ${binpath}/mongodb.conf echo -e "放入/etc/rc.local 开机启动 " echo ${binpath}/mongod --bind_ip ${ip} -f ${binpath}/mongodb.conf >> /etc/rc.local rm -rf /usr/local/bin/mongo echo -e "建立软连接 " ln -s ${binpath}/mongo /usr/local/bin/mongo echo -e "启动命令为: " echo -e ${binpath}/mongod --bind_ip ${ip} -f ${binpath}/mongodb.conf
链接: 去百度网盘下载 提取码: vjrs