前回のつづき
【お題】 DR環境にあるMongoDBに複数データベースのうちの一部だけをレプリケーションできるか?
【環境】
・レプリケーション元:東京 (192.168.101.1)
とうきょう# cat /etc/centos-release
CentOS Linux release 7.3.1611 (Core)
・レプリケーション先:ロスアンジェルス (192.168.101.21)
ろす# cat /etc/centos-release
CentOS Linux release 7.8.2003 (Core)
※MongoDBのバージョンはどっちも前回と同じ4.4
■レプリケーション元(東京)
とうきょう# grep -A 7 storage /etc/mongod.conf
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
directoryPerDB: true
# engine:
# wiredTiger:
とうきょう# systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since 木 2020-10-01 11:10:02 JST; 1h 45min ago
----(略)----
とうきょう# lvs | grep mongo
mongodata2 dst Vwi-a-tz-- 200.00g big_thinpool 0.07
mongodata1 src -wi-ao---- 200.00g
とうきょう# mount | grep mongo
/dev/mapper/src-mongodata1 on /var/lib/mongo/test1 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/mapper/dst-mongodata2 on /var/lib/mongo/test2 type xfs (rw,relatime,seclabel,attr2,inode64,sunit=1024,swidth=4096,noquota)
とうきょう# ll /var/lib/mongo
合計 140
-rw-------. 1 mongod mongod 47 10月 1 08:39 WiredTiger
-rw-------. 1 mongod mongod 21 10月 1 08:39 WiredTiger.lock
-rw-------. 1 mongod mongod 1258 10月 1 12:41 WiredTiger.turtle
-rw-------. 1 mongod mongod 61440 10月 1 12:41 WiredTiger.wt
-rw-------. 1 mongod mongod 4096 10月 1 11:10 WiredTigerHS.wt
-rw-------. 1 mongod mongod 20480 10月 1 11:10 _mdb_catalog.wt
drwx------. 2 mongod mongod 89 10月 1 08:39 admin
drwx------. 2 mongod mongod 128 10月 1 08:39 config
drwx------. 2 mongod mongod 239 10月 1 12:41 diagnostic.data
drwx------. 2 mongod mongod 110 10月 1 11:10 journal
drwx------. 2 mongod mongod 89 10月 1 08:39 local
-rw-------. 1 mongod mongod 5 10月 1 11:10 mongod.lock
-rw-------. 1 mongod mongod 36864 10月 1 11:12 sizeStorer.wt
-rw-------. 1 mongod mongod 114 10月 1 08:39 storage.bson
drwxr-xr-x. 2 mongod mongod 6 10月 1 08:37 test1
drwxr-xr-x. 2 mongod mongod 6 10月 1 08:59 test2
とうきょう# ll /var/lib/mongo/test1
合計 0
とうきょう# ll /var/lib/mongo/test2
合計 0
とうきょう# mongo
----(略)----
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
→まだ何もいない。
・test1データベースにtest1c1コレクションを作成してデータを書き込む
> use test1
switched to db test1
> db.createCollection( "test1c1" )
{ "ok" : 1 }
> show collections
test1c1
> db.test1c1.insertOne({ name:"ダギャー",age:100 })
{
"acknowledged" : true,
"insertedId" : ObjectId("5f7551b3c56e0d3f3f8944c0")
}
> db.test1c1.find()
{ "_id" : ObjectId("5f7551b3c56e0d3f3f8944c0"), "name" : "ダギャー", "age" : 100 }
・test2データベースにtest2c1コレクションを作成してデータを書き込む
> use test2
switched to db test2
> db.createCollection( "test2c1" )
{ "ok" : 1 }
> show collections
test2c1
> db.test2c1.insertOne({ name:"ぺに助",age:200 })
{
"acknowledged" : true,
"insertedId" : ObjectId("5f7552d1c56e0d3f3f8944c1")
}
> db.test2c1.find()
{ "_id" : ObjectId("5f7552d1c56e0d3f3f8944c1"), "name" : "ぺに助", "age" : 200 }
■レプリケーション先(ロスアンジェルス)
ろす# grep -A 7 storage /etc/mongod.conf
storage:
dbPath: /var/lib/mongo
journal:
enabled: true
directoryPerDB: true
# engine:
# wiredTiger:
ろす# systemctl status mongod | head -3
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since 木 2020-10-01 13:02:08 JST; 10min ago
ろす# mount | grep test1
/dev/loop0 on /var/lib/mongo/test1 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
ろす# ll /var/lib/mongo
合計 124
-rw-------. 1 mongod mongod 47 10月 1 13:02 WiredTiger
-rw-------. 1 mongod mongod 21 10月 1 13:02 WiredTiger.lock
-rw-------. 1 mongod mongod 1254 10月 1 13:12 WiredTiger.turtle
-rw-------. 1 mongod mongod 61440 10月 1 13:12 WiredTiger.wt
-rw-------. 1 mongod mongod 4096 10月 1 13:02 WiredTigerHS.wt
-rw-------. 1 mongod mongod 20480 10月 1 13:03 _mdb_catalog.wt
drwx------. 2 mongod mongod 87 10月 1 13:02 admin
drwx------. 2 mongod mongod 125 10月 1 13:02 config
drwx------. 2 mongod mongod 71 10月 1 13:12 diagnostic.data
drwx------. 2 mongod mongod 110 10月 1 13:02 journal
drwx------. 2 mongod mongod 87 10月 1 13:02 local
-rw-------. 1 mongod mongod 5 10月 1 13:02 mongod.lock
-rw-------. 1 mongod mongod 20480 10月 1 13:04 sizeStorer.wt
-rw-------. 1 mongod mongod 114 10月 1 13:02 storage.bson
drwxr-xr-x. 2 mongod mongod 6 10月 1 13:09 test1
ろす# ll /var/lib/mongo/test1
合計 0
ろす# mongo
----(略)----
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
→まだ何もいない。
■レプリケーション元(東京)からtest1データベースだけをレプリケーション先(ロスアンジェルス)にmongodumpで移行する
とうきょう# pwd
/tmp
とうきょう# mongodump -h 127.0.0.1:27017 -d test1 --out ./test1
2020-10-01T13:22:13.834+0900 writing test1.test1c1 to test1/test1/test1c1.bson
2020-10-01T13:22:13.835+0900 done dumping test1.test1c1 (1 document)
とうきょう# ll
合計 0
drwxr-xr-x. 3 root root 19 9月 30 08:19 admin
drwxr-xr-x. 3 root root 19 9月 30 08:20 local
srwx------. 1 mongod mongod 0 10月 1 11:10 mongodb-27017.sock
drwxr-xr-x. 3 root root 19 10月 1 13:22 test1
とうきょう# ls -lR test1
test1:
合計 0
drwxr-xr-x. 2 root root 55 10月 1 13:22 test1
test1/test1:
合計 8
-rw-r--r--. 1 root root 64 10月 1 13:22 test1c1.bson
-rw-r--r--. 1 root root 154 10月 1 13:22 test1c1.metadata.json
とうきょう# tar cf ./test1.tar ./test1
とうきょう# scp test1.tar 192.168.101.21:/tmp
ろす# cd /tmp
ろす# ll test1.tar
-rw-r--r--. 1 root root 10240 10月 1 13:25 test1.tar
ろす# tar xf test1.tar
ろす# ls -lR test1
test1:
合計 0
drwxr-xr-x. 2 root root 55 10月 1 13:22 test1
test1/test1:
合計 8
-rw-r--r--. 1 root root 64 10月 1 13:22 test1c1.bson
-rw-r--r--. 1 root root 154 10月 1 13:22 test1c1.metadata.json
ろす# mongorestore -h 127.0.0.1:27017 --db test1 ./test1/test1
2020-10-01T13:32:38.897+0900 The --db and --collection flags are deprecated for this use-case; please use --nsInclude instead, i.e. with --nsInclude=${DATABASE}.${COLLECTION}
2020-10-01T13:32:38.897+0900 building a list of collections to restore from test1/test1 dir
2020-10-01T13:32:38.898+0900 reading metadata for test1.test1c1 from test1/test1/test1c1.metadata.json
2020-10-01T13:32:39.136+0900 restoring test1.test1c1 from test1/test1/test1c1.bson
2020-10-01T13:32:39.138+0900 no indexes to restore
2020-10-01T13:32:39.138+0900 finished restoring test1.test1c1 (1 document, 0 failures)
2020-10-01T13:32:39.138+0900 1 document(s) restored successfully. 0 document(s) failed to restore.
ろす# ll /var/lib/mongo/test1
合計 8
-rw-------. 1 mongod mongod 4096 10月 1 13:32 collection-7-7749723106953056859.wt
-rw-------. 1 mongod mongod 4096 10月 1 13:32 index-8-7749723106953056859.wt
ろす# mongo
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
test1 0.000GB
> use test1
switched to db test1
> show collections
test1c1
> db.test1c1.find()
{ "_id" : ObjectId("5f7551b3c56e0d3f3f8944c0"), "name" : "ダギャー", "age" : 100 } ←オブジェクトIDも保持されている
> exit
bye
・念のためレプリケーション先(ロスアンジェルス)のMongodをrestartしてみる。
ろす# systemctl restart mongod
ろす# systemctl status mongod | head -3
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since 木 2020-10-01 13:37:12 JST; 11s ago
ろす# mongo
----(略)----
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
test1 0.000GB
> use test1
switched to db test1
> db.test1c1.find()
{ "_id" : ObjectId("5f7551b3c56e0d3f3f8944c0"), "name" : "ダギャー", "age" : 100 }
→複数データベースをもつレプリケーション元からレプリケーション先に一部のデータベースだけをコピーしてもレプリケーション先のMongoDBは正常に動作した。
■レプリケーション元(東京)からtest1データベースにデータを追加してレプリケーション先(ロスアンジェルス)にmongodumpで移行する
とうきょう# mongo
----(略)----
> use test1
switched to db test1
> db.test1c1.insertOne({ name:"ぴょろりん",age:0 })
{
"acknowledged" : true,
"insertedId" : ObjectId("5f757043e99a68426998497e")
}
> db.test1c1.find()
{ "_id" : ObjectId("5f7551b3c56e0d3f3f8944c0"), "name" : "ダギャー", "age" : 100 }
{ "_id" : ObjectId("5f757043e99a68426998497e"), "name" : "ぴょろりん", "age" : 0 }
> exit
bye
とうきょう# cd /tmp;pwd
/tmp
とうきょう# ll
合計 12
----(略)----
drwxr-xr-x. 3 root root 19 10月 1 13:22 test1
-rw-r--r--. 1 root root 10240 10月 1 13:24 test1.tar
・先ほどのデータを消す
とうきょう# rm -rf test1*
とうきょう# ll test1*
ls: test1* にアクセスできません: そのようなファイルやディレクトリはありません
とうきょう# mongodump -h 127.0.0.1:27017 -d test1 --out ./test1
2020-10-01T15:10:10.389+0900 writing test1.test1c1 to test1/test1/test1c1.bson
2020-10-01T15:10:10.390+0900 done dumping test1.test1c1 (2 documents)
とうきょう# ls -lR test1
test1:
合計 0
drwxr-xr-x. 2 root root 55 10月 1 15:10 test1
test1/test1:
合計 8
-rw-r--r--. 1 root root 125 10月 1 15:10 test1c1.bson ←少し増えた
-rw-r--r--. 1 root root 154 10月 1 15:10 test1c1.metadata.json ←さっきと同じサイズ?
→ブロック?単位でデータ量は増えてるかもしれないけどファイルサイズは増えてないのかもしれない?
とうきょう# tar cf ./test1.tar ./test1
とうきょう# scp test1.tar 192.168.101.21:/tmp
ろす# pwd
/tmp
ろす# ll
合計 3736
-rw-r--r--. 1 root root 1048576000 10月 1 13:39 loop1.img
srwx------. 1 mongod mongod 0 10月 1 13:37 mongodb-27017.sock
drwx------. 3 root root 17 7月 30 15:21 systemd-private-a54e06f5c3b94682b3f9d0fb1afe5255-chronyd.service-Uo7znW
drwxr-xr-x. 3 root root 19 10月 1 13:22 test1
-rw-r--r--. 1 root root 10240 10月 1 15:17 test1.tar
・先ほどの展開したデータを消す
ろす# rm -rf test1
ろす# tar xf test1.tar
ろす# ll
合計 3736
-rw-r--r--. 1 root root 1048576000 10月 1 13:39 loop1.img
srwx------. 1 mongod mongod 0 10月 1 13:37 mongodb-27017.sock
drwx------. 3 root root 17 7月 30 15:21 systemd-private-a54e06f5c3b94682b3f9d0fb1afe5255-chronyd.service-Uo7znW
drwxr-xr-x. 3 root root 19 10月 1 15:10 test1
-rw-r--r--. 1 root root 10240 10月 1 15:17 test1.tar
ろす# ls -lR test1
test1:
合計 0
drwxr-xr-x. 2 root root 55 10月 1 15:10 test1
test1/test1:
合計 8
-rw-r--r--. 1 root root 125 10月 1 15:10 test1c1.bson
-rw-r--r--. 1 root root 154 10月 1 15:10 test1c1.metadata.json
ろす# mongorestore -h 127.0.0.1:27017 --db test1 ./test1/test1
2020-10-01T15:20:40.735+0900 The --db and --collection flags are deprecated for this use-case; please use --nsInclude instead, i.e. with --nsInclude=${DATABASE}.${COLLECTION}
2020-10-01T15:20:40.736+0900 building a list of collections to restore from test1/test1 dir
2020-10-01T15:20:40.737+0900 restoring to existing collection test1.test1c1 without dropping
2020-10-01T15:20:40.737+0900 reading metadata for test1.test1c1 from test1/test1/test1c1.metadata.json
2020-10-01T15:20:40.737+0900 restoring test1.test1c1 from test1/test1/test1c1.bson
2020-10-01T15:20:40.741+0900 continuing through error: E11000 duplicate key error collection: test1.test1c1 index: _id_ dup key: { _id: ObjectId('5f7551b3c56e0d3f3f8944c0') }
2020-10-01T15:20:40.741+0900 no indexes to restore
2020-10-01T15:20:40.741+0900 finished restoring test1.test1c1 (1 document, 1 failure)
2020-10-01T15:20:40.741+0900 1 document(s) restored successfully. 1 document(s) failed to restore.
ろす# mongo
----(略)----
> use test1
switched to db test1
> db.test1c1.find()
{ "_id" : ObjectId("5f7551b3c56e0d3f3f8944c0"), "name" : "ダギャー", "age" : 100 }
{ "_id" : ObjectId("5f757043e99a68426998497e"), "name" : "ぴょろりん", "age" : 0 }
→オブジェクトIDもそのままの形でコピー成功。
■レプリケーション元(東京)からtest1データベースにデータを追加してレプリケーション先(ロスアンジェルス)にオンラインでコピーする
とうきょう# mongo
----(略)----
> use test1
switched to db test1
> db.test1c1.insertOne({ name:"ちんぴょろ",age:5 })
{
"acknowledged" : true,
"insertedId" : ObjectId("5f7576b5a7c88197b00343d2")
}
> db.test1c1.find()
{ "_id" : ObjectId("5f7551b3c56e0d3f3f8944c0"), "name" : "ダギャー", "age" : 100 }
{ "_id" : ObjectId("5f757043e99a68426998497e"), "name" : "ぴょろりん", "age" : 0 }
{ "_id" : ObjectId("5f7576b5a7c88197b00343d2"), "name" : "ちんぴょろ", "age" : 5 }
> exit
bye
とうきょう# cd /var/lib/mongo
とうきょう# ls -la test1
合計 76
drwxr-xr-x. 2 mongod mongod 87 10月 1 12:47 .
drwxr-xr-x. 9 mongod mongod 4096 10月 1 15:28 ..
-rw-------. 1 mongod mongod 36864 10月 1 15:27 collection-0-1184516869936185047.wt
-rw-------. 1 mongod mongod 36864 10月 1 15:27 index-1-1184516869936185047.wt
・dbPath内のファイルを更新時刻順にソート
とうきょう# date;find . -type f -print0 | xargs -0 ls -alt
とうきょう# date;find . -type f -print0 | xargs -0 ls -alt
2020年 10月 1日 木曜日 15:33:32 JST
-rw-------. 1 mongod mongod 14892 10月 1 15:33 ./diagnostic.data/metrics.interim
-rw-------. 1 mongod mongod 104857600 10月 1 15:33 ./journal/WiredTigerLog.0000000005
-rw-------. 1 mongod mongod 1259 10月 1 15:33 ./WiredTiger.turtle
-rw-------. 1 mongod mongod 69632 10月 1 15:33 ./WiredTiger.wt
-rw-------. 1 mongod mongod 12288 10月 1 15:33 ./config/index-6--3250962306205148151.wt
-rw-------. 1 mongod mongod 12288 10月 1 15:31 ./config/index-5--3250962306205148151.wt
-rw-------. 1 mongod mongod 911157 10月 1 15:31 ./diagnostic.data/metrics.2020-10-01T02-10-02Z-00000
-rw-------. 1 mongod mongod 36864 10月 1 15:28 ./sizeStorer.wt
-rw-------. 1 mongod mongod 36864 10月 1 15:27 ./test1/collection-0-1184516869936185047.wt
-rw-------. 1 mongod mongod 36864 10月 1 15:27 ./test1/index-1-1184516869936185047.wt
-rw-------. 1 mongod mongod 12288 10月 1 15:06 ./config/collection-4--3250962306205148151.wt
-rw-------. 1 mongod mongod 36864 10月 1 12:54 ./_mdb_catalog.wt
-rw-------. 1 mongod mongod 20480 10月 1 12:54 ./test2/collection-2-1184516869936185047.wt
-rw-------. 1 mongod mongod 20480 10月 1 12:54 ./test2/index-3-1184516869936185047.wt
-rw-------. 1 mongod mongod 36864 10月 1 11:11 ./local/collection-2--3250962306205148151.wt
-rw-------. 1 mongod mongod 36864 10月 1 11:11 ./local/index-3--3250962306205148151.wt
-rw-------. 1 mongod mongod 104857600 10月 1 11:10 ./journal/WiredTigerPreplog.0000000002
-rw-------. 1 mongod mongod 20480 10月 1 11:10 ./admin/collection-0--3250962306205148151.wt
-rw-------. 1 mongod mongod 20480 10月 1 11:10 ./admin/index-1--3250962306205148151.wt
-rw-------. 1 mongod mongod 104857600 10月 1 11:10 ./journal/WiredTigerPreplog.0000000001
-rw-------. 1 mongod mongod 5 10月 1 11:10 ./mongod.lock
-rw-------. 1 mongod mongod 4096 10月 1 11:10 ./WiredTigerHS.wt
-rw-------. 1 mongod mongod 50041 10月 1 11:10 ./diagnostic.data/metrics.2020-10-01T02-08-34Z-00000
-rw-------. 1 mongod mongod 462975 10月 1 11:08 ./diagnostic.data/metrics.2020-10-01T00-00-14Z-00000
-rw-------. 1 mongod mongod 105717 10月 1 09:00 ./diagnostic.data/metrics.2020-09-30T23-40-14Z-00000
-rw-------. 1 mongod mongod 37966 10月 1 08:40 ./diagnostic.data/metrics.2020-09-30T23-39-07Z-00000
-rw-------. 1 mongod mongod 114 10月 1 08:39 ./storage.bson
-rw-------. 1 mongod mongod 47 10月 1 08:39 ./WiredTiger
-rw-------. 1 mongod mongod 21 10月 1 08:39 ./WiredTiger.lock
→$dbPath/test1配下に以外のファイルも更新されている!
とくじ赤字のファイルはユーザがデータを書き込んでないのに1分以内に更新されてる!?
ちなみに、さっきから前々さわってないし誰もログインしてないロスアンジェルスのMongoDBもこのとおり。
ろす# date;find /var/lib/mongo -type f -print0 | xargs -0 ls -alt
2020年 10月 1日 木曜日 15:37:05 JST
-rw-------. 1 mongod mongod 15520 10月 1 15:37 /var/lib/mongo/diagnostic.data/metrics.interim
-rw-------. 1 mongod mongod 104857600 10月 1 15:36 /var/lib/mongo/journal/WiredTigerLog.0000000002
-rw-------. 1 mongod mongod 1258 10月 1 15:36 /var/lib/mongo/WiredTiger.turtle
-rw-------. 1 mongod mongod 69632 10月 1 15:36 /var/lib/mongo/WiredTiger.wt
-rw-------. 1 mongod mongod 413436 10月 1 15:33 /var/lib/mongo/diagnostic.data/metrics.2020-10-01T04-37-12Z-00000
-rw-------. 1 mongod mongod 36864 10月 1 15:28 /var/lib/mongo/sizeStorer.wt
-rw-------. 1 mongod mongod 36864 10月 1 15:27 /var/lib/mongo/config/index-6-7749723106953056859.wt
-rw-------. 1 mongod mongod 36864 10月 1 15:27 /var/lib/mongo/config/collection-4-7749723106953056859.wt
-rw-------. 1 mongod mongod 36864 10月 1 15:27 /var/lib/mongo/config/index-5-7749723106953056859.wt
-rw-------. 1 mongod mongod 36864 10月 1 15:21 /var/lib/mongo/test1/collection-7-7749723106953056859.wt
-rw-------. 1 mongod mongod 36864 10月 1 15:21 /var/lib/mongo/test1/index-8-7749723106953056859.wt
-rw-------. 1 mongod mongod 36864 10月 1 13:38 /var/lib/mongo/local/collection-2-7749723106953056859.wt
-rw-------. 1 mongod mongod 36864 10月 1 13:38 /var/lib/mongo/local/index-3-7749723106953056859.wt
-rw-------. 1 mongod mongod 104857600 10月 1 13:37 /var/lib/mongo/journal/WiredTigerPreplog.0000000002
-rw-------. 1 mongod mongod 20480 10月 1 13:37 /var/lib/mongo/admin/collection-0-7749723106953056859.wt
-rw-------. 1 mongod mongod 20480 10月 1 13:37 /var/lib/mongo/admin/index-1-7749723106953056859.wt
-rw-------. 1 mongod mongod 104857600 10月 1 13:37 /var/lib/mongo/journal/WiredTigerPreplog.0000000001
-rw-------. 1 mongod mongod 5 10月 1 13:37 /var/lib/mongo/mongod.lock
-rw-------. 1 mongod mongod 36864 10月 1 13:37 /var/lib/mongo/_mdb_catalog.wt
-rw-------. 1 mongod mongod 4096 10月 1 13:37 /var/lib/mongo/WiredTigerHS.wt
-rw-------. 1 mongod mongod 154200 10月 1 13:37 /var/lib/mongo/diagnostic.data/metrics.2020-10-01T04-02-08Z-00000
-rw-------. 1 mongod mongod 114 10月 1 13:02 /var/lib/mongo/storage.bson
-rw-------. 1 mongod mongod 47 10月 1 13:02 /var/lib/mongo/WiredTiger
-rw-------. 1 mongod mongod 21 10月 1 13:02 /var/lib/mongo/WiredTiger.lock
まあいっか。とりあえず東京サーバのtest1データベースディレクトリ内のファイルだけオンラインでコピーしてロスアンジェルスに移行してみる。
とうきょう# scp /var/lib/mongo/test1/* 192.168.101.21:/var/lib/mongo/test1/
root@192.168.101.21's password:
collection-0-1184516869936185047.wt 100% 36KB 36.0KB/s 00:00
index-1-1184516869936185047.wt 100% 36KB 36.0KB/s 00:00
ろす# ll /var/lib/mongo/test1
合計 144
-rw-------. 1 root root 36864 10月 1 15:45 collection-0-1184516869936185047.wt
-rw-------. 1 mongod mongod 36864 10月 1 15:21 collection-7-7749723106953056859.wt
-rw-------. 1 root root 36864 10月 1 15:45 index-1-1184516869936185047.wt
-rw-------. 1 mongod mongod 36864 10月 1 15:21 index-8-7749723106953056859.wt
ろす# rm /var/lib/mongo/test1/{collection-7-7749723106953056859.wt,index-8-7749723106953056859.wt}
rm: 通常ファイル `/var/lib/mongo/test1/collection-7-7749723106953056859.wt' を削除しますか? y
rm: 通常ファイル `/var/lib/mongo/test1/index-8-7749723106953056859.wt' を削除しますか? y
ろす# ll /var/lib/mongo/test1
合計 72
-rw-------. 1 root root 36864 10月 1 15:45 collection-0-1184516869936185047.wt
-rw-------. 1 root root 36864 10月 1 15:45 index-1-1184516869936185047.wt
ろす# chown mongod:mongod /var/lib/mongo/test1/*
ろす# ll /var/lib/mongo/test1
合計 72
-rw-------. 1 mongod mongod 36864 10月 1 15:45 collection-0-1184516869936185047.wt
-rw-------. 1 mongod mongod 36864 10月 1 15:45 index-1-1184516869936185047.wt
ろす# mongo
----(略)----
> use test1
switched to db test1
> db.test1c1.find()
{ "_id" : ObjectId("5f7551b3c56e0d3f3f8944c0"), "name" : "ダギャー", "age" : 100 }
{ "_id" : ObjectId("5f757043e99a68426998497e"), "name" : "ぴょろりん", "age" : 0 }
→やはり「ちんぴょろ」が居ない
甘くないなw
・mongodbのログ見てみる
ろす# cd /var/log/mongodb/
ろす# ls -ltr
合計 56
-rw-r-----. 1 mongod mongod 56066 10月 1 15:56 mongod.log
ろす# tail -100 /var/log/mongodb/mongod.log
----(略)----
{"t":{"$date":"2020-10-01T15:21:10.015+09:00"},"s":"I", "c":"NETWORK", "id":51800, "ctx":"conn5","msg":"client metadata","attr":{"remote":"127.0.0.1:55912","client":"conn5","doc":{"application":{"name":"MongoDB Shell"},"driver":{"name":"MongoDB Internal Client","version":"4.4.0"},"os":{"type":"Linux","name":"CentOS Linux release 7.8.2003 (Core)","architecture":"x86_64","version":"Kernel 3.10.0-1127.18.2.el7.x86_64"}}}}
{"t":{"$date":"2020-10-01T15:25:16.138+09:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn5","msg":"connection ended","attr":{"remote":"127.0.0.1:55912","connectionCount":0}}
{"t":{"$date":"2020-10-01T15:52:41.452+09:00"},"s":"I", "c":"NETWORK", "id":22943, "ctx":"listener","msg":"connection accepted","attr":{"remote":"127.0.0.1:55914","sessionId":6,"connectionCount":1}}
{"t":{"$date":"2020-10-01T15:52:41.452+09:00"},"s":"I", "c":"NETWORK", "id":51800, "ctx":"conn6","msg":"client metadata","attr":{"remote":"127.0.0.1:55914","client":"conn6","doc":{"application":{"name":"MongoDB Shell"},"driver":{"name":"MongoDB Internal Client","version":"4.4.0"},"os":{"type":"Linux","name":"CentOS Linux release 7.8.2003 (Core)","architecture":"x86_64","version":"Kernel 3.10.0-1127.18.2.el7.x86_64"}}}}
{"t":{"$date":"2020-10-01T15:56:27.136+09:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn6","msg":"connection ended","attr":{"remote":"127.0.0.1:55914","connectionCount":0}}
ろす# egrep -i 'err|warn' /var/log/mongodb/mongod.log
----(略)----
{"t":{"$date":"2020-10-01T13:37:12.243+09:00"},"s":"W", "c":"CONTROL", "id":22178, "ctx":"initandlisten","msg":"/sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'","tags":["startupWarnings"]}
{"t":{"$date":"2020-10-01T13:37:12.243+09:00"},"s":"W", "c":"CONTROL", "id":22181, "ctx":"initandlisten","msg":"/sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'","tags":["startupWarnings"]}
{"t":{"$date":"2020-10-01T15:20:40.743+09:00"},"s":"I", "c":"-", "id":20883, "ctx":"conn2","msg":"Interrupted operation as its client disconnected","attr":{"opId":77869}}
・ロサンジェルスのMongoDBをリスタートしてみる。
ろす# systemctl restart mongod
ろす# systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: active (running) since 木 2020-10-01 16:02:21 JST; 6s ago
Docs: https://docs.mongodb.org/manual
Process: 7949 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
Process: 7947 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 7945 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 7943 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
Main PID: 7952 (mongod)
Tasks: 33
Memory: 157.3M
CGroup: /system.slice/mongod.service
mq7952 /usr/bin/mongod -f /etc/mongod.conf
10月 01 16:02:20 pc2_centos7_k1 systemd[1]: Stopped MongoDB Database Server.
10月 01 16:02:20 pc2_centos7_k1 systemd[1]: Starting MongoDB Database Server...
10月 01 16:02:20 pc2_centos7_k1 mongod[7949]: about to fork child process, waiting until server is ready for connections.
10月 01 16:02:20 pc2_centos7_k1 mongod[7949]: forked process: 7952
10月 01 16:02:21 pc2_centos7_k1 systemd[1]: Started MongoDB Database Server.
→起動した。
ろす# mongo
MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("e9fce24e-a5e8-4e8e-9b14-627362678a17") }
MongoDB server version: 4.4.0
---
The server generated these startup warnings when booting:
2020-10-01T16:02:20.310+09:00: ***** SERVER RESTARTED *****
2020-10-01T16:02:21.443+09:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
2020-10-01T16:02:21.444+09:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
2020-10-01T16:02:21.444+09:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
---
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
> use test1
switched to db test1
> db.test1c1.find()
Error: error doing query: failed: network error while attempting to run command 'find' on host '127.0.0.1:27017'
> show collections
Error: socket exception [CONNECT_ERROR] server [couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused] :
runClientFunctionWithRetries@src/mongo/shell/session.js:361:27
runCommand@src/mongo/shell/session.js:455:25
DB.prototype._runCommandImpl@src/mongo/shell/db.js:147:12
DB.prototype.runCommand@src/mongo/shell/db.js:162:16
DB.prototype._getCollectionInfosCommand@src/mongo/shell/db.js:805:17
DB.prototype.getCollectionInfos@src/mongo/shell/db.js:855:16
shellHelper.show@src/mongo/shell/utils.js:919:9
shellHelper@src/mongo/shell/utils.js:814:15
@(shellhelp2):1:1
> exit
bye
{"t":{"$date":"2020-10-01T07:06:21.612Z"},"s":"I", "c":"QUERY", "id":22791, "ctx":"js","msg":"Failed to end logical session","attr":{"lsid":{"id":{"$uuid":"e9fce24e-a5e8-4e8e-9b14-627362678a17"}},"error":{"code":9001,"codeName":"SocketException","errmsg":"socket exception [CONNECT_ERROR] server [couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused]"}}}
ろす# systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since 木 2020-10-01 16:03:18 JST; 3min 36s ago
Docs: https://docs.mongodb.org/manual
Process: 7949 ExecStart=/usr/bin/mongod $OPTIONS (code=exited, status=0/SUCCESS)
Process: 7947 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 7945 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
Process: 7943 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
Main PID: 7952 (code=exited, status=14)
10月 01 16:02:20 pc2_centos7_k1 systemd[1]: Stopped MongoDB Database Server.
10月 01 16:02:20 pc2_centos7_k1 systemd[1]: Starting MongoDB Database Server...
10月 01 16:02:20 pc2_centos7_k1 mongod[7949]: about to fork child process, waiting until server is ready for connections.
10月 01 16:02:20 pc2_centos7_k1 mongod[7949]: forked process: 7952
10月 01 16:02:21 pc2_centos7_k1 systemd[1]: Started MongoDB Database Server.
10月 01 16:03:18 pc2_centos7_k1 systemd[1]: mongod.service: main process exited, code=exited, status=14/n/a
10月 01 16:03:18 pc2_centos7_k1 systemd[1]: Unit mongod.service entered failed state.
10月 01 16:03:18 pc2_centos7_k1 systemd[1]: mongod.service failed.
→いったん起動したけど、そのあと落ちた
なんか駄目臭いw
ろす# egrep -i 'err|warn' /var/log/mongodb/mongod.log
----(略)----
{"t":{"$date":"2020-10-01T15:20:40.743+09:00"},"s":"I", "c":"-", "id":20883, "ctx":"conn2","msg":"Interrupted operation as its client disconnected","attr":{"opId":77869}}
{"t":{"$date":"2020-10-01T16:02:20.072+09:00"},"s":"I", "c":"CONTROL", "id":23377, "ctx":"SignalHandler","msg":"Received signal","attr":{"signal":15,"error":"Terminated"}}
{"t":{"$date":"2020-10-01T16:02:20.089+09:00"},"s":"I", "c":"-", "id":4695300, "ctx":"SignalHandler","msg":"Interrupted all currently running operations","attr":{"opsKilled":3}}
{"t":{"$date":"2020-10-01T16:02:20.310+09:00"},"s":"W", "c":"CONTROL", "id":20698, "ctx":"main","msg":"***** SERVER RESTARTED *****","tags":["startupWarnings"]}
{"t":{"$date":"2020-10-01T16:02:21.443+09:00"},"s":"W", "c":"CONTROL", "id":22120, "ctx":"initandlisten","msg":"Access control is not enabled for the database. Read and write access to data and configuration is unrestricted","tags":["startupWarnings"]}
{"t":{"$date":"2020-10-01T16:02:21.444+09:00"},"s":"W", "c":"CONTROL", "id":22178, "ctx":"initandlisten","msg":"/sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'","tags":["startupWarnings"]}
{"t":{"$date":"2020-10-01T16:02:21.444+09:00"},"s":"W", "c":"CONTROL", "id":22181, "ctx":"initandlisten","msg":"/sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'","tags":["startupWarnings"]}
{"t":{"$date":"2020-10-01T16:03:18.745+09:00"},"s":"E", "c":"STORAGE", "id":22435, "ctx":"conn1","msg":"WiredTiger error","attr":{"error":2,"message":"[1601535798:745911][7952:0x7f4baa454700], file:test1/collection-7-7749723106953056859.wt, WT_SESSION.open_cursor: __posix_open_file, 806: /var/lib/mongo/test1/collection-7-7749723106953056859.wt: handle-open: open: No such file or directory"}}
{"t":{"$date":"2020-10-01T16:03:18.746+09:00"},"s":"F", "c":"STORAGE", "id":50883, "ctx":"conn1","msg":"Cursor not found","attr":{"error":{"code":43,"codeName":"CursorNotFound","errmsg":"Failed to open a WiredTiger cursor. Reason: UnknownError: 2: No such file or directory, uri: table:test1/collection-7-7749723106953056859, config: "}}}
■レプリケーション元(東京)からレプリケーション先(ロスアンジェルス)にオフラインでコピーする
【検証パターン】
※データ転送時に東京とロスアンジェルスのmongodを停止しておく
①dbPath(デフォルトでは/var/lib/mongo)直下のdbPath/test1ディレクトリの中身だけを東京からロスアンジェルスへrsyncする。
DbPath=/var/lib/mongo
rsync -auv ${DbPath}/test1/* 192.168.101.21:${DbPath}/test1/
②dbPath直下の全ファイルからdbPath/test2ディレクトリを除いた分だけを東京からロスアンジェルスへrsyncする。
DbPath=/var/lib/mongo
rsync -auv --exclude='/var/lib/mongo/test2/' ${DbPath}/* 192.168.101.21:${DbPath}/
【結果】
①ロスアンジェルスでmongod起動失敗
②ロスアンジェルスでmongod起動成功。ロスアンジェルスでtest1データベース内データの参照成功
■レプリケーション元(東京)からレプリケーション先(ロスアンジェルス)にオンラインでコピーする
※データ転送時に東京とロスアンジェルスのmongodを起動しておく
【検証パターン】
③dbPath(デフォルトでは/var/lib/mongo)直下のdbPath/test1ディレクトリの中身だけを東京からロスアンジェルスへrsyncする。
④dbPath直下の全ファイルからdbPath/test2ディレクトリを除いた分だけを東京からロスアンジェルスへrsyncする。
【結果】
③ロスアンジェルスでmongod起動失敗
④ロスアンジェルスでmongod起動失敗