保证gcc 和 g++ 在4.7以上
gcc --version g++ --version安装必要的库
apt-get -y install build-essential apt-get -y install libsnappy-dev zlib1g-dev libbz2-dev下载rocksdb的源码
https://github.com/facebook/rocksdb/releases
rocksdb-4.1.tar.gz
or
git clone https://github.com/facebook/rocksdb.git cd rocksdb git checkout v4.1
安装rocksdb
PORTABLE=1 make shared_lib INSTALL_PATH=/usr/local make install-shared设置环境变量
vim ~/.bashrcadd
export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:/blockchain/rocksdb/include export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/blockchain/rocksdb export LIBRARY_PATH=${LIBRARY_PATH}:/blockchain/rocksdb
source ~/.bashrc使用 python测试连接成功
apt-get –y install python-virtualenv python-dev virtualenv pyrocksdb_test pip install "Cython>=0.20" pip install git+git://github.com/stephan-hof/pyrocksdb.git
root@ubuntu:/blockchain/pyrocksdb_test# python Python 2.7.12 (default,Nov 19 2016,06:48:10) [GCC 5.4.0 20160609] on linux2 Type "help","copyright","credits" or "license" for more information. >>> import rocksdb >>> db=rocksdb.DB("test.db",rocksdb.Options(create_if_missing=True)) >>> db.put(b"key1",b"v1") >>> db.put(b"key2",b"v2") >>> db.get(b"key1") 'v1' >>> db.get(b"key2") 'v2' >>> del db >>> quit() root@ubuntu:/blockchain/pyrocksdb_test#