Get the App
SLTechnology News&Howtos  ›  Database  › 

Mongodb installation, configuration and simple operation

Shulou Source: shulou.com Published: 2022-06-01 13:43:40 10月09日 Update

Development old driver has a demand for me to install a mongodb, in the Internet to consult some information tested several kinds of error is not the database command does not match, the following is relatively simple and not easy to error.

Get binary compressed package

wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.8.tgz

Extract to installation directory, create data directory, configure data directory path later in configuration file

tar -xf mongodb-linux-x86_64-rhel62-3.2.8.tgz -C /usr/local/

cd /usr/local/

mv mongodb-linux-x86_64-rhel62-3.2.8 mongodb

mkdir /usr/local/mongodb/data

edit the configuration file

vim /usr/local/mongodb/mongodb.conf

#Port

port=27017

#Data file storage directory

dbpath= /usr/local/mongodb/data

#Log file storage directory

logpath= /usr/local/mongodb/mongodb.log

#Write a journal by appending

logappend=true

#Enabled as a daemon, i.e. running in the background

fork=true

#Maximum number of simultaneous connections

maxConns=500

#Allow only local access

#bind_ip=127.0.0.1

#Enable validation

#auth = true

Configure environment variables

echo 'export PATH=$PATH:/usr/local/mongodb/bin'>>/etc/profile

. /etc/profile

Start mongodb

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

Connect to MongoDB

mongo

Create an administrative user (I don't know whether it is for the development user or for ordinary users in production)

use admin

db.createUser({user:'root',pwd:'woshichenshifei',roles:[{role:'dbAdminAnyDatabase',db:'admin'},{role:'userAdminAnyDatabase',db:'admin'}]})

Check whether the creation is successful and verify whether the user authentication is correct

db.auth('root','woshichenshifei')

If the developer needs to modify the password, modify it again.

db.changeUserPassword('root','chenshifei')

Create and delete databases and regular users of databases

use chenshifei

db.createUser({user:'chenshifei',pwd:'chenshifei',roles:[{role:'readWrite',db:'chenshifei'}]})

db.dropUser('chenshifei')

exit

quit()

Open configuration file auth verify, restart mongodb and reconnect

kill `ps -ef|grep mongodb|awk 'NR==1{print $2}'`

Remove #before auth

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

mongo localhost:27017/admin -u root -p chenshifei

Give the connection address, user, password to development or dba

Tags: Data user configuration file directory database development normal authentication password method log demand maximum not easy success binary variable driver at the same time Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei NVidia OPPO Reno MySQL Microsoft