1. Download the installation package
wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.8.2.tgz
After the download is complete, unzip the compressed package
tar zxf mongodb-linux-i686-1.8.2.tgz
2. Installation preparation
Move mongodb to /usr/local/server/mongdb folder
mv mongodb-linux-i686-1.8.2 /usr/local/mongodb
Create database folders and log files
mkdir /usr/local/mongodb/data touch /usr/local/mongodb/logs
3. Set the boot to start automatically
Append the mongodb startup item to rc.local to ensure that mongodb starts when the server is powered on
echo "/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data –logpath=/usr/local/mongodb/logs –logappend --auth -–port=27017" >> /etc/rc.local
4. Start mongodb
cd to the bin folder in the mongodb directory to start mongodb
//The following is a login method that requires permissions, user connection requires a user name and password
/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs --logappend --auth --port=27017 --fork
// this does not require a password
/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs --logappend --port=27017 --fork
5. Parameter explanation: --dbpath database path (data file)
--logpath log file path --master specifies the master machine --slave specified as slave machine --source specifies the IP address of the host machine --pologSize specifies that the log file size should not exceed 64M. Because resync is very intensive and time-consuming, it is best to avoid resync by setting a large enough oplogSize (the default oplog size is 5% of the free disk size). --logappend append at the end of the log file --port enable port number --fork run in the background --only specifies which database to copy only --slavedelay refers to the time interval for slave replication detection --auth Whether to require authentication permissions to log in (username and password) -h [ --help ] show this usage information --version show version information -f [ --config ] arg configuration file specifying additional options --port arg specify port number --bind_ip arg local ip address to bind listener - all local ips bound by default -v [ --verbose ] be more verbose (include multiple times for more verbosity e.g. -vvvvv) --dbpath arg (=/data/db/) directory for datafiles Specifies the data storage directory --quiet quieter output Quiet mode --logpath arg file to send all output to instead of stdout Specifies the log storage directory --logappend appnd to logpath instead of over-writing Specifies whether the log is written to the log file by appending or overwriting --fork fork server process run as a child process --cpu periodically show cpu and iowait utilization Periodically display the usage of cpu and io --noauth run without security run in no authentication mode --auth run with security authentication mode operation --objcheck inspect client data for validity on receipt --quota enable db quota management Start database quota management --quotaFiles arg number of files allower per db, requires --quota specifies the number of files allowed per database --appsrvpath arg root directory for the babble app server --nocursors diagnostic/debugging option Debug diagnostic options --nohints ignore query hints ignore query hit rate --nohttpinterface disable http interface disable http interface, default is 28017 --noscripting disable scripting engine disable scripting engine --noprealloc disable data file preallocation disable database file size preallocation --smallfiles use a smaller default file size --nssize arg (=16) .ns file size (in MB) for new databases Default size of new database ns file --diaglog arg 0=off 1=W 2=R 3=both 7=W+some reads The method provided is read-only, write-only, or read-write, or the main write + partial read mode --sysinfo print some diagnostic system information Print system diagnostic information --upgrade upgrade db if needed update database if needed --repair run repair on all dbs --notablescan do not allow table scans do not run table scans --syncdelay arg (=60) seconds between disk syncs (0 for never) The time for the system to synchronously refresh the disk, the default is 60s Replication options: --master master mode master replication mode --slave slave mode slave replication mode --source arg when slave: specify master as <server:port> When slave, specify the address and port of the master --only arg when slave: specify a single database to replicate --pairwith arg address of server to pair with --arbiter arg address of arbiter server Arbiter server, used in master master and pair --autoresync automatically resync if slave data is stale --oplogSize arg size limit (in MB) for op log Specifies the size of the oplog --opIdMem arg size limit (in bytes) for in memory storage of op ids specifies the memory size for storing operation logs Sharding options: --configsvr declare this is a config db of a cluster Specifies the config server in the shard --shardsvr declare this is a shard db of a cluster Specify the shard server
6. Enter the CLI management interface of the database
cd to the bin folder in the mongodb directory and execute the command ./mongo
Run as follows:
[root@namenode mongodb]# ./bin/mongo MongoDB shell version: 1.8.2 connecting to: test > use test; switched to db test
If the database cannot be connected, it is a problem with the mongod.lock file in the data directory. You can use the following repair command:
mongod --repair
1. Download the installation package
wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.8.2.tgz
After the download is complete, unzip the compressed package
tar zxf mongodb-linux-i686-1.8.2.tgz
2. Installation preparation
Move mongodb to /usr/local/server/mongdb folder
mv mongodb-linux-i686-1.8.2 /usr/local/mongodb
Create database folders and log files
mkdir /usr/local/mongodb/data touch /usr/local/mongodb/logs
3. Set the boot to start automatically
Append the mongodb startup item to rc.local to ensure that mongodb starts when the server is powered on
echo "/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data –logpath=/usr/local/mongodb/logs –logappend --auth -–port=27017" >> /etc/rc.local
4. Start mongodb
cd to the bin folder in the mongodb directory to start mongodb
//The following is a login method that requires permissions, user connection requires a user name and password
/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs --logappend --auth --port=27017 --fork
// this does not require a password
/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs --logappend --port=27017 --fork
5. Parameter explanation: --dbpath database path (data file)
--logpath log file path --master specifies the master machine --slave specified as slave machine --source specifies the IP address of the host machine --pologSize specifies that the log file size should not exceed 64M. Because resync is very intensive and time-consuming, it is best to avoid resync by setting a large enough oplogSize (the default oplog size is 5% of the free disk size). --logappend append at the end of the log file --port enable port number --fork run in the background --only specifies which database to copy only --slavedelay refers to the time interval for slave replication detection --auth Whether to require authentication permissions to log in (username and password) -h [ --help ] show this usage information --version show version information -f [ --config ] arg configuration file specifying additional options --port arg specify port number --bind_ip arg local ip address to bind listener - all local ips bound by default -v [ --verbose ] be more verbose (include multiple times for more verbosity e.g. -vvvvv) --dbpath arg (=/data/db/) directory for datafiles Specifies the data storage directory --quiet quieter output Quiet mode --logpath arg file to send all output to instead of stdout Specifies the log storage directory --logappend appnd to logpath instead of over-writing Specifies whether the log is written to the log file by appending or overwriting --fork fork server process run as a child process --cpu periodically show cpu and iowait utilization Periodically display the usage of cpu and io --noauth run without security run in no authentication mode --auth run with security authentication mode operation --objcheck inspect client data for validity on receipt --quota enable db quota management Start database quota management --quotaFiles arg number of files allower per db, requires --quota specifies the number of files allowed per database --appsrvpath arg root directory for the babble app server --nocursors diagnostic/debugging option Debug diagnostic options --nohints ignore query hints ignore query hit rate --nohttpinterface disable http interface disable http interface, default is 28017 --noscripting disable scripting engine disable scripting engine --noprealloc disable data file preallocation disable database file size preallocation --smallfiles use a smaller default file size --nssize arg (=16) .ns file size (in MB) for new databases Default size of new database ns file --diaglog arg 0=off 1=W 2=R 3=both 7=W+some reads The method provided is read-only, write-only, or read-write, or the main write + partial read mode --sysinfo print some diagnostic system information Print system diagnostic information --upgrade upgrade db if needed update database if needed --repair run repair on all dbs --notablescan do not allow table scans do not run table scans --syncdelay arg (=60) seconds between disk syncs (0 for never) The time for the system to synchronously refresh the disk, the default is 60s Replication options: --master master mode master replication mode --slave slave mode slave replication mode --source arg when slave: specify master as <server:port> When slave, specify the address and port of the master --only arg when slave: specify a single database to replicate --pairwith arg address of server to pair with --arbiter arg address of arbiter server Arbiter server, used in master master and pair --autoresync automatically resync if slave data is stale --oplogSize arg size limit (in MB) for op log Specifies the size of the oplog --opIdMem arg size limit (in bytes) for in memory storage of op ids specifies the memory size for storing operation logs Sharding options: --configsvr declare this is a config db of a cluster Specifies the config server in the shard --shardsvr declare this is a shard db of a cluster Specify the shard server
6. Enter the CLI management interface of the database
cd to the bin folder in the mongodb directory and execute the command ./mongo
Run as follows:
[root@namenode mongodb]# ./bin/mongo MongoDB shell version: 1.8.2 connecting to: test > use test; switched to db test
If the database cannot be connected, it is a problem with the mongod.lock file in the data directory. You can use the following repair command:
mongod --repair