1. Download MongoDB
The default is 64-bit, this is a bit awkward ...
64-bit system: https://www.mongodb.org/dl/linux/x86_64-debian81?_ga=2.15324022.1713724367.1498550277-1089294971.1498550277
32-bit Download list address: Https://www.mongodb.org/dl/linux
32-bit v3.2 version address http://downloads.mongodb.org/linux/mongodb-linux-i686-v3.2-latest.tgz?_ga= 2.114898759.1713724367.1498550277-1089294971.1498550277
2. Linux (32-bit system) direct
wget http://downloads.mongodb.org/linux/mongodb-linux-i686-v3.2-latest.tgz?_ga= 2.114898759.1713724367.1498550277-1089294971.1498550277
3. Unzip the Directory
TAR-XVF mongodb.tgz
4. Move the directory to/usr/local/mongodb
MV MongoDB (unzipped folder)/usr/local/mongodb
5. Configure Environment variables
Modify /etc/profile
, add the following content
Export Mongodb_home=/usr/local/mongodb
Export path= $MONGODB _home/bin: $PATH
After saving, execute the following command:
Vim/etc/profile
Source/etc/profile
6. View MongoDB Version Information
mongod -v
The installation is successful! Configure it below to start
7. Create a database directory
MongoDB
You need to build your own database folder.
Mkdir-p/data/mongodb
Mkdir-p/data/mongodb/log
Touch/data/mongodb/log/mongodb.log
Add a configuration file
Create a new mongodb.conf configuration file to boot from this configuration file.
Vim/etc/mongodb.conf
Configuration file Parameter Description:
MongoDB parameter Description:?--dbpath database path (data file)?--logpath log file path?--Master is specified as the primary machine?--slave specified as the IP address of the host machine?--source specified from the machine,?--Polog SIZE specifies that the log file size does not exceed 64M. Because the resync is very large 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 Add?--port port number at the end of the log file?--Fork runs in the background?--only specifies which database is replicated?--Slavedelay refers to the time interval from replication detection?--Whether AUTH requires authentication permission to log on (user name and password) Note: Mong There are many parameters in the ODB configuration file, please refer to the official documentation for custom specific requirements.
Configuration file Contents:
Dbpath=/data/mongodb
Logpath=/data/mongodb/log/mongodb.log
Logappend=true
port=27017
Fork=true
# #auth = true # first close, create good user on start
To start a service from a configuration file:
Mongod--journal-f/etc/mongodb.conf (32-bit system requires parameter--journal)
To close a service through a configuration file:
Mongod--journal--shutdown-f/etc/mongodb.conf
8. Enter
MongoDB
Background management
Shell
Cd/usr/local/mongodb/bin
./mongo
Create data
Command Use test
Switched to DB test
Create a user, set permissions
Db.createuser (
{
User: "Test",
PWD: "Test",
Roles: [{role: ' ReadWrite ', DB: ' Test '}]
}
)
Configuring firewalls
Adding 27017 ports to the firewall
Vi/etc/sysconfig/iptables
-A input-m state--state new-m tcp-p TCP--dport 27017-j ACCEPT
/etc/init.d/iptables Reload
TEST
Command Use test
Db.abc.insert ({"A": 1, "B": 2})
> Db.abc.find ()
Installing MongoDB v3.2 notes under Linux (CentOS)