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 guide, beginner’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/mongodbfolder and that log files will be stored in the
/srv/db/mongodb.logfile. 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-startand
mongodb-stopin 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-startand
mongodb-stopand modify these files if your deployment requires an alternate initialization procedure. From now on, issuing
/opt/bin/mongodb-startor
/opt/bin/mongodb-stopwill start or stop the MongoDB process, respectively. The behavior of the
mongodprocess is controlled by the values set in
/opt/config/mongodb.
Create the
/opt/config/mongodband 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 of
mongodb. The
dbpathoption 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.logfile, 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_ipoption 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. The
portoption in this file specifies the default port, but can be modified depending on your needs.
Setting the
forkoption to equal
trueconfigures 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-startscript. 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
authoption to
truein 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-startand
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
mongoutility provides an interactive JavaScript shell for MongoDB including commands such as
mongodumpand
mongorestorefor creating and restoring backups and snapshots as well
mongoexportand
mongoimportjsonfor exporting individual collections in JSON format.
You can now fully enjoy application development with MongoDB!
转载于:https://www.cnblogs.com/Joy06/p/4785918.html
- 在Linux(centos)上安装PHP的mongodb扩展 成功试过的
- CentOS 部署 MongoDB
- mongodb shard cluster centos 7
- CentOS7下使用yum安装Mongodb3.4
- Centos环境下安装mongoDB
- CentOS 安装 MongoDB
- CentOS 7 yum方式快速安装MongoDB
- 32位linux(centos)下mongoDB的安装
- CentOS 编译安装 MongoDB
- 最简单实用的MongoDB安装教程:在CentOS中使用 yum 安装MongoDB及服务器端配置详解
- centos6.5下MongoDB2.6.4安装配置记录
- CentOS 手工编译、手动编译安装 MongoDB
- 在CentOS 7下安装Redis和MongoDB教程
- Centos 6.7 本地yum源配置及MongoDB安装
- Centos修炼-----> Centos7之Centos安装MongoDB
- CentOS6.5下安装配置MongoDB分片集群
- centos安装mongodb
- centOS配置mongoDB
- [NodeJS] 腾讯云 CentOS7.2 部署 Express+MongoDB 项目
- Centos7 设置Mongodb开机启动-自定义服务