码迷,mamicode.com
首页 > 数据库 > 详细

MongoDB一键安装

时间:2018-11-02 18:58:44      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:pre   一键安装   openssl   status   刷新   process   UNC   key   exp   

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=admin 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");

db.runCommand("shutdown")
EOF

MongoDB一键安装

标签:pre   一键安装   openssl   status   刷新   process   UNC   key   exp   

原文地址:https://www.cnblogs.com/iyoume2008/p/9897568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!