1. 程式人生 > >SSDB高可用方案

SSDB高可用方案

ssdb

SSDB簡介

SSDB 是一個 C/C++ 語言開發的高性能 NoSQL 數據庫, 支持 KV, list, map(hash), zset(sorted set) 等數據結構, 用來替代或者與 Redis 配合存儲十億級別列表的數據.

SSDB 是穩定的, 生產環境使用的, 已經在許多互聯網公司得到廣泛使用, 如奇虎 360, TOPGAME.


下載和安裝

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-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

雙主方案

master-1:10.105.10.77

work_dir = ./var
pidfile = ./var/ssdb.pid
server:
        ip: 0.0.0.0
        port: 8888
replication:
        binlog: yes
        sync_speed: -1
        slaveof:
                id: svc_2
                type: sync
                host: 10.105.10.128
                port: 8888
logger:
        level: info
        output: log.txt
        rotate:
                size: 1000000000
leveldb:
        cache_size: 500
        block_size: 32
        write_buffer_size: 64
        compaction_speed: 1000
        compression: yes

重啟ssdb

master-2:10.105.10.128

work_dir = ./var
pidfile = ./var/ssdb.pid
server:
        ip: 0.0.0.0
        port: 8888
replication:
        binlog: yes
        sync_speed: -1
        slaveof:
                id: svc_2
                type: sync
                host: 10.105.10.77
                port: 8888
logger:
        level: info
        output: log.txt
        rotate:
                size: 1000000000
leveldb:
        cache_size: 500
        block_size: 32
        write_buffer_size: 64
        compaction_speed: 1000
        compression: yes

重啟SSDB


安裝配置haproxy

yum  -y install  haproxy
vim /etc/haproxy/haproxy.cfg
global
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
    stats socket /var/lib/haproxy/stats
defaults
    mode                    http
    log                     global
    option                  dontlognull
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000
listen test
bind 0.0.0.0:8899
mode tcp
balance roundrobin
server s1 10.105.10.128:8888 weight 1 maxconn 10000 check inter 10s
server s2 10.105.10.77:8888 weight 1 maxconn 10000 check inter 10s

重新啟動haproxy,以後可以利用keepalive 將haproxy設計成雙主或準備都可以

/etc/init.d/haproxy restart

測試(客戶端連接haproxy地址)



本文出自 “有誌者,事竟成” 博客,請務必保留此出處http://wuxinglai.blog.51cto.com/9136815/1924686

SSDB高可用方案