Install MongoDB database under Centos x64 bit

Source: Internet
Author: User
Tags gz file install mongodb mkdir mongodb centos

--Install MONGO
Operating system for Centos x64
Download the. tar.gz file at the official website

The code is as follows Copy Code
cd/data/
Http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.4.3.tgz
Tar zxf mongodb-linux-x86_64-2.4.3.tgz
MV mongodb-linux-x86_64-2.4.3 MongoDB


Increase MongoDB Users

The code is as follows Copy Code
[Root@test ~]# Groupadd MongoDB
[Root@test ~]# useradd-g MongoDB mongodb-s/bin/bash


Adding environment variables

The code is as follows Copy Code
echo "Export path= $PATH:/data/mongodb/bin" >>/etc/profile
Source/etc/profile


Create a table of contents

The code is as follows Copy Code
mkdir/data/mongodb27018
Mkdir/data/mongodb27018/data

Changing directory Properties

The code is as follows Copy Code
Chown-r Mongodb.mongodb/data/mongodb
Chown-r mongodb.mongodb/data/mongodb27018


To edit a configuration file:

The code is as follows Copy Code

Vi/data/mongodb27018/mongodb.conf

# mongo.conf

#where to log
Logpath=/data/mongodb27018/mongod.log

Logappend=true

# fork and run in background
Fork = True

Port = 27018

Dbpath=/data/mongodb27018/data

# Location of Pidfile
Pidfilepath =/data/mongodb27018/mongod.pid

# Disables Write-ahead journaling
# nojournal = True

# Enables periodic logging of CPU utilization and I/O wait
#cpu = True

# Turn On/off Security. Off is currently the default
#noauth = True
#auth = True

# Verbose logging output.
#verbose = True

# Inspect all client data for validity on receipt (useful for
# Developing drivers)
#objcheck = True

# Enable DB Quota Management
#quota = True

# Set oplogging level where n is
# 0=off (default)
# 1=w
# 2=r
# 3=both
# 7=w+some Reads
#diaglog = 0

# Ignore Query Hints
#nohints = True

# Disable The HTTP interface (Defaults to localhost:27018).
#nohttpinterface = True

# Turns off server-side scripting. This'll result in greatly limited
# functionality
#noscripting = True

# Turns off table scans. Any query so would do a table scan fails.
#notablescan = True

# Disable data File preallocation.
#noprealloc = True

# specify. ns file size for new databases.
# nssize = <size>

# Accout token for Mongo monitoring server.
#mms-token = <token>

# server name for Mongo monitoring server.
#mms-name = <server-name>

# Ping interval for Mongo monitoring server.
#mms-interval = <seconds>

# Replication Options

# in replicated MONGO databases, specify here whether this is a slave or master
#slave = True
#source = master.example.com
# Slave only:specify A single database to replicate
#only = master.example.com
# or
#master = True
#source = Www.111cn.net


Modifying a connection pool for a program automatically creates a database Hzresource

You can also manually create

The code is as follows Copy Code
#mongo--port 27018
Use Hzresource

You also need to create a table Db.renw.insert ({' abc ': ' 211 '})

The code is as follows Copy Code

--Start
Su-mongod-c/data/mongodb/bin/mongod-f/data/mongodb27018/mongod.conf
Or
Cd/data/mongodb/bin
Mongod-f mongo.conf

--Test upload file
Mongofiles--port 27018-d Hzresource put 820f2c09tw1dzbttirkqwj.jpg



Boot auto Start

The code is as follows Copy Code
echo "Su-mongod-c/data/mongodb/bin/mongod-f/data/mongodb27018/mongod.conf--logappend--port=27018--fork--directo Ryperdb--journal ">>/etc/rc.local

MongoDB Startup shutdown script
VI mongodb_start_stop.sh

#!/bin/bash
#使用 SH mongodb_start_stop.sh start
#使用 SH mongodb_start_stop.sh stop shutdown
Path=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
Export PATH
Ac=$1
function Start_mongodb () {
/data/mongodb/bin/mongod--config/data/mongodb27018/mongod.conf
Echo-e "MongoDB Start success! "
}

function Stop_mongodb () {
echo "is stopping ..."
Pid= ' ps-ef|grep '/data/mongodb27018/mongod.conf ' |grep-v Grep|awk ' {print $} ';
Echo $pid
if ["${pid}"!= "]; Then
Kill-2 ${pid};
Echo-e "MongoDB stop succeeding! "
Else
Echo-e "MongoDB has not been started! "
Fi
}

function Restart_mongodb () {
Stop_mongodb
Start_mongodb
}

If ["$ac" = "Start"]; Then
Start_mongodb
elif ["$ac" = "Stop"];then
Stop_mongodb
elif ["$ac" = = "restart"]; Then
Restart_mongodb
Fi
Exit 0
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.