分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow
也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!
MongoDB是一个基于分布式文件存储的数据库。由C++语言编写。旨在为WEB应用提供可扩展的高性能数据存储解决方案。它以高性能、易部署、易使用,存储数据非常方便等优点被广泛使用。其安装配置相当简单,有如轻量级的mysql,但功能丝毫不差。本文主要描述mongoDB的启动与停止。
一、准备环境
1、当前环境# more /etc/redhat-release CentOS release 6.7 (Final)
- 1
- 2
- 3
2、安装mongod# which mongod/var/lib/mongodb/bin/mongod
- 1
- 2
- 3
参考:
Linux下快速安装MongoDB
Windows平台下安装MongoDB
3、创建数据目录# mkdir -pv /data/mongodata/{rs1,rs2,rs3}# mkdir -pv /var/lib/mongodb/conf
- 1
- 2
- 3
二、启动mongodb
1、基于命令行方式启动mongodb# mongod --dbpath=/data/mongodata/rs1 --logpath=/data/mongodata/rs1/rs1.log &缺省端口为[root@node3 rs1]# netstat -nltp|grep mongodtcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 5062/mongod 2、基于配置文件的命令行启动vi /var/lib/mongodb/conf/rs2.confport = 27000dbpath = /data/mongodata/rs2logpath = /data/mongodata/rs2/rs2.logsmallfiles = truefork = truepidfilepath = /var/run/mongo.pid# mongod --config /var/lib/mongodb/conf/rs2.conf &### Author : Leshami### Blog : http://blog.csdn.net/leshami# netstat -nltp|grep 27000tcp 0 0 0.0.0.0:27000 0.0.0.0:* LISTEN 5356/mongod 3、以守护进程方式启动mongodb# mongod --dbpath=/data/mongodata/rs3 --logpath=/data/mongodata/rs1/rs3.log --fork --port 28000# netstat -nltp|grep mongodtcp 0 0 0.0.0.0:28000 0.0.0.0:* LISTEN 5465/mongod tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 5435/mongod tcp 0 0 0.0.0.0:27000 0.0.0.0:* LISTEN 5448/mongod4、使用系统服务的方式启动mogodb启动脚本# vi /etc/init.d/mongod#!/bin/sh # chkconfig: 2345 93 18 #MogoDB home directory MONGODB_HOME=/var/lib/mongodb#mongodb command MONGODB_BIN=$MONGODB_HOME/bin/mongod#mongodb config fileMONGODB_CONF=$MONGODB_HOME/conf/mongodb.conf#mongodb PIDMONGODB_PID=/var/run/mongo.pid#set open file limitSYSTEM_MAXFD=65535MONGODB_NAME="mongodb". /etc/rc.d/init.d/functionsif [ ! -f $MONGODB_BIN ]then echo "$MONGODB_NAME startup: $MONGODB_BIN not exists! " exitfistart(){ ulimit -HSn $SYSTEM_MAXFD $MONGODB_BIN --config="$MONGODB_CONF" --fork ##added @20160901 ret=$? if [ $ret -eq 0 ]; then action $"Starting $MONGODB_NAME: " /bin/true else action $"Starting $MONGODB_NAME: " /bin/false fi}stop(){ PID=$(ps aux |grep "$MONGODB_NAME" |grep "$MONGODB_CONF" |grep -v grep |wc -l) if [[ $PID -eq 0 ]];then action $"Stopping $MONGODB_NAME: " /bin/false exit fi kill -HUP `cat $MONGODB_PID` ret=$? if [ $ret -eq 0 ]; then action $"Stopping $MONGODB_NAME: " /bin/true rm -f $MONGODB_PID else action $"Stopping $MONGODB_NAME: " /bin/false fi}restart() { stop sleep 2 start}case "$1" in start) start ;; stop) stop ;; status) status $prog ;; restart) restart ;; *) echo $"Usage: $0 {start|stop|status|restart}"esac# chmod u+x /etc/init.d/mongod# service mongod startabout to fork child process, waiting until server is ready for connections.forked process: 5543child process started successfully, parent exitingStarting mongodb: [ OK ]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
三、停止mongoDB
1、向mongod进程发送信号###SIGINT信号# ps -ef|grep mongod|grep rs1root 5435 4914 1 19:13 pts/2 00:00:14 mongod --dbpath=/data/mongodata/rs1 --logpath=/data/mongodata/rs1/rs1.log# kill -2 54352016-08-30T17:02:00.528+0800 I CONTROL[signalProcessingThread] got signal 2(Interrupt), will terminate after current cmd ends2016-08-30T17:02:00.530+0800 I REPL [signalProcessingThread] Stopping replication applier threads2016-08-30T17:02:00.554+0800 I STORAGE [conn1253] got request after shutdown()2016-08-30T17:02:00.774+0800 I CONTROL [signalProcessingThread] now exiting2016-08-30T17:02:00.774+0800 I NETWORK [signalProcessingThread] shutdown: going to close listening sockets...2016-08-30T17:02:00.774+0800 I NETWORK [signalProcessingThread] closing listening socket: 62016-08-30T17:02:00.775+0800 I NETWORK [signalProcessingThread] closing listening socket: 72016-08-30T17:02:00.775+0800 I NETWORK [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock2016-08-30T17:02:00.775+0800 I NETWORK [signalProcessingThread] shutdown: going to flush diaglog...2016-08-30T17:02:00.775+0800 I NETWORK [signalProcessingThread] shutdown: going to close sockets...2016-08-30T17:02:00.775+0800 I STORAGE [signalProcessingThread] shutdown: waiting for fs preallocator...2016-08-30T17:02:00.775+0800 I STORAGE [signalProcessingThread] shutdown: final commit...2016-08-30T17:02:00.775+0800 I JOURNAL [signalProcessingThread] journalCleanup...2016-08-30T17:02:00.775+0800 I JOURNAL [signalProcessingThread] removeJournalFiles2016-08-30T17:02:00.777+0800 I NETWORK [conn1254] end connection 192.168.1.247:58349 (0 connections now open)2016-08-30T17:02:00.779+0800 I JOURNAL [signalProcessingThread] Terminating durability thread ...2016-08-30T17:02:00.881+0800 I JOURNAL [journal writer] Journal writer thread stopped2016-08-30T17:02:00.882+0800 I JOURNAL [durability] Durability thread stopped2016-08-30T17:02:00.882+0800 I STORAGE [signalProcessingThread] shutdown: closing all files...2016-08-30T17:02:00.884+0800 I STORAGE [signalProcessingThread] closeAllFiles() finished2016-08-30T17:02:00.884+0800 I STORAGE [signalProcessingThread] shutdown: removing fs lock...2016-08-30T17:02:00.885+0800 I CONTROL [signalProcessingThread] dbexit: rc: 0###SIGTERM信号# ps -ef|grep mongod|grep rs3# ps -ef|grep mongod|grep rs3root 5465 1 1 19:14 ? 00:00:13 mongod --dbpath=/data/mongodata/rs3 --logpath=/data/mongodata/rs1/rs3.log --fork --port 28000# kill -4 5465信号 产生方式 sigint 通过ctrl+c将会对当进程发送此信号 sigterm kill命令不加参数就是发送这个信号 对进程的影响 sigint 信号被当前进程树接收到,也就是说,不仅当前进程会收到信号,它的子进程也会收到 sigterm只有当前进程收到信号,子进程不会收到。如果当前进程被kill了,那么它的子进程的父进程将会是init,也就是pid为1的进程上述信号在发出后 不再接受新的连接请求 等待现有的连接处理完毕 关闭所有打开的连接 将内存的数据写出到磁盘 安全停止2、使用系统服务脚本方式停止mongod # ps -ef|grep mongod root 5675 1 3 19:33 ? 00:00:00 /var/lib/mongodb/bin/mongod --config=/var/lib/mongodb/conf/rs2.conf root 5689 4950 0 19:33 pts/3 00:00:00 grep mongod [root@node3 conf]# [root@node3 conf]# service mongod stop Stopping mongodb: [ OK ]3、db.shutdownServer()方式 # mongo localhost:27000 > use admin > db.shutdownServer()4、使用命令行方式关闭(补充@20160901) # mongod -f /etc/mongo-m.conf --shutdown5、强制关闭mongod # kill -9 5675 缺点: 数据库直接关闭 数据丢失 数据文件容易损坏(需要进行修复)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
给我老师的人工智能教程打call!http://blog.csdn.net/jiangjunshow
![这里写图片描述](https://i-blog.csdnimg.cn/blog_migrate/2e19ffb3303a490d20ea5d00dd397156.gif)