saltstack之配置管理实践3 业务引用 haproxy
[root@linux-node1 ~]# tree /srv/salt/prod/haproxy/
/srv/salt/prod/haproxy/
├── files
│ ├── haproxy-1.6.2.tar.gz
│ └── haproxy.init
└── install.sls
1 directory, 3 files
##可以看到,haproxy的启动脚本,安装就可以完成了,有人可能存在疑惑,为啥haproxy的配置文件不放在这边呢?原因是配置文件有差异性,并不是所有的配置文件都相同的。。这样的差异性我们可以通过上一级新建目录来实现。
[root@linux-node1 ~]# mkdir /srv/salt/prod/cluster
[root@linux-node1 ~]# mkdir /srv/salt/prod/cluster/files
#################################################################
[root@linux-node1 ~]# vim /srv/salt/prod/cluster/files/haproxy-outside.cfg
global
maxconn 100000
chroot /usr/local/haproxy
uid 99
gid 99
daemon
nbproc 1
pidfile /usr/local/haproxy/logs/haproxy.pid
log 127.0.0.1 local3 info
defaults
option http-keep-alive
maxconn 100000
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
listen stats
mode http
bind 0.0.0.0:8888
stats enable
stats uri /haproxy-status
stats auth haproxy:saltstack
frontend frontend_www_example_com
bind 10.20.23.11:80
mode http
option httplog
log global
default_backend backend_www_example_com
backend backend_www_example_com
option forwardfor header X-REAL-IP
option httpchk HEAD / HTTP/1.0
balance source
server web-node1 10.20.23.144:8080 check inter 2000 rise 30 fall 15
server web-node2 10.20.23.145:8080 check inter 2000 rise 30 fall 15
######################################################################
[root@linux-node1 ~]# vim /srv/salt/prod/cluster/haproxy-outside.sls
include:
- haproxy.install
haproxy-service:
file.managed:
- name: /etc/haproxy/haproxy.cfg
- source: salt://cluster/files/haproxy-outside.cfg
- user: root
- group: root
- mode: 644
service.running:
- name: haproxy
- enable: True
- reload: True
- require:
- cmd: haproxy-init
- watch:
- file: haproxy-service
###########################################################################
[root@linux-node1 ~]# vim /srv/salt/base/top.sls
base:
'*':
- init.env_init
prod:
'linux-node[1-2]':
- cluster.haproxy-outside
###########################################################################
[root@linux-node1 ~]# salt '*' state.highstate test=True
[root@linux-node1 ~]# salt '*' state.highstate
##haproxy没有起来,报错,,可以手动启动下试试:
[root@linux-node1 ~]# /etc/init.d/haproxy start
Starting haproxy: [ALERT] 136/233319 (6666) : Starting frontend frontend_www_example_com: cannot bind socket [10.20.23.11:80]
[失败]
##原因是80端口被占用,netstat -lntup查看,,果然httpd正在运行,,把httpd关闭,重启salt '*' state.highstate 即可
##httpd的默认端口,改为8080,两台都要,,然后保存退出,,启动httpd
vim /etc/httpd/conf/httpd.conf
Listen 8080
此时就可以访问haproxy了
嗨、骚年、快来消灭0回复。