Source code installation and deployment of MongoDB under CentOS7

1. Click to enter  MongoDB official website

MongoDB official source code contains 4 parts

mongodb-org-server: server
mongodb-org-mongos: daemon process
mongodb-org-shell: command line
mongodb-org-tools: other tools

2. I use wget to download

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.22.tgz

 

3. Unzip

tar -zxf mongodb-linux-x86_64-3.2.22 -C /home/soft/

mv mongodb-linux-x86_64-3.2.22 mongodb

4. Create a folder under the current path [/home/soft/mongodb]

mkdir -p ./data/db

​
mkdir ./logs

​

5. Enter the /usr/local/mongodb/bin directory and create a configuration file

vi mongodb.conf

# Data file storage directory

dbpath =/home/soft/mongodb/data/db

#Log file storage directory

logpath =/home/soft/mongodb/logs/mongodb.log port = 27017

#port

port = 27017

#Enable as a daemon, that is, run in the background

fork = true

nohttpinterface = true

#It is suggested that the practice condition is false authentication field

auth=true

bind_ip=0.0.0.0

Other configuration file references:

Add the following to mongodb.conf

port=27017 #端口
dbpath= /usr/mongodb/mongodb-4.0.10/db #数据库存文件存放目录
logpath= /usr/mongodb/mongodb-4.0.10/log/mongodb.log #日志文件存放路径
logappend=true #使用追加的方式写日志
fork=true #以守护进程的方式运行,创建服务器进程
maxConns=100 #最大同时连接数
noauth=true #不启用验证
journal=true #每次写入会记录一条操作日志(通过journal可以重新构造出写入的数据)。
             #即使宕机,启动时wiredtiger会先将数据恢复到最近一次的checkpoint点,然后重放后续的journal日志来恢复。
storageEngine=wiredTiger  #存储引擎,有mmapv1、wiretiger、mongorocks
bind_ip = 0.0.0.0  #设置成全部ip可以访问,这样就可以在windows中去连虚拟机的MongoDB,也可以设置成某个网段或者某个ip1234567891011

 

6. Configure environment variables and open the configuration file /etc/profile

 

vi /etc/profile

Add a statement after

Add this statement: export PATH=/home/soft/mongodb/bin:$PATH

 

7. The configuration file takes effect
source /etc/profile

8. Start mongo

Configuration file example

vim mongo.conf
-------------
dbpath=/home/soft/mongodb/data/mongo/
port=27017
bind_ip=0.0.0.0
fork=false
logpath = /home/soft/mongodb/data/mongo/mongodb.log
logappend = true
auth=false

Specify the configuration file to start

./mongod -f ../mongo.conf

mongod --config /home/soft/mongodb/mongodb.conf

Add new users and databases

 

 mongo shell

MongoDB shell version: 3.2.22

connecting to: shell

> use admin

switched to db admin

> db.createUser({user:"admin",pwd:"123456",roles:[{role:"root", db:"admin"}]})

Successfully added user: {

"user" : "admin",

"roles" : [

{

"role" : "root",

"db" : "admin"

}

]

}

> db.auth("admin","123456") 

1

> use testdb

switched to db testdb

> db.createUser({user:"testdb",pwd:"testdb",roles:[{"role":"dbOwner","db":"testdb"}]})

Successfully added user: {

"user" : "testdb",

"roles" : [

{

"role" : "readWrite",

"db" : "testdb"

}

]

}

Roles are explained in detail as follows:

Database User Roles

  • read : authorizes the user to read only data, allowing the user to read the specified database
  • readWrite Authorizes the user to read/write data, allowing the user to read/write the specified database

Database Administration Roles

  • dbAdmin: Perform management operations in the current database, such as index creation, deletion, statistics, viewing, etc.
  • dbOwner: Perform arbitrary operations in the current database, such as adding, deleting, modifying, checking, etc.
  • userAdmin: Manage User in the current database , create, delete and manage users.

Backup and Restoration Roles

  • backup
  • restore

All-Database Roles

  • readAnyDatabase: authorized to read data on all databases, only available in admin
  • readWriteAnyDatabase: authorized to read and write data on all databases, only available in admin
  • userAdminAnyDatabase: authorized to manage User permissions on all databases, only available in admin
  • dbAdminAnyDatabase: authorized to manage all databases, only available in admin

Cluster Administration Roles

  • clusterAdmin: authorized to manage the highest authority of the cluster, only available in admin
  • clusterManager: authorization to manage and monitor clusters
  • clusterMonoitor: authorizes the authority to monitor the cluster, and has readonly authority to the monitoring tool
  • hostManager: manage server

super master roles

  • root: Super account and permissions, only available in admin

close service

 First connect to the server through the shell:

 mongo

 use admin

 db.shutdownServer()

 Or directly kill -15 <pid>, note that kill -9 may cause data file corruption

     (adsbygoogle = window.adsbygoogle || []).push({});  

Guess you like

Origin blog.csdn.net/taoanbang/article/details/110231364