MongoDB replica set shard (i)---initialize MongoDB installation start

Source: Internet
Author: User
Tags eval install mongodb

Written in front: MongoDB is a nosql non-relational database, a more popular product. In the data persistence and the association with the relational database is also done better, at present, the major companies in the storage of binary files (pictures, video, etc.) are widely used. It is also relatively simple to follow the Key-value data schema and object-oriented JSON statement usage. After that, I will share with you some of the experiences I have used in the learning and production applications of MongoDB. We hope that we will study together and explore together. Thank you.

The following is a simple shell scripted edit of the entire MongoDB installation process. Very simple script writing. If you have any questions, please feel free to contact me with feedback. In the process of use, you can paste the entire content into a text script similar to mongodbinit.sh. chmod Modify Permissions +x. Then execute.

Note: Replset is the name of the replica set, and you can freely edit the settings, using Replset=picture in this example. When you use Db.shutdownserver () to close the DB, only local connections are accepted.

# # #install MongoDB bags###
Yum install-y Openssl-devel OpenSSL
cd/opt/
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.0.2.tgz
Tar zxvf/opt/mongodb-linux-x86_64-rhel62-3.0.2.tgz-c/usr/local/
Ln-s/usr/local/mongodb-linux-x86_64-rhel62-3.0.2/usr/local/mongodb-3.0.2

# # #configure Limit parameters###
Cat >>/etc/security/limits.conf << EOF
* Soft Nofile 655350
* Hard Nofile 655350
* Soft Nproc 65535
* Hard Nproc 65535
* Soft Core Unlimited
* Hard Core Unlimited
* Soft Memlock 50000000
* Hard Memlock 50000000
Eof

# # #prepare The menu for data or logs###
Mkdir-pv/usr/local/mongodb-3.0.2/{data,logs,socket}
Mkdir-pv/var/run/mongodb

# # #edit MongoDB config file###
Parastr= (
"Dbpath=/usr/local/mongodb-3.0.2/data"
"Logpath=/usr/local/mongodb-3.0.2/logs/mongo.log"
"Pidfilepath=/var/run/mongodb/mongodb.pid"
"Unixsocketprefix=/usr/local/mongodb-3.0.2/socket"
"Directoryperdb=true"
"Replset=picture"
"Shardsvr=true"
"Logappend=true"
"bind_ip=0.0.0.0"
"Port = 27017"
"maxconns=20000"
"Oplogsize=30720"
"Fork=true"
"Nohttpinterface=true"
"Nojournal=true"
)

if [!-f/etc/mongodb.conf]; Then
size=${#parastr [@]};
For ((i=0;i< $size; i++))
Do
Eval tmp=\${parastr[i][@]}
echo $tmp >>/etc/mongodb.conf
Done
Fi

###/usr/local/mongodb-3.0.2/bin/mongod--config/etc/mongodb.conf

Cat >>/etc/init.d/mongo << EOF
Ulimit-shn 655350
#!/bin/sh
# Chkconfig:-64 36
# Description:mongod

Case $ in
Start
/usr/local/mongodb-3.0.2/bin/mongod--config/etc/mongodb.conf
;;

Stop
/usr/local/mongodb-3.0.2/bin/mongo 127.0.0.1:27017/admin--eval "Db.shutdownserver ()"
#/usr/local/mongodb-3.0.2/bin/mongo 127.0.0.1:27017/admin--eval "Db.auth (' System ', ' 123456 ');d b.shutdownserver ()"
;;

Status
/usr/local/mongodb-3.0.2/bin/mongo 127.0.0.1:27017/admin--eval "db.stats ()"
#/usr/local/mongodb-3.0.2/bin/mongo 127.0.0.1:27017/admin--eval "Db.auth (' System ', ' 123456 ');d b.stats ()"
;;
Esac
Eof

chmod +x/etc/init.d/mongo

/etc/init.d/mongo start

MongoDB replica set shard (i)---initialize MongoDB installation start

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.