Centos 7 安装RocksDB

1.安装依赖

可能会提示普通用户没有权限,可以在命令前加sudo

yum -y install lrzsz git gcc gcc-c++ lz4-devel
yum -y install snappy snappy-devel zlib zlib-devel bzip2 bzip2-devel lz4 lz4-devel zstd

2.下载安装cmake(gflags-2.2.2对cmake版本有要求)

直接去cmake官网下载最新版,或者如下使用命令:
wget https://cmake.org/download/cmake-3.23.1.tar.gz
tar -xvf cmake-3.23.1.tar
cd cmake-3.23.1
./bootstrap 
make
//下面这句报错就加sudo
make install
//查询版本
cmake --version

cmake 会默认安装在 /usr/local/bin 路径下。

3.安装依赖gflags

wget https://github.com/gflags/gflags/archive/v2.2.2.tar.gz
tar -xvzf gflags-2.2.2.tar.gz
cd gflags-2.2.2/
mkdir build
cd build/
cmake -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DINSTALL_HEADERS=ON -DINSTALL_SHARED_LIBS=ON -DINSTALL_STATIC_LIBS=ON ..
make
make install

4、下载安装rocksdb

注意:下载rocksdb之前一定要先查看你要链接的数据库版本是否匹配,否则会有报错:

Failed: Corruption: Snappy not supported or corrupted Snappy compressed block contents

 随后进行以下操作:

wget https://github.com/facebook/rocksdb/archive/v6.0.2.tar.gz
tar -xvzf rocksdb-6.0.2.tar.gz 
cd rocksdb-6.0.2/
mkdir build
cd build
//编译rocksdb时注意使用 -DWITH_LZ4=ON -DWITH_ZLIB=ON -DWITH_SNAPPY=ON 开启几个压缩算法的支持,因为它默认是关闭的。
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rocksdb -DWITH_LZ4=ON -DWITH_ZLIB=ON -DWITH_SNAPPY=ON ..
make
make install

 添加环境变量:

vi /etc/profile

export CPLUS_INCLUDE_PATH=\$CPLUS_INCLUDE_PATH:/usr/local/rocksdb/include/
export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/rocksdb/lib64/
export LIBRARY_PATH=\$LIBRARY_PATH:/usr/local/rocksdb/lib64/

5、ldb工具进行测试

cd rocksdb-6.0.2/build/tools/

[user@bogon tools]# ./ldb -help
ldb - RocksDB Tool

commands MUST specify --db=<full_path_to_db_directory> when necessary

The following optional parameters control if keys/values are input/output as hex or as plain strings:
  --key_hex : Keys are input/output as hex
  --value_hex : Values are input/output as hex
  --hex : Both keys and values are input/output as hex

The following optional parameters control the database internals:
  --column_family=<string> : name of the column family to operate on. default: default column family
  --ttl with 'put','get','scan','dump','query','batchput' : DB supports ttl and value is internally timestamp-suffixed
  --try_load_options : Try to load option file from DB.
  --ignore_unknown_options : Ignore unknown options when loading option file.
  --bloom_bits=<int,e.g.:14>
  --fix_prefix_len=<int,e.g.:14>
  --compression_type=<no|snappy|zlib|bzip2|lz4|lz4hc|xpress|zstd>
  --compression_max_dict_bytes=<int,e.g.:16384>
  --block_size=<block_size_in_bytes>
  --auto_compaction=<true|false>
  --db_write_buffer_size=<int,e.g.:16777216>
  --write_buffer_size=<int,e.g.:4194304>
  --file_size=<int,e.g.:2097152>


Data Access Commands:
  put <key> <value>  [--ttl]
  get <key> [--ttl]
  batchput <key> <value> [<key> <value>] [..] [--ttl]
  scan [--from] [--to]  [--ttl] [--timestamp] [--max_keys=<N>q]  [--start_time=<N>:- is inclusive] [--end_time=<N>:- is exclusive] [--no_value]
  delete <key>
  deleterange <begin key> <end key>
  query [--ttl]
    Starts a REPL shell.  Type help for list of available commands.
  approxsize [--from] [--to] 
  checkconsistency


Admin Commands:
  dump_wal --walfile=<write_ahead_log_file_path> [--header]  [--print_value]  [--write_committed=true|false] 
  compact [--from] [--to] 
  reduce_levels --new_levels=<New number of levels> [--print_old_levels]
  change_compaction_style --old_compaction_style=<Old compaction style: 0 for level compaction, 1 for universal compaction> --new_compaction_style=<New compaction style: 0 for level compaction, 1 for universal compaction>
  dump [--from] [--to]  [--ttl] [--max_keys=<N>] [--timestamp] [--count_only] [--count_delim=<char>] [--stats] [--bucket=<N>] [--start_time=<N>:- is inclusive] [--end_time=<N>:- is exclusive] [--path=<path_to_a_file>]
  load [--create_if_missing] [--disable_wal] [--bulk_load] [--compact]
  manifest_dump [--verbose] [--json] [--path=<path_to_manifest_file>]
  list_column_families full_path_to_db_directory 
  create_column_family --db=<db_path> <new_column_family_name>
  drop_column_family --db=<db_path> <column_family_name_to_drop>
  dump_live_files
  idump [--from] [--to]  [--input_key_hex] [--max_keys=<N>] [--count_only] [--count_delim=<char>] [--stats]
  repair
  backup [--backup_env_uri]  [--backup_dir]  [--num_threads]  [--stderr_log_level=<int (InfoLogLevel)>] 
  restore [--backup_env_uri]  [--backup_dir]  [--num_threads]  [--stderr_log_level=<int (InfoLogLevel)>] 
  checkpoint [--checkpoint_dir] 
  write_extern_sst <output_sst_path>
  ingest_extern_sst <input_sst_path> [--move_files]  [--snapshot_consistency]  [--allow_global_seqno]  [--allow_blocking_flush]  [--ingest_behind]  [--write_global_seqno] 

[user@bogon tools]# pwd
/user/rocksdb-6.0.2/build/tools
[user@bogon tools]# ./ldb --db=/tmp/test_db --create_if_missing put a1 b1
OK

[user@bogon tools]# ./ldb --db=/tmp/test_db scan
a1 : b1

[user@bogon tools]# ./ldb --db=/tmp/test_db get a1
b1

[user@bogon tools]# ./ldb --db=/tmp/test_db get a2
Failed: NotFound: 

也可以链接已经生成的rocksdb数据库:

//浏览
[user@bogon tools]# ./ldb --db=/user/RocksDB scan
//插值
[user@bogon tools]# ./ldb --db=/user/RocksDB put test_ticket xiaoming
ok

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

赛博朋克2078

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值