ssdb cluster + keepalived build actual combat-3.ssdb master-standby mode build

ssdb cluster + keepalived build actual combat-3.ssdb master-standby mode build

surroundings

Operating system: CentOS Linux release 7.6.1810 (Core)
ssdb: 1.9.7
IP:
master: 10.80.2.121
slave: 10.80.2.85

vip:10.80.2.156

Kernel file modification

Be sure to remember to modify your Linux kernel parameters. For the content of max open files (maximum file descriptors), please refer to Building C1000K Server (1)-Basic

Use the c1000k tool to test how many concurrent connections your system supports: c1000k download address

1. Download and install

Download software:

[root@localhost ssdb]# cd /opt/ssdb/

[root@localhost ssdb]# wget --no-check-certificate https://github.com/ideawu/c1000k/archive/master.zip

Unzip the installation package:

[root@localhost ssdb]# unzip master.zip.1 
Archive:  master.zip.1
f435ee41fca847b71aab679fed1d9b07c979cfba
   creating: c1000k-master/
 extracting: c1000k-master/.gitignore  
  inflating: c1000k-master/Makefile  
  inflating: c1000k-master/README.md  
  inflating: c1000k-master/client.c  
  inflating: c1000k-master/server.c  

Resolution:

[root@localhost ssdb]# cd c1000k-master
[root@localhost c1000k-master]# make
gcc -std=c99 -O2 -o server server.c
gcc -O2 -o client client.c

2. Check the maximum number of server connections

Start the service, at ports 1000 to 1099:

[root@localhost c1000k-master]# ./server 1000

Run the client on another client:

[root@localhost ~]# cd /opt/ssdb/c1000k-master/
[root@localhost c1000k-master]# ls
client  client.c  Makefile  README.md  server  server.c
[root@localhost c1000k-master]# ./client 127.0.0.1 1000
connections: 922
error: Connection refused

At this time, the server displays:

connections: 921
error: Too many open files

The server can accept a maximum of 921 connections

ssdb basic configuration

Refer to the official documentation: ssdb configuration

Modify the /opt/data/ssdb.conf file:

1. Monitor

The default configuration is:

server:
        ip: 127.0.0.1
        port: 8888

This will only accept local connections and change to:

server:
	#ip: 127.0.0.1
	port: 8888
	# 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: 10.80
	allow: 10.82

Such admixing 10.80.*.*and 10.82.*.*connecting segment, such as the network is not limited, and only open 0.0.0.0to

2. Log

ssdb-server will output such a log every 5 minutes. The
default configuration is:

logger:
        level: debug
        output: log.txt
        rotate:
                size: 1000000000
  • logger.level The log level. Supported log levels are: debug, info, warn, error, fatal. In general, it is recommended that you set logger.level to debug level.
  • logger.output Log output. You can write the relative path or absolute path directly. If the relative path is the directory where the relative configuration file is located.

3.LevelDB

  • leveldb.cache_size Memory cache size, unit MB. Generally, the larger the number, the better the performance. You can set it to half of the physical memory. If your machine has less memory, then change it to a smaller value. The minimum value is 16.

  • leveldb.block_size don't care

  • leveldb.write_buffer_size write buffer size in MB. If your machine's memory is small, then change it to small, otherwise change it. It should be within this range: [4, 128];

  • leveldb.compaction_speed, under normal circumstances, don't care. If your hard drive performance is very poor, at the same time, your data hardly changes, and there is no new data written, you can change it to smaller (preferably greater than 50).

  • leveldb.compression compresses the data on the hard disk, it is best to set it to yes! If yes, generally you can store data of 10 times the hard disk space, and the performance will be better.

Memory calculation:
The memory occupied by an ssdb-server instance is instantaneous (it is possible, and even if it is reached, it only lasts for a short time). The maximum is (MB):

cache_size + write_buffer_size * 66 + 32

This is the case when the compression option is not turned on. If compression: yes, the calculation formula is:

cache_size + 10 * write_buffer_size * 66 + 32

You can adjust the configuration parameters to limit the memory usage of ssdb-server.

For an instance with a general load, the continuous occupation of physical memory is:

cache_size + write_buffer_size * 4 + 32

According to actual experience, using the default configuration instance will occupy about 1GB of memory. You can refer to this experience.

4. My main library configuration:

Memory resources:

              total        used        free      shared  buff/cache   available
Mem:           3.9G        149M        3.5G         24M        210M        3.5G
Swap:          2.0G          0B        2.0G

ssbd configuration:

[root@ecloud02-carchat-prod-ssdb01 data]# cat /opt/data/ssdb.conf

# ssdb-server config
# MUST indent by TAB!

# absolute path, or relative to path of this file, directory must exists
work_dir = ./var
pidfile = ./var/ssdb.pid

server:
	#ip: 127.0.0.1
	port: 8888
	# 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: 10.80
	allow: 10.82
	# auth password must be at least 32 characters
	#auth: very-strong-password
	#readonly: yes
	# in ms, to log slowlog with WARN level
	#slowlog_timeout: 5

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: log.txt
	rotate:
		size: 1000000000

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

Note: The configuration file of SSDB uses a TAB to indicate first-level indentation, do not use spaces to indent, whether you use 1, 2, 3, 4, 5, 6, 7, 8, or Countless spaces will not work!

ssdb master-slave configuration

Refer to the official documentation: ssdb synchronization and replication configuration and monitoring

1. Modify the database configuration

What I need to configure here is: Master-slave mode, only need to modify the configuration of the slave library side:

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_1
		# sync|mirror, default is sync
		type: sync
		host: 10.80.2.121
		port: 8888

Specified for the synchronous copy replication (Sync), and the host-based configuration repository ip
For the read-only, which can be modified from the library server.readonly: yesto

Then restart the slave ssdb service to make the configuration take effect:

[root@ecloud02-carchat-prod-ssdb02 data]# systemctl restart ssdb

2. Master-slave state

Enter the main library and check the status:

[root@ecloud02-carchat-prod-ssdb01 data]# /opt/data/ssdb-cli -h 10.80.2.121 -p 8888
ssdb (cli) - ssdb command line tool.
Copyright (c) 2012-2016 ssdb.io

'h' or 'help' for help, 'q' to quit.

ssdb-server 1.9.7

ssdb 10.80.2.121:8888> info
version
	1.9.7
links
	1
total_calls
	6
dbsize
	258
binlogs
	    capacity : 20000000
	    min_seq  : 1
	    max_seq  : 4
replication
	client 10.80.2.85:13093
	    type     : sync
	    status   : SYNC
	    last_seq : 4
serv_key_range
	    kv  : "" - ""
	    hash: "" - ""
	    zset: "" - ""
	    list: "" - ""
data_key_range
	    kv  : "" - ""
	    hash: "" - ""
	    zset: "" - ""
	    list: "" - ""
leveldb.stats
	                               Compactions
	Level  Files Size(MB) Time(sec) Read(MB) Write(MB)
	--------------------------------------------------
	  0        1        0         0        0         0
	
19 result(s) (0.001 sec)
(0.001 sec)

From the library state:

[root@ecloud02-carchat-prod-ssdb01 data]# /opt/data/ssdb-cli -h 10.80.2.85 -p 8888
ssdb (cli) - ssdb command line tool.
Copyright (c) 2012-2016 ssdb.io

'h' or 'help' for help, 'q' to quit.

ssdb-server 1.9.7

ssdb 10.80.2.85:8888> info
version
	1.9.7
links
	1
total_calls
	1
dbsize
	258
binlogs
	    capacity : 20000000
	    min_seq  : 1
	    max_seq  : 4
replication
	slaveof 10.80.2.121:8888
	    id         : svc_1
	    type       : sync
	    status     : SYNC
	    last_seq   : 4
	    copy_count : 0
	    sync_count : 0
serv_key_range
	    kv  : "" - ""
	    hash: "" - ""
	    zset: "" - ""
	    list: "" - ""
data_key_range
	    kv  : "" - ""
	    hash: "" - ""
	    zset: "" - ""
	    list: "" - ""
leveldb.stats
	                               Compactions
	Level  Files Size(MB) Time(sec) Read(MB) Write(MB)
	--------------------------------------------------
	  0        1        0         0        0         0
	
19 result(s) (0.001 sec)
(0.001 sec)
  • links

The current number of server connections.

  • total_calls

The number of requests processed since the server was started.

  • dbsize

The estimated size of the database (may be very different from the hard disk occupancy, as shown by the du command), the number of bytes. If the server has compression enabled, this size is the compressed size.

  • binlogs

The write status of the current instance.

capacity: binlog 队列的最大长度
min_seq: 当前队列中的最小 binlog 序号
max_seq: 当前队列中的最大 binlog 序号
  • replication

There can be multiple replication records. Each one represents a connected slave (client), or a master (slaveof) connected to the current server.

slaveof|client host:port, 远端 master/slave 的 host:port.
type: 类型, sync|mirror.
status: 当前同步状态, DISCONNECTED|INIT|OUT_OF_SYNC|COPY|SYNC.
last_seq: 上一条发送或者收到的 binlog 的序号.
slaveof.id: master 的 id(这是从 slave's 角度来看的, 你永远不需要在 master 上配置它自己的 id).
slaveof.copy_count: 在全量同步时, 已经复制的 key 的数量.
slaveof.sync_count: 发送或者收到的 binlog 的数量.
  • Where status:
DISCONNECTED: 与 master 断开了连接, 一般是网络中断.
INIT: 初始化状态.
OUT_OF_SYNC: 由于短时间内在 master 有大量写操作, 导致 binlog 队列淘汰, slave 丢失同步点, 只好重新复制全部的数据.
COPY: 正在复制基准数据的过程中, 新的写操作可能无法及时地同步.
SYNC: 同步状态是健康的.
  • key_range.*

The keys of different data types are sorted in SSDB, so this information indicates the minimum key and maximum key of different data types.

  • leveldb.stats

This information shows the number of files and the total file size of each level of LevelDB. The smaller the level, the fewer the files, the healthier the database (the faster the query).

3. Determine the synchronization status

For the master, binlogs.max_seq refers to the sequence number of the latest write (write / update / delete) operation on the current instance, and replication.client.last_seq refers to the sequence number of the latest binlog that has been sent to the slave.

Therefore, if you want to determine whether the master-slave synchronization has been synchronized in place (real-time update), then determine whether binlogs.max_seq and replication.client.last_seq are equal, and the status is SYNC.

Experiment: The
main library writes data:

[root@ecloud02-carchat-prod-ssdb01 data]# /opt/data/ssdb-cli -h 10.80.2.121 -p 8888
ssdb (cli) - ssdb command line tool.
Copyright (c) 2012-2016 ssdb.io

'h' or 'help' for help, 'q' to quit.

ssdb-server 1.9.7

ssdb 10.80.2.121:8888> set a 123
ok
(0.001 sec)
ssdb 10.80.2.121:8888> q
bye.

View data from the library:

[root@ecloud02-carchat-prod-ssdb01 data]# /opt/data/ssdb-cli -h 10.80.2.85 -p 8888
ssdb (cli) - ssdb command line tool.
Copyright (c) 2012-2016 ssdb.io

'h' or 'help' for help, 'q' to quit.

ssdb-server 1.9.7

ssdb 10.80.2.85:8888> get a
123
(0.001 sec)

Successful verification!

PS

If you use flushdb to delete all data, the master and slave will be invalid. In the latest version of ssdb, flushdb has been disabled in master-slave mode:

ssdb 10.80.2.121:8888> flushdb
error! - flushdb is not allowed when replication is in use!
Published 136 original articles · Like 58 · Visits 360,000+

Guess you like

Origin blog.csdn.net/sunbocong/article/details/94397067