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

How to install and configure MongoDB database in Linux

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Linux how to install and configure MongoDB database, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Description:

Operating system: CentOS 5.X 64-bit

IP address: 192.168.21.130

To achieve the goal:

Install and configure the MongoDB database

Specific operations:

First, close SElinux and configure firewall

1 、 vi / etc/selinux/config

# SELINUX=enforcing # comment out

# SELINUXTYPE=targeted # comment out

SELINUX=disabled # increased

: wq! # Save exit

Setenforce 0 # makes the configuration effective immediately

2. Edit vi / etc/sysconfig/iptables #

-A RH-Firewall-1-INPUT-m state-- state NEW-m tcp-p tcp-- dport 27017-j ACCEPT # allow port 27017 to pass through the firewall

: wq! # Save exit

/ etc/init.d/iptables restart # restart the firewall for the configuration to take effect

Second, install MongoDB

MongoDB download address: the latest version of https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.0.tgz #

Upload mongodb-linux-x86_64-2.6.0.tgz to the / usr/local/src directory

Cd / usr/local/src # enter the software storage directory

Tar zxvf mongodb-linux-x86_64-2.6.0.tgz # decompression

Mv mongodb-linux-x86_64-2.6.0 / usr/local/mongodb # move the extracted folder to the MongoDB installation directory

Mkdir-p / home/data/mongodb/mongodb_data/ # create MongoDB database storage path

Mkdir-p / home/data/mongodb/mongodb_log/ # create MongoDB database log storage path

# start MongoDB

/ usr/local/mongodb/bin/mongod-port 27017-fork-dbpath=/home/data/mongodb/mongodb_data/-logpath=/home/data/mongodb/mongodb_log/mongodb.log-logappend

Netstat-lanp | grep "27017" # check whether MongoDB is started

Cd / usr/local/mongodb/bin/

. / mongo # enter the MongoDB database console

Use admin # access to admin database

Db.shutdownServer () # shut down the MongoDB database

Exit # exit

System operation and maintenance www.osyunwei.com warm reminder: the original content of qihang01 all rights reserved, reprint please indicate the source and the original text chain

Third, set up the MongoDB database

1. Cd / usr/local/mongodb/ # enter the MongoDB installation directory

Vi / usr/local/mongodb/mongodb.conf # editing

Port=27017 # Port number

Dbpath=/home/data/mongodb/mongodb_data/ # database path

Logpath=/home/data/mongodb/mongodb_log/mongodb.log # Log output file path

Pidfilepath=/usr/local/mongodb/mongo.pid

Fork=true # set up background running

Logappend=true # Log output method

Shardsvr=true

Directoryperdb=true

# auth=true # enable authentication

: wq! # Save exit

2 、 cd / usr/local/mongodb/bin/

. / mongod-- config / usr/local/mongodb/mongodb.conf # launch MongoDB

. / mongo 127.0.0.1:27017/admin-- eval "db.shutdownServer ()" # close MongoDB

Vi / etc/rc.d/init.d/mongod # set boot MongoDB

Ulimit-SHn 655350

#! / bin/sh

# chkconfig:-64 36

# description:mongod

Case $1 in

Start)

/ usr/local/mongodb/bin/mongod-maxConns 20000-config / usr/local/mongodb/mongodb.conf

Stop)

/ usr/local/mongodb/bin/mongo 127.0.0.1:27017/admin-- eval "db.shutdownServer ()"

Status)

/ usr/local/mongodb/bin/mongo 127.0.0.1:27017/admin-- eval "db.stats ()"

Esac

: wq! # Save exit

Chmod + x / etc/rc.d/init.d/mongod # add script execution permissions

Chkconfig mongod on # set boot up

Service mongod start # launch MongoDB

System operation and maintenance www.osyunwei.com warm reminder: the original content of qihang01 all rights reserved, reprint please indicate the source and the original link

3. Vi / etc/profile # add environment variables, edit, and add the following code on the last line

Export PATH=$PATH:/usr/local/mongodb/bin

: wq! # Save exit

Source / etc/profile # makes the configuration effective immediately

Mongo # enter the MongoDB console

Show dbs # View default database

Use admin # switch to admin database

Exit # exit the MongoDB console

After reading the above, have you mastered how to install and configure MongoDB database in Linux? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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