一键部署nginx负载均衡
程序员文章站
2022-07-12 16:55:06
...
先建立好httpd和nginx
在前两篇博客
[root@server1 ~]# yum install -y salt-minion
[root@server1 ~]# cd /etc/salt
[root@server1 salt]# vim minion
16 master: 172.25.40.1
[root@server1 salt]# /etc/init.d/salt-minion start
[root@server1 salt]# salt-key -L
[root@server1 salt]# salt-key -A server1
[aaa@qq.com salt]# vim /etc/yum.repos.d/rhel-source.repo #添加负载均衡yum源
[LoadBalancer]
name=LoadBalancer
baseurl=http://172.25.40.250/rhel6.5/LoadBalancer
gpgcheck=0
[aaa@qq.com salt]# cd /srv/salt/
[aaa@qq.com salt]# mkdir haproxy
[aaa@qq.com salt]# cd haproxy/
[aaa@qq.com haproxy]# vim install.sls
haproxy-install:
pkg.installed:
- pkgs:
- haproxy
file.managed:
- name: /etc/haproxy/haproxy.cfg
- source: salt://haproxy/files/haproxy.cfg
service.running:
- name: haproxy
- reload: True
- watch:
- file: haproxy-install
[aaa@qq.com salt]# salt server1 state.sls haproxy.install
将脚本写完后推送时有报错:
解决方法:
[root@server1 salt]# cd /etc/haproxy
[root@server1 haproxy]# mkdir /srv/salt/haproxy/files
[root@server1 haproxy]# cp haproxy.cfg /srv/salt/haproxy/files/
[root@server1 haproxy]# salt server1 state.sls haproxy.install #再次推送
[root@server1 haproxy]# cd /srv/salt/haproxy/files/
[root@server1 files]# vim haproxy.cfg
[root@server1 files]# /etc/init.d/haproxy restart
[root@server1 files]# netstat -antlp
将server2端口改为80
[root@server1 salt]# vim httpd/files/httpd.conf
136 Listen 80
在server2上写入默认发布目录
[root@server2 ~]# cd /var/www/html
[root@server2 html]# vim index.html
server2
推送负载均衡
[root@server1 files]# cd /srv/salt/
[root@server1 salt]# cd haproxy/
[root@server1 haproxy]# cd /srv/salt/
[root@server1 salt]# vim top.sls
base:
'server1':
- haproxy.install
'server2':
- httpd.install
'server3':
- nginx.service
[root@server1 salt]# salt '*' state.highstate