Get the App
SLTechnology News&Howtos  ›  Database  › 

MongoDB-4.2.2 installs and configures the account password for access

Shulou Source: shulou.com Published: 2022-06-01 22:44:47 11月06日 Update

0. Purpose

Download MongoDB and install it to set password access.

The following three installation packages will be downloaded from the MongoDB official website

Mongodb-org-server-4.2.2-1.el6.x86_64.rpm # MongoDB services, configuration files, startup scripts

Mongodb-org-shell-4.2.2-1.el6.x86_64.rpm # contains shell commands related to mongo operations

Mongodb-org-tools-4.2.2-1.el6.x86_64.rpm # toolset for backup and analysis of MongoDB

1. Install server# rpm-ivh mongodb-org-server-4.2.2-1.el6.x86_64.rpm# / etc/init.d/mongod startstarting mongod: [OK] 2. The installation command line is used to login to mongodb# rpm-ivh mongodb-org-shell-4.2.2-1.el6.x86_64.rpm# mongo > show dbs;admin 0.000GBconfig 0.000GBlocal 0.000GB3. Set the administrator password for MongoDB > use adminswitched to db admin > db.createUser ({user: "admin", pwd: "test123", roles: [{role: "userAdminAnyDatabase", db: "admin"}]}) Successfully added user: {"user": "admin_root", "roles": [{"role": "userAdminAnyDatabase" "db": "admin"}]} # # verify login If 1 is returned, it proves that the password is valid > db.auth ("admin", "test123") 14. Create a db library test And assign account and password * # login administrator > use admin > db.auth ("admin", "test123") # create test library > use test > db.createUser ({user: "test", pwd: "test123", roles: [{role: "dbOwner", db: "test"}]}) Successfully added user: {"user": "test", "roles": [{"role": "dbOwner" "db": "test"}]} # the program can call the following link: some failures that cannot be started in mongodb://test:test123@localhost/test operation and maintenance

1. After the service restart, there will be a problem that it cannot be opened. Look up the log as follows

# / etc/init.d/mongod startstarting mongod: [FAILED] # tail-f / var/log/mongdb/mongod.log2019-12-25T10:43:44.336+0800 I CONTROL [initandlisten] distarch: x86 * 642019-12-25T10:43:44.336+0800 I CONTROL [initandlisten] target_arch: x86 * 642019-12-25T10:43:44.336+0800 I CONTROL [initandlisten] options: {config: "/ etc/mongod.conf" Net: {bindIp: "127.0.0.1", port: 27017}, processManagement: {fork: true, pidFilePath: "/ var/run/mongodb/mongod.pid", timeZoneInfo: "/ usr/share/zoneinfo"}, storage: {dbPath: "/ var/lib/mongo", journal: {enabled: true}}, systemLog: {destination: "file", logAppend: true Path: "/ var/log/mongodb/mongod.log"} 2019-12-25T10:43:44.336+0800 E NETWORK [initandlisten] Failed to unlink socket file / tmp/mongodb-27017.sock Operation not permitted2019-12-25T10:43:44.336+0800 F-[initandlisten] Fatal Assertion 40486 at src/mongo/transport/transport_layer_asio.cpp 6932019-12-25T10:43:44.336+0800 F-[initandlisten] * * aborting after fassert () failure

Solution:

# rm-fr / tmp/mongodb-27017.sock# / etc/init.d/mongod startstarting mongod: [OK]

Tags: Password login command administrator service management configuration three backup tool fault file method log purpose program script account link question Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi vpn Shulou Tech Info Huawei MariaDB