#!/bin/bash
#############
#Date 2022/8/29
#mail it-arch
#############
echo "##########################################"
echo "Auto Install Mongodb                    ##"
echo "Press Ctrl + C to cancel                ##"
echo "Any key to continue                     ##"
echo "##########################################"
read -n 1
/etc/init.d/iptables status >/dev/null 2>&1
if [ $? -eq 0 ]
then
iptables -I INPUT -p tcp --dport 27017 -j ACCEPT && 
iptables -I INPUT -p tcp --dport 28017 -j ACCEPT &&
iptables-save >/dev/null 2>&1
else
    echo -e "\033[32m iptables is stopd\033[0m"
fi
sed -i "s/SELINUX=enforcing/SELINUX=disabled/"  /etc/selinux/config
setenforce 0
################################
if [ -d /opt ];then
    cd /opt
else
    mkdir -p /opt && cd /opt
fi
yum -y install wget
yum groupinstall "Development tools" -y
wget -c -O /opt/mongodb.tgz https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.9.tgz
tar -zxvf mongodb.tgz
mv mongodb-linux-x86_64-rhel62-3.2.9 mongodb
cd  mongodb
mkdir log && mkdir data
cd log && touch mongodb.log
cd ..
./bin/mongod --httpinterface --dbpath /opt/mongodb/data/ --logpath /opt/mongodb/log/mongodb.log --fork
echo -e "\033[32m Mongodb install success\033[0m"
netstat -lntup | grep mongod 

