centos 装mongodb

From https://www.linode.com/docs/databases/mongodb/use-mongodb-to-store-application-data-on-centos-5

Use MongoDB to Store Application Data on CentOS 5

Updated Friday, April 29th, 2011 by Linode

This guide has been deprecated and is no longer being maintained.

MongoDB is a database engine that provides access to non-relational key-value databases. It is part of the growing NoSQL movement, which seeks to provide an alternative to traditional relational database management systems (RDBMS). In addition to its schema-free design and scalable architecture, MongoDB provides a JSON-based output format and specialized language specific bindings that make it particularly attractive for use in custom application development. Although MongoDB is a relatively new project and has not yet been packaged by most major operating system distributions, the software has been used in a number of large scale production deployments such as “GitHub”, “SourceForge”, and “DISQUS”.

Before installing MongoDB, it is assume that you have followed our getting started guide. If you are new to Linux server administration, you may be interested in our introduction to Linux concepts guidebeginner’s guide and administration basics guide.

Installing MongoDB

Install Prerequisites

Issue the following commands to make sure that your system is up to date and that all of the required software is installed:

1
2
yum update
yum install wget

Install MongoDB

Download the latest binaries from the upstream source.; at the time of writing this is version 1.6.5. When downloading MongoDB, ensure that you download a version that is compiled for the proper system architecture. This document uses the 32-bit version; however, these steps will work for the 64-bit edition with a few modifications. Please note that the 32-bit version of MongoDB has a database size limit of 2 gigabytes. If you expect to store more than 2 gigabytes of data, ensure that you have deployed a 64-bit system and are using the 64-bit version of MongoDB.

1
2
3
4
cd /opt/
wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.6.5.tgz
tar zxvf mongodb-linux-i686-1.6.5.tgz
mv mongodb-linux-i686-1.6.5 /opt/mongodb

MongoDB is now deployed in the /opt/mongodb/ folder with the binaries located in the/opt/mongodb/bin/ folder. In this example, it is assumed that all database files will be stored in the/srv/db/mongodb folder and that log files will be stored in the /srv/db/mongodb.log file. Issue the following commands to create this file and directory:

1
2
mkdir -p /srv/db/mongodb
touch /srv/db/mongodb.log

In this example the name of the database will be mongodb; however, you can modify this name with another name or naming scheme as needed.

Monitor for Software Updates and Security Notices

When running software compiled or installed directly from sources provided by upstream developers, you are responsible for monitoring updates, bug fixes, and security issues. After becoming aware of releases and potential issues, update your software to resolve flaws and prevent possible system compromise. Monitoring releases and maintaining up to date versions of all software is crucial for the security and integrity of a system.

Please monitor the following MongoDB mailing lists for updates to ensure that you are aware of all updates to the software and can upgrade appropriately or apply patches and recompile as needed:

When upstream sources offer new releases, repeat the instructions for installing MongoDB and recompile your software when needed.

Create Basic Control Scripts

In typical installations, the MongoDB server process is controlled using command line arguments to binaries located at /opt/mongodb/bin/mongod. In order to simplify commands, you can create control scripts named mongodb-start and mongodb-stop in the /opt/bin/ directory. Issue the following commands to create the required directories:

1
2
mkdir /opt/bin/
mkdir /opt/config/

Issue the following sequence of commands to download the scripts and set the permissions on these files:

1
2
3
4
cd /opt/bin/
wget -O mongodb-start http://www.linode.com/docs/assets/625-mongodb-start.sh
wget -O mongodb-stop http://www.linode.com/docs/assets/626-mongodb-stop.sh
chmod +x *

Review the contents of the mongodb-start and mongodb-stop and modify these files if your deployment requires an alternate initialization procedure. From now on, issuing/opt/bin/mongodb-start or /opt/bin/mongodb-stop will start or stop the MongoDB process, respectively. The behavior of the mongod process is controlled by the values set in /opt/config/mongodb.

Create the /opt/config/mongodb and use the following example as a template:

/opt/config/mongodb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Configuration Options for MongoDB
#
# For More Information, Consider:
# - Configuration Parameters: http://www.mongodb.org/display/DOCS/Command+Line+Parameters
# - File Based Configuration: http://www.mongodb.org/display/DOCS/File+Based+Configuration

dbpath = /srv/db/mongodb
logpath = /srv/db/mongodb.log
logappend = true

bind_ip = 127.0.0.1
port = 27017
fork = true

auth = true
# noauth = true

This specifies a number of important options that you may modify to control the functionality ofmongodb. The dbpath option indicates that database files will be stored in /srv/db/mongo. The logpathdirective indicates that MongoDB’s logs will be located in the /srv/db/log/mongodb.log file, and that new log entries will be appended to the end of the log rather than overwriting existing log entries even after MongoDB restarts.

If the bind_ip option is not specified, MongoDB will bind to and listen for requests on all local IP addresses. In this case, MongoDB is configured to only listen for requests on the localhost interface. Modify this option to allow your MongoDB server to listen for requests on other IP addresses; however, consider the possible security implications of providing public access. Theport option in this file specifies the default port, but can be modified depending on your needs.

Setting the fork option to equal true configures MongoDB to run as a daemon process in the background independently of the current user’s session. Please note that MongoDB will run under the user that executes the mongodb-start script. We strongly recommend that this user not be root or another privileged user account. To provide additional security, it is recommended that you set the auth option to true in order to take advantage of MongoDB’s internal authentication capabilities. If you need to test the database without authentication, you can replace the authoption to noauth.

Using a Basic Init Script

We’ve also created a very basic “init script” as a wrapper around the mongodb-start and mongo-stopscripts described above. You will still need to modify and manage the configuration of your MongoDB server in the files above. This script only provides a means for ensuring that MongoDB will start at boot. Issue the following commands:

1
2
3
4
5
wget -O init-rpm.sh http://www.linode.com/docs/assets/624-mongodb-init-rpm.sh
mv init-rpm.sh /etc/init.d/mongodb
chmod +x /etc/init.d/mongodb
chkconfig --add mongodb
chkconfig mongodb on

You will also need to create a user and group for mongodb; issue the following command:

1
useradd -M -r --home-dir /opt/mongodb mongodb

Now issue the following command to ensure that the MongoDB user you just created will have access to all required files in the /srv/db/ hierarchy:

1
chown mongodb:mongodb -R /srv/db/

To start and stop MongoDB using the init script, issue the appropriate command from the following:

1
2
/etc/init.d/mongodb start
/etc/init.d/mongodb stop

Congratulations, you now have a fully functional installation of the MongoDB system.

Additional MongoDB Functionality

Now that MongoDB is running properly, you can begin to explore some of its features. Most interaction with MongoDB is done via the rich set of language-specific drivers. There are also a number of tools in the /opt/mongodb/bin/ directory that you might find useful for interacting with MongoDB databases. The mongo utility provides an interactive JavaScript shell for MongoDB including commands such as mongodump and mongorestore for creating and restoring backups and snapshots as well mongoexport and mongoimportjson for exporting individual collections in JSON format.

You can now fully enjoy application development with MongoDB!

时间: 2024-10-12 06:23:20

centos 装mongodb的相关文章

linux centos 装g++安装不了

今天需要编译一个项目的时候在装g++都装不上, [[email protected] hadoop]# yum install g++ Loaded plugins: fastestmirror, refresh-packagekit, security Loading mirror speeds from cached hostfile * base: mirrors.yun-idc.com * extras: mirrors.yun-idc.com * updates: mirrors.yu

Centos 安装MongoDB C++ dirver

Centos 安装MongoDB C++ dirver 前言: 图片居然显示不了, 后面在添加图片了 官网地址:https://www.mongodb.org/ 驱动下载地址: https://docs.mongodb.org/ecosystem/drivers/?_ga=1.81586452.2024551820.1440643898 下载release版本 官网安装教程地址:https://docs.mongodb.org/ecosystem/drivers/cpp/ 安装环境 CentOS

CentOS 安装MongoDB

官方网站 http://www.mongodb.org/ 下载 http://www.mongodb.org/downloads 安装教程 http://docs.mongodb.org/manual/tutorial/install-mongodb-on-linux/ 这个是针对linux服务器的 针对CentOS 的教程 http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat-centos-or-fedora-li

新手玩个人服务器(阿里云centos)-mongodb安装和启动

一首<爱你的宿命>和<后会无期>,昨晚张碧晨在中国好声音很稳定,晋级实至名归,虽然几天前我从微博就知道结局了.陈冰吼过了-- 今天看到草稿箱有篇没有完成的文章,在不怎么稳定的情绪继续完成,毕竟最爱小二班,后会无期,往往后会有期:但是后会有期,往往后会无期,珍惜身边爱你的人,这不是你的宿命,而是你的使命-- 附上mongo在 github地址: https://github.com/mongodb/mongo/tree/master/rpm <1>下载 wget http

centos下mongodb部署

MongoDB是目前在IT行业非常流行的一种非关系型数据库(NoSql),其灵活的数据存储方式,备受当前IT从业人员的青睐.Mongo DB很好的实现了面向对象的思想,在Mongo DB中,每一条记录都是一个Document对象.Mongo DB最大的优势在于所有的数据持久操作都无需开发人员手动编写SQL语句,直接调用方法就可以轻松的实现CRUD操作.在这里介绍一下mongodb的安装方法: 系统环境: CentOS release 6.5 (Final) MongoDB:mongodb-lin

centos 中 mongodb 启动失败的修复

mongodb是使用centos的yum命令安装的,整个的安装过程如下: 1. 运行 yum info mongo-10gen查看是否有mongodb源,如有跳至第3步. 2. 运行 vim /etc/yum.repos.d/10gen.repo输入如下内容并保存[10gen]name=10gen Repositorybaseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64gpgcheck=0 3. 运行 yum inst

windows和centos下mongodb安装使用

官网:https://www.mongodb.org/downloads 版本:2.6.10    (2.X最终稳定版) http://www.jb51.net/article/48217.htm   (mongodb常用操作命令) http://snowolf.iteye.com/blog/1796749/    (mongodb之CRUD) http://www.cnblogs.com/zengen/archive/2011/04/23/2025722.html    (权限.用户) htt

Centos下mongodb的安装与配置

安装MongoDB的方法有很多种,可以源代码安装,在Centos也可以用yum源安装的方法. 1.准备工作 运行yum命令查看MongoDB的包信息(正常是没有信息提示的,我这里已经按安装好了) [[email protected]~]# yum info mongodb-org Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Installed Packages Name : mongodb-or

centos安装mongodb

1.mongodb下载地址:http://www.mongodb.org/downloads,可以找到32位的tgz文件地址,如:http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.4.2.tgz2.安装MongoDB(安装到/usr) cd /usr wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.4.2.tgz tar zxvf mongodb-linux-i686-2.