#!/bin/bash
###下载二进制包到指定目录下
wget -P /tmp/ https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.4.8.tgz > /dev/null
###解压
cd /tmp
tar xf mongodb-linux-x86_64-rhel70-4.4.8.tgz
###移动目录
mv mongodb-linux-x86_64-rhel70-4.4.8 /usr/local/mongodb
####创建mongod用户,及所需目录,并授权
useradd mongod
mkdir /usr/local/mongodb/conf
mkdir /usr/local/mongodb/log
mkdir /usr/local/mongodb/data
chown mongod:mongod -R /usr/local/mongodb/*
#####修改环境变量
echo "export PATH=/usr/local/mongodb/bin:$PATH" >> /etc/profile
source /etc/profile
#####编写配置文件
cat > /usr/local/mongodb/conf/mongo.conf <<EOF
systemLog:
destination: file
path: "/usr/local/mongodb/log/mongodb.log"
logAppend: true
storage:
journal:
enabled: true
dbPath: "/usr/local/mongodb/data/"
processManagement:
fork: true
net:
port: 27017
bindIp: 127.0.0.1
EOF
#####启动MongoDB
mongod -f /usr/local/mongodb/conf/mongo.conf > /dev/null
####检测是否安装成功
netstat -nplt | grep 27017 > /dev/null
if [[ $? -eq 0 ]]
then
echo -e "\033[32mMongoDB安装成功!\033[0m"
else
echo -e "\033[31mMongoDB安装失败,请检查\033[0m"
fi

Logo

一站式 AI 云服务平台

更多推荐