#bin/bashdir='/root/'wget_stat=`which  wget|awk -F/ '{print $4}'`mongodb_tar="mongodb-linux-x86_64-rhel62-3.0.6.tgz"mongodb_packet="mongodb-linux-x86_64-rhel62-3.0.6"mongodb_packet_stat=`ls $dir$mongodb_tar`user=`grep mongodb /etc/passwd|awk -F: '{print $1}'`dir2=`ls /root/.script -d`mongodb_size=`ls -l $dir/mongodb-linux-x86_64-rhel62-3.0.6.tgz|awk '{print $5}'`cat <
  /etc/mongodb.conf ### Basic Defaultsbind_ip = 0.0.0.0port = 27017fork = truepidfilepath = /usr/local/mongodb/mongodb.pidlogpath = /usr/local/mongodb/logs/mongodb.logdbpath =/usr/local/mongodb/data/journal = trueauth = truenohttpinterface = truelogappend = trueeof1cat <
 $dir.script/restart_mongodb.shmongodb_pid=`lsof -i:27017|grep mongod|awk  '{print $2 }'`mongo_num=`lsof -i:27017|grep mongod|wc -l`if [[ $mongo_num == 0 ]];then/usr/local/mongodb/bin/mongod -f /etc/mongodb.conf&&lsof -i:27017else/bin/kill  -9 $mongodb_pid && /usr/local/mongodb/bin/mongod -f /etc/mongodb.conf&&lsof -i:27017fieof2if [[ -d $dir2 ]]; then echo "has .script" else mkdir /root/.scriptfiif [[ $user  != mongodb  ]]; then useradd -s /sbin/nologin -M  mongodbfiif [[ $wget_stat != wget ]]; then yum install -y wgetfi##install mongodbif [[ $mongodb_packet_stat != $dir$mongodb_tar ]]; then cd $dir && wget https://fastdl.mongodb.org/linux/$mongodb_tar tar -zxvf $mongodb_tar&&mv $mongodb_packet /usr/local/mongodb&&mkdir /usr/local/mongodb/data && mkdir /usr/local/mongodb/logselif [[ $mongodb_size == 50380166 ]]; then rm -rf $dir$mongodb_packet tar -zxvf $mongodb_tar&&mv $mongodb_packet /usr/local/mongodb&&mkdir /usr/local/mongodb/data && mkdir /usr/local/mongodb/logs else rm -rf $dir/mongodb-linux-x86_64-rhel62-3.0.6.tgz cd $dir && wget https://fastdl.mongodb.org/linux/$mongodb_tar tar -zxvf $mongodb_tar&&mv $mongodb_packet /usr/local/mongodb&&mkdir /usr/local/mongodb/data && mkdir /usr/local/mongodb/logsfi##start mongodbecho "/usr/local/mongodb/bin/mongod -f /etc/mongodb.conf" >>/etc/rc.local/usr/local/mongodb/bin/mongod -f /etc/mongodb.conf&&lsof -i:27017