本文接上篇puppet負載均衡的環境實驗。web
Foreman-proxy能夠採用四層或者七層負載,均可以實現,在foreman的web界面添加一個smart-proxy,後端多個真實foreman-proxy處理的目的redis
我的採用的是haproxy實現的四層和七層代理,pm01和pm03是foreman-proxy服務器,ag01是foreman服務器,lvs是負載均衡服務器(vip在lvs01服務器上),上面代理了puppet,foreman-proxy業務。後端
由於七層在作https的代理時候,出現ssl證書驗證問題,因而根據官方配置文件的提示,採用http代理,而不是https代理,同時將全部的ssl證書替換爲lvs代理的ssl證書。安全
[root@pm01 puppet]# grep -v "#" /etc/foreman-proxy/settings.yml | grep -v "^$"服務器
---cookie
:settings_directory: /etc/foreman-proxy/settings.d負載均衡
:ssl_ca_file: /var/lib/puppet/ssl/certs/ca.pemfrontend
:ssl_certificate: /var/lib/puppet/ssl/certs/lvs.jq.com.pemtcp
:ssl_private_key: /var/lib/puppet/ssl/private_keys/lvs.jq.com.pemide
:trusted_hosts:
- pm01.jq.com
- pm02.jq.com
- pm03.jq.com
- ag01.jq.com
- ag02.jq.com
- ag03.jq.com
- ca01.jq.com
- ca02.jq.com
- lvs01.jq.com
- lvs02.jq.com
- pc.jq.com
- lvs.jq.com
:daemon: true
:bind_host: 0.0.0.0
:http_port: 8000 #默認此處爲:https_port:8443
:virsh_network: default
:log_file: /var/log/foreman-proxy/proxy.log
:log_level: DEBUG
[root@pm01 puppet]# cat /etc/puppet/foreman.yaml
---
:url: "https://ag01.jq.com"
:ssl_ca: "/var/lib/puppet/ssl/certs/ca.pem"
:ssl_cert: "/var/lib/puppet/ssl/certs/lvs.jq.com.pem"
:ssl_key: "/var/lib/puppet/ssl/private_keys/lvs.jq.com.pem"
:user: ""
:password: ""
:puppetdir: "/var/lib/puppet"
:puppetuser: "puppet"
:facts: true
:timeout: 10
:threads: null
[root@lvs01 haproxy]# grep -v "#" /etc/haproxy/haproxy.cfg | grep -v "^$"
global
maxconn 40000
ulimit-n 500000
log 127.0.0.1 local0 info
uid 99
gid 99
chroot /tmp
daemon
defaults
log global
retries 2
option redispatch
option dontlognull
option httpclose
balance roundrobin
timeout connect 30000ms
timeout client 30000ms
timeout server 30000ms
timeout check 2000
listen admin_stats
bind 0.0.0.0:8080
mode http
stats refresh 5s
stats enable
stats hide-version
stats realm Haproxy\ Statistics
stats uri /haproxy
stats auth admin:password
listen puppetmaster *:8140
mode tcp
option ssl-hello-chk
balance source
server pm01 pm01.jq.com:8140 check inter 2000 fall 3
server pm03 pm03.jq.com:8140 check inter 2000 fall 3
frontend foremanproxy
bind 0.0.0.0:8000
mode http
log global
option httplog
reqadd X-Forwarded-Proto:\ https
default_backend web_server
backend web_server
mode http
log global
option httplog
balance source
cookie SERVERID insert indirect nocache
server pm01 pm01.jq.com:8000 check inter 2000 fall 3
server pm03 pm03.jq.com:8000 check inter 2000 fall 3
同時,foreman-proxy運行在8000端口,也是安全的,
上圖能夠看出,信息到了8000端口,最後仍是https在處理。
四層採用的是https的代理,haproxy配置以下:
listen foreman-proxy *:8443
mode tcp
option ssl-hello-chk
option tcplog
# #balance source
balance roundrobin
# #balance source
server pm01 pm01.jq.com:8443 check inter 2000 fall 3
server pm03 pm03.jq.com:8443 check inter 2000 fall 3
foreman web界面添加smart_proxy,只須要添加lvs服務器上的foreman-proxy便可,以下:
四層負載:
http://lvs.jq.com:8000
七層負載:
https://lvs.jq.com:8443
採用分別中止pm01和pm03服務器上foreman-proxy進程的方式測試,每次測試以前刪除foreman頁面上的主機和smart_proxy,而後再在web添加foreman-proxy地址,在pm01,pm03,ag01上執行puppet agent -t,能夠發現,主機成功添加到主機頁面。