SSDB高效能缓存系统

ssdb下载与安装

ssdb
重启命令
/usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8883.conf -s restart
-s 参数 stop start restart
参考资料:
http://ssdb.io/docs/zh_cn/config.html
make install PREFIX=/usr/local/ssdb/bin/
编译和安装
wget --no-check-certificate https://github.com/ideawu/ssdb/archive/master.zip
unzip master
cd ssdb-master
make
# 将安装在 /usr/local/ssdb 目录下
sudo make install
如果你想安装 ssdb 在其它的目录, 不在 /usr/local 目录下, 可以这样
mkdir /usr/local/ssdb/{bin,conf} -p
sudo make install PREFIX=/your/direcotry
make install PREFIX=/usr/local/ssdb/bin/
问题解决

如果出现如下错误:

g++ ...deps/snappy-1.1.0/.libs/libsnappy.a: No such file or directory
make[1]: *** [all] Error 1
或者

g++ ...deps/jemalloc-3.3.1/lib/libjemalloc.a: No such file or directory
make[1]: *** [all] Error 1
这是因为 Snappy 或者 Jemalloc 没有编译成功, 这一般是因为你的系统时钟有问题. 可以这样解决:

cd deps/snappy-1.1.0
autoreconf --force --install
./configure
make
或者

cd deps/jemalloc-3.3.1
autoreconf --force --install
./configure
make
启动和停止
# 启动主库, 此命令会阻塞住命令行
./ssdb-server ssdb.conf

# 或者启动为后台进程(不阻塞命令行)
./ssdb-server -d ssdb.conf

# 停止 ssdb-server
./ssdb-server ssdb.conf -s stop
# 对于旧版本
kill `cat ./var/ssdb.pid`

# 重启
./ssdb-server ssdb.conf -s restart
到目前为止, 你需要手动管理 ssdb-server 进程, 如果你希望在操作系统启动和停止时自动地管理, 请按下面的说明进行.

SSDB 启动脚本(随操作系统自启动)
假设你已经安装 SSDB 在默认的 /usr/local/ssdb 目录, 把 tools/ssdb.sh 脚本放到 /etc/init.d 目录下.

注意: 对于 CentOS 用户, 请将 ssdb.sh 重命名为 ssdb.
编辑下面的内容:

# each config file for one instance
configs=/data/ssdb_data/test/ssdb.conf
将 /data/ssdb_data/test/ssdb.conf 修改为你的 SSDB 配置文件的路径. 如果你有多个 SSDB 实例, 那么把它们写在一行, 用空格来分隔, 例如:

# each config file for one instance
configs=/data/ssdb_data/test/ssdb.conf /data/ssdb_data/demo/ssdb.conf


日志配置
另外参见 日志分析.

logger.level 日志级别
支持的日志级别有: debug, info, warn, error, fatal.

一般, 建议你将 logger.level 设置为 debug 级别.

logger.output 日志输出
可直接写相对路径或者绝对路径, 如果相对路径, 则是相对配置文件所在的目录.

如果你想输出日志到终端屏幕, 编辑 ssdb.conf, 将

logger:
output: log.txt
修改为

logger:
output: stdout
logger.rorate.size 日志循环和清理
设置日志拆分时的大小, 单位为字节数. 按照默认的配置, 日志会按 1000MB 大小进行切分, 切分后的文件名格式如: log.txt.20150723-230422.

切分后的日志文件不会自动被清理, 你需要自己写 crontab 脚本来清理.

LevelDB 配置
leveldb.cache_size 内存缓存大小
一般地, 这个数字越大, 性能越好. 如果你的机器内存较小, 那就把它改小, 最小值是 16.

leveldb.block_size 不用关心

leveldb.write_buffer_size 写缓冲区大小

如果你的机器内存小, 那就把它改小, 否则改大. 它应该在这个范围内: [4, 128];

leveldb.compaction_speed
一般情况下, 不用关心. 如果你的硬盘性能非常差, 同时, 你的数据几乎不变动, 也没有什么新数据写入, 可以把它改小(最好大于 50).

leveldb.compression 压缩硬盘上的数据
最好设置为 yes! 如果是 yes, 一般你能存储 10 倍硬盘空间的数据, 而且性能会更好.

内存占用
一个 ssdb-server 实例占用的内存瞬时(有可能, 而且即使达到, 也只是持续短时间)最高达到(MB):

cache_size + write_buffer_size * 66 + 32
这是对于压缩选项没有开启的情况, 如果 compression: yes, 计算公式是:

cache_size + 10 * write_buffer_size * 66 + 32
你可以调整配置参数, 限制 ssdb-server 的内存占用.

对于一般负载的实例来说, 物理内存的持续占用是:

cache_size + write_buffer_size * 4 + 32
根据实际经验, 使用默认配置的实例, 会占用约 1GB 的内存. 这个经验你可以参考.

 

#主从配置
参考资料:
http://blog.****.net/richardedu/article/details/48161299
http://ssdb.io/docs/zh_cn/replication.html

MASTER:
[root@cache01 ~]# cat /usr/local/ssdb/conf/ssdb22.conf
# ssdb-server config
# MUST indent by TAB!

# relative to path of this file, directory must exists
work_dir = /meishi/data/ssdb22/
pidfile = /var/run/ssdb22.pid

server:
ip: 0.0.0.0
port: 8889
# bind to public ip
#ip: 0.0.0.0
# format: allow|deny: all|ip_prefix
# multiple allows or denys is supported
#deny: all
allow: 127.0.0.1
allow: 192.168
allow: 10.
# auth password must be at least 32 characters
#auth: very-strong-password
#readonly: yes

replication:
binlog: yes
# Limit sync speed to *MB/s, -1: no limit
sync_speed: -1
slaveof:
# to identify a master even if it moved(ip, port changed)
# if set to empty or not defined, ip:port will be used.
#id: svc_2
# sync|mirror, default is sync
#type: sync
#host: localhost
#port: 8889

logger:
level: debug
output: /meishi/log/ssdb22.log
rotate:
size: 1000000000

leveldb:
# in MB
cache_size: 2048
# in MB
write_buffer_size: 64
# in MB/s
compaction_speed: 1000
# yes|no
compression: no

SLAVE:
[root@big4 conf]# cat ssdb_slave8889.conf
work_dir = /home/meishi/data/slave8889
pidfile = /var/run/ssdb8889.pid

server:
ip: 192.168.0.103
port: 8889

replication:
binlog: yes
sync_speed: -1
slaveof:
id: svc_1
type: sync
host: 10.9.142.198
port: 8889

logger:
level: debug
output: /home/meishi/log/ssdb8889.log
rotate:
size: 1000000000

leveldb:
cache_size: 2048
write_buffer_size: 64
compaction_speed: 1000
compression: no


#检查状态
MASTER:
[root@big4 conf]# /usr/local/redis3.2/bin/redis-cli -h 10.9.142.198 -p 8889
10.9.142.198:8889> INFO
ssdb-server
version
1.9.4
links
2751
total_calls
30466488
dbsize
3955503996
binlogs
capacity : 20000000
min_seq : 55049176
max_seq : 75056457
replication
client 192.168.0.103:26463
type : sync
status : SYNC
last_seq : 75056457
serv_key_range
kv : "" - ""
hash: "" - ""
zset: "" - ""
list: "" - ""
data_key_range
kv : "" - ""
hash: "Device:00000000" - "user_recipe:99999"
zset: "DeviceU:1002447" - "sys_msg_num"
list: "" - ""
leveldb.stats
Compactions
Level Files Size(MB) Time(sec) Read(MB) Write(MB)
--------------------------------------------------
0 0 0 156 0 9581
1 2 66 412 21180 20207
2 16 184 837 46082 45987
3 178 5549 272 17190 14476
10.9.142.198:8889>


SLAVE:
[root@big4 conf]# /usr/local/redis3.2/bin/redis-cli -h 192.168.0.103 -p 8889
192.168.0.103:8889> INFO
ssdb-server
version
1.9.4
links
1
total_calls
35
dbsize
3954070831
binlogs
capacity : 20000000
min_seq : 55040034
max_seq : 75042555
replication
slaveof 10.9.142.198:8889
id : svc_1
type : sync
status : SYNC
last_seq : 75056970
copy_count : 75016151
sync_count : 26502
serv_key_range
kv : "" - ""
hash: "" - ""
zset: "" - ""
list: "" - ""
data_key_range
kv : "" - ""
hash: "Device:00000000" - "user_recipe:99999"
zset: "DeviceU:1002447" - "sys_msg_num"
list: "" - ""
leveldb.stats
Compactions
Level Files Size(MB) Time(sec) Read(MB) Write(MB)
--------------------------------------------------
0 0 0 621 0 9767
1 7 160 1305 22234 20997
2 64 1597 1969 36016 35583
3 136 4301 65 3213 1174
192.168.0.103:8889>

 

#配置双主:
##配置主svc_1节点
###创建配置文件
[root@cache01 conf]# pwd
/usr/local/ssdb/conf
[root@cache01 conf]# cat ssdb8881.conf
work_dir = /meishi/data/ssdb8881/
pidfile = /var/run/ssdb8881.pid

server:
ip: 10.9.142.198
port: 8881
replication:
binlog: yes
sync_speed: -1
slaveof:
id: svc_1
type: mirror
host: 192.168.0.103
port: 8881
logger:
level: debug
output: /meishi/log/ssdb8881.log
rotate:
size: 1000000000
leveldb:
cache_size: 2048
write_buffer_size: 64
compaction_speed: 1000
compression: no

#拷贝配置文件
[root@cache01 conf]# scp ssdb8881.conf ssdb8882.conf
[root@cache01 conf]# scp ssdb8881.conf ssdb8883.conf
[root@cache01 conf]# scp ssdb8881.conf ssdb8884.conf
[root@cache01 conf]# scp ssdb8881.conf ssdb8885.conf
#修改配置文件
[root@cache01 conf]# sed -i 's#8881#8882#g' ssdb8882.conf
[root@cache01 conf]# sed -i 's#8881#8883#g' ssdb8883.conf
[root@cache01 conf]# sed -i 's#8881#8884#g' ssdb8884.conf
[root@cache01 conf]# sed -i 's#8881#8885#g' ssdb8885.conf
#创建数据目录
[root@cache01 conf]# mkdir /meishi/data/ssdb8881/ -p
[root@cache01 conf]# mkdir /meishi/data/ssdb8882/ -p
[root@cache01 conf]# mkdir /meishi/data/ssdb8883/ -p
[root@cache01 conf]# mkdir /meishi/data/ssdb8884/ -p
[root@cache01 conf]# mkdir /meishi/data/ssdb8885/ -p
#启动程序
[root@cache01 conf]# /usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8881.conf
[root@cache01 conf]# /usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8882.conf
[root@cache01 conf]# /usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8883.conf
[root@cache01 conf]# /usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8884.conf
[root@cache01 conf]# /usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8885.conf
#检查启动状态
[root@cache01 conf]# netstat -lnpt |grep ssdb
tcp 0 0 10.9.142.198:8881 0.0.0.0:* LISTEN 21206/ssdb-server
tcp 0 0 10.9.142.198:8882 0.0.0.0:* LISTEN 21224/ssdb-server
tcp 0 0 10.9.142.198:8883 0.0.0.0:* LISTEN 21240/ssdb-server
tcp 0 0 10.9.142.198:8884 0.0.0.0:* LISTEN 21286/ssdb-server
tcp 0 0 10.9.142.198:8885 0.0.0.0:* LISTEN 21302/ssdb-server
#加入自启动脚本
[root@cache01 conf]# tail -6 /meishi/scripts/start.sh
#启动ssdb
/usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8881.conf
/usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8882.conf
/usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8883.conf
/usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8884.conf
/usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8885.conf
[root@cache01 conf]#


##配置主svc_2节点
###创建配置文件
[root@big4 conf]# pwd
/usr/local/ssdb/conf
[root@big4 conf]# cat ssdb8881.conf
work_dir = /home/meishi/data/ssdb8881/
pidfile = /var/run/ssdb8881.pid

server:
ip: 192.168.0.103
port: 8881
replication:
binlog: yes
sync_speed: -1
slaveof:
id: svc_2
type: mirror
host: 10.9.142.198
port: 8881
logger:
level: debug
output: /home/meishi/log/ssdb8881.log
rotate:
size: 1000000000
leveldb:
cache_size: 2048
write_buffer_size: 64
compaction_speed: 1000
compression: no
[root@big4 conf]#
#拷贝配置文件
[root@big4 conf]# scp ssdb8881.conf ssdb8882.conf
[root@big4 conf]# scp ssdb8881.conf ssdb8883.conf
[root@big4 conf]# scp ssdb8881.conf ssdb8884.conf
[root@big4 conf]# scp ssdb8881.conf ssdb8885.conf
#修改配置文件
[root@big4 conf]# sed -i 's#8881#8882#g' ssdb8882.conf
[root@big4 conf]# sed -i 's#8881#8883#g' ssdb8883.conf
[root@big4 conf]# sed -i 's#8881#8884#g' ssdb8884.conf
[root@big4 conf]# sed -i 's#8881#8885#g' ssdb8885.conf
#创建数据目录
[root@big4 conf]# mkdir /home/meishi/data/ssdb8881
[root@big4 conf]# mkdir /home/meishi/data/ssdb8882
[root@big4 conf]# mkdir /home/meishi/data/ssdb8883
[root@big4 conf]# mkdir /home/meishi/data/ssdb8884
[root@big4 conf]# mkdir /home/meishi/data/ssdb8885
#启动程序
[root@big4 conf]# /usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8881.conf
[root@big4 conf]# /usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8882.conf
[root@big4 conf]# /usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8883.conf
[root@big4 conf]# /usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8884.conf
[root@big4 conf]# /usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8885.conf
#检查启动状态
[root@big4 conf]# netstat -lnpt |grep ssdb
tcp 0 0 192.168.0.103:8881 0.0.0.0:* LISTEN 4415/ssdb-server
tcp 0 0 192.168.0.103:8882 0.0.0.0:* LISTEN 4504/ssdb-server
tcp 0 0 192.168.0.103:8883 0.0.0.0:* LISTEN 4509/ssdb-server
tcp 0 0 192.168.0.103:8884 0.0.0.0:* LISTEN 4541/ssdb-server
tcp 0 0 192.168.0.103:8885 0.0.0.0:* LISTEN 4563/ssdb-server
#加入自启动脚本
[root@big4 conf]# tail -6 /home/start.sh
#启动ssdb
/usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8881.conf
/usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8882.conf
/usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8883.conf
/usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8884.conf
/usr/local/ssdb/bin/ssdb-server -d /usr/local/ssdb/conf/ssdb8885.conf
[root@big4 conf]#

 

 

 

 

 

 

 

 

 




 

上一篇:【学习笔记】阶与原根


下一篇:用EasyX写成绩管理系统