Many resources are called in the Intranet environment ( database 、web Interfaces, etc. ) It's all through the intranet DNS Services for domain names -IP Mapping .

But often DNS After the mapping is modified , The resources connected in the application have not changed .

It used to be generally believed that linux Of dns Caching causes , A complete analysis was made today , give the result as follows :

1、Linux The local part of the system DNS The cache of

CentOS The system itself does not contain DNS Cache mechanism , Unless it's installed and started nscd service (name server cache daemon).

nscd After the service is started, it will default to all local dns Parsing makes a layer of cache , Expiration time defaults to 3600 second , Restarting the application will not reset nscd The cache of , Unless with /etc/init.d/nscd reload, Forced to refresh nscd cache .

Turn on nscd Services can greatly reduce application requests DNS Frequency of service , At the same time, to a certain extent, it can be used to DNS There is a certain fault tolerance for service failures . But the disadvantages are very obvious ,DNS Service mapping changes cannot be perceived by applications in real time , Every time the mapping is modified, it must be on all client machines reload nscd.

The above conclusion is approved by DNS The service log is verified .

2、JVM Local to the virtual machine DNS cache

Realize in java.net.InetAddress A simple DNS Caching mechanisms , It used to be mistaken for Linux Of DNS cache ,jdk6/7 The default is cache 30 second .

The cache range is JVM Virtual machine process , That is to say, the same JVM In progress ,30 Only one domain name will be requested in seconds DNS The server once , Can greatly reduce the impact of the application on DNS Analysis of network loss and pair DNS The pressure of service .

The above conclusion is approved by JAVA Test program and DNS The service log is verified .

3、 Long connection processing ( Database link 、redis Connect 、zookeeper、activeMQ Connections etc. )

according to 1、2 Two conclusions , When Intranet DNS After a domain name mapping is modified , The app is at most 30 It's going to change in seconds . But this is not the case , The reason is that a lot of resources are “ A long connection ” The way .

For example, the database connection pool is a typical long connection , To ensure connection pool efficiency , We can't set the validity period of a single connection too short . As a result, this kind of long connection cannot respond quickly DNS The mapping of the server changes .

There is only one solution :DNS After the mapping of the server changes , Need to restart the application , So that the long connection follows the new DNS Mapping to build .

The above conclusion is approved by JAVA Test program and DNS The service log is verified .

Give me a break , Finally back to the origin :

In order to ensure that these long connection resources in the application can respond in time DNS Changes in mapping , At present, we still have to restart the application to solve the problem .

Linux Intranet environment DNS Modify the domain name to ,JAVA Can applications switch in real time

  1. Linux How to install and deploy the system in offline or Intranet environment Docker Services and other services

    How to work in offline environment or pure Intranet environment Linux Install and deploy on the machine Docker Services or other services . This time we use Docker Service and Ansible Service as an example . Gets all of the rpm package Promise to get rpm The bag machine can access the Internet . Ben ...

  2. In the Intranet environment for Elasticsearch 5.0.2 add to head service

    background : The server of this project is Intranet environment , No network , So it needs to be in an offline environment , install head service . The installation packages you need to use are : node Installation package elasticsearch Of head Plugin source code explain : This time it's just about elas ...

  3. Build Intranet environment NTP The server

    Said in the previous :ntp and ntpdate difference ① Both services are centos Self contained (centos7 I don't bring it with me ntp).ntp The package name for is ntp:ntpdate Our installation package is ntpdate. They are not provided by an installation package . ② ...

  4. Centos7.2 Intranet environment installation MySQL5.7.24

    1. Configure local yum Source Intranet environment , First you need to configure the local yum Source , To solve the problem MySQL Dependent installation of , Refer to this article for details : Click on the open 2. View the server environment uname -a 3. Go to the official website to download MySQL Installation package MySQL Official website : ...

  5. linux Intranet time synchronization configuration

    At work , The time of machines in Intranet environment will be different , In some test environments, it takes a millisecond and no error is allowed , But I don't want to synchronize Internet time , Then we can choose a machine as a time server for other machines to synchronize time , For example, every 1 Minute synchronization time . One ...

  6. dnspod-sr Intranet lightweight DNS Preferred solution - Operation saves time

    dnspod-sr Intranet lightweight DNS Preferred solution - Operation saves time undefined

  7. Deployment on Intranet environment k8s+docker colony : colony ftp Of yum Source configuration

    Contact docker It's been a year , I want to share some of my knowledge with you . Because the company's computer room is an intranet environment, unable to connect to the Internet , So all the deployment here is based on the Intranet environment . First , Need to pass through ftp Service production local yum Source , It can be downloaded from ht ...

  8. Intranet environment use ansible install software When you need an extranet , How to bind a proxy

    Intranet environment use ansible install software When you need an extranet , How to bind a proxy ? Method 1 : stay ansible In the script of ,yum install The place of , Add the statement : environment: https_p ...

  9. Linux Learning experience jnlp Documents and java Application security settings

    author : Fengxueting Source :http://www.cnblogs.com/FengXueTing-px/ Welcome to reprint jnlp Documents and java Application security settings 1. Preface 2. jnlp File open for 3.java Applications ...

Random recommendation

  1. GLSL Entry point not found

    Solution : In reference to OpenGL The header file #include <GL/glew.h>#include <GL/glut.h> Add before #define GLUT_DISABLE_AT ...

  2. Where does beauty come from?

    One more question, rational beauty should come from a dedicated brain and mind. Should there be more ...

  3. iOS - NSURLConnection Network request

    Preface @interface NSURLConnection : NSObject class NSURLConnection : NSObject DEPRECATED: The NSURLConne ...

  4. Java Database connection code collection ( turn )

    Java Database connection interface (JDBC) yes Java For database connection and operation API Set . There are different database vendors that provide implementation classes for this interface , about Java For the programmer , Programmers don't need to care about the underlying implementation of the database , A unified ...

  5. Android ART brief introduction

    One .    Android ART brief introduction Android DEX/ODEX/OAT file

  6. windows modify Host It didn't take effect after .

    open CMD command , Input ipconfig /flushdns that will do

  7. Once from 0 To 1 Of java Project practice checklist

    Although work is a simple thing to do repeatedly , But not all the simple things you have a chance to do . We work on weekdays , Most of the time it's just tinkering , And it's also very important . Do the repair work well , Do a good job of optimization , Enough to get you promoted and raised ! But if there's a chance ...

  8. [openjudge- Search for ] The castle problem (The Castle)

    Title Description describe chart 1 It's a topographic map of a castle . Please write a program , Count the total number of rooms in the castle , How big is the biggest room . The castle is divided into mn(m≤50,n≤50) Square block , Each square can have 0~4 face a wall . Input Program from standard input device ...

  9. NodeJS + PhantomJS Grab page information and screenshots

    utilize PhantomJS Making screenshots of web pages is economical and applicable , But it's API Less , It's hard to do other functions . for example , Its own Web Server Mongoose You can only support at the same time 10 A request , It's not very practical to expect him to be an independent service ...

  10. cookie It is easy to use

    cookie It is easy to use // The organization of the current login Id HttpCookie SingleValueCookie = new HttpCookie("DepartmentId", &qu ...