Linux installation Configuration MongoDB 3.0 version of the database tutorial

Source: Internet
Author: User
Tags auth eval install mongodb mkdir mongodb mongodb download iptables firewall

Description

Operating system: CentOS 5.X 64-bit

IP Address: 192.168.21.128

To achieve the purpose:

Install Configuration MongoDB Database

Specific actions:

First, close the SELinux, configure the firewall

1, Vi/etc/selinux/config

#SELINUX =enforcing #注释掉

#SELINUXTYPE =targeted #注释掉

Selinux=disabled #增加

: wq! #保存退出

Setenforce 0 #使配置立即生效

2, Vi/etc/sysconfig/iptables #编辑

-A rh-firewall-1-input-m state--state new-m tcp-p TCP--dport 27017-j ACCEPT #允许27017端口通过防火墙

: wq! #保存退出

/etc/init.d/iptables Restart #重启防火墙使配置生效

Second, install MongoDB

MongoDB Download Address: https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz #目前最新版

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

CD/USR/LOCAL/SRC #进入软件存放目录

Tar zxvf mongodb-linux-x86_64-3.0.6.tgz #解压

MV Mongodb-linux-x86_64-3.0.6/usr/local/mongodb #移动解压文件夹到MongoDB安装目录

Mkdir-p/data/mongodb/mongodb_data/#创建MongoDB数据库存放路径

Mkdir-p/data/mongodb/mongodb_log/#创建MongoDB数据库日志存放路径

#启动MongoDB

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

NETSTAT-LANP | grep "27017" #查看MongoDB是否启动

cd/usr/local/mongodb/bin/

./mongo #进入MongoDB数据库控制台

Use admin #进入admin数据库

Db.shutdownserver () #关闭MongoDB数据库

Exit #退出

Third, set up MongoDB database

1, cd/usr/local/mongodb/#进入MongoDB安装目录

Vi/usr/local/mongodb/mongodb.conf #编辑

port=27017 #端口号

dbpath=/data/mongodb/mongodb_data/#数据库路径

Logpath=/data/mongodb/mongodb_log/mongodb.log #日志输出文件路径

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

Fork=true #设置后台运行

Logappend=true #日志输出方式

Shardsvr=true

#auth =true #开启认证

: wq! #保存退出

2, cd/usr/local/mongodb/bin/

/usr/local/mongodb/bin/mongod--config/usr/local/mongodb/mongodb.conf #启动MongoDB

/usr/local/mongodb/bin/mongo 127.0.0.1:27017/admin--eval "Db.shutdownserver ()" #关闭MongoDB

Vi/etc/rc.d/init.d/mongod #设置开机启动MongoDB

Ulimit-shn 655350

#!/bin/sh

# Chkconfig:-64 36

# Description:mongod

Case is 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! #保存退出

chmod +x/etc/rc.d/init.d/mongod #添加脚本执行权限

Chkconfig Mongod on #设置开机启动

Service Mongod Start #启动MongoDB

Note: If the Administrator account password is set, please use the following command

Account: Root

Password: 123456

/usr/local/mongodb/bin/mongo 127.0.0.1:27017/admin--eval "Db.auth (' root ', ' 123456 ');d b.shutdownserver ()"

/usr/local/mongodb/bin/mongo 127.0.0.1:27017/admin--eval "Db.auth (' root ', ' 123456 ');d b.stats ()"

3, Vi/etc/profile #添加环境变量, edit, add the following code on the last line

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

: wq! #保存退出

Source/etc/profile #使配置立即生效

MONGO #进入MongoDB控制台

Show DBS #查看默认数据库

Use admin #切换到admin数据库

Exit #退出MongoDB控制台

At this point, the MongoDB database installation configuration is complete.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.