1. nginx
Nginx binds multiple Web servers to the same IP address to achieve load balancing among multiple web servers and reduce the load of a single web server to improve overall performance and stability.
The following is a simple method for installing and configuring nginx:
1) download and decompress nginx to the local directory: http://nginx.org/en/download.html
2) nginx configuration is mainly to modify its configuration file/CONF/nginx. conf. The following link describes the attributes of the nginx. conf configuration file:
Http://www.cnblogs.com/xiaogangqq123/archive/2011/03/02/1969006.html
To use nginx to configure Server Load balancer for Web servers, you need to modify the following:
A) configure the upstream attribute under the HTTP tag, for example:
[Plain]View plaincopy
- Upstream mysvr {
- # The weigth parameter indicates the weight. A higher weight indicates a higher probability of being assigned.
- Server 192.168.8.1x: 3128 Weight = 5;
- Server 192.168.8.2x: 80 Weight = 1;
- Server 192.168.8.3x: 80 Weight = 6;
- }
Weight is optional. If weight is not configured, all Web servers have the same weight by default.
B) modify the server label under the HTTP label, for example:
[Plain]View plaincopy
- Server {
- Listen 83;
- SERVER_NAME localhost;
- Location /{
- Root/root;
- Index index. jsp;
- Proxy_pass http: // mysvr;
- Proxy_set_header host $ HOST: 83;
- Proxy_set_header X-real-IP $ remote_addr;
- Proxy_set_header X-forwarded-for $ proxy_add_x_forwarded_for;
- }
- ......
- }
It should be noted that SERVER_NAME and listen respectively set the user access address and port; proxy_pass specifies the list of servers to be switched (defined in upstream ); proxy_set_header host sets the address in the HTTP packet to be redirected to the address specified in proxy_pass. You can also specify the port number here. If this parameter is not specified, port 80 is redirected by default.
For other attributes that need to be set, see the details in the above link.
3) after the configuration is complete, enter the nginx root directory in the console. Run nginx or nginx-s start to start the nginx server, run nginx-s stop or nginx-s quit to disable nginx (do not use Ctrl + C to force the end ).
2. memcached
Memcached is a key-value ing cache system. In webapplication, memcached can be used to cache frequently accessed objects. In distributed Web Server Clusters, memcached must be used to support the consistency of sessions in individual web servers.
Here we need to use an open-source project, namely memcached Session Manager (MSM). The following link is the official website of this open-source project:
Http://code.google.com/p/memcached-session-manager/
The following link is the official installation and Configuration Wizard:
Http://code.google.com/p/memcached-session-manager/wiki/SetupAndConfiguration
The following is a simple method to use MSM to manage the unified session storage of Tomcat server groups in clusters through nginx:
1) download, install, and run memcached:
Linux: http://memcached.org/
Http://code.jellycan.com/memcached/ for Windows
2) download the required jar package and place it in the Lib path of Tomcat:
A) memcached-session-Manager-$ {version}. jar, Basic Package
B) memcached-session-manager-tc6-$ {version}. Jar (for Tomcat 6) or memcached-session-manager-tc7-$ {version}. Jar (for Tomcat 7), server support package
C) spymemcached-2.8.12.jar and couchbase-client-1.1.4.jar, cache support package
D) msm-javolution-serializer.jar and javolution-5.4.3.1.jar, serialization support package
3) In the/CONF/context. xml file of Tomcat, add the following code under the root tag <context>:
[HTML]View plaincopy
- <Managerclassnamemanagerclassname = "De. javakaffee. Web. MSM. memcachedbackupsessionmanager"
- Memcachednodes = "$ {tag}: localhost: 11211"
- Requesturiignorepattern = ". */. (PNG | GIF | JPG | CSS | JS) $"
- Sessionbackupasync = "false"
- Sessionbackuptimeout = "100"
- Transcoderfactoryclass = "De. javakaffee. Web. MSM. serializer. javolution. javolutiontranscoderfactory"
- Copycollectionsforserialization = "false"/>
$ {Tag} can be replaced with any string to mark the webserver.
4) after completing the preceding configuration, start Tomcat. If no error occurs, the configuration is successful. When the session ID is obtained through the GETID method of httpsession, the above mark is displayed at the end of the ID.
Reprinted: http://blog.csdn.net/sadfishsc/article/details/9151083