继续给全新工作mac搭建开发环境。
去安装MongoDB和MongoDB Compass
mac MongoDB
此处最新MongoDB是4.2版本
感觉或许用官网介绍的安装,或更好?
去根据官网介绍去安装
✘ xxx@xxx ~ brew update Updated 1 tap (homebrew/core). ==> New Formulae manticoresearch mpi4py ==> Updated Formulae pyenv ✔ conan fig2dev haxe imapfilter libedit nomad starship ack di fluid-synth hyperscan inlets libetpan packer tunnel adwaita-icon-theme django-completion gdcm hypre jenkins libopenmpt paket youtube-dl axel dvc gmic i2p jmeter libtiff s3-backer clojure eprover haproxy imageoptim-cli jruby nodenv siril xxx@xxx ~ brew tap mongodb/brew Updating Homebrew... ==> Auto-updated Homebrew! Updated 1 tap (homebrew/core). ==> Updated Formulae ansible asdf grafana ==> Tapping mongodb/brew Cloning into '/usr/local/Homebrew/Library/Taps/mongodb/homebrew-brew'... remote: Enumerating objects: 13, done. remote: Counting objects: 100% (13/13), done. remote: Compressing objects: 100% (10/10), done. remote: Total 13 (delta 4), reused 5 (delta 1), pack-reused 0 Unpacking objects: 100% (13/13), done. Tapped 6 formulae (45 files, 59.7KB).
然后去安装
xxx@xxx ~ brew install mongodb-community@4.2 Updating Homebrew... ==> Installing mongodb-community from mongodb/brew ==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.2.1.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.1: 21 files, 273.5MB, built in 1 minute 35 seconds
此处除了安装二进制外,还会安装:
- * the configuration file (/usr/local/etc/mongod.conf)
- * the log directory path (/usr/local/var/log/mongodb)
- * the data directory path (/usr/local/var/mongodb)
然后根据提示,想要以服务方式运行,需要制定全程
brew services start mongodb-community@4.2
感觉很是麻烦啊
所以在想,要不要换成不带版本号的,只是mongodb
但是看到:
看起来是:
有2个版本:
- Community版本
- Enterprise版本
希望彻底搞清楚其区别
【已解决】MongoDB版本区别:Community vs Enterprise
然后删除上面,带后缀的mongodb-community@4.2
xxx@xxx ~ brew uninstall mongodb-community@4.2 Uninstalling /usr/local/Cellar/mongodb-community/4.2.1... (21 files, 273.5MB)
重新安装不带后缀的:
xxx@xxx ~ brew install mongodb Error: No available formula with the name "mongodb" ==> Searching for a previously deleted formula (in the last month)... Warning: homebrew/core is shallow clone. To get complete history run: git -C "$(brew --repo homebrew/core)" fetch --unshallow Error: No previously deleted formula found. ==> Searching for similarly named formulae... These similarly named formulae were found: mongodb/brew/mongodb-community mongodb/brew/mongodb-community@3.2 mongodb/brew/mongodb-community@3.6 mongodb/brew/mongodb-community-shell mongodb/brew/mongodb-community@3.4 mongodb/brew/mongodb-community@4.0 To install one of them, run (for example): brew install mongodb/brew/mongodb-community ==> Searching taps... ==> Searching taps on GitHub... Error: No formulae found in taps.
发现没有mongodb
算了,去安装带Community的:
✘ xxx@xxx ~ brew install mongodb-community ==> Installing mongodb-community from mongodb/brew ==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.2.1.tgz Already downloaded: /Users/xxx/Library/Caches/Homebrew/downloads/b9e75fbe5e76acebf8e6aebdc55ee6c7c28118fa9a4723e70da021117c8708a6--mongodb-macos-x86_64-4.2.1.tgz ==> 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.1: 21 files, 273.5MB, built in 5 seconds
然后再去安装shell:
brew install mongodb-community-shell
log
xxx@xxx ~ brew install mongodb-community-shell ==> 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.1/bin/mongo ==> Summary 🍺 /usr/local/Cellar/mongodb-community-shell/4.2.0: 8 files, 45MB, built in 5 seconds
然后去看看对应的
- * a configuration file: /usr/local/etc/mongod.conf
- * a log directory path: /usr/local/var/log/mongodb
- * a data directory path: /usr/local/var/mongodb
✘ xxx@xxx ~ ll /usr/local/etc/mongod.conf -rw-r--r-- 1 xxx admin 161B 11 5 09:50 /usr/local/etc/mongod.conf xxx@xxx ~ ll /usr/local/var/log/mongodb xxx@xxx ~ ll /usr/local/var/mongodb
都是存在的。
然后以服务方式启动(开机启动)
xxx@xxx ~ brew services start mongodb-community ==> Tapping homebrew/services Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'... remote: Enumerating objects: 14, done. remote: Counting objects: 100% (14/14), done. remote: Compressing objects: 100% (9/9), done. remote: Total 14 (delta 0), reused 7 (delta 0), pack-reused 0 Unpacking objects: 100% (14/14), done. Tapped 1 command (43 files, 59.2KB). ==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)
注:想要取消开机启动用
brew services stop mongodb-community
注:想要手动启动mongod:
mongod --config /usr/local/etc/mongod.conf
手动关闭mongod
mongo admin --eval "db.shutdownServer()"
然后去确认是否已启动了:
xxx@xxx ~ ps -ef | grep mongod 2123006755 48455 1 0 10:26上午 ?? 0:00.87 /usr/local/opt/mongodb-community/bin/mongod --config /usr/local/etc/mongod.conf 2123006755 48468 39917 0 10:27上午 ttys003 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn mongod
是可以看到mongod运行了的
以及通过brew的service的list也可以看到正在运行:
✘ ⚙ xxx@xxx ~ brew services list Name Status User Plist mongodb-community started xxx /Users/xxx/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
去看看log
xxx@xxx ~ tail /usr/local/var/log/mongodb/output.log xxx@xxx ~ cat /usr/local/var/log/mongodb/mongo.log 2019-11-05T10:26:24.784+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none' 2019-11-05T10:26:24.818+0800 I CONTROL [initandlisten] MongoDB starting : pid=48455 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=xxx 2019-11-05T10:26:24.818+0800 I CONTROL [initandlisten] db version v4.2.1 2019-11-05T10:26:24.818+0800 I CONTROL [initandlisten] git version: edf6d45851c0b9ee15548f0f847df141764a317e 2019-11-05T10:26:24.818+0800 I CONTROL [initandlisten] allocator: system 2019-11-05T10:26:24.819+0800 I CONTROL [initandlisten] modules: none 2019-11-05T10:26:24.819+0800 I CONTROL [initandlisten] build environment: 2019-11-05T10:26:24.819+0800 I CONTROL [initandlisten] distarch: x86_64 2019-11-05T10:26:24.819+0800 I CONTROL [initandlisten] target_arch: x86_64 2019-11-05T10:26:24.819+0800 I CONTROL [initandlisten] options: { config: "/usr/local/etc/mongod.conf", net: { bindIp: "127.0.0.1" }, storage: { dbPath: "/usr/local/var/mongodb" }, systemLog: { destination: "file", logAppend: true, path: "/usr/local/var/log/mongodb/mongo.log" } } 2019-11-05T10:26:24.820+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,cache_overflow=(file_max=0M),session_max=33000,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,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress], 2019-11-05T10:26:25.430+0800 I STORAGE [initandlisten] WiredTiger message [1572920785:430424][48455:0x1140ed5c0], txn-recover: Set global recovery timestamp: (0,0) 2019-11-05T10:26:25.472+0800 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0) 2019-11-05T10:26:25.503+0800 I STORAGE [initandlisten] Timestamp monitor starting 2019-11-05T10:26:25.505+0800 I CONTROL [initandlisten] 2019-11-05T10:26:25.505+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2019-11-05T10:26:25.505+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2019-11-05T10:26:25.505+0800 I CONTROL [initandlisten] 2019-11-05T10:26:25.514+0800 I STORAGE [initandlisten] createCollection: admin.system.version with provided UUID: 25c65367-700e-4b26-a61d-2a327cfbcf2b and options: { uuid: UUID("25c65367-700e-4b26-a61d-2a327cfbcf2b") } 2019-11-05T10:26:25.543+0800 I INDEX [initandlisten] index build: done building index _id_ on ns admin.system.version 2019-11-05T10:26:25.544+0800 I SHARDING [initandlisten] Marking collection admin.system.version as collection version: <unsharded> 2019-11-05T10:26:25.545+0800 I COMMAND [initandlisten] setting featureCompatibilityVersion to 4.2 2019-11-05T10:26:25.545+0800 I SHARDING [initandlisten] Marking collection local.system.replset as collection version: <unsharded> 2019-11-05T10:26:25.547+0800 I STORAGE [initandlisten] Flow Control is enabled on this deployment. 2019-11-05T10:26:25.548+0800 I SHARDING [initandlisten] Marking collection admin.system.roles as collection version: <unsharded> 2019-11-05T10:26:25.549+0800 I STORAGE [initandlisten] createCollection: local.startup_log with generated UUID: a4739413-5cc2-4f51-b237-584a1a797ed0 and options: { capped: true, size: 10485760 } 2019-11-05T10:26:25.577+0800 I INDEX [initandlisten] index build: done building index _id_ on ns local.startup_log 2019-11-05T10:26:25.577+0800 I SHARDING [initandlisten] Marking collection local.startup_log as collection version: <unsharded> 2019-11-05T10:26:25.578+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/usr/local/var/mongodb/diagnostic.data' 2019-11-05T10:26:25.581+0800 I SHARDING [LogicalSessionCacheRefresh] Marking collection config.system.sessions as collection version: <unsharded> 2019-11-05T10:26:25.581+0800 I NETWORK [initandlisten] Listening on /tmp/mongodb-27017.sock 2019-11-05T10:26:25.581+0800 I NETWORK [initandlisten] Listening on 127.0.0.1 2019-11-05T10:26:25.581+0800 I NETWORK [initandlisten] waiting for connections on port 27017 2019-11-05T10:26:25.583+0800 I CONTROL [LogicalSessionCacheReap] Sessions collection is not set up; waiting until next sessions reap interval: config.system.sessions does not exist 2019-11-05T10:26:25.583+0800 I STORAGE [LogicalSessionCacheRefresh] createCollection: config.system.sessions with provided UUID: f084703b-3d81-455f-8ba8-b88489616e96 and options: { uuid: UUID("f084703b-3d81-455f-8ba8-b88489616e96") } 2019-11-05T10:26:25.610+0800 I INDEX [LogicalSessionCacheRefresh] index build: done building index _id_ on ns config.system.sessions 2019-11-05T10:26:25.638+0800 I INDEX [LogicalSessionCacheRefresh] index build: starting on config.system.sessions properties: { v: 2, key: { lastUse: 1 }, name: "lsidTTLIndex", ns: "config.system.sessions", expireAfterSeconds: 1800 } using method: Hybrid 2019-11-05T10:26:25.638+0800 I INDEX [LogicalSessionCacheRefresh] build may temporarily use up to 500 megabytes of RAM 2019-11-05T10:26:25.639+0800 I INDEX [LogicalSessionCacheRefresh] index build: collection scan done. scanned 0 total records in 0 seconds 2019-11-05T10:26:25.639+0800 I INDEX [LogicalSessionCacheRefresh] index build: inserted 0 keys from external sorter into index in 0 seconds 2019-11-05T10:26:25.646+0800 I INDEX [LogicalSessionCacheRefresh] index build: done building index lsidTTLIndex on ns config.system.sessions 2019-11-05T10:26:26.073+0800 I SHARDING [ftdc] Marking collection local.oplog.rs as collection version: <unsharded> xxx@xxx ~
如此即可
然后用shell去登录看看
xxx@xxx ~ mongo MongoDB shell version v4.2.1 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("211b0ab5-c67e-4629-bb20-753c999c7fba") } MongoDB server version: 4.2.1 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: 2019-11-05T10:26:25.505+0800 I CONTROL [initandlisten] 2019-11-05T10:26:25.505+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2019-11-05T10:26:25.505+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2019-11-05T10:26:25.505+0800 I CONTROL [initandlisten] --- 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 users > show dbs admin 0.000GB config 0.000GB local 0.000GB > db test
也是正常的了。
当前安装的MongoDB版本是:4.2.1
另外顺带去看看mongod的一些文件:
⚙ xxx@xxx ~ cd /usr ⚙ xxx@xxx /usr cd local ⚙ xxx@xxx /usr/local ll total 0 drwxrwxr-x 2 xxx admin 64B 11 1 11:39 Caskroom drwxrwxr-x 14 xxx admin 448B 11 5 10:23 Cellar drwxrwxr-x 2 xxx admin 64B 11 1 11:39 Frameworks drwxrwxr-x 19 xxx admin 608B 11 1 11:42 Homebrew drwxrwxr-x 34 xxx admin 1.1K 11 5 10:22 bin drwxrwxr-x 7 xxx admin 224B 11 5 09:50 etc drwxrwxr-x 17 xxx admin 544B 11 1 11:48 include drwxrwxr-x 10 xxx admin 320B 11 1 11:48 lib drwxrwxr-x 17 xxx admin 544B 11 5 10:23 opt drwxrwxr-x 3 xxx admin 96B 11 1 11:48 sbin drwxrwxr-x 13 xxx admin 416B 11 4 17:27 share drwxrwxr-x 5 xxx admin 160B 11 5 09:50 var ⚙ xxx@xxx /usr/local cd var ⚙ xxx@xxx /usr/local/var ll total 0 drwxrwxr-x 4 xxx admin 128B 11 1 11:42 homebrew drwxr-xr-x 3 xxx admin 96B 11 5 09:50 log drwxr-xr-x 20 xxx admin 640B 11 5 10:31 mongodb ⚙ xxx@xxx /usr/local/var cd mongodb ⚙ xxx@xxx /usr/local/var/mongodb ll total 568 -rw------- 1 xxx admin 47B 11 5 10:26 WiredTiger -rw------- 1 xxx admin 21B 11 5 10:26 WiredTiger.lock -rw------- 1 xxx admin 1.2K 11 5 10:31 WiredTiger.turtle -rw------- 1 xxx admin 60K 11 5 10:31 WiredTiger.wt -rw------- 1 xxx admin 4.0K 11 5 10:26 WiredTigerLAS.wt -rw------- 1 xxx admin 20K 11 5 10:27 _mdb_catalog.wt -rw------- 1 xxx admin 20K 11 5 10:27 collection-0--947074982306490440.wt -rw------- 1 xxx admin 20K 11 5 10:27 collection-2--947074982306490440.wt -rw------- 1 xxx admin 20K 11 5 10:31 collection-4--947074982306490440.wt drwx------ 4 xxx admin 128B 11 5 10:36 diagnostic.data -rw------- 1 xxx admin 20K 11 5 10:27 index-1--947074982306490440.wt -rw------- 1 xxx admin 20K 11 5 10:27 index-3--947074982306490440.wt -rw------- 1 xxx admin 20K 11 5 10:31 index-5--947074982306490440.wt -rw------- 1 xxx admin 24K 11 5 10:31 index-6--947074982306490440.wt drwx------ 5 xxx admin 160B 11 5 10:26 journal -rw------- 1 xxx admin 6B 11 5 10:26 mongod.lock -rw------- 1 xxx admin 36K 11 5 10:31 sizeStorer.wt -rw------- 1 xxx admin 114B 11 5 10:26 storage.bson
和:
✘ ⚙ xxx@xxx /usr/local/var/mongodb ll /usr/local/bin/mongo* lrwxr-xr-x 1 xxx admin 43B 11 5 10:22 /usr/local/bin/mongo -> ../Cellar/mongodb-community/4.2.1/bin/mongo lrwxr-xr-x 1 xxx admin 44B 11 5 10:22 /usr/local/bin/mongod -> ../Cellar/mongodb-community/4.2.1/bin/mongod lrwxr-xr-x 1 xxx admin 47B 11 5 10:22 /usr/local/bin/mongodump -> ../Cellar/mongodb-community/4.2.1/bin/mongodump lrwxr-xr-x 1 xxx admin 49B 11 5 10:22 /usr/local/bin/mongoexport -> ../Cellar/mongodb-community/4.2.1/bin/mongoexport lrwxr-xr-x 1 xxx admin 48B 11 5 10:22 /usr/local/bin/mongofiles -> ../Cellar/mongodb-community/4.2.1/bin/mongofiles lrwxr-xr-x 1 xxx admin 49B 11 5 10:22 /usr/local/bin/mongoimport -> ../Cellar/mongodb-community/4.2.1/bin/mongoimport lrwxr-xr-x 1 xxx admin 49B 11 5 10:22 /usr/local/bin/mongoreplay -> ../Cellar/mongodb-community/4.2.1/bin/mongoreplay lrwxr-xr-x 1 xxx admin 50B 11 5 10:22 /usr/local/bin/mongorestore -> ../Cellar/mongodb-community/4.2.1/bin/mongorestore lrwxr-xr-x 1 xxx admin 44B 11 5 10:22 /usr/local/bin/mongos -> ../Cellar/mongodb-community/4.2.1/bin/mongos lrwxr-xr-x 1 xxx admin 47B 11 5 10:22 /usr/local/bin/mongostat -> ../Cellar/mongodb-community/4.2.1/bin/mongostat lrwxr-xr-x 1 xxx admin 46B 11 5 10:22 /usr/local/bin/mongotop -> ../Cellar/mongodb-community/4.2.1/bin/mongotop
再去安装MongoDB Compass
【记录】mac搭建开发环境:安装MongoDB Compass
【后记】
想要管理mongod的服务,比如停止和启动等,可以通过:
brew services stop mongodb-community brew services start mongodb-community brew services restart mongodb-community
举例:
xxx ~/dev/xxx/AppCrawler master ●✚ brew services stop mongodb-community Stopping `mongodb-community`... (might take a while) ==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-community) xxx ~/dev/xxx/AppCrawler master ●✚ brew services start mongodb-community ==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community) brew services restart mongodb-community Stopping `mongodb-community`... (might take a while) ==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-community) ==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)
供参考。
转载请注明:在路上 » 【记录】mac搭建开发环境:安装最新版MongoDB