guoddoutlookcom 2015-09-02
前言:随着公司应用需求的增加,需要不断的扩展,服务器数量也随之增加,当服务器数量不断增加,我们会发现一台puppetmaster响应很慢,压力大,解析缓慢,有什么优化的方案吗?可以使用Puppetmaster配置多端口,结合Nginx web代理,这样puppetmaster承受能力至少可以提升10倍以上。
一、安装配置mongrel服务:
要使用puppet多端口配置,需要指定mongrel类型,默认没有安装,需要安装。在Puppetmaster服务器端执行如下命令(前提是已经安装了对应版本的epel RedHat源):
rpm -Uvh http://mirrors.sohu.com/Fedora-epel/5/x86_64/epel-release-5-4.noarch.rpm
yum install -y rubygem-mongrel
在vi /etc/sysconfig/puppetmaster文件末尾添加如下两行、
同时注释掉原相同配置项,分别代表多端口、mongrel类型:
PUPPETMASTER_PORTS=(18140 18141 18142 18143 18144)
PUPPETMASTER_EXTRA_OPTS="--servertype=mongrel --ssl_client_header=HTTP_X_SSL_SUBJECT"
二、安装配置Nginx服务器:
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.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;
}
server{
listen 8140;
root /etc/puppet;
ssl on;
ssl_session_timeout 5m;
#如下为Puppetmaster服务器端证书地址
ssl_certificate /var/lib/puppet/ssl/certs/192-9-117-162-usr/local.com.pem;
ssl_certificate_key /var/lib/puppet/ssl/private_keys/192-9-117-162-usr/local.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 /usr/locallication/x-raw;
#主要用于推送文件,定义files别名路径
alias /etc/puppet/files/;
}
# Modules files sections
location ~/production/file_content/modules/.+/ {
root /etc/puppet/modules;
types { }
default_type usr/locallication/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;
}
}
然后重启服务器端/etc/init.d/puppetmaster restart ,重启nginx WEB,在客户端测试即可。
三、Puppet多master主部署:
如果配置多主集群的话,可以共享33.10 master1的证书,然后另外一台master挂载证书即可,192.168.33.10 nfs配置方式如下:
Vi /etc/exports 内容:
/var/lib/puppet/ *(no_root_squash,rw,sync)
然后在192.168.33.11master2上执行:
mount -t nfs 192.168.33.10:/var/lib/puppet/ssl /var/lib/puppet/ssl
然后重启master2puppetmaster服务。
添加多端口服务,同上需要安装:
yum install -y rubygem-mongrel
同时修改master2/etc/sysconfig/puppet.conf里面:
[main]段添加bind address = 0.0.0.0,使监听端口为0.0.0.0全局所有地址。
这样在master1 nginx可以upstream,最终master1 nginx.conf upstream配置如下:
upstreampuppetmaster {
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;
#config add 2014-10-10
server 192.168.33.11:18140;
server 192.168.33.11:18141;
server 192.168.33.11:18142;
server 192.168.33.11:18143;
server 192.168.33.11:18144;
}
如果需要做keepalived高可用集群,其实也不难,大家可以发散思维去搭建一下哦。更多精彩文章,欢迎持续关注!
Puppet 学习系列:
相关阅读:
Puppet 的详细介绍:请点这里
Puppet 的下载地址:请点这里