Puppet自動化Nginx+Mongrel負載均衡配置

前言 * 隨着公司應用需求的增加,需要不斷的擴展,服務器數量也隨之增加,當服務器數量不斷增加,我們會發現一臺puppetmaster壓力大,解析緩慢,那這時有什麼優化的辦法嗎?答案是有滴!Puppet官網上有類似的解決方案,puppetmaster可以配置多端口,結合WEB代理,這樣puppetmaster承受能力至少可以提升10倍以上。

一、硬件環境:

服務器系統:CentOS6.0 x86_64

Ruby版本:ruby-1.8.7

Puppet 版本:puppet-2.7.20

Nginx 版本: nginx-1.2.6

二、Mongrel安裝:

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

在puppetmaster服務器端執行如下命令(前提是已經安裝了對應版本的epel redhat源):

yum install -y rubygem-mongrel

三、配置puppetmaster

在/etc/sysconfig/puppetmaster文件末尾添加如下兩行,分別代表多端口、mongrel類型。

echo -e "PUPPETMASTER_PORTS=( 18140 18141 18142 18143 18144 )nPUPPETMASTER_EXTRA_OPTS="—servertype=mongrel --ssl_client_header=HTTP_X_SSL_SUBJECT"" >>/etc/sysconfig/puppetmaster

四、安裝Nginx服務

安裝之前請確保系統已經安裝pcre-devel正則庫,然後再編譯安裝Nginx,需要添加SSL模塊參數

cd /usr/src ;wget -c http://nginx.org/download/nginx-1.2.6.tar.gz ;tar xzf nginx-1.2.6.tgz && cd nginx-1.2.6 &&./configure --prefix=/usr/local/nginx --with-http_ssl_module &&make &&make install

五、配置Nginx:

Nginx安裝完畢後,需要配置Nginx來代理本地Puppetmaster多個端口,Nginx使用puppetmaster默認8140端口,客戶端請求8140端口,Nginx自動負載到18140 18141 18142 18143 18144 這幾個端口。vi /usr/local/nginx/conf/vhosts.conf 內容如下:

雙擊代碼全選
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
server {
listen 8140;
root /etc/puppet;
ssl on;
ssl_session_timeout 5m;
#如下爲Puppetmaster服務器端證書地址
ssl_certificate /var/lib/puppet/ssl/certs/192-9-117-162-app.com.pem;
ssl_certificate_key /var/lib/puppet/ssl/private_keys/192-9-117-162-app.com.pem;
ssl_client_certificate /var/lib/puppet/ssl/ca/ca_crt.pem;
ssl_crl /var/lib/puppet/ssl/ca/ca_crl.pem;
ssl_verify_client optional;
# File sections
location /production/file_content/files/ {
types { }
default_type application/x-raw;
#主要用於推送文件,定義files別名路徑
alias /etc/puppet/files/;
}
# Modules files sections
location ~ /production/file_content/modules/.+/ {
root /etc/puppet/modules;
types { }
default_type application/x-raw;
rewrite ^/production/file_content/modules/(.+)/(.+)$ /$1/files/$2 break;
}
location / {
#設置跳轉到puppetmaster負載均衡
proxy_pass http://puppetmaster;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Client-Verify $ssl_client_verify;
proxy_set_header X-SSL-Subject $ssl_client_s_dn;
proxy_set_header X-SSL-Issuer $ssl_client_i_dn;
proxy_buffer_size 10m;
proxy_buffers 1024 10m;
proxy_busy_buffers_size 10m;
proxy_temp_file_write_size 10m;
proxy_read_timeout 120;
}
 
}

在Nginx.conf配置文件中添加如下代碼即可。

雙擊代碼全選
1
2
3
4
5
6
7
8
upstream puppetmaster {
server 127.0.0.1:18140;
server 127.0.0.1:18141;
server 127.0.0.1:18142;
server 127.0.0.1:18143;
server 127.0.0.1:18144;
}
include vhosts.conf;

六、驗證配置
重啓puppetmaster和nginx服務:

雙擊代碼全選
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@192-9-117-162 ~]# /etc/init.d/puppetmaster restart ;/usr/local/nginx/sbin/nginx
停止 puppetmaster:
Port: 18140 [失敗]
Port: 18141 [失敗]
Port: 18142 [失敗]
Port: 18143 [失敗]
Port: 18144 [失敗]
啓動 puppetmaster:
Port: 18140 [確定]
Port: 18141 [確定]
Port: 18142 [確定]
Port: 18143 [確定]
Port: 18144 [確定]

在客戶端執行puppet agent --server=192-9-117-162-app.com --test 測試成功即可

本文出自 “煙雨樓臺” 博客,請務必保留此出處http://wgkgood.blog.51cto.com/1192594/1092277

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章