ansible roles 安装负载均衡

ansible roles 安装负载均衡业务

步骤: 

首先在 lb01 上 配置负载均衡

参考  Nginx 负载均衡设置

[root@m01 /etc/ansible/roles/lbfunc/tasks]#cat main.yml 
- name: copy lb_proxy.conf 
  copy: 
    src: lb_proxy.conf 
    dest: /etc/nginx/conf.d/lb_proxy.conf
  notify: Restart nginx sevice

- name: copy proxy_params
  copy:
    src: proxy_params
    dest: /etc/nginx/proxy_params
  notify: Restart nginx sevice

 

 

[root@m01 /etc/ansible/roles/lbfunc/handlers]#cat main.yml 
- name: Restart nginx sevice
  systemd: 
    name: nginx
    state: restarted

 

步骤: 

ansible-galaxy init lbfunc
rm -rf defaults meta README.md

 

负载均衡配置文件: lb_proxy.conf

upstream blog {
        server 172.16.1.7:80;
        server 172.16.1.8:80;
}

server {
        listen 80;
        server_name wordpress.baimei.com;
        
        location / {
                proxy_pass http://blog;
                include proxy_params;
        }
}

server {
        listen 80;
        server_name zh.baimei.com;
       
        location / {
                proxy_pass http://blog;
                include proxy_params;
        }       
}

 

proxy_params 文件内容:

[root@m01 ~/ansible/proxy]#cat proxy_params 
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_connect_timeout 30;
proxy_send_timeout 60;
proxy_read_timeout 60;

proxy_buffering on;
proxy_buffer_size 32k;
proxy_buffers 4 128k;

测试: 

一定把本机的 hosts  地址改一下 : 10.0.0.4

 

关闭一个 web01

测试成功

 

欢迎来撩 : 汇总all

白眉大叔

关于白眉大叔linux云计算: 白眉大叔

热门文章