自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

nginx負載均衡程序安裝札記

網(wǎng)絡(luò) 網(wǎng)絡(luò)優(yōu)化 網(wǎng)絡(luò)運維
將nginx負載均衡設(shè)定的關(guān)鍵內(nèi)容作為總結(jié),在本文中進行了介紹。只對nginx的安裝和其中的配置文件重點說明,我們可以將此文作為札記,在對程序過程模糊的時候可進行參閱。

對于Nginx負載均衡的設(shè)定問題我們說過很多,也總結(jié)歸納過很多。在此,我們?yōu)榱遂柟糖懊娴闹R,將其中的安裝要點再為大家重申一下。對于環(huán)境的構(gòu)建,我們不過多的介紹了,前面已經(jīng)說的很清楚,現(xiàn)在我們從安裝開始說起,直接將配置代碼最為重點呈獻給大家。

 安裝Nginx

1>安裝
Nginx發(fā)音為[engine x],是由俄羅斯人Igor Sysoev建立的項目,基于BSD許可。據(jù)說他當(dāng)初是F5的成員之一,英文主頁:http://nginx.net。俄羅斯的一些大網(wǎng)站已經(jīng)使用它超過兩年多了,一直表現(xiàn)不凡。Nginx的編譯參數(shù)如下:

  1. [root@localhost]#./configure --prefix=/usr/local/server/nginx --with-openssl=/usr/include \  
  2. --with-pcre=/usr/include/pcre/ --with-http_stub_status_module --without-http_memcached_module \  
  3. --without-http_fastcgi_module --without-http_rewrite_module --without-http_map_module \  
  4. --without-http_geo_module --without-http_autoindex_module 

在這里,需要說明一下,由于Nginx的配置文件中我想用到正則,所以需要pcre模塊的支持。我已經(jīng)安裝了pcre及pcre-devel的 rpm包,但是 Ngxin 并不能正確找到 .h/.so/.a/.la 文件,因此我稍微變通了一下:

  1. [root@localhost]#mkdir /usr/include/pcre/.libs/  
  2. [root@localhost]#cp /usr/lib/libpcre.a /usr/include/pcre/.libs/libpcre.a  
  3. [root@localhost]#cp /usr/lib/libpcre.a /usr/include/pcre/.libs/libpcre.la 

然后,修改objs/Makefile大概在908行的位置上,注釋掉以下內(nèi)容:   ./configure --disable-shared

接下來,就可以正常執(zhí)行make及make install了。

2>修改配置文件/usr/local/server/nginx/conf/nginx.conf
以下是我的nginx.conf內(nèi)容,僅供參考:

  1. #運行用戶  
  2. usernobody nobody;  
  3. #啟動進程  
  4. worker_processes2;  
  5. #全局錯誤日志及PID文件  
  6. error_loglogs/error.log notice;  
  7. pidlogs/nginx.pid;  
  8. #工作模式及連接數(shù)上限  
  9. events {  
  10. use epoll;  
  11. worker_connections1024;}  
  12. #設(shè)定http服務(wù)器,利用它的反向代理功能提供負載均衡支持  
  13. http {  
  14. #設(shè)定mime類型  
  15. include conf/mime.types;  
  16. default_typeapplication/octet-stream; 

#p#

  1. #設(shè)定日志格式  
  2. log_format main '$remote_addr - $remote_user [$time_local] ' 
  3. '"$request" $status $bytes_sent ' 
  4. '"$http_referer" "$http_user_agent" ' 
  5. '"$gzip_ratio"';  
  6. log_format download '$remote_addr - $remote_user [$time_local] ' 
  7. '"$request" $status $bytes_sent ' 
  8. '"$http_referer" "$http_user_agent" ' 
  9. '"$http_range" "$sent_http_content_range"';  
  10. #設(shè)定請求緩沖  
  11. client_header_buffer_size1k;  
  12. large_client_header_buffers4 4k;  
  13. #開啟gzip模塊  
  14. gzip on;  
  15. gzip_min_length1100;  
  16. gzip_buffers 4 8k;  
  17. gzip_types text/plain;  
  18. output_buffers 1 32k;  
  19. postpone_output1460;  
  20. #設(shè)定access log  
  21. access_loglogs/access.logmain;  
  22. client_header_timeout3m;  
  23. client_body_timeout3m;  
  24. send_timeout 3m;  
  25. sendfileon;  
  26. tcp_nopushon;  
  27. tcp_nodelay on;  
  28. keepalive_timeout65;  
  29. #設(shè)定負載均衡的服務(wù)器列表  
  30. upstream mysvr {  
  31. #weigth參數(shù)表示權(quán)值,權(quán)值越高被分配到的幾率越大  
  32. #本機上的Squid開啟3128端口  
  33. server 192.168.8.1:3128 weight=5;  
  34. server 192.168.8.2:80 weight=1;  
  35. server 192.168.8.3:80 weight=6;}  
  36. #設(shè)定虛擬主機  
  37. server {  
  38. listen80;  
  39. server_name 192.168.8.1 www.yejr.com;  
  40. charset gb2312;  
  41. #設(shè)定本虛擬主機的訪問日志  
  42. access_loglogs/www.yejr.com.access.logmain;  
  43. #如果訪問 /img/*, /js/*, /css/* 資源,則直接取本地文件,不通過squid  
  44. #如果這些文件較多,不推薦這種方式,因為通過squid的緩存效果更好  
  45. location ~ ^/(img|js|css)/{  
  46. root/data3/Html;  
  47. expires 24h;} 
  1. #對 "/" 啟用負載均衡  
  2. location / {  
  3. proxy_passhttp://mysvr;  
  4. proxy_redirectoff;  
  5. proxy_set_headerHost $host;  
  6. proxy_set_headerX-Real-IP $remote_addr;  
  7. proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;  
  8. client_max_body_size10m;  
  9. client_body_buffer_size 128k;  
  10. proxy_connect_timeout 90;  
  11. proxy_send_timeout90;  
  12. proxy_read_timeout90;  
  13. proxy_buffer_size 4k;  
  14. proxy_buffers 4 32k;  
  15. proxy_busy_buffers_size 64k;  
  16. proxy_temp_file_write_size 64k;}  
  17. #設(shè)定查看Nginx狀態(tài)的地址  
  18. location /NginxStatus {  
  19. stub_status on;  
  20. access_logon;  
  21. auth_basic"NginxStatus";  
  22. auth_basic_user_fileconf/htpasswd;}}} 

3>查看 Nginx 運行狀態(tài)
輸入地址 http://192.168.8.1/NginxStatus/,輸入驗證帳號密碼,即可看到類似如下內(nèi)容:
Active connections: 328
server accepts handled requests
9309 8982 28890
Reading: 1 Writing: 3 Waiting: 324

***行表示目前活躍的連接數(shù)

第三行的第三個數(shù)字表示Nginx運行到當(dāng)前時間接受到的總請求數(shù),如果快達到了上限,就需要加大上限值了。

責(zé)任編輯:佟健 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-05-07 12:27:53

nginx負載均衡

2013-04-22 11:29:14

Nginx

2012-07-31 09:25:42

nginx負載均衡反向代理

2011-12-02 22:51:46

Nginx負載均衡

2010-05-05 22:05:32

nginx負載均衡

2011-09-01 10:23:47

Nginx負載均衡器負載均衡

2010-05-07 12:23:23

nginx負載均衡

2011-01-07 11:14:17

Nginx負載均衡負載均衡

2014-07-28 11:37:49

NginxTomcat

2010-03-30 13:37:14

Nginx負載均衡

2010-05-04 10:44:18

JBOSS負載均衡

2017-11-09 10:42:11

Nginx負載均衡策略

2019-09-18 10:39:08

負載均衡反向代理TCP

2024-11-11 09:51:46

Nginx部署負載

2010-03-25 18:52:15

Nginx負載均衡

2019-11-04 15:35:53

Nginx反向代理負載均衡

2019-06-24 15:58:53

TCPUDPNginx

2017-12-18 12:04:02

Nginx代理均衡

2012-11-06 16:51:29

nginx負載均衡

2020-01-14 09:40:00

Nginx負載均衡正向代理
點贊
收藏

51CTO技術(shù)棧公眾號