Redis cluster construction and redislive monitoring and deployment
redis cluster construction and monitoring environment
Achieve a cluster of 3 masters and 3 slaves. Single machine IP: 192.168.40.128
Basic cluster construction
Simple download
Via
wget http://download.redis.io/releases/redis-4.0.10.tar.gz
Unzip
tar zxvf redis-4.0.10.tar.gz
Specify the installation path, switch to root user and execute
make && make PREFIX=/usr/ local/redis install
, there may be a problem of insufficient permissions, sudo will also report an error, use root directly to operate.
Install compilation tools
sudo apt-get update
-
sudo apt-get install gcc
sudo apt-get install make
sudo apt-get install tcl
#Create the redis cluster folder
Because it is /usr, So always operate under root permissions
##cd /usr/local/redis
mkdir cluster
cd cluster
mkdir 7000 7001 7002 7003 7004 7005
Modify the configuration fileCopy the config file in redis conf to six folders, and modify the following content
# 端口号 port 7000 # 后台启动 daemonize yes # 开启集群 cluster-enabled yes #集群节点配置文件 cluster-config-file nodes-7000.conf # 集群连接超时时间 cluster-node-timeout 5000 # 进程pid的文件位置 pidfile /home/ubuntu/redis-4.0.10/pid/redis-7000.pid #工作文件夹 dir "/home/ubuntu/redis-4.0.10/working" # 开启aof appendonly yes # aof文件路径 appendfilename "appendonly-7005.aof" # rdb文件路径 dbfilename dump-7000.rdb
Startup script
cd / home/ubuntu/redis-4.0.10/
touch start.link.sh
For easy operation, create a script
- Modify the startup script to
#!/bin/bash export BASE_FLOD="/usr/local/redis" {BASE_FLOD}/bin/redis-server /usr/local/redis/cluster/7000/redis.conf /usr/local/redis/bin/redis-server /usr/local/redis/cluster/7001/redis.conf /usr/local/redis/bin/redis-server /usr/local/redis/cluster/7002/redis.conf /usr/local/redis/bin/redis-server /usr/local/redis/cluster/7003/redis.conf /usr/local/redis/bin/redis-server /usr/local/redis/cluster/7004/redis.conf /usr/local/redis/bin/redis-server /usr/local/redis/cluster/7005/redis.conf #cd src #./redis-trib.rb create --replicas 1 192.168.40.128:7000 192.168.40.128:7001 192.168.40.128:7002 192.168.40.128:7003 192.168.40.128:7004 192.168.40.128:7005
Cluster startup
- The associated program is written in ruby. So to set up rudy's operating environment, you need to install rudbygem
sudo apt-get install ruby rubygems -y
- gem install redis, running here will feel very slow, you need to wait patiently, in the redis installation directory, src folder redis-trib.rb
- run
redis-trib. rb create --replicas 1 192.168.40.128:7000 192.168.40.128:7001 192.168.40.128:7002 192.168.40.128:7003 192.168.40.128:7004 192.168.40.12 8:7005
, check whether the configured information is correct, there is no direct Just yes.
[OK] All 16384 slots covered.means the group connection is started successfully.
Node check, restart Check the cluster running status: use the command
./redis-trib.rb check 192.168.40.128:7000, check the status of the cluster
Performance test Comes with the test tool redis-benchmark
redis-benchmark - h 192.168.40.128 -p 6379 -c 100 -n 100000
100 concurrent connections, 100000 requests, detect the performance of the redis server whose host is localhost and the port is 6379.
redis-benchmark -h 192.168.40.128 -p 6379 -q -d 100
Test the performance of accessing data packets with a size of 100 bytes.
redis-benchmark -t set,lpush -n 100000 -q
Only test the performance of certain operations.
redis-benchmark -n 100000 -q script load "redis.call('set','foo','bar')"
Only test some Performance of numerical access.
Cluster password settingNo password is required for the initial cluster establishment. After the startup is completed, first check whether the configuration file of each node has read and write permissions. If There is no read and write permissions. You need to modify the read and write permissions by chmod. Connect each node separately for settings through
./redis-cli -c -p port config set masterauth password config set requirepass password config rewrite
If you find that the connection cannot be reached after restarting, modify the startup script redis-.sh line 99 and configure Startup script password startup
@r = Redis.new(:host => @info[:host], :port => @info[:port], :timeout => 60,:password => "yangfan@1995")
Code test
/*
*集群连接测试
*/
@Test
public void testJedisCluster() {
Set<HostAndPort> nodes = new LinkedHashSet<>();
//所有主机节点ip和端口
nodes.add(new HostAndPort("192.168.40.128", 7000));
nodes.add(new HostAndPort("192.168.40.128", 7001));
nodes.add(new HostAndPort("192.168.40.128", 7002));
nodes.add(new HostAndPort("192.168.40.128", 7003));
nodes.add(new HostAndPort("192.168.40.128", 7004));
nodes.add(new HostAndPort("192.168.40.128", 7005));
//没有密码
//JedisCluster cluster = new JedisCluster(nodes);
//添加密码调用
JedisCluster cluster = new JedisCluster(nodes, 5000, 5000, 10, "yangfan@1995", new GenericObjectPoolConfig());
//cluster.zadd("test_1", String.valueOf(""),"id_2");
System.out.println(cluster.zscore("test_1", "id_1"));
try {
cluster.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Copy after login
/* *集群连接测试 */ @Test public void testJedisCluster() { Set<HostAndPort> nodes = new LinkedHashSet<>(); //所有主机节点ip和端口 nodes.add(new HostAndPort("192.168.40.128", 7000)); nodes.add(new HostAndPort("192.168.40.128", 7001)); nodes.add(new HostAndPort("192.168.40.128", 7002)); nodes.add(new HostAndPort("192.168.40.128", 7003)); nodes.add(new HostAndPort("192.168.40.128", 7004)); nodes.add(new HostAndPort("192.168.40.128", 7005)); //没有密码 //JedisCluster cluster = new JedisCluster(nodes); //添加密码调用 JedisCluster cluster = new JedisCluster(nodes, 5000, 5000, 10, "yangfan@1995", new GenericObjectPoolConfig()); //cluster.zadd("test_1", String.valueOf(""),"id_2"); System.out.println(cluster.zscore("test_1", "id_1")); try { cluster.close(); } catch (IOException e) { e.printStackTrace(); } }
The relationship between master-slave mode, sentry, and cluster
- The master-slave mode specifies the replication and persistence relationship, and the master-slave backup relationship.
- Sentinel: When the master database encounters an exception and interrupts the service, developers can manually method to select a slave database to upgrade to the master database so that the system can continue to provide services. It is mainly a detection tool to solve the problem of manual switching of master-slave relationship during master-slave replication, and can automatically switch master-slave.
使用哨兵,redis每个实例也是全量存储,每个redis存储的内容都是完整的数据,浪费内存且有木桶效应。为了最大化利用内存,可以采用集群,就是分布式存储。即每台redis存储不同的内容,共有16384个slot。每个redis分得一些slot,hash_slot = crc16(key) mod 16384 找到对应slot,键是可用键,如果有{}则取{}内的作为可用键,否则整个键是可用键集群至少需要3主3从,且每个实例使用不同的配置文件,主从不用配置,集群会自己选。
监控部署
RedisLive搭建部署
运行环境部署
git clone https://github.com/kumarnitin/RedisLive.git
下载redislive,解压缩unzip -o -d /home/ubuntu/ RedisLive-master.zip
进入src文件夹,复制example文件,编辑
"RedisServers": [ { "server": "192.168.40.128", "port" : 7000, "password" : "yangfan@1995" }, //...多个监听 ], "DataStoreType" : "redis", "RedisStatsServer": //存储的redis监听接口 { "server" : "127.0.0.1", "port" : 6379 }, "SqliteStatsStore" : { "path": "/home/ubuntu/redis-4.0.10/working/redislive.db" //进行存储的文件 } }
Copy after loginubuntu@ubuntu:~/redis-4.0.10$ mkdir pid
ubuntu@ubuntu:~/redis-4.0.10$ mkdir log
ubuntu@ubuntu:~/redis-4.0.10$ mkdir working
//保存aof,rdb,node-config文件。RedisLive分为两部分,其中一部分为监控脚本,另一部分为web服务,所以需要分别启动。`./redis-monitor.py
--duration=120`./redis-live.py
redis.clients.jedis.exceptions.JedisNoReachableClusterNodeException: No reachable node in cluster redis node的redis.conf 绑定ip设置为指定的redis节点ip,启动集群时只用指定ip启动,不使用192.168.40.128
connect refuse 关闭防火墙
No module named redis
查看python位置
which python
先备份
sudo cp /usr/bin/python /usr/bin/python_cp
删除
sudo rm /usr/bin/python
默认设置成python3.5,创建链接
sudo ln -s /usr/bin/python3.5 /usr/bin/python
Q&A
相关推荐:
The above is the detailed content of Redis cluster construction and redislive monitoring and deployment. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Square Root in Java. Here we discuss how Square Root works in Java with example and its code implementation respectively.

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to the Armstrong Number in Java. Here we discuss an introduction to Armstrong's number in java along with some of the code.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is
