shell新人写的mongodb一键装机脚本

MongoDB · ruyi · 于 2年前发布 · 1094 次阅读

脚本文件如下,经测试可用:

[root@zbg02 tmp]# vi mongo.sh

#!/bin/bash
echo "start install mongodb"

find /tmp -name 'mongodb-linux*'|awk -F '/' '{print $3}' >/tmp/version.sh;

mkdir -p  /software/database_software/mongodb_config /software/database_software/mongodb_security /software/installation_package /data/mongodb_data /data/mongodb_log;

for i in `cat /tmp/version.sh` ;do mv /tmp/$i  /software/installation_package/;done

tar zxvf /software/installation_package/$i  -C /software/database_software/;

find /software/database_software/ -name 'mongodb-linux*'|awk -F '/' '{print $4}' >/tmp/varsiondir.sh;

for m in `cat /tmp/varsiondir.sh` ;do mv /software/database_software/$m/ /software/database_software/mongodb;done


echo 'dbpath=/data/mongodb_data   #数据存放目录 '                                    >>       /software/database_software/mongodb_config/mongo.cnf
echo 'logpath=/data/mongodb_log/mongod.log  #日志文件目录'               >>       /software/database_software/mongodb_config/mongo.cnf
echo '#pidfilepath=/home/momgo/mongod.pid  #pid端口文件'                   >>       /software/database_software/mongodb_config/mongo.cnf
echo 'port=10000   #mongodb端口'                                                                >>       /software/database_software/mongodb_config/mongo.cnf
echo 'directoryperdb=true #存储每个db在以dbname命名的文件夹中'                    >>       /software/database_software/mongodb_config/mongo.cnf
echo 'logappend=true   #追加方式写日志文件'                                                                 >>       /software/database_software/mongodb_config/mongo.cnf
echo 'fork=true        #后台运行'                                                                           >>       /software/database_software/mongodb_config/mongo.cnf
echo '#auth=true      #开启认证'                                                                            >>       /software/database_software/mongodb_config/mongo.cnf
echo 'journal=true     #启用日志选项,MongoDB的数据操作将会写入到journal文件夹的文件里'                     >>       /software/database_software/mongodb_config/mongo.cnf
echo 'oplogSize=51200   #同步操作记录文件大小(MB)'                                                          >>       /software/database_software/mongodb_config/mongo.cnf
echo '#keyFile=/software/database_software/mongodb_security/mongodb-keyfile'                                >>       /software/database_software/mongodb_config/mongo.cnf
echo '#storageEngine=wiredTiger'                                                                            >>       /software/database_software/mongodb_config/mongo.cnf
echo '#replSet=hotel'                                                                                       >>       /software/database_software/mongodb_config/mongo.cnf

echo 'export PATH=$PATH:/software/database_software/mongodb/bin'                                            >>        /etc/profile
echo 'numactl --interleave=all /software/database_software/mongodb/bin/mongod --config /software/database_software/mongodb_config/mongo.cnf'     >> /etc/rc.local



source /etc/profile;

echo "success install mongodb"

如果这篇文章对您有帮助,不妨微信小额赞助我一下,让我有动力继续写出高质量的帖子。

共收到 2 条回复 Shell MongoDB 装机脚本
forecho#12年前 0 个赞

昨天刚安装了一回 mongo,你这个跟官网给的安装教程有什么不一样的吗?

ruyi#22年前 0 个赞

@forecho #1楼 基本一样的,只是这个脚本把所有命令写到shell里面了,执行脚本就安装好了。

回复本帖 (需要登录)