qweewq123qwe 发表于 2018-11-13 10:19:41

nginx负载均衡+keepalive心跳检测

  环境标准:
  一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
  内核:2.6.32-642.el6.x86_64

  系统:CentOS>  ip:
  web01:10.0.0.8nginx解析手机端均做了nginx的负载均衡但是只均衡一台机器可以后续往里填
  web02:10.0.0.200nginx解析电脑端均做了nginx的负载均衡但是只均衡一台机器可以后续往里填
  lb01:10.0.0.201nginx负载均衡lb01主负载均衡
  lb02:10.0.0.31nginx负载均衡lb02备的负载均衡
  vip:10.0.0.5(虚拟)keepalive虚拟路由冗余保证负载均衡存在解决单点问题
  存放目录:/home/oldboy/tools/
  安装目录:/application/
  运行用户:www
  脚本目录:/server/script(在这里暂时没有使用脚本)
  ip功能介绍:
  一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
  web01:
  第一个里程碑:部署配置nginx
  1.mkdir -p /home/oldboy/tools
  2.cd /home/oldboy/tools
  3.wget http://nginx.org/download/nginx-1.10.2.tar.gz
  4.useradd-s /sbin/nologin -M www
  5. tar xf nginx-1.10.2.tar.gz
  6.cdnginx-1.10.2
  7.yum install -ypcre-devel openssl-devel
  8.yum install gcc-c++ -y
  9. ./configure--user=www --group=www --prefix=/application/nginx-1.10.2 --with-http_stub_status_module--with-http_ssl_module
  10.make && make install
  11.ln -s /application/nginx-1.10.2 /application/nginx
  12.vim /application/nginx/config/nginx.conf
  ===================================================
  worker_processes1;
  events {
  worker_connections1024;
  }
  http {
  include       mime.types;
  default_typeapplication/octet-stream;
  sendfile      on;
  keepalive_timeout65;
  log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
  '$status $body_bytes_sent "$http_referer" '
  '"$http_user_agent" "$http_x_forwarded_for"';
  access_loglogs/access.logmain;
  include   extra/blog.conf;
  }
  ===================================================
  13.mkdir /application/nginx/config/extra
  14.vim /application/nginx/config/extra/blog.conf
  ====================================================
  server {
  listen       80;
  server_nameblog.ls.com;
  location / {
  root   html/blog;
  indexindex.php gen.html index.html index.htm;
  }
  location ~ .*\.(php|php5)?$ {
  root   html/blog;
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_indexindex.php;
  include       fastcgi.conf;
  }
  }
  =====================================================
  15.mkdir /application/nginx/html/blog
  16.echo "hello word!!! i am web01" > /application/nginx/html/blog/index.html
  17. /application/nginx/sbin/nginx -t
  18. /application/nginx/sbin/nginx
  第二个里程碑:测试
  # curl 10.0.0.8
  hello web01
  一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
  web02:
  第一个里程碑:部署配置nginx
  1.mkdir -p /home/oldboy/tools
  2.cd /home/oldboy/tools
  3.wget http://nginx.org/download/nginx-1.10.2.tar.gz
  4.useradd-s /sbin/nologin -M www
  5. tar xf nginx-1.10.2.tar.gz
  6.cdnginx-1.10.2
  7.yum install -ypcre-devel openssl-devel
  8.yum install gcc-c++ -y
  9. ./configure--user=www --group=www --prefix=/application/nginx-1.10.2 --with-http_stub_status_module--with-http_ssl_module
  10.make && make install
  11.ln -s /application/nginx-1.10.2 /application/nginx
  12.vim /application/nginx/config/nginx.conf
  =========================================================
  worker_processes1;
  events {
  worker_connections1024;
  }
  http {
  include       mime.types;
  default_typeapplication/octet-stream;
  sendfile      on;
  keepalive_timeout65;
  log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
  '$status $body_bytes_sent "$http_referer" '
  '"$http_user_agent" "$http_x_forwarded_for"';
  access_loglogs/access.logmain;
  include   extra/blog.conf;
  }
  =========================================================
  15.mkdir /application/nginx/html/blog
  16.echo "hello word!!! i am web02" > /application/nginx/html/blog/index.html
  17. /application/nginx/sbin/nginx -t
  18. /application/nginx/sbin/nginx
  第二个里程碑:测试
  # curl 10.0.0.200
  hello web02
  一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
  lb01:
  第一个里程碑:部署配置nginx
  1.mkdir -p /home/oldboy/tools
  2.cd /home/oldboy/tools
  3.wget http://nginx.org/download/nginx-1.10.2.tar.gz
  4.useradd-s /sbin/nologin -M www
  5. tar xf nginx-1.10.2.tar.gz
  6.cdnginx-1.10.2
  7.yum install -ypcre-devel openssl-devel
  8.yum install gcc-c++ -y
  9. ./configure--user=www --group=www --prefix=/application/nginx-1.10.2 --with-http_stub_status_module--with-http_ssl_module
  10.make && make install
  11.ln -s /application/nginx-1.10.2 /application/nginx
  12.vim /application/nginx/config/nginx.conf
  =========================================================
  worker_processes1;
  events {
  worker_connections1024;
  }
  http {
  include       mime.types;
  default_typeapplication/octet-stream;
  sendfile      on;
  keepalive_timeout65;
  log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
  '$status $body_bytes_sent "$http_referer" '
  '"$http_user_agent" "$http_x_forwarded_for"';
  access_loglogs/access.logmain;
  upstream dn {
  server 10.0.0.8;
  }
  upstream sj {
  server 10.0.0.200;
  }
  server {
  listen       80;
  server_nameblog.ls.com;
  location / {
  if ( $http_user_agent ~* 'curl' )
  {
  proxy_pass http://dn;
  }
  proxy_pass http://sj;
  proxy_set_header X-Forwarded-For $remote_addr;
  proxy_set_header Host $host;
  }
  }
  }
  =========================================================
  13. /application/nginx/sbin/nginx -t
  14. /application/nginx/sbin/nginx
  第二个里程碑:测试
  # curl 10.0.0.201
  hello web02
  # curl 10.0.0.201
  hello web01
  一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
  lb02:
  第一个里程碑:部署配置nginx
  1.mkdir -p /home/oldboy/tools
  2.cd /home/oldboy/tools
  3.wget http://nginx.org/download/nginx-1.10.2.tar.gz
  4.useradd-s /sbin/nologin -M www
  5. tar xf nginx-1.10.2.tar.gz
  6.cdnginx-1.10.2
  7.yum install -ypcre-devel openssl-devel
  8.yum install gcc-c++ -y
  9. ./configure--user=www --group=www --prefix=/application/nginx-1.10.2 --with-http_stub_status_module--with-http_ssl_module
  10.make && make install
  11.ln -s /application/nginx-1.10.2 /application/nginx
  12.vim /application/nginx/config/nginx.conf
  =========================================================
  worker_processes1;
  events {
  worker_connections1024;
  }
  http {
  include       mime.types;
  default_typeapplication/octet-stream;
  sendfile      on;
  keepalive_timeout65;
  log_formatmain'$remote_addr - $remote_user [$time_local] "$request" '
  '$status $body_bytes_sent "$http_referer" '
  '"$http_user_agent" "$http_x_forwarded_for"';
  access_loglogs/access.logmain;
  upstream dn {
  server 10.0.0.8;
  }
  upstream sj {
  server 10.0.0.200;
  }
  server {
  listen       80;
  server_nameblog.ls.com;
  location / {
  if ( $http_user_agent ~* 'curl' )
  {
  proxy_pass http://dn;
  }
  proxy_pass http://sj;
  proxy_set_header X-Forwarded-For $remote_addr;
  proxy_set_header Host $host;
  }
  }
  }
  =========================================================
  13. /application/nginx/sbin/nginx -t
  14. /application/nginx/sbin/nginx
  第二个里程碑:测试
  # curl 10.0.0.31
  hello web02
  # curl 10.0.0.31
  hello web01
  一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
  lb01:keepalive
  yum install keepalived -y
  vim /etc/keepalived/keepalived.conf
  ----------------------------------------------
  ! Configuration File for keepalived
  global_defs {
  notification_email {
  shuaileo@163.com
  }
  notification_email_from shuaileo@163.com
  smtp_server smtp.163.com
  smtp_connect_timeout 30
  router_id LVS_DEVEL1
  }
  vrrp_instance VI_1 {
  state MASTER                  #标记为主
  interface eth0
  virtual_router_id 51
  priority 150
  advert_int 1
  authentication {
  auth_type PASS
  auth_pass 1111
  }
  virtual_ipaddress {
  10.0.0.5/24 dev eth0 label eth0:0
  }
  }
  -------------------------------------------------
  /etc/init.d/keepalive start
  一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
  lb02:keepalive
  yum install keepalived -y
  vim /etc/keepalived/keepalived.conf
  ----------------------------------------------
  ! Configuration File for keepalived
  global_defs {
  notification_email {
  shuaileo@163.com
  }
  notification_email_from shuaileo@163.com
  smtp_server smtp.163.com
  smtp_connect_timeout 30
  router_id LVS_DEVEL1
  }
  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.0.0.5/24 dev eth0 label eth0:0
  }
  }
  -----------------------------------------------
  /etc/init.d/keepalive start
  第二个里程碑:测试
  ip a
  curl 10.0.0.5
  一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
  linux端:
  vim /etc/hosts
  --------------------
  10.0.0.3 blog.ls.com
  --------------------
  # curl blog.ls.com
  hello web01
  Windows客户端:
  vim /etc/hosts
  --------------------
  10.0.0.3 blog.ls.com
  --------------------
  浏览器端打开blog.ls.com
  hello web02

页: [1]
查看完整版本: nginx负载均衡+keepalive心跳检测