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

Puppet利用Nginx多端口實現(xiàn)負載均衡

原創(chuàng)
運維 系統(tǒng)運維
隨著公司應(yīng)用需求的增加,需要不斷的擴展,服務(wù)器數(shù)量也隨之增加,當(dāng)服務(wù)器數(shù)量不斷增加,我們會發(fā)現(xiàn)一臺puppetmaster壓力大,解析緩慢,而且時不時出現(xiàn)"time out"之類的報錯,那這時有什么優(yōu)化的辦法嗎?其實不然,我們可以利用Nginx多端口實現(xiàn)負載均衡,這樣在很大程度上優(yōu)化了puppet的處理能力。

  【51CTO原創(chuàng)稿件】隨著公司應(yīng)用需求的增加,需要不斷的擴展,服務(wù)器數(shù)量也隨之增加,當(dāng)服務(wù)器數(shù)量不斷增加,我們會發(fā)現(xiàn)一臺puppetmaster壓力大,解析緩慢,而且時不時出現(xiàn)"time out"之類的報錯,那這時有什么優(yōu)化的辦法嗎?我們在Puppet官網(wǎng)上找尋解決方案,發(fā)現(xiàn)puppetmaster可以配置多端口,結(jié)合WEB代理(推薦Nginx),這樣puppetmaster承受能力至少可以提升數(shù)倍以上,相當(dāng)于在很大程度上優(yōu)化了puppet的處理能力。

  1.遵循前面的環(huán)境設(shè)定,我們這里的服務(wù)器環(huán)境及軟件版本分別為:

  服務(wù)器系統(tǒng):CentOS5.8 x86_64

  Ruby版本:ruby-1.8.5

  Puppet版本:puppet-2.7.9

  Nginx版本:nginx-0.8.46

  2.Mongrel安裝

  要使用puppet多端口配置,需要指定mongrel類型,默認沒有安裝,需要安裝:

  yum install -y rubygem-mongrel

  3.配置puppetmaster

  在/etc/sysconfig/puppetmaster文件末尾添加如下兩行,分別代表多端口、mongrel類型,內(nèi)容如下所示:

  PUPPETMASTER_PORTS=(8141 8142 8143 8144 8145)

  PUPPETMASTER_EXTRA_OPTS="--servertype=mongrel --ssl_client_header=HTTP_X_SSL_SUBJECT"

  4.安裝Nginx服務(wù)

  安裝之前請確保系統(tǒng)已經(jīng)安裝pcre-devel正則庫,然后再編譯安裝Nginx,需要添加SSL模塊參數(shù)支持,Nginx的安裝過程如下所示:

  yum -y install pcre-devel

  cd /usr/local/src

  wget http://nginx.org/download/nginx-0.8.46.tar.gz

  tar zxvf nginx-0.8.46.tar.gz

  cd nginx-0.8.46

  ./configure --prefix=/usr/local/nginx --with-http_ssl_module

  make && make install && cd ../

  添加www用戶組及用戶,命令如下所示:

  groupadd www

  useradd -g www www

  5.我們依據(jù)puppet需求來修改配置文件nginx.conf,內(nèi)容如下所示:

  1. user www; 
  2. worker_processes  8; 
  3. events { 
  4. worker_connections  65535; 
  5. http { 
  6. include       mime.types; 
  7. default_type  application/octet-stream; 
  8. sendfile        on; 
  9. tcp_nopush     on; 
  10. keepalive_timeout  65; 
  11. #定義puppet客戶端訪問puppet-server端日志格式 
  12. log_format main '$remote_addr - $remote_user [$time_local] "$request" $request_length $request_time $time_local' 
  13. '$status $body_bytes_sent $bytes_sent $connection $msec "$http_referer" ' 
  14. '"$http_user_agent" $http_x_forwarded_for $upstream_response_time $upstream_addr $upstream_status '; 
  15. access_log  /usr/local/nginx/logs/access.log  main; 
  16. upstream puppetmaster { 
  17. server 127.0.0.1:8141; 
  18. server 127.0.0.1:8142; 
  19. server 127.0.0.1:8143; 
  20. server 127.0.0.1:8144; 
  21. server 127.0.0.1:8145; 
  22. server { 
  23. listen 8140; 
  24. root /etc/puppet; 
  25. ssl on; 
  26. ssl_session_timeout 5m; 
  27. #如下為puppetmaster服務(wù)器端證書地址 
  28. ssl_certificate /var/lib/puppet/ssl/certs/server.cn7788.com.pem; 
  29. ssl_certificate_key /var/lib/puppet/ssl/private_keys/server.cn7788.com.pem; 
  30. ssl_client_certificate /var/lib/puppet/ssl/ca/ca_crt.pem; 
  31. ssl_crl /var/lib/puppet/ssl/ca/ca_crl.pem; 
  32. ssl_verify_client optional; 
  33. #File sections 
  34. location /production/file_content/files/ { 
  35. types { } 
  36. default_type application/x-raw; 
  37. #定義puppet推送路徑別名 
  38. alias /etc/puppet/files/; 
  39. # Modules files sections 
  40. location ~ /production/file_content/modules/.+/ { 
  41. root /etc/puppet/modules; 
  42. types { } 
  43. default_type application/x-raw; 
  44. rewrite ^/production/file_content/modules/(.+)/(.+)$ /$1/files/$2 break; 
  45. location / { 
  46. ##設(shè)置跳轉(zhuǎn)到puppetmaster負載均衡 
  47. proxy_pass http://puppetmaster; 
  48. proxy_redirect off; 
  49. proxy_set_header Host $host; 
  50. proxy_set_header X-Real-IP $remote_addr; 
  51. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
  52. proxy_set_header X-Client-Verify $ssl_client_verify; 
  53. proxy_set_header X-SSL-Subject $ssl_client_s_dn; 
  54. proxy_set_header X-SSL-Issuer $ssl_client_i_dn; 
  55. proxy_buffer_size 10m; 
  56. proxy_buffers 1024 10m; 
  57. proxy_busy_buffers_size 10m; 
  58. proxy_temp_file_write_size 10m; 
  59. proxy_read_timeout 120; 

 

  6.修改完nginx.conf文件以后,我們要啟動nginx及puppet-server,這時應(yīng)該如何操作呢?

  1.我們首先關(guān)閉puppetmaster進程,然后先啟動nginx,不然nginx是會啟動失敗的,命令如下所示:

  /usr/local/nginx/sbin/nginx

  nginx占用puppetmaster默認的8140端口后,我們可以用如下命令來檢查8140端口是否被nginx接管,如下所示:

  lsof -i:8140

  此命令顯示結(jié)果表明8140被nginx進程接管,如下所示:

  COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

  nginx   4121  root    6u  IPv4  20668      0t0  TCP *:8140 (LISTEN)

  nginx   4122  www  6u  IPv4  20668      0t0  TCP *:8140 (LISTEN)

  我們再啟動puppetmaster,命令如下所示:

  service puppetmaster start

  如果ruby版本為1.8.5的話,等會運行puppetmaster會有如下警告,如下所示:

   Starting puppetmaster:

  Port: 8141** Ruby version is not up-to-date; loading cgi_multipart_eof_fix

  [  OK  ]

  Port: 8142** Ruby version is not up-to-date; loading cgi_multipart_eof_fix

  [  OK  ]

  Port: 8143** Ruby version is not up-to-date; loading cgi_multipart_eof_fix

  [  OK  ]

  Port: 8144** Ruby version is not up-to-date; loading cgi_multipart_eof_fix

  [  OK  ]

  Port: 8145** Ruby version is not up-to-date; loading cgi_multipart_eof_fix

  [  OK  ]

  這段警告值的意思為:

  It's just a warning. Mongrel wants a Ruby version of at least 1.8.6.

  But it still runs just fine with previous versions. Just ignore the warning.

  翻譯為中文的意思是:

  Mongrel需要ruby至少是1.8.6以上的版本,但它仍然在當(dāng)前版本運行,請忽咯當(dāng)前警告,為了保證整個puppet運行環(huán)境的穩(wěn)定,我這里選擇還是沿用1.8.5版本的ruby。

本文作者:余洪春(撫琴煮酒),英文名Andrew.Yu。

 個人博客地址:http://andrewyu.blog.51cto.com/

 Sina微博地址:http://weibo.com/yuhongchun027。

責(zé)任編輯:黃丹 來源: 51CTO.com
相關(guān)推薦

2018-03-14 11:13:35

Web服務(wù)器Nginx

2013-04-22 11:29:14

Nginx

2012-07-31 09:25:42

nginx負載均衡反向代理

2009-07-22 10:25:37

2020-01-14 09:40:00

Nginx負載均衡正向代理

2018-02-01 10:31:12

Nginx負載均衡軟件

2020-04-20 20:27:59

Nginx動靜分離負載均衡

2015-04-13 09:44:14

Nginxkeepalived負載均衡

2019-11-12 13:56:15

NginxTomcat負載均衡

2024-07-17 08:36:53

2014-08-22 10:36:37

nginx負載均衡

2023-12-07 12:29:49

Nginx負載均衡策略

2010-03-24 10:35:02

Nginx負載均衡器

2019-03-13 12:04:41

Nginx負載均衡動靜分離

2011-12-02 22:51:46

Nginx負載均衡

2010-05-06 10:01:26

nginx負載均衡

2011-09-01 10:23:47

Nginx負載均衡器負載均衡

2018-10-12 08:43:54

2011-01-07 11:14:17

Nginx負載均衡負載均衡

2010-05-07 12:23:23

nginx負載均衡
點贊
收藏

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