ubuntu 16.04安装mongodb
<p>说明:由于ubuntu 14取消了对mongodb包的支持,因此,ubuntu 14必须通过源码包的形式进行安装。Ubuntu 16 TLS有mongodb的包的支持,可以直接安装</p><p>1. 导入密钥</p>
<pre><span class="p"><strong>root@ros-OptiPlex-3050:~# wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -<br>OK<br><br></strong><br></span></pre>
<p>2. 创建一个列表文件MongoDB</p>
<p>root@ros-OptiPlex-3050:~# echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list<br>deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.2 multiverse</p>
<p>3. 安装</p>
<p>root@ros-OptiPlex-3050:~# sudo apt-get install mongodb-org </p>
<p> </p>
<p>root@block-PowerEdge-T30:~# nano /lib/systemd/system/mongod.service<br><br></p>
<p><br>Description=MongoDB Database Server<br>Documentation=https://docs.mongodb.org/manual<br>After=network.target<br><br><br>User=mongodb<br>Group=mongodb<br>EnvironmentFile=-/etc/default/mongod<br>ExecStart=/usr/bin/mongod --config /etc/mongod.conf<br>PIDFile=/var/run/mongodb/mongod.pid<br># file size<br>LimitFSIZE=infinity<br># cpu time<br>LimitCPU=infinity<br># virtual memory size<br>LimitAS=infinity<br># open files<br>LimitNOFILE=64000<br># processes/threads<br>LimitNPROC=64000<br># locked memory<br>LimitMEMLOCK=infinity<br># total threads (user+kernel)<br>TasksMax=infinity<br>TasksAccounting=false</p>
<p># http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings<br><br><br>WantedBy=multi-user.target<br><br></p>
<p>root@block-PowerEdge-T30:~# mongo<br>MongoDB shell version v4.2.15<br>connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb<br>2021-08-03T17:14:56.317+0800 E QUERY Error: 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 :<br>connect@src/mongo/shell/mongo.js:353:17<br>@(connect):2:6<br>2021-08-03T17:14:56.318+0800 F - exception: connect failed<br>2021-08-03T17:14:56.318+0800 E - exiting with code 1<br><br>root@block-PowerEdge-T30:~# service mongod start<br>root@block-PowerEdge-T30:~# service mongod stop<br>root@block-PowerEdge-T30:~# service mongod status<br>● mongod.service - MongoDB Database Server<br> Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)<br> Active: inactive (dead) since 二 2021-08-03 17:29:50 CST; 4s ago<br> Docs: https://docs.mongodb.org/manual<br> Main PID: 12346 (code=exited, status=0/SUCCESS)<br><br>8月 03 17:22:51 block-PowerEdge-T30 systemd: Started MongoDB Database Server.<br>8月 03 17:29:44 block-PowerEdge-T30 systemd: Started MongoDB Database Server.<br>8月 03 17:29:50 block-PowerEdge-T30 systemd: Stopping MongoDB Database Server...<br>8月 03 17:29:50 block-PowerEdge-T30 systemd: Stopped MongoDB Database Server.<br><br><br><br><br></p>
<p>4. 添加用户</p>
<p>> show dbs<br>admin 0.078GB<br>local 0.078GB<br>> use admin<br>switched to db admin<br>> show collections<br>system.indexes<br>system.version<br>> db.createUser({user:"hett",pwd:"hett",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})<br>Successfully added user: {<br> "user" : "hett",<br> "roles" : [<br> {<br> "role" : "userAdminAnyDatabase",<br> "db" : "admin"<br> }<br> ]<br>}<br>> show collections<br>system.indexes<br>system.users<br>system.version<br>> db.system.users.find()<br>{ "_id" : "admin.hett", "user" : "hett", "db" : "admin", "credentials" : { "MONGODB-CR" : "52d2a50b4f7c87f3df99d02892b7946f" }, "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ] }<br>> exit<br><br>6. 错误</p>
<p>2021-08-04T09:31:35.877+0800 I CONTROL options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port$<br>2021-08-04T09:31:35.877+0800 E NETWORK Failed to unlink socket file /tmp/mongodb-27017.sock Operation not perm$<br>2021-08-04T09:31:35.877+0800 F - Fatal Assertion 40486 at src/mongo/transport/transport_layer_asio.cpp 6$<br>2021-08-04T09:31:35.877+0800 F - \n\n***aborting after fassert() failure\n\n<br><br></p>
<p> </p>
<pre><br><br></pre><br><br>
来源:https://www.cnblogs.com/youran-he/p/11465914.html
頁:
[1]