https://repo.mongodb.org/yum/redhat/6Server/mongodb-org/3.4/x86_64/RPMS/
1. Download all RPM Packages
Upload to Server
[Email protected] ~]# lltotal 93528-RW-------. 1 root root 1231 Feb 02:07 anaconda-ks.cfg-rw-r--r--1 root root 5900 Jul 06:42 mongodb-org-3.4.6-1.el6.x86 _64.rpm-rw-r--r--1 root root 12182737 Jul 06:42 mongodb-org-mongos-3.4.6-1.el6.x86_64.rpm-rw-r--r--1 root root 2060 8908 Jul 06:42 mongodb-org-server-3.4.6-1.el6.x86_64.rpm-rw-r--r--1 root root 11767549 Jul 06:42 Mongodb-org-shell -3.4.6-1.el6.x86_64.rpm-rw-r--r--1 root root 51195582 Jul 06:42 mongodb-org-tools-3.4.6-1.el6.x86_64.rpm[[email Protected] ~]#
2. Installation
Yum Localinstall mongodb-org-*
3. Modify the configuration file
Vi/etc/mongod.conf
# mongod.conf# for documentation of all options, see:# Http://docs.mongodb.org/manual/reference/configuration-options/# where to write logging data.systemLog: destination: file logAppend: true path: /opt/mongo/log/mongo.log #日志文件 # where and how to store data.storage: dbPath: /opt/mongo/data #数据 journal: enabled: true# engine:# mmapv1:# wiredtiger:# how the process runsprocessManagement: fork: true # fork and run in background pidfilepath: /opt/mongo/mongopid/mongo.pid # location of pidfile #pid # network interfacesnet: port: 62114 #端口和监听的IP bindip: 192.168.56.15 # listen to local interface only, comment to listen on all interfaces. #security: #operationProfiling: #replication: #sharding: ## enterprise-only options#auditlog: #snmp:[[email protected] ~]# chown -r Mongod.mongod /opt/mongo
4. Start MONGO
Systemctl Start Mongod
5. Enter MONGO
Mongo --host 192.168.56.15 --port 62114server has startup warnings: 2017-07-22T07:07:43.607+0800 I CONTROL [initandlisten] 2017-07-22t07:07:43.607+0800 i control [initandlisten] ** warning: access control is not enabled for the database.2017-07-22T07:07:43.608+0800 i control [initandlisten] ** read and write access to data and configuration is unrestricted.2017-07-22t07:07:43.608+0800 i control [initandlisten] 2017-07-22t07:0 7:43.608+0800 i control [initandlisten] 2017-07-22t07:07:43.608+0800 i Control [initandlisten] ** warning: /sys/kernel/mm/transparent_hugepage/enabled is ' always '. 2017-07-22t07:07:43.608+0800 i control [initandlisten] ** we suggest setting it to ' Never ' 2017-07-22t07:07:43.608+0800 i control [initandlisten] 2017-07-22t07:07:43.608+0800 i control [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ' always '. 2017-07-22t07:07:43.608+ 0800 i control [initandlisten] ** we suggest setting it to ' Never ' 2017-07-22t07:07:43.608+0800 i control [initandlisten] 2017-07-22t07:07:43.608+0800 i control [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 4096 Processes, 1024000 files. number of processes should be at least 512000 : 0.5 times number of files.2017-07-22t07:07:43.608+0800 i control [ initandlisten] solution [[email protected] ~]# tail -n 4 /etc/security/ limits.conf mongod soft nofile 64000mongod hard nofile 64000mongod Soft nproc 32000mongod hard nproc 32000[[email protected] ~]# [[email protected] ~]# echo "Never" >/sys/kernel/mm/transparent_hugepage/enabled[[email protected] ~]# echo "Never" >/sys/kernel/mm/transparent_hugepage/defrag never here the system restarts fail so put this two echo in/etc/rc.local
6. Add user name and password
Added Super admin MONGO--host 192.168.56.15--port 62114 db.createuser ({User: "admin", pwd: "123456", Roles:[{role: " Useradminanydatabase ", DB:" Admin "}]})
7. Exit let MONGO user authentication login
vim /etc/mongod.confsecurity: #打开注释 authorization: enabled #增加一行 systemctl restart mongod test: [[email protected] ~]# mongo --host 192.168.56.15 --port 62114 Mongodb shell version v3.4.6connecting to: mongodb://192.168.56.15:62114/mongodb server version: 3.4.6> show dbs;2017-07-22T07:43:14.962+0800 E query [thread1] error: listdatabases failed:{"OK" : 0, "ErrMsg" : "not authorized on admin to execute command { listdatabases: 1.0 } "," Code " : 13," codename " : " Unauthorized "} :[email protected]/mongo/shell/utils.js:25:13[email protected]/mongo/shell/mongo.js:62:1[email Protected]/mongo/shell/utils.js:769:19[email protected]/mongo/shell/utils.js:659:15@ (SHELLHELP2):1:1> test passed [[email protected] ~]# mongo --host 192.168.56.15 --port 62114 -u admin -p 123456mongodb shell version v3.4.6connecting to: mongodb:// 192.168.56.15:62114/mongodb server version: 3.4.6> show dbs;admin 0.000gblocal 0.000gb>
8. The administrator adds a library and assigns a specific user (the library is created by default and does not write things unseen)
> db.createuser ({ user: "test",... pwd: "123456",... roles:[{"Role": "ReadWrite", "DB": "Mall"},... { "Role": "DbAdmin", "DB": "Mall"},... {"role": "Dbowner", "DB": "Mall"},... {"role": "read", "DB": "Mall"}]}) Successfully added user: {"User" : "test", "Roles" : [{"role" : "ReadWrite", "DB" : "Mall"} , {"Role" : "DbAdmin", "DB" : "Mall"},{"role" : "Dbowner", "DB" : "Mall"} , {"Role" : "read", "DB" : "mall"}]}> > show dbs; # Admin login also can't see admin 0.000gblocal 0.000gb> mongo --host 192.168.56.15 --port 62114 -u test -p 123456> db.auth ("Test", "123456") 1> use mall; #test User login can switchswitched to db mall>
9. Insert data log in with test user
Test user > Db.inventory.insert ({_id:10, type: "Misc", Item: "Card", qty:15}) Writeresult ({"ninserted": 1}) > ADM In user after inserting data can see [[email protected] ~]# MONGO--host 192.168.56.15--port 62114-u admin-p 123456MongoDB shell vers Ion v3.4.6connecting To:mongodb://192.168.56.15:62114/mongodb Server version:3.4.6> show dbs;admin 0.000GBlocal 0.0 00GBmall 0.000gb>
10 service did not shut down directly shut down the server causing MongoDB to start up
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M00/9C/94/wKiom1lyq1TDA6HzAAFbDaQ9Fbw716.png-wh_500x0-wm_ 3-wmp_4-s_3274284369.png "title=" 2.png "alt=" Wkiom1lyq1tda6hzaafbdaq9fbw716.png-wh_50 "/>
Workaround:
[Email protected] mongopid]# mv mongo.pid Mongo.pid.ori [[email protected] mongopid]# Pwd/opt/mongo/mongopid[[email PR Otected] mongopid]#
11.windows Client Connection MongoDB
This article is from the "Brick Blog" blog, please be sure to keep this source http://wsxxsl.blog.51cto.com/9085838/1949913
The installation of MongoDB