1. Mongodb
Version: mongodb-linux-x86_64-static-legacy-1.8.1.tgz
: Http://www.mongodb.org/downloads
Mongodb provides two download editions: mongodb-linux-x86_64-1.8.1.tgz and mongodb-linux-x86_64-static-legacy-1.8.1.tgz
Difference: the "legacy static" version is used only when the linux system is an old one, mongodb cannot be started, or a floating point exception occurs,
Try to use mongodb-linux-x86_64-1.8.1.tgz
2. Introduction
(The following content extracted from the Internet, the original address: http://hi.baidu.com/moioo/blog/item/8d464a8f05eb37f6513d923e.html)
MongDB is a scalable, high-performance, open-source, free-mode, document-oriented database. It is not a common RDBMS and belongs to the "NoSql" category.
It is not the same as a general key-value-based db, because it has powerful functions and has implemented many functions similar to SQL,
Such as index, limit, skip, group .....
When the application data volume reaches the sea level, the traditional Mysql and Oracle cannot meet our performance requirements, but there is a certain amount of data query requirements, you can consider
MongoDB.
3. installation:
Since RHEL4.3 uses the mongodb-linux-x86_64-1.8.1.tgz version,
Error: error while loading shared libraries: requires glibc 2.5 or later dynamic linker
So use version: mongodb-linux-x86_64-static-legacy-1.8.1.tgz
1) Create the mongodb program running directory and the default data storage directory:
# Mkdir-p/usr/local/mongodb-1.18.1
# Mkdir-p/data/db
2) decompress:
# Tar zxf mongodb-linux-x86_64-static-legacy-1.8.1.tgz-C/usr/local/mongodb
3) cd to the mongodb installation directory and run:
#./Mongod -- dbpath =/data/db/-- logpath =/data/db/mongodb. log -- logappend
4. python Testing
1) RHEL4.3 adopts the default python version 2.3.4.
Upgrade to python 2.7.1
(1) download the python2.7.1 source code package http://www.python.org/getit/, :python-2.7.1.tgz
Install: # tar zxf Python-2.7.1.tgz
# Cd Python-2.7.1
# Configure
# Make
# Make install
Modify path
# Mv/usr/bin/python/usr/bin/python_2.3 // rename the original version 2.3
# Mv/usr/local/bin/python2.7/usr/bin/python // obtain the new version 2.7 to the/usr/bin/directory.
# Python-V // check whether the new version of python is effective
(2) install setuptools corresponding to python2.7.1
Download: http://pypi.python.org/pypi/setuptools version: setuptools-0.6c11-py2.7.egg
Installation: # chmod + x setuptools-0.6c11-py2.7.egg
#./Setuptools-0.6c11-py2.7.egg
2) download and install the mongodb python driver package
Download http://www.mongodb.org/downloads, :pydesk-1.11.tar.gz
Install: # tar zxf pymongo-1.11.tar.gz
# Cd pymongo-1.11
# Python setup. py build
# Python setup. py install
Test: # python
>>> Import pymongo
3) warehouse receiving speed test
Test script
######################################## ################
#! /Usr/bin/python
#-*-Coding: UTF-8 -*-
Import OS, sys
Import random
Import string
Import time
Import pymongo
Insertinfo = {}
Valid_letters = 'abcdefghijklmnopqrstuvwxyzbcdefghijklmnopqrstuvwxyz1234567890'
Def getrandstring (length ):
Return ''. join ([random. choice (valid_letters) for I in range (0, length)])
Conn = pymongo. Connection ('127. 0.0.1 ', 127) // create a database Connection
Conn. drop_database ('test') // delete an existing database 'test'
Print 'database _ names: % s' % conn. database_names () // print when all database names
Print 'nodes: % s' % conn. nodes // print the node name
Print 'port: % s' % conn. port // print the single slogan
Print 'host: % s' % conn. host // print the host address
# Print 'serverinfo: ', conn. server_info () // print server Information
Db = conn. test // create a database connection
Mycollection = db. test_collection_2 // create a collection. If the test database and the collection do not exist
At this time, it is not actually created until the data is inserted.
Print 'dbname: % s \ n' % db. name // print the name of the currently connected database
Print "test_collection_2 index info:", mycollection. index_information () // print the index information of the collection.
Print "connection information ------------------"
For myconn in db. collection_names (): // print all colleciton of the current connection
Print myconn
# Print 'insert data ----------------------'
Print mycollection. count () // print the number of data entries of the current collection
Begtime = time. time ()
Pretime = begtime
For I in range (random 00): // generate a random string of the loop
Insertinfo ["_ id"] = I // manually insert the "_ id" value.
Insertinfo ["y"] = str (getrandstring (random. randint (15, 30 )))
Insertinfo ["z"] = str (getrandstring (random. randint (15, 30 )))
Insertinfo ["m"] = str (getrandstring (random. randint (15, 30 )))
Mycollection. insert (insertinfo, safe = False, check_keys = False) // insert data to the current collection
If db. error () is not None: // check whether the insertion is successful. Otherwise, the error message is output.
Print db. error ()
Print insertinfo
Print mycollection. index_information ()
If I % 10000 = 0:
Print I, mycollection. count (), (time. time ()-pretime)
Pretime = time. time ()
Endtime = time. time ()
Print 'run time: % s' % (endtime-begtime)
"""
Print 'insert finish, outpu insert info ------------------'
For item in mycollection. find ():
For key in item. keys ():
Print key + ":", item [key]
"""
Conn. disconnect () // closes the database connection
######################################## ################
Test results:
Local vmwarevm: MB memory, single cpu.
1 million data, insertion time: 404.967557907 seconds.
List of generated data files:
# Ls-l/data/db
##########################
-Rw ------- 1 root 64 M Jun 13 test.0
-Rw ------- 1 root 128 M Jun 13 test.1
-Rw ------- 1 root 256 M Jun 13 test.2
-Rw ------- 1 root 16 M Jun 13 09: 37 test. ns
##########################