查看“︁MongoDB/Install”︁的源代码
来自康健生活
←
MongoDB/Install
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 引言 == == 安装 == === mac === ==== brew ==== {{shc|<syntaxhighlight lang="bash"> brew update</syntaxhighlight>|➜ ~}} {{Shc_out|<syntaxhighlight lang="bash"> brew tap mongodb/brew</syntaxhighlight>|<syntaxhighlight lang="bash"> Running `brew update --preinstall`... ==> Auto-updated Homebrew! Updated 1 tap (homebrew/cask). ==> Updated Casks Updated 3 casks. ==> Tapping mongodb/brew Cloning into '/usr/local/Homebrew/Library/Taps/mongodb/homebrew-brew'... remote: Enumerating objects: 846, done. remote: Counting objects: 100% (343/343), done. remote: Compressing objects: 100% (254/254), done. remote: Total 846 (delta 179), reused 144 (delta 86), pack-reused 503 Receiving objects: 100% (846/846), 185.40 KiB | 246.00 KiB/s, done. Resolving deltas: 100% (417/417), done. Tapped 14 formulae (30 files, 252KB). </syntaxhighlight>|➜ ~}} 开始安装。 {{shc|<syntaxhighlight lang="bash"> brew install mongodb-community</syntaxhighlight>|➜ ~}} 执行到这里,我遇到了一个错误。<code>Error: Permission denied @ apply2files - /usr/local/lib/docker/cli-plugins</code>。 {{shc|<syntaxhighlight lang="bash"> sudo chown -R $(whoami) $(brew --prefix)/* </syntaxhighlight>|➜ ~}} 再执行。 {{Shc_out|<syntaxhighlight lang="bash"> brew reinstall mongodb-community </syntaxhighlight>|<syntaxhighlight lang="bash"> ==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-5.0.6.tgz Already downloaded: /Users/kangjian/Library/Caches/Homebrew/downloads/6d6c69ce66861b3aac721c356f0d9560ccd34acc1b74b7ff669532fbebf8cc0c--mongodb-macos-x86_64-5.0.6.tgz ==> Reinstalling mongodb/brew/mongodb-community ==> Caveats To 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/5.0.6: 11 files, 181.5MB, built in 5 seconds ==> `brew cleanup` has not been run in the last 30 days, running now... Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP. Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`). Pruned 3 symbolic links and 4 directories from /usr/local </syntaxhighlight>|➜ ~}} 运行 mongo。 {{Shc_out|<syntaxhighlight lang="bash"> brew services start mongodb-community </syntaxhighlight>|<syntaxhighlight lang="bash"> ==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community) </syntaxhighlight>|➜ ~}} 停止 mongo。 {{Shc_out|<syntaxhighlight lang="bash"> brew services stop mongodb-community </syntaxhighlight>|<syntaxhighlight lang="bash"> Stopping `mongodb-community`... (might take a while) ==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-community) </syntaxhighlight>|➜ ~}} === Windows === 环境变量 <syntaxhighlight lang="javascript"> C:\Program Files\MongoDB\Server\4.4\bin</syntaxhighlight> 日志 <syntaxhighlight lang="javascript"> C:\Program Files\MongoDB\Server\4.4\log</syntaxhighlight> 数据库 <syntaxhighlight lang="javascript"> C:\Program Files\MongoDB\Server\4.4\data</syntaxhighlight> ==== 启动 MongoDB 服务 ==== <syntaxhighlight lang="bash"> mongod --dbpath C:\Program Files\MongoDB\Server\4.4\data\db</syntaxhighlight> ==== 开机自启动 ==== <syntaxhighlight lang="bash"> mongod --dbpath "C:\Program Files\MongoDB\Server\4.4\data\db" --logpath "C:\Program Files\MongoDB\Server\4.4\log\mongo.log" -install -serviceName "MongoDB"</syntaxhighlight> ==== 手动启动 ==== <syntaxhighlight lang="bash"> sc delete mongodb</syntaxhighlight> <syntaxhighlight lang="bash"> mongod --dbpath "C:\Program Files\MongoDB\Server\4.4\data\db" --logpath "C:\Program Files\MongoDB\Server\4.4\log\mongo.log" -install -serviceName "MongoDB"</syntaxhighlight> <syntaxhighlight lang="bash"> net start mongodb</syntaxhighlight> === Centos === 添加 yum 源 {{shc|<syntaxhighlight lang="bash"> vi /etc/yum.repos.d/mongodb-org-4.0.repo</syntaxhighlight>|#}} {{hc|mongodb-org-4.0.repo|<syntaxhighlight lang="bash"> [mongodb-org-4.0] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc</syntaxhighlight>}} {{shc|<syntaxhighlight lang="bash"> yum install -y mongodb-org && systemctl start mongod</syntaxhighlight>|#}} === 远程访问配置 === 修改mongodb的配置文件 让其监听所有外网 IP。 {{shc|<syntaxhighlight lang="bash"> vi /etc/mongod.conf</syntaxhighlight>|#}} {{hcdiff|head=mongod.conf|output=<syntaxhighlight lang="bash" highlight="5"> ... # network interfaces net: port: 27017 bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting. ... </syntaxhighlight>|output2=<syntaxhighlight lang="bash" highlight="5"> ... # network interfaces net: port: 27017 bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting. ... </syntaxhighlight>}} {{shc|<syntaxhighlight lang="bash"> systemctl restart mongod.service</syntaxhighlight>|#}} === docker === == 创建 == {{shc|<syntaxhighlight lang="bash"> mongo</syntaxhighlight>|$}} <syntaxhighlight lang="javascript"> use admin db.createUser( { user:"kangkk", pwd:"123456", roles:[{role:"root",db:"admin"}] } ) // 删除用户 db.dropUser("kangkk")</syntaxhighlight> 添加数据库用户 <syntaxhighlight lang="javascript"> use data db.createUser( { user: "user01", pwd: "123456", roles: ["readWrite"] } )</syntaxhighlight>
此页面嵌入的页面:
模板:Hc
(
查看源代码
)
模板:Hc/style.css
(
查看源代码
)
模板:Hcdiff
(
查看源代码
)
模板:Hcdiff/style.css
(
查看源代码
)
模板:Shc
(
查看源代码
)
模板:Shc/style.css
(
查看源代码
)
模板:Shc out
(
查看源代码
)
模板:Shc out/style.css
(
查看源代码
)
返回
MongoDB/Install
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。