Load Balancing is built on the existing network structure, it provides a cheap, effective, and transparent method to expand the bandwidth of network devices and servers, increase throughput, enhance network data processing capabilities, and improve network flexibility and availability.
I have recently learned many articles about Server Load balancer technology on the Internet, but I am not very clear about it. Now I have published the test note diary for you to learn and use; this article only introduces entry-level Server Load balancer, and is still learning ......
I. Basic Information
Operating System: CentOS6.0
Servers: three servers (Load Balancing, WEB1, and WEB2)
Server Load balancer technology: Nginx
Web Service technology: apache
IP Address: Nginx 192.168.1.113, Web1 192.168.1.77, and Web2 192.168.1.78
Ii. Web Server installation and configuration
Refer to the apache server building article in this blog:
Iii. installation and configuration of the Server Load balancer (Nginx)
3.1 install basic support suite
Yum-y install gcc openssl-devel pcre-devel
3.2 install nginx
Cdwget http://nginx.org/download/nginx-1.5.8.tar.gztar xzvf nginx-1.5.8.tar.gzcd nginx-1.5.8./cofnigure -- prefix =/usr/local/nginxmakemake install
3.3 configure nginx
Edit/usr/local/nginx/conf/nginx. conf
Cd/usr/local/nginx/conf/
Mv nginx. conf nginx. conf. bak
Vim nginx. conf
Add the following content
User apache;
Worker_processes 10;
Pid logs/nginx. pid;
Events {
Use epoll;
Worker_connections 2048;
}
Http {
Include mime. types;
Default_type application/octet-stream;
Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" "$ http_x_forwarded_for "';
Access_log logs/access. log main;
Sendfile on;
Tcp_nopush on;
Upstream bkjia {
Server 192.168.1.77: 80;
Server 192.168.1.78: 80;
}
Keepalive_timeout 65;
Server {
Listen 80;
Server_name www.bkjia.com;
Access_log logs/bkjia. access. log main;
Location /{
Proxy_pass http: // bkjia;
Proxy_set_header Host $ host;
Proxy_set_header X-Real-IP $ remote_addr;
Proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;
}
Error_page 500 502 503 x.html;
Location =/50x.html {
Root html;
}
}
}
Note: You can change the red font based on your actual situation;
4. Start Nginx
4.1 verify that nginx configuration is normal
#/Usr/local/nginx/sbin/nginx-t
Note: The following content is returned, otherwise it will be changed as prompted;
Nginx: the configuration file/usr/local/nginx/conf/nginx. conf syntax is OK
Nginx: configuration file/usr/local/nginx/conf/nginx. conf test is successful
4.2 start Nginx
#/Usr/local/nginx/sbin/nginx
4.3 stop Nginx
# Killall-9 nginx
4.4 DNS domain name resolution
If you have a domain name, you can go to the DNS service provider for resolution settings. I changed the hosts file on the Local Computer for testing. Edit C: \ Windows \ System32 \ drivers \ etc \ hosts, add the following content in the last line:
192.168.1.113 www.bkjia.com
4.5 Test Access
Open your browser and enter
Nginx load balancing: nginx: [emerg] cocould not build the types_hash
Nginx Load Balancing module ngx_http_upstream_module details
Nginx + Firebug allows the browser to tell you which Server Load balancer distributes requests
Ubuntu install Nginx php5-fpm MySQL (LNMP environment setup)
Nginx details: click here
Nginx: click here