Monday, April 28, 2014

Setup mongodb

Step 1: Add MongoDB Yum Repository
Add following content in yum repository configuration file /etc/yum.repos.d/mongodb.repo.
For 64bit Systems:
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
For 32bit Systems:
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686/
gpgcheck=0
enabled=1
Step 2: Install MongoDB
Lets use yum package manager to install mongodb-org package, it will automatically install all its dependencies. To install any specific revision of mongodb specify package name with version likemongodb-org-2.6.1. Following command will install latest stable version available.
# yum install mongodb-org
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
 * atomic: www7.atomicorp.com
 * base: mirror.nbrc.ac.in
 * epel: mirrors.ispros.com.bd
 * extras: mirror.nbrc.ac.in
 * rpmforge: be.mirror.eurid.eu
 * rpmfusion-free-updates: mirror.smartmedia.net.id
 * updates: mirror.nbrc.ac.in
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mongodb-org.i686 0:2.6.0-1 will be installed
--> Processing Dependency: mongodb-org-tools = 2.6.0 for package: mongodb-org-2.6.0-1.i686
--> Processing Dependency: mongodb-org-shell = 2.6.0 for package: mongodb-org-2.6.0-1.i686
--> Processing Dependency: mongodb-org-server = 2.6.0 for package: mongodb-org-2.6.0-1.i686
--> Processing Dependency: mongodb-org-mongos = 2.6.0 for package: mongodb-org-2.6.0-1.i686
--> Running transaction check
---> Package mongodb-org-mongos.i686 0:2.6.0-1 will be installed
---> Package mongodb-org-server.i686 0:2.6.0-1 will be installed
---> Package mongodb-org-shell.i686 0:2.6.0-1 will be installed
---> Package mongodb-org-tools.i686 0:2.6.0-1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================
 Package                           Arch        Version           Repository          Size
==========================================================================================
Installing:
 mongodb-org                       i686        2.6.0-1           mongodb            4.6 k
Installing for dependencies:
 mongodb-org-mongos                i686        2.6.0-1           mongodb            6.7 M
 mongodb-org-server                i686        2.6.0-1           mongodb            8.9 M
 mongodb-org-shell                 i686        2.6.0-1           mongodb            4.2 M
 mongodb-org-tools                 i686        2.6.0-1           mongodb             88 M

Transaction Summary
==========================================================================================
Install       5 Package(s)                             
                                                       
Total download size: 108 M                             
Installed size: 270 M                                  
Is this ok [y/N]: y                                    
Downloading Packages:                                  
(1/5): mongodb-org-2.6.0-1.i686.rpm                              | 4.6 kB     00:00
(2/5): mongodb-org-mongos-2.6.0-1.i686.rpm                       | 6.7 MB     00:21
(3/5): mongodb-org-server-2.6.0-1.i686.rpm                       | 8.9 MB     00:27
(4/5): mongodb-org-shell-2.6.0-1.i686.rpm                        | 4.2 MB     00:16
(5/5): mongodb-org-tools-2.6.0-1.i686.rpm                        |  88 MB     04:24
----------------------------------------------------------------------------------------
Total                                                   327 kB/s | 108 MB     05:36
Running rpm_check_debug                                
Running Transaction Test                               
Transaction Test Succeeded                             
Running Transaction                                                                         
Warning: RPMDB altered outside of yum.                                                      
** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:                       
google-chrome-stable-34.0.1847.116-1.i386 has missing requires of libnss3.so(NSS_3.14.3)    
  Installing : mongodb-org-tools-2.6.0-1.i686                                                1/5
  Installing : mongodb-org-server-2.6.0-1.i686                                               2/5
  Installing : mongodb-org-mongos-2.6.0-1.i686                                               3/5
  Installing : mongodb-org-shell-2.6.0-1.i686                                                4/5
  Installing : mongodb-org-2.6.0-1.i686                                                      5/5
                                                                                            
Installed:                                                                                  
  mongodb-org.i686 0:2.6.0-1                                                                
                                                                                            
Dependency Installed:                                                                       
  mongodb-org-mongos.i686 0:2.6.0-1  mongodb-org-server.i686 0:2.6.0-1  
  mongodb-org-shell.i686 0:2.6.0-1 mongodb-org-tools.i686 0:2.6.0-1

Complete!

Step 3: Start MongoDB
Package mongodb-org-server provided MongoDB init script, Use that script to start service.
# service mongod start
Configure MongoDB to auto start on system boot.
# chkconfig mongod on
Step 4: Check MongoDB Version and Test Setup
Use following command to check installed mongodb version
# mongo --version

MongoDB shell version: 2.6.0
Connect MongoDB using command line and execute some test commands for checking proper working.
# mongo
> db.test.save( { a: 1 } )
> db.test.find()

  { "_id" : ObjectId("52b0dc8285f8a8071cbb5daf"), "a" : 1 }

Enabling authentication

The first thing to do before you can start making use of mongo’s UAC features it to enable authentication. Usually this is disabled by default.
This can be enabled either by editing your mongodb.conf file and adding the line
auth = true
You can also start mongod with the auth parameter.
Save the file, and reboot MongoDB.
service mongodb restart
That’s it! Your mongo server should be up and running! To test your Mongo configuration from another node (or to test authentication locally), run the command:
mongo <server_ip>/admin -u root -p <password>
to authenticate as root to make changes to the db structure or add users, or
mongo <server_ip>/project -u web_user -p <password>
to authenticate as web_user.

Install php driver

git clone https://github.com/mongodb/mongo-php-driver.git
cd mongo-php-driver
phpize
./configure
make
make install
echo "extension=mongo.so" >> /build/php/etc/php.ini


Related Posts:

  • Vòng đời của tên miền VNTên miền ở trạng thái tự do (Available) => Chủ thể đăng ký sử dụng => Tên miền hết hạn. Sau 3 ngày kể từ ngày hết hạn => tên miền sẽ bị tạm ngưng, nhưng chủ thể vẫn có quyền nộp phí gia hạn trong vòng 17 ngày tiếp th… Read More
  • Vòng đời của tên miền Quốc tếMỗi tên miền từ khi được khởi tạo đến lúc ngưng sử dụng đều có một "vòng đời" riêng của nó, thậm chí có những tên miền còn sở hữu nhiều vòng đời.Dưới đây, chúng tôi sẽ trình bày vòng đời của một số tên miền quốc tế thường sử … Read More
  • Fix lỗi không vào mạng khi clone centos với VMware Cách 1: At first, I checked the configuration of its NIC $ ping www.google.com ping: nuknown host www.google.com  $ cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" HWADDR="00:50:56:B0:7F:24" NM_CONTROLLED="n… Read More
  • Thiết lập IP tĩnh cho cho centos 1, Để xác định địa chỉ ip và các network interface ta dùng command: Ifconfig –a 2, Để xem những thiết bị được kết nối vào computer từ IRQ 1 – IRQ 15 : Cat /proc/interrupts 3, Thiết lập địa chỉ ip tạm thời cho một card mạ… Read More
  • Quy định về tên miền Việt Nam (.VN) Định nghĩa các đuôi tên miền¶ COM.VN: Dành cho tổ chức, cá nhân hoạt động thương mại. BIZ.VN: Dành cho các tổ chức, cá nhân hoạt động kinh doanh, tương đương với tên miền COM.VN. EDU.VN: Dành cho các tổ chức, cá nhân hoạt đ… Read More