mongodb源码安装脚本
#!/bin/bash
#mongodb一键安装
IP=192.168.72.141
DIR=/usr/local
echo "下载mongodb文件包"
##########添加mongodb用户
groupadd mongodb
useradd -r -g mongodb -s /sbin/nologin -M mongodb
#######安装命令
yum install wget -y
##########下载mongodb
echo "-------------------------------"
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.10.tgz -P /tmp/
cd /tmp/
tar -zxvf mongodb-linux-x86_64-4.0.10.tgz -C $DIR/
mv $DIR/mongodb-linux-x86_64-4.0.10/ $DIR/mongodb
mkdir $DIR/mongodb/logs
mkdir $DIR/mongodb/data
mkdir $DIR/mongodb/etc
echo "创建配置文件及日志文件"
echo "-------------------------------"
touch $DIR/mongodb/etc/mongodb.conf
######编写配置文件
cat >> $DIR/mongodb/etc/mongodb.conf << EOF
bind_ip=$IP
port=27017
logpath=$DIR/mongodb/logs/mongodb.log
dbpath=$DIR/mongodb/data/
pidfilepath=$DIR/mongodb/mongodb.pid
fork=true
logappend=true
shardsvr=true
directoryperdb=true
auth=true
replSet=test
EOF
cd $DIR/mongodb/logs/
touch mongodb.log
#######修改目录权限
chown -R mongodb:mongodb $DIR/mongodb
cd $DIR/mongodb/bin/
##########启动mongodb服务
$DIR/mongodb/bin/mongod -f $DIR/mongodb/etc/mongodb.conf
ps aux | grep mongo