Mongodb installation and configuration notes
- 2020-05-14 05:20:02
- OfStack
1. Copy Mongodb to the specified server
To mongodb http official website: / / www mongodb. org/mongodb downloads download, unzip and install directory to need to server, and configure. Such as:
[root@SHNHDX17-165 ~]# scp -r root@10.3.18.80:/data/web/dxm/mongodb/mongodb-linux-x86_64-2.4.5 data/web/
The mongodb directory copy will be placed in the ~/data/web directory of the 10.11.17.165 server.
2. Establish data and log directories
Enter the mongodb root directory, create a new data directory to store data, a new log directory to store logs, and then create a new log file in that directory, for example, mongodb.log.
[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 configuration files
In the mongodb root directory, create a new configuration file with any name, such as mongodb.conf, and then add the configuration information in the configuration file:
port=27017 [represents the port number, which defaults to if not specified 27017 】
dbpath=/root/data/web/mongodb/data/ [database path]
logpath=/root/data/web/mongodb/logs/mongodb.log [log path]
logappend=true Log files are automatically accumulated, not overwritten.
4. Start the Mongodb service (according to the configuration file)
Execute the command
[root@SHNHDX17-165 mongodb]# ./bin/mongod -f mongodb.conf
The following information will appear:
all output going to: /root/data/web/mongodb/logs/mongodb.log
5. Use the client to connect to the database
Restart one terminal and switch to the mongodb directory
[root@SHNHDX17-164 ~]# cd data/web/mongodb
Then enter
[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]
>
Connection successful.
6. Configure self-boot (optional)
Set to boot Mongodb automatically
[root@SHNHDX17-165 ~]# echo "/root/data/web/mongodb/bin/mongod -f /root/data/web/mongodb/mongodb.conf -fork " >> /etc/rc.local
Setting environment variables
vi ~/.bash_profile
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:/root/data/web/mongodb/bin