快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

nginx+keepalived实现高可靠web网站-创新互联

组网图:

创新互联专注于企业成都全网营销、网站重做改版、郊区网站定制设计、自适应品牌网站建设、成都h5网站建设电子商务商城网站建设、集团公司官网建设、外贸营销网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为郊区等各大城市提供网站开发制作服务。

配置信息:

左边nigx 服务器的 /usr/local/nginx/conf/nginx.conf

#user  nobody;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid     logs/nginx.pid;

events {

  worker_connections  1024;

}

http {

  include    mime.types;

  default_type  application/octet-stream;

  #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

  #          '$status $body_bytes_sent "$http_referer" '

  #          '"$http_user_agent" "$http_x_forwarded_for"';

  #access_log  logs/access.log  main;

  sendfile     on;

  #tcp_nopush   on;

  #keepalive_timeout  0;

  keepalive_timeout  65;

  #gzip  on;

  server {

    listen    80;

    server_name  192.168.248.200;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {

      root  html;

      index  index.html index.htm;

    }

    #error_page  404        /404.html;

    # redirect server error pages to the static page /50x.html

    #

    error_page  500 502 503 504  /50x.html;

    location = /50x.html {

      root  html;

    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80

    #

    #location ~ .php$ {

    #   proxy_pass  http://127.0.0.1;

    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    #

    #location ~ .php$ {

    #   root      html;

    #   fastcgi_pass  127.0.0.1:9000;

    #   fastcgi_index  index.php;

    #   fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

    #   include     fastcgi_params;

    #}

    # deny access to .htaccess files, if Apache's document root

    # concurs with nginx's one

    #

    #location ~ /.ht {

    #   deny  all;

    #}

  }

  # another virtual host using mix of IP-, name-, and port-based configuration

  #

  #server {

  #   listen    8000;

  #   listen    somename:8080;

  #   server_name  somename  alias  another.alias;

  #   location / {

  #     root  html;

  #     index  index.html index.htm;

  #   }

  #}

  # HTTPS server

  #

  #server {

  #   listen    443 ssl;

  #   server_name  localhost;

  #   ssl_certificate    cert.pem;

  #   ssl_certificate_key  cert.key;

  #   ssl_session_cache   shared:SSL:1m;

  #   ssl_session_timeout  5m;

  #   ssl_ciphers  HIGH:!aNULL:!MD5;

  #   ssl_prefer_server_ciphers  on;

  #   location / {

  #     root  html;

  #     index  index.html index.htm;

  #   }

  #}

}

右边的nginx 服务器的配置文件 /usr/loca/nginx/conf/nginx.conf内容如下:

#user  nobody;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid     logs/nginx.pid;

events {

  worker_connections  1024;

}

http {

  include    mime.types;

  default_type  application/octet-stream;

  #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

  #          '$status $body_bytes_sent "$http_referer" '

  #          '"$http_user_agent" "$http_x_forwarded_for"';

  #access_log  logs/access.log  main;

  sendfile     on;

  #tcp_nopush   on;

  #keepalive_timeout  0;

  keepalive_timeout  65;

  #gzip  on;

  server {

    listen    80;

    server_name  192.168.248.200;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {

      root  html;

      index  index.html index.htm;

    }

    #error_page  404        /404.html;

    # redirect server error pages to the static page /50x.html

    #

    error_page  500 502 503 504  /50x.html;

    location = /50x.html {

      root  html;

    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80

    #

    #location ~ .php$ {

    #   proxy_pass  http://127.0.0.1;

    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

    #

    #location ~ .php$ {

    #   root      html;

    #   fastcgi_pass  127.0.0.1:9000;

    #   fastcgi_index  index.php;

    #   fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

    #   include     fastcgi_params;

    #}

    # deny access to .htaccess files, if Apache's document root

    # concurs with nginx's one

    #

    #location ~ /.ht {

    #   deny  all;

    #}

  }

  # another virtual host using mix of IP-, name-, and port-based configuration

  #

  #server {

  #   listen    8000;

  #   listen    somename:8080;

  #   server_name  somename  alias  another.alias;

  #   location / {

  #     root  html;

  #     index  index.html index.htm;

  #   }

  #}

  # HTTPS server

  #

  #server {

  #   listen    443 ssl;

  #   server_name  localhost;

  #   ssl_certificate    cert.pem;

  #   ssl_certificate_key  cert.key;

  #   ssl_session_cache   shared:SSL:1m;

  #   ssl_session_timeout  5m;

  #   ssl_ciphers  HIGH:!aNULL:!MD5;

  #   ssl_prefer_server_ciphers  on;

  #   location / {

  #     root  html;

  #     index  index.html index.htm;

  #   }

  #}

}

左边nginx服务器的默认 html文件内容为: ( /usr/local/nginx/html/index.html)

I am nginx master

右边nginx服务器的默认html文件内容为:(路径同上)

I am nginx-slave

左边nginx服务器的keepalived配置文件为:( /etc/keepalived/keepalived.conf)

global_defs {

  router_id NodeA

}

vrrp_instance VI_1 {

  state MASTER   #设置为主服务器

  interface ens33  #监测网络接口

  virtual_router_id 51  #主、备必须一样

  priority 100  #(主、备机取不同的优先级,主机值较大,备份机值较小,值越大优先级越高)

  advert_int 1  #VRRP Multicast广播周期秒数

  authentication {

  auth_type PASS  #VRRP认证方式,主备必须一致

  auth_pass 1111  #(密码)

}

virtual_ipaddress {

  192.168.248.200

}

右边nginx服务器的keepalived配置文件内容如下:

global_defs {

  router_id NodeB

}

vrrp_instance VI_1 {

  state BACKUP  #设置为主服务器

  interface ens33  #监测网络接口

  virtual_router_id 51  #主、备必须一样

  priority 90 #(主、备机取不同的优先级,主机值较大,备份机值较小,值越大优先级越高)

  advert_int 1  #VRRP Multicast广播周期秒数

  authentication {

  auth_type PASS  #VRRP认证方式,主备必须一致

  auth_pass 1111  #(密码)

}

virtual_ipaddress {

  192.168.248.200

}

启动nginx服务器和配置防火墙

#/usr/local/nginx/sbin/nginx

#firewall-cmd --permanent --add-port=80/tcp

#firewall-cmd --reload

实际测试结果如下:

关闭左边的nginx的ens33端口后,造成nginx备生主,


网站栏目:nginx+keepalived实现高可靠web网站-创新互联
文章URL:http://6mz.cn/article/ccsdei.html

其他资讯