Go学习--安装gorocksdb,从而使用rocksdb

golang使用rocksdb用到的是gorocksdb,在这之前需要在linux系统下安装好rocksdb,在安装gorocksdb
在此记录安装流程和中间遇到的问题

一、安装rocksdb

1.保证版本在4.7以上

gcc --version
g++ --version

2.必要的库

apt-get -y install build-essential
apt-get -y install libsnappy-dev zlib1g-dev libbz2-dev

3.获取rocksdb源码

git clone https://github.com/facebook/rocksdb.git
cd rocksdb
git checkout 5.7fb (这里选择5.6以上)

4.安装

PORTABLE=1 make shared_lib
INSTALL_PATH=/usr/local make install-shared

5.设置环境变量

vim ~/.bashrc

export CPLUS_INCLUDE_PATH=${CPLUS_INCLUDE_PATH}:/xxx/rocksdb/include
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/xxx/rocksdb
export LIBRARY_PATH=${LIBRARY_PATH}:/xxx/rocksdb

source ~/.bashrc


二、部署gorocksdb

1.安装

CGO_CFLAGS="-I/path/to/rocksdb/include"

CGO_LDFLAGS="-L/path/to/rocksdb -lrocksdb -lstdc++ -lm -lz -lbz2 -lsnappy -llz4 -lzstd"

go get github.com/tecbot/gorocksdb

2.错误记录:

(1) error while loading shared libraries: xxx.so.x

解决方法:

cat /etc/ld.so.conf

include ld.so.conf.d/*.conf

echo “/usr/local/lib” >> /etc/ld.so.conf

ldconfig

(2) 出现文件找不到问题,错误信息如下:

# github.com/tecbot/gorocksdb
../github.com/tecbot/gorocksdb/backup.go:4:24: fatal error: rocksdb/c.h: No such file 
or directory
// #include "rocksdb/c.h"
compilation terminated.

解决方法

go build -tags=embed

你可能感兴趣的:(Golang,Golang学习笔记)