前言 * 随着公司应用需求的增加,需要不断的扩展,服务器数量也随之增加,当服务器数量不断增加,我们会发现一台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 内容如下:
- 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配置文件中添加如下代码即可。
- 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服务:
- [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 测试成功即可
本文转自 wgkgood 51CTO博客,原文链接:http://blog.51cto.com/wgkgood/1092277