MongoDB一键安装

#!/bin/bash

export lang=C
echo '#1.关闭本地的MongoDB'
#service mongodb stop
echo '#2.清空本地MongoDB的安装文件'
rm -rf /opt/server/*
rm -rf /opt/var/data/*
#rm -rf /opt/var/log/

echo '#3.创建MongoDB的介质存放目录、安装目录'
mkdir -p /opt/soft/
mkdir -p /opt/server/
mkdir -p /opt/var/data/mongodb/
mkdir -p /opt/var/logs/mongodb/

echo '#4.拷贝安装介质'
mv /softwares/mongodb-linux-x86_64-rhel62-4.0.0.tgz /opt/soft/
cd /opt/soft/
ls
echo '#5.解包该介质'
tar  zxvf mongodb-linux-x86_64-rhel62-4.0.0.tgz
echo '#6.把解包文件移动至安装目录'
mv mongodb-linux-x86_64-rhel62-4.0.0 /opt/server/mongodb

echo '#7.修改并刷新本地的profile文件'
cat <<EOF >/etc/profile   
export PATH=$PATH:/opt/server/mongodb/bin
EOF

source /etc/profile

echo '#8.生成本地的key file文件,授权600'
openssl rand -base64 100 > /opt/var/data/mongodb/mongodb.key
chmod 600 /opt/var/data/mongodb/mongodb.key

echo '#9.修改MongoDB的初始化参数文件'
dd if=/dev/zero of=/opt/server/mongodb/mongodb.conf count=0
cat   <<EOF > /opt/server/mongodb/mongodb.conf
dbpath=/opt/var/data/mongodb
logpath=/opt/var/logs/mongodb/alert_mongodb.log
#pidfilepath=/opt/var/data/mongodb/master.pid
#keyFile=/opt/var/data/mongodb/mongodb.key
directoryperdb=true
logappend=true
#replSet=RS1
bind_ip=0.0.0.0
port=27017
#auth=true
oplogSize=1000
fork=true
noprealloc=true
maxConns=20000
EOF

echo '#10.修改MongoDB的启动脚本,并授于 执行的权限'
cat   <<EOF > /etc/rc.d/init.d/mongodb
#!/bin/sh
# chkconfig: - 64 36
# description:mongod
case \$1 in
start)
/opt/server/mongodb/bin/mongod -f /opt/server/mongodb/mongodb.conf
;;
stop)
/opt/server/mongodb/bin/mongo 127.0.0.1:27017/admin --eval "db.shutdownServer()"
;;
status)
/opt/server/mongodb/bin/mongo 127.0.0.1:27017/admin --eval "db.stats()"
;;
esac
EOF

chmod +x /etc/rc.d/init.d/mongodb

echo '#11.启动MongoDB'
service mongodb start
#about to fork child process, waiting until server is ready for connections.
#forked process: 2556
#child process started successfully, parent exiting
mongo <<EOF
use admin;
db.createUser(
  { user: "root",
    pwd: "root",
    roles: [ { role: "root", db: "admin" } ]
  }
);
db.auth("root","root");
use admin;
db.shutdownServer();
EOF

上一篇:[置顶] 对于最新的Android病毒,Smack完全可以抵御


下一篇:复数 一级ADT实现