M102: MongoDB for DBAs chapter 4 replication学习记录[通俗易懂]

M102: MongoDB for DBAs chapter 4 replication学习记录[通俗易懂]M102:MongoDBforDBAschapter4replication运行环境操作系统:windows10家庭中文版Mongodb:Mongodb3.4Mongodb安装路径:E:>MongoDB\Ser

M102:

M102: MongoDB for DBAs chapter 4 replication

运行环境

操作系统:windows 10 家庭中文版
Mongodb :Mongodb 3.4

Mongodb安装路径:E:>MongoDB\Server\3.4\bin\
Mongodb存储路径:E:>MongoDB\data

课后习题

4.1题目

Download Handouts:

replication.js

In this chapter’s homework we will create a replica set and add some data to it.

  1. Download the replication.js handout.

  2. We will create a three member replica set. Pick a root working directory to work in. Go to that directory in a console window.

Given we will have three members in the set, and three mongod processes, create three data directories:

mkdir 1
mkdir 2
mkdir 3
  1. We will now start a single mongod as a standalone server. Given that we will have three mongod processes on our single test server, we will explicitly specify the port numbers (this wouldn’t be necessary if we had three real machines or three virtual machines). We’ll also use the –smallfiles parameter and –oplogSize so the files are small given we have a lot of server processes running on our test PC.
# starting as a standalone server for problem 1:
mongod --dbpath 1 --port 27001 --smallfiles --oplogSize 50

Note: for all mongod startups in the homework this chapter, you can optionally use –logPath, –logappend, and –fork. Or, since this is just an exercise on a local PC, you could simply have a separate terminal window for all and forgo those settings. Run “mongod –help” for more info on those.

  1. In a separate terminal window (cmd.exe on Windows), run the mongo shell with the replication.js file:
mongo --port 27001 --shell replication.js

Then run in the shell:

homework.init()

This will load a small amount of test data into the database.

Now run:

homework.a()

and enter the result. This will simply confirm all the above happened ok.

解答

按题目要求下载了replication.js文件到路径E:\MongoDB\m201\chapter_4_replication

在data目录下创建3个空文件夹:

C:\Users\Shinelon>e:

E:\>cd MongoDB

E:\MongoDB>mkdir data\1

E:\MongoDB>mkdir data\2

E:\MongoDB>mkdir data\3

E:\MongoDB>dir data
 驱动器 E 中的卷是 tools
 卷的序列号是 7C2B-B6D8

 E:\MongoDB\data 的目录

2018/04/12  14:10    <DIR>          .
2018/04/12  14:10    <DIR>          ..
2018/04/12  14:10    <DIR>          1
2018/04/12  14:10    <DIR>          2
2018/04/12  14:10    <DIR>          3

按要求制定dbpath为创建的1文件夹,启动mongod服务:

E:\MongoDB>Server\3.4\bin\mongod.exe --dbpath data\1 --port 27001 --smallfiles --oplogSize 50
2018-04-11T23:12:34.999-0700 I CONTROL  [initandlisten] MongoDB starting : pid=8648 port=27001 dbpath=data\1 64-bit host=DESKTOP-MP9NVQ7
2018-04-11T23:12:34.999-0700 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2018-04-11T23:12:34.999-0700 I CONTROL  [initandlisten] db version v3.4.6
2018-04-11T23:12:34.999-0700 I CONTROL  [initandlisten] git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5
2018-04-11T23:12:34.999-0700 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips  22 Sep 2016
2018-04-11T23:12:34.999-0700 I CONTROL  [initandlisten] allocator: tcmalloc
2018-04-11T23:12:35.000-0700 I CONTROL  [initandlisten] modules: none
2018-04-11T23:12:35.000-0700 I CONTROL  [initandlisten] build environment:
2018-04-11T23:12:35.000-0700 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2018-04-11T23:12:35.001-0700 I CONTROL  [initandlisten]     distarch: x86_64
2018-04-11T23:12:35.001-0700 I CONTROL  [initandlisten]     target_arch: x86_64
2018-04-11T23:12:35.001-0700 I CONTROL  [initandlisten] options: { net: { port: 27001 }, replication: { oplogSizeMB: 50 }, storage: { dbPath: "data\1", mmapv1: { smallFiles: true } } }
2018-04-11T23:12:35.007-0700 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=7656M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2018-04-11T23:12:35.684-0700 W STORAGE  [initandlisten] Detected configuration for non-active storage engine mmapv1 when current storage engine is wiredTiger
2018-04-11T23:12:35.684-0700 I CONTROL  [initandlisten]
2018-04-11T23:12:35.685-0700 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-04-11T23:12:35.685-0700 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-04-11T23:12:35.686-0700 I CONTROL  [initandlisten]
2018-04-12T14:12:36.052+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'data/1/diagnostic.data'
2018-04-12T14:12:36.248+0800 I INDEX    [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" }
2018-04-12T14:12:36.248+0800 I INDEX    [initandlisten]          building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2018-04-12T14:12:36.262+0800 I INDEX    [initandlisten] build index done.  scanned 0 total records. 0 secs
2018-04-12T14:12:36.265+0800 I COMMAND  [initandlisten] setting featureCompatibilityVersion to 3.4
2018-04-12T14:12:36.268+0800 I NETWORK  [thread1] waiting for connections on port 27001

开启新的客户端,按要求导入replication.js文件:

C:\Users\Shinelon>e:

E:\>MongoDB\Server\3.4\bin\mongo.exe --port 27001 --shell MongoDB\m201\chapter_4_replication\replication.js
MongoDB shell version v3.4.6
connecting to: mongodb://127.0.0.1:27001/
MongoDB server version: 3.4.6
type "help" for help
Server has startup warnings:
2018-04-11T23:12:35.684-0700 I CONTROL  [initandlisten]
2018-04-11T23:12:35.685-0700 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-04-11T23:12:35.685-0700 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-04-11T23:12:35.686-0700 I CONTROL  [initandlisten]
>

初始化homework包:

> homework.init()
ok

执行输出程序:

> homework.a()
5001

答案为5001

4.2题目

Now convert the mongod instance (the one in the problem 4.1 above, which uses “–dbpath 1”) to a single server replica set. To do this, you’ll need to stop the mongod (NOT the mongo shell instance) and restart it with “–replSet” on its command line. Give the set any name you like.

Then go to the mongo shell. Once there, run

rs.initiate()

Note: if you do not specify a configuration, the mongod will pick one based on your computer’s hostname.

When you first ran homework.init(), we loaded some data into the mongod. You should see it in the replication database. You can confirm with:

use replication
db.foo.find()

Once done with that, run

homework.b()

in the mongo shell and enter that result below.

解答

按要求使用ctrl+c强制关闭了mongod服务:

2018-04-12T14:22:25.799+0800 I CONTROL  [thread2] Ctrl-C signal
2018-04-12T14:22:25.799+0800 I CONTROL  [consoleTerminate] got CTRL_C_EVENT, will terminate after current cmd ends
2018-04-12T14:22:25.800+0800 I NETWORK  [consoleTerminate] shutdown: going to close listening sockets...
2018-04-12T14:22:25.800+0800 I NETWORK  [consoleTerminate] closing listening socket: 660
2018-04-12T14:22:25.801+0800 I NETWORK  [consoleTerminate] shutdown: going to flush diaglog...
2018-04-12T14:22:25.801+0800 I FTDC     [consoleTerminate] Shutting down full-time diagnostic data capture
2018-04-12T14:22:25.805+0800 I STORAGE  [consoleTerminate] WiredTigerKVEngine shutting down
2018-04-12T14:22:26.140+0800 I STORAGE  [consoleTerminate] shutdown: removing fs lock...
2018-04-12T14:22:26.143+0800 I CONTROL  [consoleTerminate] now exiting
2018-04-12T14:22:26.143+0800 I CONTROL  [consoleTerminate] shutting down with code:12

以replSet模式再次启动:

E:\MongoDB>Server\3.4\bin\mongod.exe --replSet sbc --dbpath data\1 --port 27001 --smallfiles --oplogSize 50
2018-04-11T23:23:21.650-0700 I CONTROL  [initandlisten] MongoDB starting : pid=1176 port=27001 dbpath=data\1 64-bit host=DESKTOP-MP9NVQ7
2018-04-11T23:23:21.650-0700 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2018-04-11T23:23:21.651-0700 I CONTROL  [initandlisten] db version v3.4.6
2018-04-11T23:23:21.651-0700 I CONTROL  [initandlisten] git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5
2018-04-11T23:23:21.652-0700 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips  22 Sep 2016
2018-04-11T23:23:21.652-0700 I CONTROL  [initandlisten] allocator: tcmalloc
2018-04-11T23:23:21.652-0700 I CONTROL  [initandlisten] modules: none
2018-04-11T23:23:21.653-0700 I CONTROL  [initandlisten] build environment:
2018-04-11T23:23:21.655-0700 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2018-04-11T23:23:21.655-0700 I CONTROL  [initandlisten]     distarch: x86_64
2018-04-11T23:23:21.655-0700 I CONTROL  [initandlisten]     target_arch: x86_64
2018-04-11T23:23:21.656-0700 I CONTROL  [initandlisten] options: { net: { port: 27001 }, replication: { oplogSizeMB: 50, replSet: "sbc" }, storage: { dbPath: "data\1", mmapv1: { smallFiles: true } } }
2018-04-11T23:23:21.661-0700 I -        [initandlisten] Detected data files in data\1 created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-04-11T23:23:21.662-0700 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=7656M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2018-04-11T23:23:22.603-0700 W STORAGE  [initandlisten] Detected configuration for non-active storage engine mmapv1 when current storage engine is wiredTiger
2018-04-11T23:23:22.603-0700 I CONTROL  [initandlisten]
2018-04-11T23:23:22.604-0700 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-04-11T23:23:22.604-0700 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-04-11T23:23:22.604-0700 I CONTROL  [initandlisten]
2018-04-12T14:23:22.835+0800 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'data/1/diagnostic.data'
2018-04-12T14:23:22.932+0800 I REPL     [initandlisten] Did not find local voted for document at startup.

今天的文章M102: MongoDB for DBAs chapter 4 replication学习记录[通俗易懂]分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/67017.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注