安装之前需要确定服务器是否挂yum源,木有的自行百度挂源哈

  1. 安装依赖
1
2
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
  1. 下载安装cmake(所有的安装包都放在文末,环境不通外网的可以直接去下载)(注意下面添加的环境变量路径改成自己的)
1
2
3
4
5
6
7
8
9
10
curl -O   https://cmake.org/files/v3.6/cmake-3.6.0-Linux-x86_64.tar.gz
tar -xvzf cmake-3.6.0-Linux-x86_64.tar.gz
yum remove cmake

cat >>/etc/profile <<EOF

export PATH=\$PATH:/opt/cmake-3.6.0-Linux-x86_64/bin

EOF
source /etc/profile
  1. 安装gflags(我这里不知道为什么下载下来的是v2.2.2.tar.gz,这不重要,照常解压就行)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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

cat >>/etc/profile <<EOF

export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/lib

EOF
source /etc/profile
  1. 下载安装RocksDB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
wget https://github.com/facebook/rocksdb/archive/v6.14.6.tar.gz
tar -xvzf rocksdb-6.14.6.tar.gz
cd rocksdb-6.14.6/
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/rocksdb ..
make
make install

cat >>/etc/profile <<EOF

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/

EOF

source /etc/profile
  1. ldb工具进行测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
cd rocksdb-6.14.6/build/tools/

执行./ldb -help,会出现下面的说明

ldb - RocksDB Tool

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

commands can optionally specify --env_uri=<uri_of_environment> if 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.
--disable_consistency_checks : Set options.force_consistency_checks = false.
--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> [--create_if_missing] [--ttl]
get <key> [--ttl]
batchput <key> <value> [<key> <value>] [..] [--create_if_missing] [--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
list_file_range_deletes [--max_keys=<N>] : print tombstones in SST files.


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>]
file_checksum_dump [--path=<path_to_manifest_file>]
list_column_families
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]
unsafe_remove_sst_file <SST file number>
MUST NOT be used on a live DB.

# ./ldb --db=/tmp/test_db --create_if_missing put a1 b1
OK
# ./ldb --db=/tmp/test_db scan
a1 : b1
# ./ldb --db=/tmp/test_db get a1
b1
# ./ldb --db=/tmp/test_db get a2
Failed: NotFound:
# cd /tmp/test_db/
# ll
-rw-r--r-- 1 root root 26 Jun 9 17:52 000003.log
-rw-r--r-- 1 root root 16 Jun 9 17:52 CURRENT
-rw-r--r-- 1 root root 37 Jun 9 17:52 IDENTITY
-rw-r--r-- 1 root root 0 Jun 9 17:52 LOCK
-rw-r--r-- 1 root root 18821 Jun 9 17:53 LOG
-rw-r--r-- 1 root root 18589 Jun 9 17:52 LOG.old.1623232363821351
-rw-r--r-- 1 root root 18821 Jun 9 17:52 LOG.old.1623232374342461
-rw-r--r-- 1 root root 18821 Jun 9 17:52 LOG.old.1623232385039046
-rw-r--r-- 1 root root 13 Jun 9 17:52 MANIFEST-000001
-rw-r--r-- 1 root root 5793 Jun 9 17:52 OPTIONS-000005

安装包百度云链接:
链接:https://pan.baidu.com/s/1oFANkJPUIQUzwJLF3NF3mw
提取码:ofwb

文章借鉴https://blog.51cto.com/u_860143/2452514