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

Mongodb configuration

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Installation instructions

System environment: Centos-6.3

Installation software: mongodb-linux-x86_64-2.2.2.tgz

Download address: http://www.mongodb.org/downloads

Installation machine: 192.168.15.237

Upload location: / usr/local/

Software installation location: / usr/local/mongodb

Data storage location: / var/mongodb/data

Log location: / var/mongodb/logs

Check if mongodb is installed

Rpm-qa | grep mongodb

Service mongodb status

Installation

[root@localhost /] # cd usr/local/

[root@localhost /] # groupadd mongodb

[root@localhost /] # useradd mongodb-g mongodb

[root@localhost /] # cd / usr/local

[root@localhost local] # tar-zxv-f mongodb-linux-x86_64-2.2.2.tgz

[root@localhost local] # mv mongodb-linux-x86_64-2.2.2 mongodb

[root@localhost local] # chown-R mongodb: mongodb mongodb

[root@localhost local] # cd mongodb

[root@localhost mongodb] # mkdir / var/mongodb

[root@localhost mongodb] # mkdir / var/mongodb/data

[root@localhost mongodb] # mkdir / var/mongodb/logs

[root@localhost mongodb] # vi / etc/sysconfig/iptables / / add port 27017 to the firewall

[root@localhost mongodb] # service iptables restart / / restart the firewall

Configuration

Add CentOS boot entry

[root@localhost mongodb] # vi + / etc/rc.d/rc.local

Append the mongodb startup command to this file:

/ usr/local/mongodb/bin/mongod-dbpath=/var/mongodb/data-logpath / var/mongodb/logs/log.log-fork

Start mongodb

[root@localhost mongodb] #

/ usr/local/mongodb/bin/mongod-dbpath=/var/mongodb/data-logpath / var/mongodb/logs/log.log-fork

You can see the following message indicating that the installation has completed and started successfully:

Forked process: 18394

All output going to: / var/mongodb/logs/log.log test

# terminate the server process

Db.user.shutdownServer ()

# enter shell mode of mongodb

/ usr/local/mongodb/bin/mongo

# View database list

Show dbs

# switch / create database (the current database is automatically created when creating a collection (table))

Use admin

# add users

Db.addUser ("zhoulf", "123456", true)

# change password (change password for existing users)

Db.addUser ("zhoulf", "zhoulf")

# display current db status

Db.stats ()

# current db version

Db.version ()

# Delete the currently used database

Db.dropDatabase ()

# View the address of the linked machine of the current db

Db.getMongo ()

# simply insert data

Db.user.insert ({"fname": "zhoulf", "company": "navinfo"})

# insert data in a loop

For (var I = 1; I

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

Database

Wechat

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

12
Report