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-linux-2.4.10-X86_64 (install under centos/linux, start service script)

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

Share

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

1, download

Get the downloaded version mongodb-linux-x86_64-2.4.10.tgz from http://www.mongodb.org/downloads

2, add users

Groupadd mongod

Useradd-s / sbin/nologin-M-g mongod mongod

3, decompress and move to the appropriate location

[root@localhost] # tar-zxvf mongodb-linux-x86_64-2.4.10.tgz

[root@localhost] # cd mongodb-linux-x86_64-2.4.10

[root@localhost mongodb-linux-x86_64-2.4.10] # ls

Bin GNU-AGPL-3.0 README THIRD-PARTY-NOTICES

[root@localhost mongodb-linux-x86_64-2.4.10] # cd bin/

[root@localhost bin] # ls

Bsondump mongo mongod mongodump mongoexport mongofiles mongoimport mongooplog mongoperf mongorestore mongos mongosniff mongostat mongotop

[root@localhost] # mv mongodb-linux-x86_64-2.4.10 / mongodb

Set its directory permissions if necessary

Chmod 755 / mongodb-linux-x86_64-2.4.10 /-R

Soft links to system directory commands can be established if necessary

Ln-s / mongodb/bin/mongo / usr/bin/mongo

Ln-s / mongodb/bin/mongod / usr/bin/mongod

3. Set up the running directory manually and authorize it

Mkdir-p date

Mkdir-p logs

Mkdir-p conf

Mkdir-p run

Chmod Ubunw data-R

Chmod Ubunw logs-R

Chmod Ubunw run-R

Chown-R mongod:mongod date logs run

4, create a configuration file

Vim etc/mongod.conf

[root@localhost conf] # cat mongod.conf

# Start MongoDB as a daemon on port 8908

Port = 8908

Fork = true # daemonize it!

Journal = true #

Rest = true

Logappend = true

Auth = true

Dbpath = / mongodb/data/

Logpath = / mongodb/logs/mongod.log

Pidfilepath = / mongodb/run/mongod.pid

= =

Note: for more startup parameters, please use the following command in your mongodb home directory bin directory to view the startup parameters:

[root@localhost bin] # pwd

/ mongodb/bin

[root@localhost bin] #. / mongod-help

Allowed options:

General options:

-h [--help] show this usage information

-- version show version information

-f [--config] arg configuration file specifying additional options

-v [--verbose] be more verbose (include multiple times for more

Verbosity e.g.-vvvvv)

-- quiet quieter output

-- port arg specify port number-27017 by default

-- bind_ip arg comma separated list of ip addresses to listen on

-all local ips by default

-- maxConns arg max number of simultaneous connections-20000 by

Default

-- logpath arg log file to send write to instead of stdout-has

To be a file, not directory

-- logappend append to logpath instead of over-writing

-- pidfilepath arg full path to pidfile (if not set, no pidfile is

Created)

-- keyFile arg private key for cluster authentication

-- setParameter arg Set a configurable parameter

-- nounixsocket disable listening on unix sockets

-- unixSocketPrefix arg alternative directory for UNIX domain sockets

(defaults to / tmp)

-- fork fork server process

-- syslog log to system's syslog facility instead of file

Or stdout

-- auth run with security

-- cpu periodically show cpu and iowait utilization

-- dbpath arg directory for datafiles-defaults to / data/db/

-- diaglog arg 0=off 1 W 2R 3=both 7=W+some reads

-- directoryperdb each database will be stored in a separate

Directory

-- ipv6 enable IPv6 support (disabled by default)

-- journal enable journaling

-- journalCommitInterval arg how often to group/batch commit (ms)

-- journalOptions arg journal diagnostic options

-jsonp allow JSONP access via http (has security

Implications)

-- noauth run without security

-- nohttpinterface disable httpinterface

-nojournal disable journaling (journaling is on by default

For 64 bit)

-- noprealloc disable data file preallocation-will often hurt

Performance

-- noscripting disable scripting engine

-- notablescan do not allow table scans

-- nssize arg (= 16) .ns file size (in MB) for new databases

-- profile arg 0=off 1=slow, 2=all

-- quota limits each database to a certain number of files

(8 default)

-quotaFiles arg number of files allowed per db, requires-- quota

-- repair run repair on all dbs

-- repairpath arg root directory for repair files-defaults to

Dbpath

-- rest turn on simple rest api

-- shutdown kill a running server (for init scripts)

-slowms arg (= 100) value of slow for profile and console log

-- smallfiles use a smaller default file size

-- syncdelay arg (= 60) seconds between disk syncs (0=never, but not

Recommended)

-- sysinfo print some diagnostic system information

-- upgrade upgrade db if needed

Replication options:

OplogSize arg size to use (in MB) for replication op log. Default is

5% of disk space (i.e. Large is good)

Master/slave options (old; use replica sets instead):

-- master master mode

-- slave slave mode

-- source arg when slave: specify master as

-- only arg when slave: specify a single database to replicate

-slavedelay arg specify delay (in seconds) to be used when applying

Master ops to slave

-- autoresync automatically resync if slave data is stale

Replica set options:

-- replSet arg arg is [/]

-- replIndexPrefetch arg specify index prefetching behavior (if secondary)

[none | _ id_only | all]

Sharding options:

-- configsvr declare this is a config db of a cluster; default port

27019; default dir / data/configdb

-- shardsvr declare this is a shard db of a cluster; default port

27018

5. Create the startup service file

[root@localhost conf] # cat / etc/init.d/mongod

#! / bin/bash

# mongod-Startup script for mongod

# chkconfig: 35 85 15

# description: Mongo is a scalable, document-oriented database.

# processname: mongod

# config: / etc/mongod.conf

# pidfile: / var/run/mongo/mongod.pid

. / etc/rc.d/init.d/functions

# things from mongod.conf get there by mongod reading it

# NOTE: if you change any OPTIONS here, you get what you pay for:

# this script assumes all options are in the config file.

BASEDIR= "/ mongodb"

CONFIGFILE= "$BASEDIR/conf/mongod.conf"

OPTIONS= "- f $CONFIGFILE"

SYSCONFIG= "/ etc/sysconfig/mongod"

# FIXME: 1.9.x has a-- shutdown flag that parses the config file and

# shuts down the correct running pid, but that's unavailable in 1.8

# for now. This can go away when this script stops supporting 1.8.

DBPATH= `awk-F ='/ ^ dbpath=/ {print $2}'"$CONFIGFILE" `

PIDFILE= `awk-F ='/ ^ dbpath\ s =\ s / {print $2}'"$CONFIGFILE" `

Mongod=$ {MONGOD-$BASEDIR/bin/mongod}

MONGO_USER=mongod

MONGO_GROUP=mongod

If [- f "$SYSCONFIG"]; then

. "$SYSCONFIG"

Fi

# Handle NUMA access to CPUs (SERVER-3574)

# This verifies the existence of numactl as well as testing that the command works

NUMACTL_ARGS= "--interleave=all"

If which numactl > / dev/null 2 > / dev/null & & numactl $NUMACTL_ARGS ls / > / dev/null 2 > / dev/null

Then

NUMACTL= "numactl $NUMACTL_ARGS"

Else

NUMACTL= ""

Fi

Start ()

{

Echo-n $"Starting mongod:"

Daemon-- user "$MONGO_USER" $NUMACTL $mongod $OPTIONS

RETVAL=$?

Echo

[$RETVAL-eq 0] & & touch / var/lock/subsys/mongod

}

Stop ()

{

Echo-n $"Stopping mongod:"

Killproc-p "$PIDFILE"-d 300 / usr/bin/mongod

RETVAL=$?

Echo

[$RETVAL-eq 0] & & rm-f / var/lock/subsys/mongod

}

Restart () {

Stop

Start

}

Ulimit-n 12000

RETVAL=0

Case "$1" in

Start)

Start

Stop)

Stop

Restart | reload | force-reload)

Restart

Condrestart)

[- f / var/lock/subsys/mongod] & & restart | |:

Status)

Status $mongod

RETVAL=$?

*)

Echo "Usage: $0 {start | stop | status | restart | reload | force-reload | condrestart}"

RETVAL=1

Esac

Exit $RETVAL

6. Start the service

[root@localhost logs] # service mongod restart

Stopping mongod: [failed]

Starting mongod: about to fork child process, waiting until server is ready for connections.

Forked process: 1605

All output going to: / mongodb/logs/mongod.log

Child process started successfully, parent exiting

[OK]

[root@localhost logs] # ps-ef | grep mongod

Root 1407 1346 0 17:08 pts/1 00:00:00 vim / etc/init.d/mongod

Mongod 1564 1 1 17:13? 00:00:00 / mongodb/bin/mongod-f / mongodb/conf/mongod.conf

Root 1577 1410 0 17:14 pts/2 00:00:00 grep mongod

[root@localhost logs] # lsof-iRu 8908

-bash: lsof: command not found

[root@localhost logs] # netstat-anpt

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

Tcp 0 0 0.0.0. 0 8908 0.0.0. 0 LISTEN 1564/mongod

Tcp 0 0 0.0.0. 0 9908 0.0.0. 0 LISTEN 1564/mongod

7shell enters the service command line to view

The system uses the 270117 port number by default, so the login is not successful

[root@localhost bin] #. / mongo

MongoDB shell version: 2.4.10

Connecting to: test

Wed May 21 17:28:09.809 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145

Exception: connect failed

Because the port number has been changed, you need to specify the port number when using it.

[root@localhost bin] #. / mongo-port 8908

MongoDB shell version: 2.4.10

Connecting to: 127.0.0.1:8908/test

Welcome to the MongoDB shell.

For interactive help, type "help".

For more comprehensive documentation, see

Http://docs.mongodb.org/

Questions? Try the support group

Http://groups.google.com/group/mongodb-user

>

Check the data directory and automatically generate the following files

[root@localhost mongodb] # cd data/

[root@localhost data] # ll

The total dosage is 507936

-rw- 1 mongod mongod 67108864 May 21 17:37 admin.0

-rw- 1 mongod mongod 134217728 May 21 17:37 admin.1

-rw- 1 mongod mongod 16777216 May 21 17:37 admin.ns

Drwxr-xr-x 2 mongod mongod 4096 May 21 18:01 journal

-rw- 1 mongod mongod 67108864 May 21 18:01 local.0

-rw- 1 mongod mongod 16777216 May 21 18:01 local.ns

-rwxr-xr-x 1 mongod mongod May 21 18:01 mongod.lock

-rw- 1 mongod mongod 67108864 May 21 18:02 test.0

-rw- 1 mongod mongod 134217728 May 21 18:00 test.1

-rw- 1 mongod mongod 16777216 May 21 18:02 test.ns

OK. The above situation is considered to be successful and the service is running normally.

8, basic user management-commands are case sensitive

Http://blog.51yip.com/nosql/1575.html, please refer to this blog post.

9, more shell operation management commands

Please check the http://quanzhong.iteye.com/blog/916237 blog post.

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