JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

详细讲解一键部署nginx负载均衡

wys521 2024-09-18 23:58:42 精选教程 33 ℃ 0 评论

先建立好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
[root@server1 salt]# vim /etc/yum.repos.d/rhel-source.repo #添加负载均衡yum源
[LoadBalancer]
name=LoadBalancer
baseurl=http://172.25.40.250/rhel6.5/LoadBalancer
gpgcheck=0
[root@server1 salt]# cd /srv/salt/
[root@server1 salt]# mkdir haproxy
[root@server1 salt]# cd haproxy/
[root@server1 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
[root@server1 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

测试:

后面小编会分享更多这方面的干货,感兴趣的朋友走一波关注哩~

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表