Finally, when you---order the Load balancer system (NGINX+MEMCACHED+FTP upload image +iis)

Source: Internet
Author: User
Tags ftp site memcached manager

See also graduation

Opposite the University of Commerce and Industry Graduates Corporation at the graduation photo, a face is full of smiles, perhaps is satisfied with his four years of practice, perhaps is looking forward to enter the prosperous society ...
Coincides with the time of the continuous drizzle and the sky catkins, it seems that they are in the heart of those parting sadness, and the future of vision and hesitation.
Think of graduation, come and go in a hurry, leaving only a photo of the class and bedroom friends: Goodbye, treasure! A little pity!
See also graduation, another year, feeling two words, cherish time, good refueling, nonsense end, back to the theme.

Background

Since graduation, has been in the current company to do the development of order meal system, when there is no word of mouth, not hungry, not to mention the United States to sell outside, Baidu sold outside ... Because the size is relatively small, is a server contains a database, IIS ... And then it's over. Finally wait for the litters group development meal system, thought can learn more server related things, production environment I can't touch, but still understand a lot of content: session how to use database to save, picture how to use a separate server and so on, although all is pediatrics, but first contact these when, Still have a lot of emotion: think before have been white.

And then, finally, one of our customers daily orders at 5K (12, still pretty good), I thought the opportunity came again, just as I was filled with joy of the two server, then they told us that they use other people's system, then, the order began to be less, then, the group to their city, and then , then there is no more.

No audience, no good performance also has no meaning, although sometimes will be a temporary rise, set an environment to play, but a problem on the give up, after all, no useful.

Finally, a distribution of customers, every day there are 2K orders, I think it is time to learn the "load balance", and then have the following, I am also the first real use of this, not the right place, welcome treatise.

Nginx Installation and Configuration

This part of the basic operation is similar, blog Park also has a lot of articles explained very detailed, I also refer to this piece of article, written quite detailed, nginx+iis to achieve load balancing

Configuration, I am the server node added configuration server_name www.xxx.com a.xxx.com; Easy access by domain name.

External network unreachable?

After the configuration is complete, the server access is very normal, with IP, the domain name access is also normal, firewall port also added an exception, just situations, only remembered, the earlier time configuration Server-u, (if the installation did not open the firewall) to choose the program to add exceptions, in fact, the domain name resolution has already completed , ping test is normal, two server separate access is also normal, so only may be a firewall problem, configuration is simple, control Panel---Windows Firewall---Advanced settings---Inbound rules---new RULES---program---Select nginx---next .... Complete

    

After setting the network domain name access is OK

Session Database Configuration

After using two servers, to consider the issue of session sharing, before development, but also use the database to save, a little bit of understanding, so this time also use the database to save.

To use the database to save the session, first configure the database (nonsense), followed by the relevant configuration in Web. config.

The configuration database is relatively simple, navigate to the specified. NET version, execute the following commands, such as my server is a 64-bit operating system, with the. NET 4.0, the following commands are as follows

Locate the specified folder: CD C:\Windows\Microsoft.NET\Framework64\v4.0.30319

Execute command: aspnet_regsql.exe-s xx\sql2008-u user-p passward-d sessiondb-ssadd-sstype C

Above this command-s indicates the server name, also can write IP,-u represents the user name,-p means the password-D indicates the name of the database to be generated

When you execute a command, some servers may prompt you to add them before the command. \ direct add on it, the prompt is OK, then you find that you have automatically generated a data for the name of-D after the name.

  

Next is the Web. config configuration to add the following to the <system.web> node.

The database link string section is the database-related information generated above, as described in

Complete the above operation, you can normally access, and then, search for business, add shopping cart, submit orders, such as a series of booking process is completed, in order to facilitate viewing, I added a "1" on the first page header of a server, to distinguish two servers, because there is no configuration weight

So basically the average per server request once.

Yes, I do. A series of processes are normal, but is it really done? Actually, it's early!

  

Image upload

Before a single server, upload pictures themselves to the root directory/uplpad/, the path is saved to ~/upload/201601/xxx.png, the foreground display using Server.MapPath (picture path) on it.

Divided into multiple servers, the previous way can only save pictures to the server, the other server can not be accessed, I refer to the original Discuz code, the use of FTP to upload to the remote server, the specific operation is as follows:

1, select a server as a picture server, select a folder, such as images as the location of all the pictures stored.

2, build a site in IIS, the root directory is the first step to create the images folder, binding several domain names such as: Img0.ihangjing.com,img1.ihangjing.com ... When the picture is saved, randomly selects a data in the 0-x, and the last path to save the image is IMG (n). Ihangjing.com/upload/yyyymm/xxx.png.

3, create an FTP site, the root directory is also the first step to create the Images folder, set a good user name such as: Ftpuser, password such as: Ftppwd.

4. Configure FTP-related information, as follows:

    

5, upload the picture, call the implementation of the FTP code, save the file on it.

FTPs FTPs = new FTPs ();

FTPs. UploadFile ("/" +strday, Dirurl + "/" + TempFileName, FTPS.FTPUPLOADENUM.WEBIMG);

6, through the above process, the picture path is the absolute path to save, so when requesting a picture, regardless of which server, the display is normal.

  

Note: FTPs code is basically reference Discuz, do some adjustment, here do not paste code, interested in their own download ha.

Cache configuration Memcached

The previous cache was used by the class System.Web.Caching.Cache this is to save the memory of this server, it should be accurate (for each application domain to create an instance of the class), when multiple servers, each server is slow to exist in its own memory, if a server data updates, cannot be notified to another server, the data of that other database is "dirty data"

Before the site, with the PC site there is a cache update is not timely, later lazy used for a relatively simple way to deal with: when the PC-side update cache, through the HTTP interface to update the site's cache. So, there are two steps to updating the cache before:

Updatecachebykey ("Webpromotionconfig"); Update Other site Caches
Easyeatcache.getcacheservice (). Removeobject ("/webpromotionconfig");//Update the site cache

Although this can really solve most of the problems, but the trouble, so decided to use the memcached cache server, the specific operation is as follows:

1, download the installation files, for everyone convenience I upload a file here. Click I download

2, as for the installation, start these have a lot of articles are written a lot of detail, we search by themselves, I am referring to this article: Http://www.tuicool.com/articles/VjEvQb

In fact, there are two basic operations

Installation Services: memcached.exe-d Install

Start Service: memcached.exe-m 1024-d start

Enter the list of services and see that the service is working properly, such as:

    

Because I used two servers, two servers were installed and started the service.

    

3, the implementation of the client, I use the Memcached Providers, the original is used Memcached.ClientLibrary.dll, the website has been unable to open, nor error, later checked, originally this can only be used in. NET 2.0, only decisively give up, With the configuration file configuration using local cache, or memcached (most of our customers still use only one server, this configuration is much more convenient), the final code cache layer structure is as follows:

    

4,web.config configuration Memcached Providers, the wording is similar, the following is my own configuration file (personally tested is available, please rest assured that use)

    

    

5, after the above operation, the original project cache has switched to the memcached. Step is on these, the actual operation still encountered many problems, such as: from Memcached.clientlibrary replaced Memcached Providers, data has been cached, and finally

There is no way, only to restart the service, and then good, specific what reason also did not understand, re-start is really a good way. Look at the data cache log, the heart is finally more practical, I want to get a memcached manager to monitor the specific data, add the server has prompted the user name password is incorrect

, this will be put aside for a while, the back is free and then study carefully. If any friend knows, please do not hesitate to enlighten ha.

   

Order notification merchant, distribution clerk

We order to notify the merchant, the Distribution Clerk app is to call the WCF notification via IIS to the socket server, and then pushed by the server to the appropriate app, interested can look at my previous article, "SuperSocket-based IIS active push message to Android client"

Now that I have become more than one server, I just need to modify the server IP under WCF. Such as

    

At present, the socket server, or a server, if the merchant and the distribution staff reached a certain amount, a single server is unable to support, I think the next step is to consider the socket load balancing things, if any friends understand, also please enlighten under ha.

Conclusion

I was the first to deploy, before this is really not sure whether I can complete the matter, halfway also want to give up (nothing is difficult, as long as willing to give up), and finally still rely on the strength of the unwilling: there are difficulties we have to go on, no difficulty in making difficulties.

Although the finishing structure has been deployed, the use is normal, but there are a lot of problems waiting, for example, session sharing with the database is good, or use Memcached it, so after deployment can support the current customer's order volume ...

Article to complete here, feel helpful, move hands pointing a praise, picture happy, think write not good, also accept shoot brick Kazakhstan, write incorrect place, please kindly enlighten next Kazakhstan, common progress.

Finally again Spit Groove: Last wrote an article "Order Meal system synchronization hungry business orders" was taken first page, a start said is wrong, put back, and later said again mistaken, and took out, I was drunk. If there is also to do this piece, everyone exchanges under OH.

Become a good programmer!

Finally wait until you---ordering system load balancer (nginx+memcached+ftp upload image +iis)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.