Environmental preparation:
Hardware requirements: 50G hard disk, 8G memory, 4 core CPU
Software requirements: Linux operating system: CentOS6.5_X64 mongodb-linux-x86_64-2.6.10.tgz
purpose:
Install and configure MongoDB database
Specific operation:
First, close SElinux, configure the firewall
1.vi / etc / selinux / config
# SELINUX = enforcing #comment out
# SELINUXTYPE = targeted #Commented out
SELINUX = disabled #Increase
: wq! #Save and exit
setenforce 0 #Make the configuration take effect immediately
2.vi / etc / sysconfig / iptables #edit
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 27017 -j ACCEPT #Allow port 27017 to pass through the firewall
: wq! #Save and exit
/etc/init.d/iptables restart #Restart the firewall for the configuration to take effect
Install MongoDB
(1). Download the MongoDB installation package: mongodb-linux-x86_64-2.6.10.tgz
(To install MongoDB according to the procedure in the following official website link, the version to be installed is v2.6.9:
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat/)
# tar -zxvf mongodb-linux-x86_64-2.6.10.tgz
Create a folder for mongodb runtime under / root and put it into mongodb component
# mkdir -p mongodb
# cp -R -n mongodb-linux-x86_64-2.6.10 / mongodb
mv mongodb-linux-x86_64-2.6.10 / usr / local / mongodb #Move the unzipped folder to the MongoDB installation directory
mkdir -p / data / mongodb / mongodb_data / #Create MongoDB database storage path
mkdir -p / data / mongodb / mongodb_log / #Create MongoDB database log storage path
Setting environment variables
# vi ~ / .bashrc
Add in the last line of the file:
export PATH = / usr / local / mongodb / mongodb-linux-x86_64-2.6.10 / bin: $ PATH
Save and exit the file
Enter the command for the environment variables to take effect:
# source ~ / .bashrc
Establish a default data storage location:
mkdir-p / data / db
Establish mongodb log storage location:
mkdir / usr / local / mongodb / logs
Start the database command:
# mongod--logpath = / usr / local / mongodb / logs / mongodb.log --fork
#mongod --logpath = / usr / local / mongodb / logs / mongodb.log --fork --nojournal (The second startup method: Yes, the journal was also started when mongodb was started before. This is when mongodb is down It is used to reply to the write operation, but it takes up more hard disk and memory resources.
(2). Start MongoDB
/ usr / local / mongodb / bin / mongod --port 27017 --fork --dbpath = / data / mongodb / mongodb_data / --logpath = / data / mongodb / mongodb_log / mongodb.log --logappend
about to fork child process, waiting until server is ready for connections.
forked process: 2102
child process started successfully, parent exiting
After installation, the default database listening port is 27017, and the default database storage path is / var / lib / mongo
After installation, use the following command to start MongoDB:
#service mongod start
(3). Check your startup status
netstat -ntpl #Check if MongoDB is started
Use this command to check the startup status: ps aux | grep mongod
(4). Add system services and daemons
Configure MongoDB to start at startup: chkconfig mongod on
# echo "/usr/local/mongodb/mongodb-linux-x86_64-2.6.10/bin/mongod--logpath=/root/mongodb/logs/mongodb.log --fork" >> /etc/rc.local
1). Modify the mongodb system file settings to start automatically at boot
i. Stop the mongodb service first: service mongod stop
ii. Restart the mongodb service using the following command:
#mongod --logpath = / usr / local / mongodb / logs / mongodb.log --fork --nojournal
iii. Finally modify the mongodb part in the boot file: vi /etc/rc.local, add this line: /usr/local/mongodb/mongodb-linux-x86_64-2.6.10/bin/mongod--logpath= /usr/local/mongodb/logs/mongodb.log--fork, followed by --nojournal, save.
(5). Test the MongoDB database
a) Execute the import command:
# /usr/local/mongodb/mongodb-linux-x86_64-2.6.10/bin/mongorestore --db project / root / newDump / project
b) After importing, perform the following operations to verify whether the number of data is available:
# mongo login database
#> useproject
#> db.stock.getIndexes () (note: if there is garbled characters, set the shell terminal to utf8), if shown, the data import is successful.
Install and configure MongoDB database under CentOS6.5_X64