1. Copy MongoDB to the specified server
To the MongoDB official website http://www.mongodb.org/downloads download MongoDB, unzip and test the directory to the server that needs to be installed, and then configure. For example:
Copy Code code as follows:
[root@shnhdx17-165 ~]# scp-r root@10.3.18.80:/data/web/dxm/mongodb/mongodb-linux-x86_64-2.4.5 data/web/
Will copy the MongoDB directory to the ~/data/web directory of the 10.11.17.165 server.
2. Establish data, log directory
Go to the MongoDB root directory, create a new data directory to store the information, create a new log directory, and then create a new log file in the directory, such as Mongodb.log.
Copy Code code as follows:
[root@shnhdx17-165 mongodb]# mkdir data
[root@shnhdx17-165 mongodb]# mkdir logs
[root@shnhdx17-165 mongodb]# CD logs
[root@shnhdx17-165 logs]# Touch Mongodb.log
3. Create a configuration file
Create a new configuration file in the MongoDB root, any file name, such as mongodb.conf, and then add configuration information to the configuration file:
Copy Code code as follows:
PORT=27017 "represents the port number and defaults to 27017 if not specified"
dbpath=/root/data/web/mongodb/data/"Database Path"
Logpath=/root/data/web/mongodb/logs/mongodb.log "Log Path"
Logappend=true "Log files are automatically cumulative, not overwritten"
4. Start the MongoDB service (according to the configuration file)
Execute command
Copy Code code as follows:
[root@shnhdx17-165 mongodb]#./bin/mongod-f mongodb.conf
The following message appears:
Copy Code code as follows:
All output going to:/root/data/web/mongodb/logs/mongodb.log
5. Use the client to connect to the database
Reopen a terminal and switch to the MongoDB directory
Copy Code code as follows:
[root@shnhdx17-164 ~]# CD Data/web/mongodb
And then enter
Copy Code code as follows:
[root@shnhdx17-164 mongodb]# Bin/mongo localhost:27017
MongoDB Shell version:2.4.5
Connecting To:localhost:27017/test
Server has startup warnings:
Fri Nov 8 13:05:59.823 [Initandlisten]
Fri Nov 8 13:05:59.823 [Initandlisten] * * * warning:you are running on a NUMA machine.
Fri Nov 8 13:05:59.823 [Initandlisten] * * We suggest launching mongod like this to avoid performance problems:
Fri Nov 8 13:05:59.823 [Initandlisten] * * Numactl--interleave=all Mongod [Other options]
Fri Nov 8 13:05:59.823 [Initandlisten]
>
The connection was successful.
6. Configure from start (optional)
Set up automatic boot MongoDB
Copy Code code as follows:
[root@shnhdx17-165 ~]# echo "/root/data/web/mongodb/bin/mongod-f/root/data/web/mongodb/mongodb.conf-fork" >> /etc/rc.local
Setting environment variables
Copy Code code as follows:
VI ~/.bash_profile
Path= $PATH: $HOME/bin: $JAVA _home/bin:/root/data/web/mongodb/bin