<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MongoDB &#8211; wqh博客</title>
	<atom:link href="https://wangqianhong.com/tag/mongodb/feed/" rel="self" type="application/rss+xml" />
	<link>https://wangqianhong.com</link>
	<description>和而不同</description>
	<lastBuildDate>Fri, 08 Mar 2024 04:29:49 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://wangqianhong.com/wp-content/uploads/2020/09/cropped-1-1-1-32x32.png</url>
	<title>MongoDB &#8211; wqh博客</title>
	<link>https://wangqianhong.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Docker运行MongoDB</title>
		<link>https://wangqianhong.com/2022/02/docker%e8%bf%90%e8%a1%8cmongodb/</link>
					<comments>https://wangqianhong.com/2022/02/docker%e8%bf%90%e8%a1%8cmongodb/#respond</comments>
		
		<dc:creator><![CDATA[wqh_work]]></dc:creator>
		<pubDate>Sat, 19 Feb 2022 05:31:00 +0000</pubDate>
				<category><![CDATA[技术文章]]></category>
		<category><![CDATA[Centos]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[MongoDB]]></category>
		<guid isPermaLink="false">https://wangqianhong.com/?p=2841</guid>

					<description><![CDATA[<p>MongoDB是NoSQL类型的数据库。它支持的数据结构非常松散，是类似json的bson格式，因此&#8230; <a href="https://wangqianhong.com/2022/02/docker%e8%bf%90%e8%a1%8cmongodb/" class="more-link read-more" rel="bookmark">继续阅读 <span class="screen-reader-text">Docker运行MongoDB</span><i class="fa fa-arrow-right"></i></a></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2022/02/docker%e8%bf%90%e8%a1%8cmongodb/">Docker运行MongoDB</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>MongoDB是NoSQL类型的数据库。它支持的数据结构非常松散，是类似json的bson格式，因此可以存储比较复杂的数据类型。</p>



<h3>拉取镜像</h3>



<pre class="wp-block-code"><code>docker pull mongodb/mongodb-community-server</code></pre>



<h3>配置文件</h3>



<p>创建文件<code>/mnt/mongodb/mongo.conf</code></p>



<pre class="wp-block-preformatted"><code>systemLog:
  destination: file
  path: /var/log/mongodb/mongod.log
  logAppend: true
storage:
  dbPath: /data/db
net:
  port: 27017
  bindIp: 0.0.0.0
security:
  authorization: enabled</code>

systemLog 写入日志文件的地址是容器中的路径
storage 数据库目录是容器中的路径
net 指定容器mongodb启动监听27017端口, 0.0.0.0 是为了让宿主机可以访问容器的mongodb服务
security 开启账号密码登录验证方式</pre>



<h3>运行镜像</h3>



<pre class="wp-block-code"><code>docker run --name mongodb -p 27017:27017 -e TZ=Asia/Shanghai -v /mnt/mongodb/mongo.conf:/etc/conf/mongo.conf -v /data/mongodb:/data -d mongodb/mongodb-community-server:latest -f /etc/conf/mongo.conf</code></pre>



<h3>新增账号</h3>



<pre class="wp-block-code"><code> docker exec -it mongo mongosh</code></pre>



<p>切换的admin</p>



<pre class="wp-block-preformatted">test&gt; <code>use admin</code>
switched to db admin
admin&gt; <code>db.createUser({user:"账号",pwd:"密码",roles:["root"]})</code>
{ ok: 1 }</pre>



<p>验证账号</p>



<pre class="wp-block-preformatted">admin&gt; <code>db.auth("账号","密码")</code>
{ ok: 1 }</pre>



<p></p>
<p><a rel="nofollow" href="https://wangqianhong.com/2022/02/docker%e8%bf%90%e8%a1%8cmongodb/">Docker运行MongoDB</a>最先出现在<a rel="nofollow" href="https://wangqianhong.com">wqh博客</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://wangqianhong.com/2022/02/docker%e8%bf%90%e8%a1%8cmongodb/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
