The simplest start method is foreground startup. Only the data directory is specified and the default port 27107 is used. It can be directly used under cli. /mongo is connected to the local mongodb, which is generally only used for temporary development and testing.
The code is as follows: |
Copy code |
./Mongod -- dbpath =/path/mongodb |
2. Start binding a fixed IP address and port, so mongo needs to specify the IP address and port when connecting to mongod.
The code is as follows: |
Copy code |
./Mongod -- dbpath =/path/mongodb -- bind_ip = 10.10.10.10 -- port = 12345 // Connect to mongod ./Mongo 10.10.10.10: 12345 |
3. Run daemon in the background. Simply add "&" to the command "&".
The code is as follows: |
Copy code |
./Mongod -- dbpath =/path/mongodb -- bind_ip = 10.10.10.10 -- port = 12345 &
|
You can also use the -- fork parameter that comes with mongod to specify the log path.
The code is as follows: |
Copy code |
./Mongod -- dbpath =/path/mongodb -- fork = true logpath =/path/mongod. log |
4. (recommended) save the configuration as a configuration file.
The code is as follows: |
Copy code |
Port = 12345 Bind_ip = 10.10.10.10 Logpath =/path/mongod. log Pidfilepath =/path/mongod. pid Logappend = true Fork = true |
Then introduce the configuration file when mongod is started.
The code is as follows: |
Copy code |
./Mongod-f/path/mongod. conf |