ansible roles 安装高可用(lb01 lb02)

给 lb01,lb02, 做一个高可用 keepalive 

这里有个疑问:就是 lb01 上 nginx  挂掉后,  高可用并不起作用(主机挂掉起作用)

 

yum install -y keepalived

- hosts: ssh
  roles:
    - role: ssh

- hosts: baimei
  roles:
    - role: basic
    - role: rsync
      when: ansible_hostname is match "backup"
    - role: nfs
      when: (ansible_hostname is match "nfs") or ( ansible_hostname is match "web*")
    - role: php
      when: (ansible_hostname is match "lb*") or (ansible_hostname is match "web*")
    - role: nginx
      when: (ansible_hostname is match "lb*") or (ansible_hostname is match "web*")
    - role: mysqlserver
      when: ansible_hostname is match "db01"
    - role: webserver
      when: ansible_hostname is match "web*"
    - role: lbfunc
      when: ansible_hostname is match "lb*"
    - role: keepalived
      when: ansible_hostname is match "lb*"

 

[root@m01 /etc/ansible/roles/keepalived/tasks]#cat main.yml 
- name: install keepalived
  yum: 
    name: keepalived
    state: present
- name: start keepalived serviced
  systemd:
    name: keepalived
    state: started
    enabled: yes

- name: copy keepalived_lb01.conf
  copy:
    src: keepalived_lb01.conf
    dest: /etc/keepalived/keepalived.conf
  when: ansible_hostname is match "lb01"


- name: copy keepalived_lb02.conf
  copy:
    src: keepalived_lb02.conf
    dest: /etc/keepalived/keepalived.conf
  when: ansible_hostname is match "lb02"

 

[root@m01 /etc/ansible/roles/keepalived/files]#cat keepalived_lb01.conf 
global_defs {                   #全局配置
    router_id lb01              #标识身份->名称
}

vrrp_instance VI_1 {
    state MASTER                #标识角色状态
    interface eth0              #网卡绑定接口
    virtual_router_id 50        #虚拟路由id
    priority 150                #优先级
    advert_int 1                #监测间隔时间
    authentication {            #认证
        auth_type PASS          #认证方式
        auth_pass 1111          #认证密码
    }
    virtual_ipaddress {         
        10.0.0.3                #虚拟的VIP地址
    }
}

 

[root@m01 /etc/ansible/roles/keepalived/files]#cat keepalived_lb02.conf 
global_defs {
    router_id lb02
}

vrrp_instance VI_1 {
    state BACKUP        
    interface eth0
    virtual_router_id 50
    priority 100
    advert_int 1
    authentication {    
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.0.3
    }
}

 

欢迎来撩 : 汇总all

白眉大叔

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

热门文章