Beijing Taobao project day15

Time:2021-8-29

1. Redis cluster description

1.1 what are the disadvantages of fragmentation / sentry

1. Fragmentation disadvantage: the main function of fragmentation is to expand memory, but it has no high availability effect
2. Disadvantages of sentry: the data is not expanded, and the sentry itself has no high availability mechanism
Requirements: it can not only realize the expansion of memory, but also realize the high availability mechanism (without a third party)

1.2 redis cluster construction

1.2.1 description of redis cluster construction

1. First shut down all redis servers
Beijing Taobao project day15

2. Check whether the configuration file is edited correctly
3. Delete redundant configuration files
Beijing Taobao project day15

4. Restart the redis server
Beijing Taobao project day15

5. Build a redis cluster

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 introduction to cluster

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

1.4 interview questions

1. A total of 16384 keys can be stored in the redis cluster?? incorrect
A: 16384 is just the number of slots. It is only responsible for planning who manages the data. How to store the data is determined by redis memory
2. How many hosts can there be in a redis cluster? 16384 main engine
3. If multi-threaded operation is encountered in redis, is there a thread safety problem? No,
Because: redis server is a single process and single thread operation. Each operation is executed by one thread, so there will be no thread safety problem
4. How does redis optimize memory data? LRU / LFU / random algorithm / TTL

1.5 integration of redis cluster with springboot

1.5.1 edit the properties file

Note: write the nodes of the redis cluster into the pro configuration file

#Configure a single redis server
#redis.host=192.168.126.129
#redis.port=6379

##Configure redis fragmentation
#redis.nodes=192.168.126.129:6379,192.168.126.129:6380,192.168.126.129:6381

#Redis cluster configuration
redis.nodes=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.5.2 edit configuration class

package com.jt.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;
import java.util.Set;

@Configuration // identifies me as a configuration class
@PropertySource("classpath:/properties/redis.properties")
public class RedisConfig {

    //Redis cluster operation
    @Value("${redis.nodes}")
    private String nodes;   //node,node,node

    @Bean
    public JedisCluster jedisCluster(){
        Set<HostAndPort> nodeSet = new HashSet<>();
        String[] nodeArray = nodes.split(",");
        for (String node : nodeArray){ //host:port
            String host = node.split(":")[0];
            int port = Integer.parseInt(node.split(":")[1]);
            nodeSet.add(new HostAndPort(host,port));
        }
       return new JedisCluster(nodeSet);
    }


   /* *//**
     *Springboot integrates redis fragmentation, in essence: shardedjedis objects, which are managed by containers
     *//*
    @Value("${redis.nodes}")
    private String nodes;   //node,node,node

    @Bean
    public ShardedJedis shardedJedis(){
        List<JedisShardInfo> shards = new ArrayList<>();
        String[] nodeArray = nodes.split(",");
        for(String node : nodeArray){ //node=ip:port
            String host = node.split(":")[0];
            int port = Integer.parseInt(node.split(":")[1]);
            //Prepare fragment node information
            JedisShardInfo info = new JedisShardInfo(host,port);
            shards.add(info);
        }
        return new ShardedJedis(shards);
    }*/



   /* @Value("${redis.host}")
    private String host;
    @Value("${redis.port}")
    private Integer port;

    @Bean
    public Jedis jedis(){
        return new Jedis(host,port);
    }*/
}

1.5.3 edit AOP configuration

Inject redis cache object into AOP
Beijing Taobao project day15

2. Construction of Jingtao front desk project

2.1 composition design of Jingtao rack

Beijing Taobao project day15

2.2 jt-web project creation

2.2.1 create jt-web server

Beijing Taobao project day15

2.2.2 add Inheritance / dependency / Plug-in

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

    <!-- Project coordinates -- >
    <modelVersion>4.0.0</modelVersion>
    <artifactId>jt-web</artifactId>
    <!-- Pack war -- >
    <packaging>war</packaging>

    <!-- Parent project -- >
    <parent>
        <artifactId>jt2007</artifactId>
        <groupId>com.jt</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <!-- Add dependency -- >
    <dependencies>
        <dependency>
            <groupId>com.jt</groupId>
            <artifactId>jt-common</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

    <!-- 4. Add Maven plug-in -- >
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

2.2.3 importing static resource files

Note: import the file SRC directory in the pre class materials into JT web
Beijing Taobao project day15

2.2.4 description of main startup class

Note: the JT web server will load the automatic configuration of the data source when it is started, but the web server does not configure the data source, so an error is reported
Beijing Taobao project day15

Add data source on startup class
Beijing Taobao project day15

2.2.5 configure working directory

Beijing Taobao project day15

2.3 domain name reverse proxy

Requirements: users are required to pass http://www.jt.com Visit localhost: 8092 server

2.3.1 modifying the host file

Beijing Taobao project day15

2.3.2 modifying the nginx configuration file

#Configure foreground server
    server {
        listen 80;
        server_name www.jt.com;

        location / {
            proxy_pass http://localhost:8092;
        }
    }

After modification, restart the nginx server
Beijing Taobao project day15

2.3.3 page effect display

Beijing Taobao project day15

2.4 disable HTTPS in Google browser

Type the address:
Beijing Taobao project day15

After modification, empty the cache and restart the browser

2.5 enable suffix type matching

Note: because the commodities of Jingdong Mall are displayed through
url:https://item.jd.com/100213774…

URL address summary:
    one http://www.jt.com/index          The request will be intercepted by the controller
    two http://www.jt.com/index.html   By default, the request means to obtain the resource file and will not be intercepted
    Under normal conditions: the controller only intercepts prefix type requests. If it needs to intercept suffix type requests, it needs to be configured separately

3 jump to the login registration page

3.1 realize general page Jump

url1: http://www.jt.com/user/login.html      Jump to page login.jsp
url2: http://www.jt.com/user/register.html   Jump to page register.jsp

Requirement: can you use a controller method to jump to a general page?

package com.jt.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/user")
public class UserController {

    /**
     *Jump to user login / registration page
     * url1: http://www.jt.com/user/register.html
     * url2: http://www.jt.com/user/login.html
     */
    @RequestMapping("/{moduleName}")
    public String module(@PathVariable String moduleName){

        return moduleName;
    }

}

3.2 embodiment of pseudo static

Pseudo static is relative to real static,Usually we want to enhance the friendliness of search engines, the article content will be generated into static pages, but some friends want to display some information in real time. Or you want to use dynamic scripts to solve some problems. You can’t display the website content in a static way. But this loses the friendliness to the search engine. How to find an intermediate method between the two, which is producedPseudo static technique。 Pseudo static technology shows that it is in the form of static pages such as HTML, but it is actually handled by dynamic scripts such as ASP.

Summary: a form of dynamic page ending in. HTML

task

1. Preview what is cross domain?

1. Jsonp 2. CORS mode