The third stage: building the day15 redis cluster

Half bump 2020-11-09 16:06:39
stage building day15 day redis


  1. Realization Redis colony

=============

1.1 Why you need to build a cluster

redis Fragmentation features :
1. Can achieve Redis The expansion of memory data .
2.redis The slicing itself has no high availability effect . If the outage will directly affect the use of users .

redis Sentinel characteristics :
1.Redis Sentinels can achieve Redis High availability of nodes . But the sentinel itself doesn't implement a high availability mechanism .( It's better not to introduce third parties )
2.Redis The sentry has a master-slave structure The backup of memory data is realized . But did not achieve the effect of memory expansion .

upgrade :
need Redis Content expansion also requires Redis High availability, so you should use Redis colony .

1.2 About Redis How to build a cluster

  1. Close all redis The server
    sh stop.sh
  2. Delete redundant files
     Insert picture description here
    3. restart redis The server Execute mount command
`redis-cli --cluster create --cluster-replicas 1 192.168.126.129:7000 192.168.126.129:7001 192.168.126.129:7002 192.168.126.129:7003 192.168.126.129:7004 192.168.126.129:7005`

1.3 Redis Introductory cases

`@Test
public void testCluster(){
Set<HostAndPort> nodes = new HashSet<>();
nodes.add(new HostAndPort("192.168.126.129", 7000));
nodes.add(new HostAndPort("192.168.126.129", 7001));
nodes.add(new HostAndPort("192.168.126.129", 7002));
nodes.add(new HostAndPort("192.168.126.129", 7003));
nodes.add(new HostAndPort("192.168.126.129", 7004));
nodes.add(new HostAndPort("192.168.126.129", 7005));
JedisCluster jedisCluster = new JedisCluster(nodes);
jedisCluster.set("cluster", " Cluster testing !!!!");
System.out.println(jedisCluster.get("cluster"));
}`

1.4 About the electoral mechanism - Cleft brain

explain : When the cluster goes on At election , If continuity 3 Time There were The result of the even vote The brain cleft phenomenon may appear in patients with cerebral palsy .
problem : What is the probability of cleft brain ??? 1/8
mathematical modeling :
Throw silver coins in succession 3 How much is the concept of flat ticket ? 1/8=12.5%
for the first time : Zhengzheng Pros and cons Anyway Against 1/2
The second time : Zhengzheng Pros and cons Anyway Against 1/2
third time : Zhengzheng Pros and cons Anyway Against 1/2
The prevention of : Increasing the number of master nodes can effectively reduce the occurrence of cleft brain .

1.5 About group interview questions

problem 1: Redis Most storage in the cluster 16384 Data ???
In the wrong Partitions are only responsible for partitioning data The storage of data is determined by memory .
crc16(key1)%16384 = 1000
crc16(key2)%16384 = 1000
problem 2: Redis The maximum number of hosts in the cluster ?? 16384 host .
One host occupies one channel

1.6 SpringBoot Integrate Redis colony

1.6.1 edit pro The configuration file

`# To configure redis Single server
redis.host=192.168.126.129
redis.port=6379
# To configure redis Fragmentation mechanism
redis.nodes=192.168.126.129:6379,192.168.126.129:6380,192.168.126.129:6381
# Configure sentinel nodes
redis.sentinel=192.168.126.129:26379
# To configure redis colony
redis.clusters=192.168.126.129:7000,192.168.126.129:7001,192.168.126.129:7002,192.168.126.129:7003,192.168.126.129:7004,192.168.126.129:7005`

1.6.2 edit RedisConfig Configuration class

`@Configuration
@PropertySource("classpath:/properties/redis.properties")
public class JedisConfig {
@Value("${redis.clusters}")
private String clusters;
@Bean
public JedisCluster jedisCluster(){
Set<HostAndPort> nodes = new HashSet<>();
String[] nodesArray = clusters.split(",");
for (String node : nodesArray){
String host = node.split(":")[0];
int port = Integer.parseInt(node.split(":")[1]);
HostAndPort hostAndPort = new HostAndPort(host,port);
nodes.add(hostAndPort);
}
return new JedisCluster(nodes);
}
}`

1.6.3 edit CacheAOP

 Insert picture description here

1.7 About Jingtao project background description

Summary of knowledge points :
1. Frame strengthening stage
1.1SpringBoot Description of each configuration file pom.xml To configure Commonly used annotations springboot Start the execution process
1.2 About SpringBoot Common use Attribute assignment @Value , Development environment optimization , Profile import , Integrate Mybatis , Integrate MybatisPlus , Integrate web resources (JSP)
1.3 Jingtao backstage project construction
1.3.1 Distributed thinking According to the module / Split by hierarchy
1.3.2 Ideas for the creation of polymerization engineering Parent project Unified management jar package , Tools API project , Business function system
1.4 UI Tools Data interaction between the front end and the back end If you want to show a particular format structure , Must be returned as required VO object .
1.5 JSON Structure form 1.Object type 2.Array type 3. Complex type ( You can nest at infinite levels )
1.6 Backstage goods / Merchandise classified CURD operation .
1.7 Introduce rich text editor / Realize file upload business .
1.8 Reverse proxy / Forward agency
1.9 NGINX Realize image echo , NGINX install / command / Process item description / Domain name agent / Load balancing mechanism / Description of relevant properties
1.10 windows tomcat Server cluster deployment .
2.Linux Study
2.1 What is? VM virtual machine . Network configuration description The bridge /NAT Pattern
2.2 Introduce Linux Development , Introduce Linux Basic commands install Linux JDK tomcatLinux Deploy . Linux install Mysql data
2.3 Linux install Nginx The server . Whole project Linux Deploy .

3. Project real deployment
3.1 Realize the separation of reading and writing data / Load balancing / Database high availability mycat
3.2 Redis command /redis Single operation /redis Fragmentation /redis sentry /redis colony /
3.3 AOP Related knowledge .

 Insert picture description here

  1. Jingtao project front desk building

============

2.1 Jingtao project architecture

 Insert picture description here

2.2 Jingtao foreground project construction

2.2.1 Create project

 Insert picture description here

2.2.2 Add inheritance / rely on / plug-in unit

explain : edit jt-web Of pom.xml The configuration file The packing method should be changed to war secondly Add inheritance / rely on / plug-in unit

`<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>jt-web</artifactId>
<packaging>war</packaging>
<parent>
<artifactId>jt</artifactId>
<groupId>com.jt</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<!--2. Add dependency information -->
<dependencies>
<!-- What depends essentially on is jar Package file -->
<dependency>
<groupId>com.jt</groupId>
<artifactId>jt-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<!--3. Add the plug-in -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>`

Import the files from the pre class materials into . As shown in the figure .
 Insert picture description here

2.2.3 About web Description of project data source error report

SpringBoot When the program starts, it needs to load the database, but there is no configuration information of the data source . Result in an error .
 Insert picture description here
How to solve : Add exclude data source start .
 Insert picture description here

2.2.4 modify SpringBoot Start item

 Insert picture description here

2.2.5 Start the effect test

 Insert picture description here

2.2.6 edit Nginx The configuration file

explain : Require users to pass http://www.jt.com visit localhost:8092 The server .
modify nginx Restart the server after that .

`# To configure jt-web The server
server {
listen 80;
server_name www.jt.com;
location / {
proxy_pass http://127.0.0.1:8092;
}
}`

edit hosts file .
 Insert picture description here

2.2.7 About Google browser https Disable problem

Google browser type : chrome://net-internals/#hsts:
After the modification is completed , Restart the browser .
 Insert picture description here

2.3 A note on pseudo static

2.3.1 Business description

problem 1: Jingdong has a lot of goods , If all adopt the form of static page to show data for users , If there is 100 Ten thousand goods , So you need 100 Ten thousand products xxx.html page . ask : Does Jingdong do this ???
Implementation rules :
Should be dynamic access to goods ID Number . Then query the database , Then adjust the specified page , Fill in the data .

problem 2: Why does Jingdong adopt .html The request at the end shows the product ?
answer : use .html The page at the end , More easily included by search engines , Increase the exposure of the website .
 Insert picture description here

2.3.2 How search engines work

Working principle core : Inverted index mechanism . Search the position of the article according to the key words .
 Insert picture description here

2.3.3 Pseudo static thought

Pseudo static is relative to real static , Usually we do it for Enhance the friendliness of search engines , All the content of the article will be generated into a static page , But some friends in order to display some information in real time . Or I want to use dynamic script to solve some problems . Can't use static way to show website content . But this has lost the friendly side to search engine . How to find a middle way between the two , This produces Pseudo static technology . Pseudo static technology means that what is shown is to html One kind of static page form , But it's actually using ASP A class of dynamic scripts to deal with .

summary : With .html Dynamic page at the end . Enhance search engine friendliness .

2.3.4 Pseudo static implementation

explain : If you need to implement pseudo static , You need to intercept .html At the end of the request . Otherwise, the program thinks that you are accessing specific static resources, as shown in the figure
 Insert picture description here
Configuration class introduction

@Configuration //web.xml The configuration file
public class MvcConfigurer implements WebMvcConfigurer{
// Enable matching suffix configuration
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
// Turn on suffix type matching . xxxx.html
configurer.setUseSuffixPatternMatch(true);
}
}
版权声明
本文为[Half bump]所创,转载请带上原文链接,感谢

  1. 【计算机网络 12(1),尚学堂马士兵Java视频教程
  2. 【程序猿历程,史上最全的Java面试题集锦在这里
  3. 【程序猿历程(1),Javaweb视频教程百度云
  4. Notes on MySQL 45 lectures (1-7)
  5. [computer network 12 (1), Shang Xuetang Ma soldier java video tutorial
  6. The most complete collection of Java interview questions in history is here
  7. [process of program ape (1), JavaWeb video tutorial, baidu cloud
  8. Notes on MySQL 45 lectures (1-7)
  9. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  10. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  11. 精进 Spring Boot 03:Spring Boot 的配置文件和配置管理,以及用三种方式读取配置文件
  12. Refined spring boot 03: spring boot configuration files and configuration management, and reading configuration files in three ways
  13. 【递归,Java传智播客笔记
  14. [recursion, Java intelligence podcast notes
  15. [adhere to painting for 386 days] the beginning of spring of 24 solar terms
  16. K8S系列第八篇(Service、EndPoints以及高可用kubeadm部署)
  17. K8s Series Part 8 (service, endpoints and high availability kubeadm deployment)
  18. 【重识 HTML (3),350道Java面试真题分享
  19. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  20. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  21. [re recognize HTML (3) and share 350 real Java interview questions
  22. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  23. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  24. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  25. RPC 1: how to develop RPC framework from scratch
  26. 造轮子系列之RPC 1:如何从零开始开发RPC框架
  27. RPC 1: how to develop RPC framework from scratch
  28. 一次性捋清楚吧,对乱糟糟的,Spring事务扩展机制
  29. 一文彻底弄懂如何选择抽象类还是接口,连续四年百度Java岗必问面试题
  30. Redis常用命令
  31. 一双拖鞋引发的血案,狂神说Java系列笔记
  32. 一、mysql基础安装
  33. 一位程序员的独白:尽管我一生坎坷,Java框架面试基础
  34. Clear it all at once. For the messy, spring transaction extension mechanism
  35. A thorough understanding of how to choose abstract classes or interfaces, baidu Java post must ask interview questions for four consecutive years
  36. Redis common commands
  37. A pair of slippers triggered the murder, crazy God said java series notes
  38. 1、 MySQL basic installation
  39. Monologue of a programmer: despite my ups and downs in my life, Java framework is the foundation of interview
  40. 【大厂面试】三面三问Spring循环依赖,请一定要把这篇看完(建议收藏)
  41. 一线互联网企业中,springboot入门项目
  42. 一篇文带你入门SSM框架Spring开发,帮你快速拿Offer
  43. 【面试资料】Java全集、微服务、大数据、数据结构与算法、机器学习知识最全总结,283页pdf
  44. 【leetcode刷题】24.数组中重复的数字——Java版
  45. 【leetcode刷题】23.对称二叉树——Java版
  46. 【leetcode刷题】22.二叉树的中序遍历——Java版
  47. 【leetcode刷题】21.三数之和——Java版
  48. 【leetcode刷题】20.最长回文子串——Java版
  49. 【leetcode刷题】19.回文链表——Java版
  50. 【leetcode刷题】18.反转链表——Java版
  51. 【leetcode刷题】17.相交链表——Java&python版
  52. 【leetcode刷题】16.环形链表——Java版
  53. 【leetcode刷题】15.汉明距离——Java版
  54. 【leetcode刷题】14.找到所有数组中消失的数字——Java版
  55. 【leetcode刷题】13.比特位计数——Java版
  56. oracle控制用户权限命令
  57. 三年Java开发,继阿里,鲁班二期Java架构师
  58. Oracle必须要启动的服务
  59. 万字长文!深入剖析HashMap,Java基础笔试题大全带答案
  60. 一问Kafka就心慌?我却凭着这份,图灵学院vip课程百度云