Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The Shell script deploys MongoDB with one click

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Shell script one-click deployment of MongoDB basic implementation ideas:

Install MongoDB → to create multiple instances (the number of instances created can be customized according to the requirements) → opens all instances and displays ports

#! / bin/bash# Auto install MongoDB## check whether MongoDB has installed local= "/ etc/yum.repos.d/MongoDB.repo" rpm-Q mongodb-org & > / dev/nullif [$?-ne 0]; then# configure local YUM source ls / etc/yum.repos.d/ | grep Mongo & > / dev/nullif [$?-ne 0] Then touch $local echo "[mongodb-org]" > > $local echo "name=mongodb" > > $local echo "baseurl= https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/3.6/x86_64/" > > $local echo" gpgcheck=1 "> > $local echo" enabled=1 "> > $local echo" gpgkey= https://www.mongodb.org/static/pgp/server-3.6.asc" > > $local yum list Yum install mongodb-org-y else echo "configure local YUM source configuration completed" yum list yum install mongodb-org-y fielse echo "MongoDB has been installed ~" fi# repeatedly compares keys (may not succeed once) for ((iTune1) I / dev/nullif [$?-ne 0]; then yum install mongodb-org-y fidone# listens on all network segments sed-I "/ bindIp/s/127.0.0.1/0.0.0.0/" / etc/mongod.confsystemctl start mongod.service# to check whether normal netstat-atnp is enabled | grep 27017 & > / dev/nullif [$?-eq 0] Then echo "MongoDB service starts, instance establishment completes" else echo "startup fails" exit 1fiecho = = "echo" is about to start to create instance "sleep cycle to create multiple instances for ((item2loci > 0interniposit +)) do# determines whether there is if in the data directory and log files [!-e / data/mongodb/mongodb$i] & & [!-e / data/mongodb/mongod$i.log] "then read-p" whether to start creating the $I instance (yzone): "create p = `expr $I-1` case $create in y) # establish the data storage path mkdir-p / data/mongodb/mongodb$i# the log file corresponding to the new multi-instance touch / data/mongodb/mongodb$i.log# log file rights chmod 777 / data/mongodb/mongodb$i.log# replication original Set the file cp-p / etc/mongod.conf / etc/mongod$i.conf# to modify the corresponding data file storage path & log file path sed-I "/ path/s/\ / var\ / log\ / mongodb\ / mongod.log/\ / data\ / mongodb\ / mongodb$i.log/" / etc/mongod$i.conf sed-I "/ dbPath/s/\ / var\ / lib\ / mongo/\ / data\ / mongodb\ / mongodb$i/ "/ etc/mongod$i.conf point= `cat / etc/mongod.conf | grep port | awk'{print $2}'`# change the port number corresponding to the instance sed-I" / port/s/27017/ `expr $point + $P` / "/ etc/mongod$i.conf# launch the corresponding instance mongod-f / etc/mongod$i.conf netstat-atnp | grep $cat & > / dev/ Null if [$?-eq 0] Then echo "$I" instance enabled successfully "else echo" fatal error "exit 1 fi" N) echo "create a total of $p instances (including instance No.1)" # Show the port number of all instances netstat-atnp | grep mongod | awk'{print $4}'| awk-F:'{print $2}'> shili echo "port number is:" cat shili break *) enter "echo", please enter "esacelse echo" $I instance has been created "fidonerm-rf shili"

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report