In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the methods of dealing with session in the Linux distributed environment. The content of the article is of high quality, so the editor shares it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.
What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.
The first kind: sticky session
Principle: sticky session refers to locking the user to a server. For example, when the user first requests, the load balancer forwards the user's request to server a. If the load balancer sets sticky session, then every subsequent request of the user will be forwarded to server a, which is equivalent to gluing the user and server a together. This is the sticky session mechanism.
Pros: it is simple and does not require any processing of session.
Disadvantages: lack of fault tolerance, if the current access to the server failure, the user is transferred to the second server, his session information will be invalid.
Applicable scenario: failure has little impact on the customer; server failure is a low-probability event.
Implementation: taking nginx as an example, the sticky session can be realized by configuring the ip_hash attribute in the upstream module.
?
one
two
three
four
five
six
Upstream mycluster {
# what is added here are the two tomcat servers started above
Ip_hash;# viscous session
Server 192.168.22.229:8080 weight=1
Server 192.168.22.230:8080 weight=1
}
Second: server session replication
Principle: when the session on any server changes (add, delete, modify), the node serializes all the contents of the session and broadcasts it to all other nodes, regardless of whether the other servers need session or not, to ensure session synchronization.
Advantages: fault-tolerant, session between servers can respond in real time.
Disadvantages: it will cause some pressure on the network load, and if the amount of session is large, it may cause network congestion and slow down the server performance.
Implementation method:
① sets tomcat, server.xml enables tomcat cluster function
Address: just enter the native ip and set the port number to prevent port conflicts.
② adds information to the application: notifies the application that it is currently in a clustered environment and supports distributed
Add options in web.xml
The third kind: session sharing mechanism
Use distributed caching schemes such as memcached and redis, but require that memcached or redis be clustered.
There are also two mechanisms for using session sharing, which are as follows:
① viscous session treatment
Principle: different tomcat specifies to access different master memcached. Information between multiple memcached is synchronized, capable of master-slave backup and high availability. When the user accesses, first create a session in the tomcat, and then put a copy of the session on its corresponding memcahed. Memcache only serves as a backup, and all reads and writes are on tomcat. When a tomcat is hung up, the cluster locates the user's access to the slave tomcat, and then finds the session according to the sessionid stored in the cookie. If it cannot be found, it goes to the corresponding memcached to session, and then copies it to the slave tomcat.
② non-viscous session treatment
Principle: memcached master and slave copy, write session all write to slave memcached service, read from master memcached, tomcat itself does not store session
Advantages: fault tolerance, session real-time response.
Implementation: using open source msm plug-ins to solve the session sharing between tomcat: memcached_session_manager (msm)
a. Copy the relevant jar package to the tomcat/lib directory
Java memcached client: spymemcached.jarmsm project related jar package: 1. Core package, memcached-session-manager- {version} .jar2. Tomcat version of the corresponding jar package: memcached-session-manager-tc {tomcat-version}-{version} .jar sequence chemical kit: optional kryo,javolution,xstream, etc., if not set, use jdk default serialization.
b. Configure context.xml to join the manager that handles session
Sticky mode configuration:
Non-sticky configuration:
Fourth: session persistence to database
Principle: needless to say, take out a database specifically used to store session information. Ensure the persistence of session.
Pros: if there is a problem with the server, session will not be lost
Disadvantages: if the site has a large number of visitors, storing session in the database will put a lot of pressure on the database and require additional overhead to maintain the database.
The fifth terracotta to achieve session replication
Principle: the basic principle of terracotta is that when a node changes, terracotta only sends the changed part to the terracotta server, and then the server forwards it to the node that really needs the data. It can be regarded as the optimization of the second scheme.
Advantages: this puts very little pressure on the network, and each node does not have to waste cpu time and memory to do a lot of serialization operations. This mechanism of data sharing among clusters is applied to session synchronization, which not only avoids the dependence on database, but also achieves the effect of load balancing and disaster recovery.
Original link: http://blog.csdn.net/u010028869/article/details/50773174?ref=myread
On the Linux distributed environment to deal with session methods to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.