中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MongoDB-linux-2.4.10-X86_64(centos/linux下安裝,啟動服務腳本)

發布時間:2020-09-06 06:39:04 來源:網絡 閱讀:2017 作者:gmx200406 欄目:MongoDB數據庫

1,下載

 從http://www.mongodb.org/downloads獲取下載版本mongodb-linux-x86_64-2.4.10.tgz


2,添加用戶

groupadd mongod 

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

 

3,解壓并移動到相應位置

[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


如有必要可設置其目錄權限

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

如有必要可建立系統目錄命令軟鏈接

ln -s /mongodb/bin/mongo /usr/bin/mongo 

ln -s /mongodb/bin/mongod /usr/bin/mongod 


3,手工建立運行目錄并授權

mkdir -p date

mkdir -p logs

mkdir -p conf

mkdir -p run

chmod u+w data -R 

chmod u+w logs -R 

chmod u+w run -R 

chown -R mongod:mongod date logs run


4,建立配置文件

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


=======================================

注:如果更多的啟動參數,請在你的mongodb主目錄bin目錄下使用如下命令查看啟動參數:

[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 2=R 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 http interface

  --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 <server:port>

  --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 <setname>[/<optionalseedhostlist>]

  --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,建立啟動服務文件

[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,啟動服務

[root@localhost logs]# service mongod restart  

Stopping mongod:                                           [失敗]

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

                                                           [確定]

[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 -i: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         


7,shell進入服務命令行查看

系統默認使用270117端口號,故登錄不成功

[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


由于改變了端口號,故使用時需要指定端口號

[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


查看data目錄,自動生成如下文件

[root@localhost mongodb]# cd data/

[root@localhost data]# ll

總用量 507936

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

-rw------- 1 mongod mongod 134217728 5月  21 17:37 admin.1

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

drwxr-xr-x 2 mongod mongod      4096 5月  21 18:01 journal

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

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

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

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

-rw------- 1 mongod mongod 134217728 5月  21 18:00 test.1

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

OK,以上情況視為安裝成功,服務正常運行


8,基本用戶管理--命令區分大小寫

http://blog.51yip.com/nosql/1575.html 請參考該博文


9,更多shell操作管理命令

請查看http://quanzhong.iteye.com/blog/916237 博文


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

阜城县| 南宁市| 彩票| 乐安县| 乌兰县| 故城县| 武川县| 柳林县| 家居| 哈密市| 吉隆县| 仁化县| 龙南县| 抚宁县| 乐亭县| 琼结县| 郑州市| 襄汾县| 虞城县| 北宁市| 临沧市| 新巴尔虎右旗| 措美县| 托克逊县| 确山县| 泸水县| 西盟| 高阳县| 赣州市| 德阳市| 滕州市| 东平县| 营口市| 晋城| 和静县| 白朗县| 临朐县| 荣成市| 阜康市| 巴东县| 宝山区|