Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Installation and deployment of MongoDB3.0

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you the installation and deployment of MongoDB3.0 detailed tutorials, I believe that most people do not know how to deploy, in order to let you learn, so to sum up the following content.

Download the binary package:

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

# tar xf mongodb-linux-x86_64-3.0.15.tgz

# cd mongodb-linux-x86_64-3.0.15

Create data storage path, log storage path, program path

# mkdir / data/mongodata-p

# mkdir / data/log/mongolog-p

# mkdir / data/mongo-p

Copy all current files

# cp-r * / data/mongo

Configure environment variables

# more / etc/profile.d/mongodb.sh

Export PATH=$PATH:/data/mongo/bin

# source / etc/profile.d/mongodb.sh

Configure mongodb Profil

# cd / data/mongo/bin/

# vim mongodb.conf

# data file storage directory

Dbpath = / data/mongodata

# Log file storage directory

Logpath = / data/log/mongolog/mongodb.log

# Port

Port = 27017

# enabled as a daemon, that is, running in the background

Fork = true

Nohttpinterface = true

Identify servic

# mongod-dbpath=/data/mongodata-logpath=/data/log/mongolog/mongodb.log-logappend-fork

Start from a configuration file

# mongod-f / root/mongodb/bin/mongodb.conf

test

# mongo

MongoDB shell version: 3.0.15

Connecting to: test

Show dbs

Local 0.078GB

Quit ()

WARNING: Readahead for / data/mongodata is set to 4096KB

WARNING: You are running this process as the root user, which is not recommended.

WARNING: / sys/kernel/mm/transparent_hugepage/enabled is' always'.

We suggest setting it to 'never'

WARNING: / sys/kernel/mm/transparent_hugepage/defrag is' always'.

We suggest setting it to 'never'

WARNING: soft rlimits too low. Rlimits set to 3802 processes, 65536 files. Number of processes should be at least 32768: 0.5 times number of files.

There is a warning to start, remove

# vim / etc/rc.local

If test-f / sys/kernel/mm/transparent_hugepage/enabled; then

Echo never > / sys/kernel/mm/transparent_hugepage/enabled

Fi

If test-f / sys/kernel/mm/transparent_hugepage/defrag; then

Echo never > / sys/kernel/mm/transparent_hugepage/defrag

Fi

Ulimit-u 65535

# echo never > / sys/kernel/mm/transparent_hugepage/enabled

# echo never > / sys/kernel/mm/transparent_hugepage/defrag

# runlevel

# chmod + x / etc/rc.local

File limit adjustment

# vim / etc/security/limits.conf

Soft nproc 32000hard nproc 32000

Restart:

Mongo

Use admin

Switched to db admin

Db.shutdownServer ()

Configure Startup Service

# vim / usr/lib/systemd/system/systemd-mongodb.service

[Unit]

Description=mongodb

After=network.target

[Service]

Type=forking

PIDFile=/data/mongodata/mongod.lock

ExecStart=/data/mongo/bin/mongod-f / data/mongo/bin/mongodb.conf

ExecReload=/bin/kill-s HUP $MAINPID

ExecStop=/bin/kill-s QUIT $MAINPID

PrivateTmp=true

[Install]

WantedBy=multi-user.target

Turn on the machine

# systemctl enable systemd-mongodb

Enter and view the database. There is only one local library. The admin library does not exist.

Show dbs

Local 0.078GB

Show tables

The newly created account has grant permission, that is, the authorization permission for account management.

Use admin

Switched to db admin

Db.createUser (

... {

... User: "dba"

... Pwd: "dba"

... Roles: [{role: "userAdminAnyDatabase", db: "admin"}]

...}

.)

Successfully added user: {

"user": "dba"

"roles": [

{

"role": "userAdminAnyDatabase"

"db": "admin"

}

]

}

Show dbs

Admin 0.078GB

Local 0.078GB

User: user name

Pwd: password

Roles: specify the role of the user, and you can set an empty role for the new user with an empty array; in the roles field, you can specify built-in roles and user-defined roles. The characters in role can be selected:

Built-In Roles (built-in roles):

Database user roles: read, readWrite; database management roles: dbAdmin, dbOwner, userAdmin; cluster management roles: clusterAdmin, clusterManager, clusterMonitor, hostManager; backup and recovery roles: backup, restore; all database roles: readAnyDatabase, readWriteAnyDatabase, userAdminAnyDatabase, dbAdminAnyDatabase superuser roles: root

/ / there are also several roles that indirectly or directly provide access to the system superuser (dbOwner, userAdmin, userAdminAnyDatabase) internal role: _ _ system

Specific roles:

Read: allows the user to read the specified database

ReadWrite: allows users to read and write to a specified database

DbAdmin: allows users to perform administrative functions in a specified database, such as index creation, deletion, viewing statistics, or accessing system.profile

UserAdmin: allows users to write to the system.users collection. You can create, delete and manage users in a specified database.

ClusterAdmin: available only in the admin database, giving users administrative rights to all shard and replication set related functions.

ReadAnyDatabase: available only in admin databases, giving users read access to all databases

ReadWriteAnyDatabase: available only in admin databases, giving users read and write permissions to all databases

UserAdminAnyDatabase: available only in admin databases, giving users userAdmin permissions for all databases

DbAdminAnyDatabase: available only in admin databases, giving users dbAdmin permissions for all databases.

Root: available only in the admin database. Super account, super privilege

Creation and deletion of databases and collections in Mongodb

Insert data

Show dbs / / query all databases

Admin 0.078GB

Cmz 0.078GB

Local 0.078GB

Show collections / / query all collections (tables) are equivalent to show tables

Create a database or switch to a database (switch if it exists, create if it doesn't exist)

Use cmz

Switched to db cmz

Create a collection, delete a collection (generally, you don't have to create a collection, you can automatically create a collection when you insert data):

Db.createCollection ('col') / / create a collection

{"ok": 1}

Show collections

Col

Db.col.drop () / / Delete the collection

True

5. Backup

-h indicates the IP of the database host

-- port indicates the port of the database

-u indicates the user name of the database

-p indicates the password of the database

-d indicates the name of the database

-c specify the name of collection

-o indicate the name of the file to be exported

-Q indicates the filtering criteria for the exported data

-- name of authenticationDatabase authentication data

-- compress gzip during backup

-- oplog use oplog for taking a point-in-time snapshot

Full database backup

Mongodump-h 10.0.0.4-- authenticationDatabase admin-o / mnt/

Backup cmz Library

Mongodump-h 10.0.0.4-- authenticationDatabase admin-d cmz-o / mnt1/

Back up the col collection of cmz libraries

Mongodump-h 10.0.0.4-- authenticationDatabase admin-d cmz-c col-o / mnt2/

Create a test library

Use test

Switched to db test

Db.createUser (

... {

... User: "jrw"

... Pwd: "jrw"

... Roles: [

... {role: "readWrite", db: "test"}

...]

...}

.)

Successfully added user: {

"user": "jrw"

"roles": [

{

"role": "readWrite"

"db": "test"

}

]

}

Show users

{

"_ id": "test.jrw"

"user": "jrw"

"db": "test"

"roles": [

{

"role": "readWrite"

"db": "test"

}

]

}

After reading this article, have you learned how to install and deploy MongoDB3.0? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel. Thank you for reading.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report