CentOS 7 아래 keepalived 를 통 해 nginx 메 인 방식 의 더 블 열 비 를 설정 합 니 다.

6530 단어 유 닉 스 사용
여기 서 저 희 는 두 대의 Nginx 서버 를 전단 으로 하고 하 나 는 Keepalived 에서 상태 감 측 을 실현 하여 Nginx 가 정상적으로 대외 적 으로 서 비 스 를 제공 하도록 합 니 다. 즉, 주 Nginx 서비스 프로 세 스 가 죽은 후에 keepalived 는 자신의 검 측 체 제 를 통 해 사이트 의 방문 을 Nginx 에서 전환 할 수 있 습 니 다.메 인 서버 IP: 192.168.1.217 서비스 IP: 192.168.1.218 가상 IP: 192.168.1.219 당신 은 사이트 도 메 인 이름 을 192.168.1.219 에 대응 하 는 공공 네트워크 IP 로 분석 할 수 있 습 니 다. 그러면 메 인 서버 는 돌아 가면 서 이 가상 IP 를 연결 하여 사이트 의 정상 적 인 대외 방문 을 보장 할 수 있 습 니 다.
- 설치 nginx
  • yum 을 통 해 nginx 설치
  • 상세 한 내용 은 상편 박문
  • 을 보십시오.
    - keepalived 설치
  • yum install keepalived

  • - keepalived 설정
  • nginx - 001 서버 설정
    
    #       
    
    cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
    vim /etc/keepalived/keepalived.conf
    
    #       
    
    ! Configuration File for keepalived
    global_defs {
        router_id nginx_server_1
    }
    vrrp_script chk_nginx {
        script "/etc/keepalived/nginx_check.sh"
        interval 2
        weight 20
        !weight   
        !         0,,Master:weight+priority>Backup:weight+priority(   )
        !          0,Master:priority:priority+weight(  )
        !weight   
        !         0,,Master:priority>Backup:priority(   )
        !          0,Master:priority+weight:priority(  )
        !    ,weight       Master Backup priority  
    }
    vrrp_instance VI_1 {
        state MASTER
        interface eno16777984
        virtual_router_id 51
        mcast_src_ip 192.168.1.217
        priority 100
        nopreempt
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        track_script {
            chk_nginx
        }
        virtual_ipaddress {
            192.168.1.219/24
        }
    }
    
    
    #  nginx     , nginx     ,keepalived    nginx
    
    vim /etc/keepalived/nginx_check.sh
    
    #      
    
    
    #!/bin/bash
    
    A=`ps -C nginx --no-header |wc -l`
    if [ $A -eq 0 ];then
        /usr/sbin/nginx
        sleep 2
        if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
            killall keepalived
        fi
    fi
    
    
    #       
    
    chmod +xxx /etc/keepalived/nginx_check.sh
  • nginx - 002 서버 설정 (부터)
  • 
    #       
    
    cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak
    vim /etc/keepalived/keepalived.conf
    
    #       :
        state      , BACKUP
        route_id      
        priority     
    )
    
    ! Configuration File for keepalived
    global_defs {
        router_id nginx_server_2
    }
    vrrp_script chk_nginx {
        script "/etc/keepalived/nginx_check.sh"
        interval 2
        weight 20
        !weight   
        !         0,,Master:weight+priority>Backup:weight+priority(   )
        !          0,Master:priority:priority+weight(  )
        !weight   
        !         0,,Master:priority>Backup:priority(   )
        !          0,Master:priority+weight:priority(  )
        !    ,weight       Master Backup priority  
    }
    vrrp_instance VI_1 {
        state BACKUP
        interface eno16777984
        virtual_router_id 51
        mcast_src_ip 192.168.1.218
        priority 90
        nopreempt
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        track_script {
            chk_nginx
        }
        virtual_ipaddress {
            192.168.1.219/24
        }
    }

    - keepalived 시작
    systemctl start keepalived
    systemctl enable keepalived
    

    - keepalived + nginx 의 주종 테스트
  • 호스트 에서 ip a 를 보고 192.168.1.219 를 성공 적 으로 연결 하 였 습 니 다.
  • shutdown 호스트, 컴퓨터 192.168.1.219 에서 성공 적 으로 연결 되 었 는 지 확인 합 니 다.vip 성공 표류 설명
  • 좋은 웹페이지 즐겨찾기