> For the complete documentation index, see [llms.txt](https://close.gitbook.io/yun-wei-bi-ji/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://close.gitbook.io/yun-wei-bi-ji/centos/keepalived/gao-ke-yong-nginx+keepalived.md).

# 高可用--Nginx+keepalived

### 主从

#### Nginx安装

> 源码安装：请看 Nginx 篇 Yum安装:：yum install epel-release -y && yum install nginx -y

#### keepalived 安装

> 源码安装：请参考 Lvs + keepalived 中安装keepalived Yum 安装：yum install keepavlied -y

#### keepalived 主要配置:

主

```bash
···
vrrp_instance VI_1 {  
    state MASTER  
    interface eth0  
    virtual_router_id 51  
    priority 100  
    advert_int 1  
    authentication {  
        auth_type PASS  
        auth_pass 1111  
    }  
    virtual_ipaddress {  
        10.128.25.24  
    }  
}  

···
```

从

```bash
vrrp_instance VI_1 {  
    state BACKUP  
    interface eth0  
    virtual_router_id 51  
    priority 90  
    advert_int 1  
    authentication {  
        auth_type PASS  
        auth_pass 1111  
    }  
    virtual_ipaddress {  
        10.128.25.24  
    }  
}  
```

### 主主

> #### 初始化

主一

```bash
vrrp_instance VI_1 {  
    state MASTER  
    interface eth0  
    virtual_router_id 51  
    priority 100  
    advert_int 1  
    authentication {  
        auth_type PASS  
        auth_pass 1111  
    }  
    virtual_ipaddress {  
        10.128.25.24  
    }  
}  
  
#VIP2  
  
vrrp_instance VI_2 {  
    state BACKUP  
    interface eth0  
    virtual_router_id 52  
    priority 90  
    advert_int 1  
    authentication {  
        auth_type PASS  
        auth_pass 2222  
    }  
    virtual_ipaddress {  
        10.128.25.26  
    }  
}  
```

主二

```bash
vrrp_instance VI_1 {  
    state BACKUP  
    interface eth0  
    virtual_router_id 51  
    priority 90  
    advert_int 1  
    authentication {  
        auth_type PASS  
        auth_pass 1111  
    }  
    virtual_ipaddress {  
        10.128.25.24  
    }  
}  
#VIP2  
  
vrrp_instance VI_2 {  
    state MASTER  
    interface eth0  
    virtual_router_id 52  
    priority 100  
    advert_int 1  
    authentication {  
        auth_type PASS  
        auth_pass 2222  
    }  
    virtual_ipaddress {  
        10.128.25.26  
    }  
}  
```
