linux system MongoDB single node installation tutorial
- 2020-06-19 12:27:41
- OfStack
preface
MongoDB is a high-performance, open source, no model, based on the distributed file storage, document databases, believe no stranger to everyone, but here more introduced, this paper mainly introduced about mongo single node installation tutorial (linux), share out for your reference learning, few words said, below 1 look at the detailed installation process.
The installation package
Download address: (https: / / www. mongodb. com/download - center)
User permissions/directory
1. Create dbuser user
groupadd dbgroup
useradd dbuser -m -d /home/dbuser -g dbgroup
2. Deployment directory
mkdir -p /opt/local
chown -R dbuser:dbgroup /opt/local
cd /opt/local
3. Unzip the installation package
tar -xzvf mongodb-linux-x86_64-enterprise-suse11-3.2.7.tgz
mv mongodb-linux-x86_64-enterprise-suse11-3.2.7 mongodb
cd mongodb
mkdir conf data log
conf as profile directory data as data file directory log as log file directory
The configuration file
vim conf/mongo.conf
storage:
dbPath: "/opt/local/mongodb/data/"
engine: wiredTiger
# directoryPerDB: true
journal:
enabled: true
systemLog:
destination: file
path: "/opt/local/mongodb/log/mongodb.log"
logAppend: true
# timeStampFormat: iso8601-utc
operationProfiling:
slowOpThresholdMs: 10000
replication:
oplogSizeMB: 700
processManagement:
fork: true
pidFilePath: "/opt/local/mongodb/mongod.pid"
net:
port: 27017
http:
enabled: false
unixDomainSocket:
enabled : false
The startup port is 27017, and the http management interface is closed. slowOpThredsholdMs is the threshold for slow operation detection, which can be adjusted as needed;
Initialize the
1. Start mongod, which can be accessed anonymously by default
./bin/mongod -f conf/mongodb.conf
2. Connect to mongo
./bin/mongo --port 27017
3. Initialize the administrator
use admin
db.createUser({user:'admin',pwd:'admin@2016',roles:[{role:'clusterAdmin',db:'admin'},{role:'userAdminAnyDatabase',db:'admin'}]})
use appdb
db.createUser({user:'appuser',pwd:'appuser@2016',roles:[{role:'dbOwner',db:'appdb'}]})
4. Created administrator user and application account respectively, and then
Restart mongo to enable authentication
pkill mongod
./bin/mongod -f conf/mongodb.conf -auth
Connecting to mongo thereafter requires authentication
Common commands
Start the command
./bin/mongod -f conf/mongodb.conf
Stop command
kill -2 `cat mongod.pid`
rm mongod.pid
Test port
mkdir -p /opt/local
chown -R dbuser:dbgroup /opt/local
cd /opt/local
0
See the log
mkdir -p /opt/local
chown -R dbuser:dbgroup /opt/local
cd /opt/local
1
End connections
mkdir -p /opt/local
chown -R dbuser:dbgroup /opt/local
cd /opt/local
2
Monitoring commands
./bin/mongostat --port 27071 -u admin -p admin@2016 --authenticationDatabase=admin --discover -n 30 3
conclusion