最新消息:20210917 已从crifan.com换到crifan.org

【已解决】给Win中VMWare中macOS安装MongoDB和恢复MongoDB数据

macOS crifan 422浏览 0评论
折腾:
【未解决】Win中VMWare中macOS中调试抓包项目
期间,需要去恢复macOS中MongoDB的环境和数据。
参考之前的:
【记录】mac搭建开发环境:安装最新版MongoDB
好像只需要
brew install mongodb-community
brew install mongodb-community-shell
以及之后的管理
brew services stop mongodb-community
brew services start mongodb-community
brew services restart mongodb-community
去试试
crifanli@crifanlideMac  /  brew install mongodb-community
Error: No available formula with the name "mongodb-community"
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.
找不到。
mac install mongodb
Install MongoDB Community Edition on macOS — MongoDB Manual
brew tap mongodb/brew
brew install mongodb-community
去试试
✘ crifanli@crifanlideMac  /  brew tap mongodb/brew
==> Tapping mongodb/brew
Cloning into '/usr/local/Homebrew/Library/Taps/mongodb/homebrew-brew'...
remote: Enumerating objects: 91, done.
remote: Counting objects: 100% (91/91), done.
remote: Compressing objects: 100% (77/77), done.
remote: Total 290 (delta 35), reused 33 (delta 14), pack-reused 199
Receiving objects: 100% (290/290), 63.43 KiB | 254.00 KiB/s, done.
Resolving deltas: 100% (127/127), done.
Tapped 9 formulae (36 files, 123KB).
crifanli@crifanlideMac  /  brew install mongodb-community
==> Installing mongodb-community from mongodb/brew
==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.2.8.tgz
######################################################################## 100.0%
==> Caveats
To have launchd start mongodb/brew/mongodb-community now and restart at login:
  brew services start mongodb/brew/mongodb-community
Or, if you don't want/need a background service you can just run:
  mongod --config /usr/local/etc/mongod.conf
==> Summary
🍺  /usr/local/Cellar/mongodb-community/4.2.8: 21 files, 306.3MB, built in 9 seconds
可以安装了
然后再去看看版本
crifanli@crifanlideMac  /  which mongo
/usr/local/bin/mongo
crifanli@crifanlideMac  /  which mongod
/usr/local/bin/mongod
crifanli@crifanlideMac  /  mongo --version
MongoDB shell version v4.2.8
git version: 43d25964249164d76d5e04dd6cf38f6111e21f5f
allocator: system
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64
crifanli@crifanlideMac  /  mongod --version
db version v4.2.8
git version: 43d25964249164d76d5e04dd6cf38f6111e21f5f
allocator: system
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64
crifanli@crifanlideMac  / 
再去:
✘ crifanli@crifanlideMac  /  brew install mongodb-community-shell
Updating Homebrew...
==> Installing mongodb-community-shell from mongodb/brew
==> Downloading https://fastdl.mongodb.org/osx/mongodb-shell-macos-x86_64-4.2.0.tgz
######################################################################## 100.0%
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/mongo
Target /usr/local/bin/mongo
is a symlink belonging to mongodb-community. You can unlink it:
  brew unlink mongodb-community


To force the link and overwrite all conflicting files:
  brew link --overwrite mongodb-community-shell


To list all files that would be deleted:
  brew link --overwrite --dry-run mongodb-community-shell


Possible conflicting files are:
/usr/local/bin/mongo -> /usr/local/Cellar/mongodb-community/4.2.8/bin/mongo
==> Summary
🍺  /usr/local/Cellar/mongodb-community-shell/4.2.0: 8 files, 45MB, built in 2 seconds
✘ crifanli@crifanlideMac  / 
很明显是:安装了,但是没有建立好软连接
但是,鉴于前面mongo已经能找到,且工作正常, 所以就放弃继续brew link了。
继续启动mongod服务:
  ✘ crifanli@crifanlideMac  /  brew services start mongodb-community
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 36, done.
remote: Counting objects: 100% (36/36), done.
remote: Compressing objects: 100% (32/32), done.
remote: Total 813 (delta 12), reused 17 (delta 3), pack-reused 777
Receiving objects: 100% (813/813), 226.98 KiB | 343.00 KiB/s, done.
Resolving deltas: 100% (329/329), done.
Tapped 1 command (39 files, 304.2KB).
==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)
貌似启动成功了。
去看看,的确能连接上:
✘ crifanli@crifanlideMac  /  mongo
MongoDB shell version v4.2.8
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("2869eb58-5eb4-44ae-bbe7-4dc95b48ff7c") }
MongoDB server version: 4.2.8
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
Server has startup warnings:
2020-06-27T23:23:46.951-0700 I  CONTROL  [initandlisten]
2020-06-27T23:23:46.951-0700 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-06-27T23:23:46.951-0700 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2020-06-27T23:23:46.951-0700 I  CONTROL  [initandlisten]
2020-06-27T23:23:46.951-0700 I  CONTROL  [initandlisten]
2020-06-27T23:23:46.951-0700 I  CONTROL  [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
---
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()
---

> show dbs;
admin   0.000GB
config  0.000GB
local   0.000GB
然后想办法恢复之前的数据
先要找到之前的帖子,才记得起是哪些数据,以及如何恢复
找到了:
【已解决】Mac中导入别处导出的MongoDB的data目录的数据
之前是,下载别人目录下面的所有文件,去恢复的
很明显不是好做法。
此处改为,把公司另外一台Mac中MongoDB数据,导出 备份 ,然后此处再去 导入 恢复
换去公司Mac中操作:
看到,要恢复的MongoDB数据,貌似很多。
但是其中很多现在已不需要用了。
所以,还是想办法,只恢复 必须的一些数据
看到了其中的
是需要的,其他的。貌似都不需要?
还是去代码中看看
如果都不需要,那么就只回复有限所需数据即可。
还真是 只用到这个 forcast 的authority
然后再把自己的数据加上去即可。
那一共没几条数据,所以干脆:
尝试在Win中,用GUI界面中手动添加即可
所以去试试:
【已解决】Win中尝试用Robot 3T连接和操作VMWare中macOS中MongoDB
【总结】
Win中VMWare的macOS恢复MongoDB环境,步骤是:
(1)mac中安装MongoDB
brew tap mongodb/brew
brew install mongodb-community
brew install mongodb-community-shell
(2)修改默认配置,允许外部IP访问
把配置
/usr/local/etc/mongod.conf
中默认的127.0.0.1:
net:
  bindIp: 127.0.0.1
其意味着:只绑定到当前电脑(macOS虚拟机)-》导致外部无法访问,要报错。
改为:
net:
  bindIp: 0.0.0.0
意思是:允许外部IP访问。
(3)恢复MongoDB数据
背景:只需要恢复原公司Mac中单个数据库中单个集合的数据
原公司Mac中,备份导出数据:
mongoexport -d forecast -c authority -o forcast.authority_20200628.json
新macOS虚拟机中去恢复导入数据:
mongoimport -d forecast -c authority --file forcast.authority_20200628.json
即可。
另:想要插入新数据,则去Robot 3T -》 右键-》Insert Document-》填入数据-》Save,即可。

转载请注明:在路上 » 【已解决】给Win中VMWare中macOS安装MongoDB和恢复MongoDB数据

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
90 queries in 0.192 seconds, using 23.34MB memory