ubuntu/linux 下载安装并配置mongo(db)

官方:https://docs.mongodb.com/v3.6/tutorial/install-mongodb-enterprise-on-ubuntu/
有条件的可以直接看官网, 下面是我个人用到的一些, 多余的部分就被我减掉了

将GPG_Key 添加到本机

#  import the MongoDB public GPG Key from https://www.mongodb.org/static/pgp/server-3.6.asc
wget -qO - https://www.mongodb.org/static/pgp/server-3.6.asc | sudo apt-key add -

添加下载版本

# Create a /etc/apt/sources.list.d/mongodb-enterprise.list file for MongoDB.
# 其它版本可以看官方文档去指定 这里我下载安装的是3.4版本的
#官网有根据ubuntu版本对应的 mongo 版本:查看自己 ubuntu 版本代码:lsb_release -a
可以根据提示自行配置(自己动手丰衣足食, 手动狗头)
echo "deb http://repo.mongodb.com/apt/ubuntu "$(lsb_release -sc)"/mongodb-enterprise/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise-3.4.list

更新apt_get (差不多这个意思,反正必须跑这步就是了 =。=)

Reload local package database.

sudo apt-get update

安装mongo:

Install the MongoDB Enterprise packages.

Install MongoDB Enterprise version 3.6.

Issue the following command:

sudo apt-get install -y mongodb-enterprise

指定版本的下载方法(例如:3.6.23版本):

Install a specific release of MongoDB Enterprise.

sudo apt-get install -y mongodb-enterprise=3.6.23 mongodb-enterprise-server=3.6.23 mongodb-enterprise-shell=3.6.23 mongodb-enterprise-mongos=3.6.23 mongodb-enterprise-tools=3.6.23
If you only install mongodb-enterprise=3.6.23 and do not include the component packages, the latest version of each MongoDB package will be installed regardless of what version you specified.

查看可被使用的版本(大概是这样, 自己百度翻一下吧 O(∩_∩)O哈哈~)

Pin a specific version of MongoDB Enterprise.

Although you can specify any available version of MongoDB, apt-get will upgrade the packages when a newer version becomes available. To prevent unintended upgrades, pin the package. To pin the version of MongoDB at the currently installed version, issue the following command sequence:

 
echo "mongodb-enterprise hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-server hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-shell hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-mongos hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-tools hold" | sudo dpkg --set-selections

配置mongo 生成 mongo.conf文件

Run MongoDB Enterprise Edition

By default, MongoDB instance stores:

  • its data files in /var/lib/mongodb
  • its log files in /var/log/mongodb
# 我觉的最有用的一句:
mongo.conf 该文件会被默认生成在/etc/ 下
cd /etc/
vim mongo.conf
# 配置可以自定义 参看:
https://www.cnblogs.com/presleyren/p/13717202.html

#配置文件可以自己建一个 touch mongo.conf or vim mongo.conf
#指定配置文件启动 mongno
mongod -f mongo.conf
mongod --config mongo.conf
# 查看 mongo 进程:
ps -ef|grep mongod
# 结束 mongo进程 应该是:
killall -9 mongod
# 我没有用过,大概是这个命令,我启动了就没管, 随便 百度 or google 一下就有关闭的命令啦

配置可以自定义 参看: https://www.cnblogs.com/presleyren/p/13717202.html

原文地址:https://www.cnblogs.com/presleyren/p/15736787.html