Ubuntu 18.04服务器安装MongoDB

zz/2023/9/24 23:07:29

1.导入包管理系统使用的公钥。

wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -

执行此命令,如果收到的是OK就是正常的。但是,如果收到指示gnupg未安装的错误,则可以:

//如果反馈不是OK 则执行这步
sudo apt-get install gnupg 
//在执行
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -

2.为MongoDB 创建文件

echo "deb [ arch=amd64,arm64,s390x ] http://repo.mongodb.com/apt/ubuntu bionic/mongodb-enterprise/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list

3.安装MongoDB Enterprise软件包

sudo apt-get update

4.安装MongoDB Enterprise软件包

sudo apt-get install -y mongodb-enterprise

注意:安装完软件包之后,需要给文件一些权限。

官方说明:

By default, MongoDB runs using the mongodb user account. If you change the user that runs the MongoDB process, you must also modify the permission to the /var/lib/mongodb and /var/log/mongodb directories to give this user access to these directories.

To specify a different log file directory and data file directory, edit the systemLog.path and storage.dbPathsettings in the /etc/mongod.conf. Ensure that the user running MongoDB has access to these directories.

sudo -R mongodb:mongodb /var/lib/mongodb

此处很关键,不然会出错 :mongodb运行状态 Active 等于failed。

更改mongod.conf配置文件中的bindIp地址。将127.0.0.1本地地址改为.0.0.0.0通用地址

5.检查mongodb安装启动是否成功

sudo systemctl start mongod

如果出现:Failed to start mongod.service: Unit mongod.service not found.

sudo systemctl daemon-reload

在执行一次启动(sudo systemctl start mongod)

查看状态:

sudo systemctl status mongod

确保服务器重启后,自启动MongoDB:

sudo systemctl enable mongod

停止MongoDB:

sudo systemctl stop mongod

重启MongoDB:

sudo systemctl restart mongod

6.验证Mongodb

在服务器终端输入:

mongo  use adminshow dbs

出现如下:

注意:如果有人出现更改mongod.conf文件配置中的authorization:enabled之后,show不出库,是因为开启了验证模式。

需要执行db.auth('root','123456'),在show dbs。然而我没搞明白的是设置authorization:enabled之后Navicat使用SSH连接不上,因为不知道在那个地方验证。所以我没设置。

创建账号:

db.createUser({ user: "root", pwd: "123456", roles: [ { role: "root", db: "admin" } ] })
db.auth("root","123456")
//反馈1正确。

7.连接Navicat 管理工具。

我使用的是阿里云服务器:控制台-->实例-->(找到所属服务器)-->更多-->网络和安全组-->安全组配置-->添加安全组规则

将端口防火墙打开之后,连接Navicat:


http://www.ngui.cc/zz/2543039.html

相关文章

Crypto aes-128-cbc加密

1.crypto (node.js) 1.1 加密 var key 2cef781a9c0411eb var str JSON.stringify({ "ip": "192.168.12.1", "mac": "80:3F:5D:0E:04:2B", "wan_ip": "0.0.0.0", "internet"…

Electron: 渲染进程开启子线程 Worker

在Vue中需要使用例外的线程去执行轮询的任务,这里以获取网卡信息为例。 注:这里是在Electron中使用的,可以使用Node.js实例 “child_process”,如果是纯Vue工程无法使用Node实例。 1.创建一个renderer.js文件,放在public静态文…

vue前端遮罩层问题

在Vue的开发中,一旦我们用到对话框,经常出现的问题是对话框被遮罩层挡住,无论是Element-UI dialog还是bootstrap的Modal,如下图所示:造成这个问题的原因是对话框组件的父元素的position有fixed或者relative值&#xff…

字符串常用的14种方法,记得关注收藏

字符串常用的14种方法,记得收藏 1、将字符串转换成char数组 ToCharArray() 2、将char数组转换成字符串 new string(char[]); 3、将字符串转换成小写 ToLower() 4、将字符串转换成大写 ToUpper() 5、比较两个字符串的时候,忽略大小写 S1.Equals(s2,…); 6…

关于数据库的查询(交叉连接,内连接,外连接-左外连接,外连接-右外连接,全连接)

1.交叉连接 select * from 表1 as 别名1 cross join 表2 as 别名2 说明1: 不带WHERE条件子句,它将会返回被连接的两个表的笛卡尔积,返回结果的 行数等于两个表行数的乘积 2.内连接 select * from 表1 as 别名1 inner join 表2 as 别名2 …

打开照相机和相册

step1:修改xml文件. <LinearLayoutandroid:orientation"vertical"android:layout_width"match_parent"android:layout_height"match_parent"><Buttonandroid:id"id/take_photo"android:layout_width"match_parent"…

String字符编码格式

String.getBytes();//得到一个操作系统默认的编码格式的字节数组. String.getBytes(“UTF-8”);//根据指定的decode编码返回某字符串在该编码下的 byte数组表示. new String(btye[] b, “UTF-8”);//按照指定的方法编码 2.编码解码 String info1"中";byte[] info2 …

Large Dual Encoders Are Generalizable Retrievers

Large Dual Encoders Are Generalizable Retrievers(arXiv) 原文地址&#xff1a;https://arxiv.org/pdf/2112.07899.pdf Motivation 之前的研究发现&#xff0c;在一个领域上训练的双塔模型通常不能泛化到其他领域的检索任务。一种普遍的看法是双塔模型的bottleneck layer …

EasyExcel保姆级教程(1)

由于博猪所在行业使用到关于Excel导入、导出的功能比较多&#xff0c;本文主要详细介绍一下博猪使用的阿里巴巴的easyExcel&#xff0c;让Excel相关操作没那么多烦恼。 前言 Excel的缺点 Java解析、生成Excel比较有名的框架有Apache poi、jxl。但他们都存在一个严重的问题就是…

华为云文字识别接口

在华文云提供的文档基础上进行了简单的整理&#xff0c;需要引入华为相关的jar包 import com.oss.oss_demo.util.OcrClientToken; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import …