InstallMongoDB_7.sh
#!/bin/bash MongoDB_Package=mongodb-linux-x86_64-enterprise-rhel70-3.4.20.tgz PrepareENV() { userdel -r mongod groupadd mongod useradd -g mongod mongod yum install -y net-snmp } InstallMongoDB() { mkdir unpackdir tar -zxvf ${MongoDB_Package} -C unpackdir mongodb_unpackname=$(ls unpackdir|grep -i mongodb) cd unpackdir/ mv ${mongodb_unpackname} /usr/local/mongodb chown -R mongod:mongod /usr/local/mongodb } InitMongoDB() { mkdir -p /app/mongodb/{27017/{db,log},backup,scripts} # Init config file echo -e ' fork=true port=27017 quiet=true dbpath=/app/mongodb/27017/db logpath=/app/mongodb/27017/log/mongodb.log logappend=true journal=true directoryperdb=true wiredTigerDirectoryForIndexes=true maxConns=65535 profile=1 slowms=500 replSet=myrepl #指定副本集 oplogSize=40960 storageEngine=wiredTiger wiredTigerCacheSizeGB=1 wiredTigerCollectionBlockCompressor=snappy #shardsvr=true #配置节点角色(>=3.4 shard节点专用) #configsvr=true #指定config节点角色(>=3.4 config节点专用) #configdb=MSCHOST #指定config #keyFile=/app/mongodb/27017/keyFile setParameter=enableLocalhostAuthBypass=1 '> /app/mongodb/27017/mongodb.config if test -f /sys/kernel/mm/transparent_hugepage/enabled; then echo never > /sys/kernel/mm/transparent_hugepage/enabled fi if test -f /sys/kernel/mm/transparent_hugepage/defrag; then echo never > /sys/kernel/mm/transparent_hugepage/defrag fi openssl rand -base64 745 >/app/mongodb/27017/keyFile chmod 600 /app/mongodb/27017/keyFile echo ' /usr/local/mongodb/bin/mongod -f /app/mongodb/27017/mongodb.config /usr/local/mongodb/bin/mongod -f /app/mongodb/27017/mongodb.config --shutdown ' } PrepareENV InstallMongoDB InitMongoDB
InstallMongoDB_multi.sh
#!/bin/bash InitMongoDB() { mkdir -p /app/mongodb/{27018/{db,log},backup,scripts} mkdir -p /app/mongodb/{27019/{db,log},backup,scripts} mkdir -p /app/mongodb/{27020/{db,log},backup,scripts} # Init config file echo -e ' dbpath=/app/mongodb/27018/db logpath=/app/mongodb/27018/log/mongodb.log fork=true logappend=true port=27018 '> /app/mongodb/27018/mongodb.config echo -e ' dbpath=/app/mongodb/27019/db logpath=/app/mongodb/27019/log/mongodb.log fork=true logappend=true port=27019 '> /app/mongodb/27019/mongodb.config echo -e ' dbpath=/app/mongodb/27020/db logpath=/app/mongodb/27020/log/mongodb.log fork=true logappend=true port=27020 '> /app/mongodb/27020/mongodb.config if test -f /sys/kernel/mm/transparent_hugepage/enabled; then echo never > /sys/kernel/mm/transparent_hugepage/enabled fi if test -f /sys/kernel/mm/transparent_hugepage/defrag; then echo never > /sys/kernel/mm/transparent_hugepage/defrag fi echo ' /usr/local/mongodb/bin/mongod -f /app/mongodb/27018/mongodb.config /usr/local/mongodb/bin/mongod -f /app/mongodb/27018/mongodb.config --shutdown /usr/local/mongodb/bin/mongod -f /app/mongodb/27019/mongodb.config /usr/local/mongodb/bin/mongod -f /app/mongodb/27019/mongodb.config --shutdown /usr/local/mongodb/bin/mongod -f /app/mongodb/27020/mongodb.config /usr/local/mongodb/bin/mongod -f /app/mongodb/27020/mongodb.config --shutdown ' } InitMongoDB