1. Download MongoDB
The default is 64-bit, this is a little awkward ...
64-bit system download address: 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. Extract Directory
TAR-XVF mongodb.tgz
4. Move directory to/usr/local/mongodb
MV MongoDB (unpacked folder)/usr/local/mongodb 5. Configure Environment Variables
Modify/etc/profile and add the following
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 was successful! Configure below to start 7. Create a database directory
MongoDB need to build the database folder yourself.
Mkdir-p/data/mongodb
Mkdir-p/data/mongodb/log
Touch/data/mongodb/log/mongodb.log
Add configuration file
Create a new mongodb.conf configuration file to start with this profile.
Vim/etc/mongodb.conf
Configuration file Parameter Description:
MongoDB parameter Description:
--dbpath database path (data file)
--logpath log file path
--master specified as master machine
--slave specified as from machine
--so URCE Specifies the IP address of the primary machine
--pologsize Specifies that the log file size does not exceed 64M. Because Resync is a very large and time-consuming operation, it is best to avoid resync by setting a large enough oplogsize (the default The Oplog size is 5% of the size of the free disk.
--logappend the end of the log file add
--port enable the port number
--fork run in the background
--only specify which database to copy only
--slavedelay refers to from replication detection Interval
--auth whether to require authentication permission logins (username and password)
Note: MongoDB configuration file contains a lot of parameters, custom specific requirements, please refer to the official documentation
Configuration file Contents:
Dbpath=/data/mongodb
Logpath=/data/mongodb/log/mongodb.log
Logappend=true
port=27017
Fork=true
# #auth = true # First Close, create a good user to start
To start a service from a configuration file:
Mongod--journal-f/etc/mongodb.conf (32-bit system needs to add parameters--journal)
To shut down a service by using a configuration file:
Mongod--journal--shutdown-f/etc/mongodb.conf
8. Enter MongoDB admin Shell
Cd/usr/local/mongodb/bin
./mongo
Creating 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
Add 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 ()
Source: https://m.baidu.com/from=2001a/bd_page_type=1/ssid=0/uid=0/pu=usm%401%2Csz%401320_2003%2Cta%40iphone_1_ 10.0_1_11.6/baiduid=dbb63436892e8072fb5f78658b4a3130/w=0_10_/t=iphone/l=3/tc?ref=www_iphone&lid= 12944001903239221549&order=6&fm=alop&tj=www_normal_6_0_10_title&vit=osres&m=8&srd=1 &cltj=cloud_title&asres=1&title=linux (CentOS)%e4%b8%8b%e5%ae%89%e8%a3%85mongodbv3.2%e7%ac%94%e8%ae %b0-t..._%e5%8d%9a%e5%ae%a2%e5%9b%ad&dict=32&w_qd=ilpt2aeptyoa_yisi57ajcuqokkuqm2hocbcsewv0j35ifx8q__ &sec=25640&di=765d7cbe10592194&bdenc=1&tch=124.300.121.1394.2.329&nsrc=ilpt2aeptyoa_ Yixcfoxcgzb8c3jv3t5aaggqmbx0diyokaoxp4khresrdj7lnzeup7wdosoxbt8x8wa07ql7gwtap1s&eqid= B3a25526968dd000100000035a1682aa&wd=&clk_info=%7b%22srcid%22%3a1599%2c%22tplname%22%3a%22www_normal%22 %2c%22t%22%3a1511424894134%2c%22xpath%22%3a%22div-div-div-a-p%22%7d&sfopen=1