简体   繁体   English

如何在Ubuntu上安装MongoDb并在安装时设置配置

[英]How do i install MongoDb on Ubuntu and set the config at install time

I am creating an automated deployment for a cloud server and I need to get Mongodb installed, configured and running in one script. 我正在为云服务器创建自动部署,我需要在一个脚本中安装,配置和运行Mongodb。 I won't have access to the server as the deployment server pulls my scripts from git. 我将无法访问服务器,因为部署服务器从git中提取脚本。

My issue is I need to set the logpath and dbpath to another location. 我的问题是我需要将logpath和dbpath设置为另一个位置。 How do i do this using apt-get. 我如何使用apt-get做到这一点。 What I use at the moment is below but it sets the path to the default location. 我现在使用的是下面但是它设置了默认位置的路径。

apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | tee -a /etc/apt/sources.list.d/10gen.list
apt-get -y update
apt-get -y install mongodb-10gen

To do this easily, write the mongodb.conf first yourself (use sudo, create it as /etc/mongodb.conf with permissions of 644 and root:root) - use an existing one as a template or grab it from git and alter the dbpath and logpath appropriately. 要轻松完成此操作,首先自己编写mongodb.conf(使用sudo,将其创建为权限为644和root:root的/etc/mongodb.conf) - 使用现有的模板作为模板或从git中获取并更改适当地使用dbpath和logpath。

Also easy - just remove those default folders and create symbolic links to point at your desired install paths - no modification to files necessary at all. 也很简单 - 只需删除这些默认文件夹并创建符号链接以指向所需的安装路径 - 根本不需要修改文件。

If, for some reason you don't want to do that, and you want to do it post-install, then you are going to have to stop the service from starting up with the configured file so that it doesn't start up, pre-allocate files etc. There are a couple of options to do that, that have been covered in pretty decent detail here . 如果由于某种原因您不想这样做,并且您希望在安装后执行此操作,那么您将不得不停止服务启动配置文件以使其无法启动,预先分配文件等。有几个选项可以做到这一点, 这里有相当不错的细节。

As described there, your options are to either temporarily block all new services from starting or do a download-only fetch with apt-get and manipulate the files to not start mongod automatically before you install, or alter the package to manipulate the config file before it starts. 如上所述,您可以选择临时阻止所有新服务启动,或者使用apt-get执行仅下载获取,并在安装之前操作文件以不自动启动mongod,或者更改程序包以在之前操作配置文件开始。

Or, finally, you can install as normal and let it start, then stop the mongod service ( service mongod stop ), remove the files that were created in the configured paths, and then alter the mongodb.conf with your new values (or overwrite with your own), restart the service. 或者,最后,您可以正常安装并让它启动,然后停止mongod服务( service mongod stop ),删除在配置的路径中创建的文件,然后使用新值更改mongodb.conf(或覆盖用你自己的),重启服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM