Environment: centos6.5 192.168.16.70
Configure Single Instance MongoDB:
[email protected] soft]# tar XF mongodb-linux-x86_64-rhel62-3.2.7.tgz
[[email protected] soft]# ls
mongodb-linux-x86_64-rhel62-3.2.7
mongodb-linux-x86_64-rhel62-3.2.7.tgz
[email protected] soft]# MV Mongodb-linux-x86_64-rhel62-3.2.7/usr/local/mongodb
[email protected] soft]# cd/usr/local/mongodb/
[[email protected] mongodb]# ls
bin gnu-agpl-3.0 MPL-2 README third-party-notices
[email protected] mongodb]# ulimit-n
1024x768
[[email protected] mongodb]# ulimit-n 25000//Specify the maximum number of files that can be opened at the same time
[email protected] mongodb]# ulimit-u
3648
[[email protected] mongodb]# Ulimit-u 25000//number of programs the user can open up
[email protected] mongodb]# ulimit-n
25000
[email protected] mongodb]# ulimit-u
25000
[email protected] mongodb]# mkdir-p/data/mongodb1
[email protected] mongodb]# mkdir-p/data/logs/mongodb
[email protected] mongodb]# Touch/data/logs/mongodb/mongodb1.log
[email protected] mongodb]# cd/usr/local/mongodb/
[[email protected] mongodb]# ls
bin gnu-agpl-3.0 MPL-2 README third-party-notices
[email protected] mongodb]# mkdir conf
[email protected] mongodb]# vim conf/mongodb1.conf
port=27017
DBPATH=/DATA/MONGODB1
Logpath=/data/logs/mongodb/mongodb1.log
logappend=true
fork=true
maxconns=5000
Storageengine=mmapv1
[email protected] mongodb]# pwd
/usr/local/mongodb
[[email protected] mongodb]# ls
bin conf gnu-agpl-3.0 MPL-2 README third-party-notices
[[email protected] mongodb]# bin/mongod-f/usr/local/mongodb/conf/mongodb1.conf//start MongoDB database-F Specify configuration file
About -to-fork child process, waiting until server was ready for connections.
forked process:1652
Child Process started successfully, parent exiting
[email protected] mongodb]# Ps-ef | grep mongod
Root 1652 1 2 04:53? 00:00:00 bin/mongod-f/usr/local/mongodb/conf/mongodb1.conf
Root 1666 1607 0 04:53 pts/0 00:00:00 grep mongod
[email protected] mongodb]# NETSTAT-LNPT | grep 27017
TCP 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 1652/bin/mongod
[email protected] mongodb]# lsof-i:27017
COMMAND PID USER FD TYPE DEVICE size/off NODE NAME
mongod 1652 Root 6u IPv4 12709 0t0 TCP *:27017 (LISTEN)
[[email protected] conf]# vim/etc/rc.local//Set boot from
Rm-rf/data/mongodb1/mongod.lock
/usr/local/mongodb/bin/mongod-f/usr/local/mongodb/conf/mongodb1.conf
[[email protected] mongodb]# Bin/mongo//Login MongoDB database
MongoDB Shell version:3.2.7
Connecting To:test
Welcome to the MongoDB shell.
for interactive help, type ' help '.
for more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the Support group
Http://groups.google.com/group/mongodb-user
Server has startup warnings:
2017-03-28t04:53:32.052+0800 I CONTROL [initandlisten] * * Warning:you is running this process as the root user, whic H is not recommended.
2017-03-28t04:53:32.052+0800 I CONTROL [Initandlisten]
> Show DBS
Local 0.078GB
> Exit
Bye
To remove the error problem:
[Email protected] mongodb]# echo never >/sys/kernel/mm/transparent_hugepage/enabled
[Email protected] mongodb]# echo never >/sys/kernel/mm/transparent_hugepage/defrag
[[email protected] ~]# vim. Bash_profile
。。。。。。。。。。。。。。。。
Alias Mongo=/usr/local/mongodb/bin/mongo
。。。。。。。。。。。。。。。。。。。
[[email protected] ~]# source. bash_profile
three ways to turn off services:
method One:
[email protected] mongodb]# Bin/mongo
MongoDB Shell version:3.2.7
Connecting To:test
Server has startup warnings:
2017-03-28t05:16:53.926+0800 I CONTROL [initandlisten] * * Warning:you is running this process as the root user, whic H is not recommended.
2017-03-28t05:16:53.926+0800 I CONTROL [Initandlisten]
> Use admin
switched to DB admin
> Db.shutdownserver ();
server should is down ...
2017-03-28t05:38:06.756+0800 I NETWORK [Thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2017-03-28t05:38:06.758+0800 W NETWORK [Thread1] Failed to connect to 127.0.0.1:27017, reason:errno:111 Connection re Fused
2017-03-28t05:38:06.758+0800 I NETWORK [thread1] Reconnect 127.0.0.1:27017 (127.0.0.1) failed failed
> Exit
Bye
Method Two:
[Email protected] mongodb]# bin/mongod-f/usr/local/mongodb/conf/mongodb2.conf--shutdown
Killing process with pid:1829
method Three: Kill process number (not recommended to kill process method, MongoDB cluster node data is not easy to save)
[email protected] mongodb]# bin/mongod-f/usr/local/mongodb/conf/mongodb2.conf
About -to-fork child process, waiting until server was ready for connections.
forked process:1882
Child Process started successfully, parent exiting
[email protected] mongodb]# Ps-ef | grep mongod
Root 1882 1 2 05:41? 00:00:00 bin/mongod-f/usr/local/mongodb/conf/mongodb2.conf
Root 1896 1717 0 05:41 pts/1 00:00:00 grep mongod
[email protected] mongodb]# Kill 1882
[email protected] mongodb]# Ps-ef | grep mongod
Root 1899 1717 0 05:41 pts/1 00:00:00 grep mongod
Open two instances and configure a dual instance MongoDB:
[Email protected] conf]# pwd
/usr/local/mongodb/conf
[Email protected] conf]# vim mongodb2.conf
port=27018
Dbpath=/data/mongodb2
Logpath=/data/logs/mongodb/mongodb2.log
Logappend=true//Log Append
Fork=true
maxconns=5000
STORAGEENGINE=MMAPV1//Storage Engine
[[email protected] conf]# ls/data///build MONGODB2 Data file directory
Logs MONGODB1 MONGODB2
[[email protected] conf]# ls/data/logs/mongodb///build Mongodb2.log log file
Mongodb1.log Mongodb2.log
[[email protected] mongodb2]# chmod 777/data/logs/mongodb/mongodb2.log//Add permissions to Mongodb2.log
To write a start-stop script:
[Email protected] mongodb2]# CD/ETC/INIT.D
[[email protected] init.d]# Vim MongoDB
#!/bin/bash
Instance=$1
Action=$2
Case ' $ACTION ' in
Start
/usr/local/mongodb/bin/mongod-f/usr/local/mongodb/conf/"$INSTANCE". conf
;;
Stop
/usr/local/mongodb/bin/mongod-f/usr/local/mongodb/conf/"$INSTANCE". conf
;;
Restart
/usr/local/mongodb/bin/mongod-f/usr/local/mongodb/conf/"$INSTANCE". conf--shutdown
/usr/local/mongodb/bin/mongod-f/usr/local/mongodb/conf/"$INSTANCE". conf
;;
Esac
[email protected] init.d]# chmod +x MongoDB
[email protected] init.d]#/etc/init.d/mongodb mongodb1 start
About -to-fork child process, waiting until server was ready for connections.
forked process:1957
Child Process started successfully, parent exiting
[email protected] init.d]#/etc/init.d/mongodb mongodb2 start
About -to-fork child process, waiting until server was ready for connections.
forked process:1973
Child Process started successfully, parent exiting
[email protected] init.d]# Ps-ef | grep mongodb
Root 1957 1 1 05:56 00:00:00/usr/local/mongodb/bin/mongod-f/usr/local/mongodb/conf/mongodb1.conf
Root 1973 1 1 05:56 00:00:00/usr/local/mongodb/bin/mongod-f/usr/local/mongodb/conf/mongodb2.conf
Root 1987 1902 0 05:56 pts/2 00:00:00 grep mongodb
MongoDB configuration Single instance and dual instance