In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
MongoDB is a database based on distributed file storage. Written in C++ language. Designed to provide scalable high-performance data storage solutions for WEB applications. It is widely used because of its high performance, easy to deploy, easy to use, convenient data storage and so on. Its installation and configuration is quite simple, like a lightweight mysql, but the functionality is exactly the same. This article mainly describes the start and stop of mongoDB.
First, prepare the environment
1. Current environment
# more / etc/redhat-release
CentOS release 6.7 (Final)
2. Install mongod
# which mongod
/ var/lib/mongodb/bin/mongod
Reference:
Quick installation of MongoDB under Linux
Install MongoDB on Windows platform
3. Create a data directory
# mkdir-pv / data/mongodata/ {rs1,rs2,rs3}
# mkdir-pv / var/lib/mongodb/conf
2. Start mongodb
1. Start mongodb based on the command line
# mongod-dbpath=/data/mongodata/rs1-logpath=/data/mongodata/rs1/rs1.log &
The default port is
[root@node3 rs1] # netstat-nltp | grep mongod
Tcp 0 0 0.0.0 0 27017 0.0.0 0 15 * LISTEN 5062/mongod
2. Command line startup based on configuration file
Vi / var/lib/mongodb/conf/rs2.conf
Port = 27000
Dbpath = / data/mongodata/rs2
Logpath = / data/mongodata/rs2/rs2.log
Smallfiles = true
Fork = true
Pidfilepath = / var/run/mongo.pid
# mongod-- config / var/lib/mongodb/conf/rs2.conf &
# Author: Leshami
# Blog: http://blog.csdn.net/leshami
# netstat-nltp | grep 27000
Tcp 00 0.0.0.0 27000 0.0.0.015 * LISTEN 5356/mongod
3. Start mongodb in daemon mode
# mongod-dbpath=/data/mongodata/rs3-logpath=/data/mongodata/rs1/rs3.log-fork-port 28000
# netstat-nltp | grep mongod
Tcp 00 0.0.0.0 28000 0.0.0.015 * LISTEN 5465/mongod
Tcp 0 0 0.0.0 0 27017 0.0.0 0 15 * LISTEN 5435/mongod
Tcp 00 0.0.0.0 27000 0.0.0.015 * LISTEN 5448/mongod
4. Start mogodb by using system services
Startup script
# 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 file
MONGODB_CONF=$MONGODB_HOME/conf/mongodb.conf
# mongodb PID
MONGODB_PID=/var/run/mongo.pid
# set open file limit
SYSTEM_MAXFD=65535
MONGODB_NAME= "mongodb"
. / etc/rc.d/init.d/functions
If [!-f $MONGODB_BIN]
Then
Echo "$MONGODB_NAME startup: $MONGODB_BIN not exists!"
Exit
Fi
Start () {
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 uplix / etc/init.d/mongod
# service mongod start
About to fork child process, waiting until server is ready for connections.
Forked process: 5543
Child process started successfully, parent exiting
Starting mongodb: [OK]
3. Stop mongoDB
1. Send signals to the mongod process
# SIGINT signal
# ps-ef | grep mongod | grep rs1
Root 5435 4914 1 19:13 pts/2 00:00:14 mongod-dbpath=/data/mongodata/rs1-logpath=/data/mongodata/rs1/rs1.log
# kill-2 5435
2016-08-30T17:02:00.528+0800 I CONTROL [signalProcessingThread] got signal 2 (Interrupt), will terminate after current cmd ends
2016-08-30T17:02:00.530+0800 I REPL [signalProcessingThread] Stopping replication applier threads
2016-08-30T17:02:00.554+0800 I STORAGE [conn1253] got request after shutdown ()
2016-08-30T17:02:00.774+0800 I CONTROL [signalProcessingThread] now exiting
2016-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: 6
2016-08-30T17:02:00.775+0800 I NETWORK [signalProcessingThread] closing listening socket: 7
2016-08-30T17:02:00.775+0800 I NETWORK [signalProcessingThread] removing socket file: / tmp/mongodb-27017.sock
2016-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] removeJournalFiles
2016-08-30T17:02:00.777+0800 I NETWORK [conn1254] end connection 192.168.1.247 30T17:02:00.777+0800 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 stopped
2016-08-30T17:02:00.882+0800 I JOURNAL [durability] Durability thread stopped
2016-08-30T17:02:00.882+0800 I STORAGE [signalProcessingThread] shutdown: closing all files...
2016-08-30T17:02:00.884+0800 I STORAGE [signalProcessingThread] closeAllFiles () finished
2016-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 signal
# ps-ef | grep mongod | grep rs3
# ps-ef | grep mongod | grep rs3
Root 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
Signal generation mode
Sigint will send this signal to the current process through ctrl+c
The sigterm kill command sends this signal with no arguments.
Impact on the process
The sigint signal is received by the current process tree, that is, not only the current process will receive the signal, but also its child processes
Sigterm only the current process receives the signal, and the child process does not receive it. If the current process is kill, the parent of its child process will be init, that is, the process with pid 1
After the above signal is sent,
New connection requests are no longer accepted
Wait for the existing connection to be processed
Close all open connections
Write out the data in memory to disk
Safe stop
2. Stop mongod by using system service script
# 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 () mode
# mongo localhost:27000
> use admin
> db.shutdownServer ()
4. Use command-line shutdown (supplement @ 20160901)
# mongod-f / etc/mongo-m.conf-- shutdown
5. Force the shutdown of mongod
# kill-9 5675
Disadvantages:
Database shuts down directly
Data loss
The data file is easily damaged (needs to be repaired)
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.