Different application servers, session how to share

One: mysql database shared sessionid one: all the session_id are stored in the mysql database, each request to when they are going to check the database inside sessionid, to achieve the purpose of the method sessionid synchronization of two: sessionid table with all table together, if mysql made from the master, the needs of every database exists in this form, and from time to time synchronize the advantages and disadvantages: the above two methods, a method is better to separate the session table and table service, reduces database pressure, mysql is a disk-based database, reading and writing was relatively slow, if the read and write frequently, efficiency is very low, and therefore do not recommend this approach. Second By sharing session cookie to the user session information to access a page on the cookies produced, cookie-A transfer station when a user accesses the server, session information is generated and stored in a cookie when the user accesses a server assigned to B, the first check the server has no session information, and if not, then put inside the session cookie information synchronized to the server B drawback: cookie sharing session, security is not high, intercepted or forged increased possibility, if the client is prohibited cookie, there may not be shared session Adoption of the server sync shared session using a single server as a login server, after the login is successful, we can use a script or daemon session information is synchronized to other servers, so that other servers have session information, you can Stay signed in the. Cons: sync server is slow, after a visit at the distribution may not wait until the synchronization finished, and once the login server is down, the entire system can not run four through NFS share sessionNFS (network file system) allows different machines. , different operating systems to share files. Preparing an NFS server, writes all the generated session information to the server each time the user visits, all to the server to obtain session information, so that we can share the information session. Disadvantages: too dependent, if the NFS server goes down, you can not work, of course, you can consider setting up a cluster. Fives. Use memcache to synchronize sessionmemcache is a distributed caching system, memcache workflow: When a user accesses the server, the data is first obtained from memcache, if you can not get the data acquired from the database, and the data is synchronized to the memcache , the second time will be able to get access to the data from memcache. So no matter what server-generated session information is stored in memcache, you can share the advantages and disadvantages sessionid: This synchronization session, will not increase the burden on the database, and more than cookie security, in memory, speed reading faster disadvantages: memcache data is stored in the form of a block of memory, memory can not be fully utilized, it will produce memory fragmentation. And memcache exists only in memory, once the server is down, the data is lost, six. Memcache sharing session and shared by redis sessionredis, as are the data stored in the memory, the difference is redis will periodically update the data write into the disk or the modified operating appended to the log file, and may be implemented on the basis of the master


Guess you like

Origin blog.51cto.com/14500648/2430034