- 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
- Close all redis The server
sh stop.sh - Delete redundant files
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
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 .
- Jingtao project front desk building
============
2.1 Jingtao project architecture
2.2 Jingtao foreground project construction
2.2.1 Create project
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 .
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 .
How to solve : Add exclude data source start .
2.2.4 modify SpringBoot Start item
2.2.5 Start the effect test
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 .
2.2.7 About Google browser https Disable problem
Google browser type : chrome://net-internals/#hsts:
After the modification is completed , Restart the browser .
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 .
2.3.2 How search engines work
Working principle core : Inverted index mechanism . Search the position of the article according to the key words .
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
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);
}
}