Get the App
SLTechnology News&Howtos  ›  Database  › 

Linux installation Mongodb4.0 and remote configuration

Shulou Source: shulou.com Published: 2022-06-01 13:57:10 10月04日 Update

1. Download and install

Official website address: www.mongodb.com/download-center? jmp=nav#community

Here's the community version of linux 7:

Decompress tar zxvf mongodb-linux-x86_64-rhel70-4.0.1.tgzmv mongodb-linux-x86_64-rhel70-4.0.1 /usr/local/mongodb

generate a configuration file

vim /usr/local/mongodb/bin/mongodb.conf

dbpath = /usr/local/mongodb/data/db #directory where data files are stored logpath = /usr/local/mongodb/logs/mongodb.log #directory where log files are stored port = 27017 #port fork = true #enabled as a daemon, i.e. running bind_ip=0.0.0.0 in the background #Allow all connections

Start mongodb:

./ usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongodb.conf

Configure environment variables for ease of operation

vim ~/.bash_profile #Modify PATH=$PATH:$HOME/bin:/usr/local/mongodb/binsource ~/.bash_profile for this user #Update user environment variables

OK, now you can use mongodb directly, command line input mongo, you can directly enter the database.

2. Configure mongodb First, understand the following MongoDB user roles:

1. Database user roles: read, readWrite;

2. Database administration roles: dbAdmin, dbOwner, userAdmin;

3. Cluster management roles: clusterAdmin, clusterManager, clusterMonitor, hostManager;

4. Backup and restore roles: backup, restore;

5. All database roles: readAnyDatabase, readWriteAnyDatabase, userAdminAnyDatabase, dbAdminAnyDatabase

6. Super User Role: root

//There are also several roles that indirectly or directly provide system superuser access (dbOwner, userAdmin, userAdminAnyDatabase)

MongoDB does not have user authentication enabled by default, which means that visitors also have super administrator privileges. userAdminAnyDatabase: Has permission to assign roles and users, but does not have permission to query and write

Enter mongo on the command line and go to mongodb.

Previous query documents all said that the new user was db.addUser, but the new version of Mongodb (seems to have changed after 3.0) has not used this command. Create a user, note that the account follows the database.

use admindb.createUser({user:'test',pwd:'123456',roles:[{role:'dbAdmin',db:'admin'}]})

Note: docker install mongodb

docker pull mongodocker run -itd --name=mongo_test -p 27017:27017 mongo

Tags: Users roles data databases commands configurations variables files permissions environment management directories input that is background addresses backups comments documents Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei OPPO Reno Xiaomi vpn MySQL