设为首页 收藏本站
查看: 736|回复: 0

[经验分享] nginx负载均衡+keepalive心跳检测

[复制链接]

尚未签到

发表于 2018-11-13 10:19:41 | 显示全部楼层 |阅读模式
  环境标准:
  一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
  内核: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.cd  nginx-1.10.2
  7.yum install -y  pcre-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_processes  1;
  events {
  worker_connections  1024;
  }
  http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  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;
  include     extra/blog.conf;
  }
  ===================================================
  13.mkdir /application/nginx/config/extra
  14.vim /application/nginx/config/extra/blog.conf
  ====================================================
  server {
  listen       80;
  server_name  blog.ls.com;
  location / {
  root   html/blog;
  index  index.php gen.html index.html index.htm;
  }
  location ~ .*\.(php|php5)?$ {
  root   html/blog;
  fastcgi_pass   127.0.0.1:9000;
  fastcgi_index  index.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
  第二个里程碑:测试
  [root@test html]# 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.cd  nginx-1.10.2
  7.yum install -y  pcre-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_processes  1;
  events {
  worker_connections  1024;
  }
  http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  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;
  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
  第二个里程碑:测试
  [root@test html]# 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.cd  nginx-1.10.2
  7.yum install -y  pcre-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_processes  1;
  events {
  worker_connections  1024;
  }
  http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  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;
  upstream dn {
  server 10.0.0.8;
  }
  upstream sj {
  server 10.0.0.200;
  }
  server {
  listen       80;
  server_name  blog.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
  第二个里程碑:测试
  [root@test html]# curl 10.0.0.201
  hello web02
  [root@test html]# 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.cd  nginx-1.10.2
  7.yum install -y  pcre-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_processes  1;
  events {
  worker_connections  1024;
  }
  http {
  include       mime.types;
  default_type  application/octet-stream;
  sendfile        on;
  keepalive_timeout  65;
  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;
  upstream dn {
  server 10.0.0.8;
  }
  upstream sj {
  server 10.0.0.200;
  }
  server {
  listen       80;
  server_name  blog.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
  第二个里程碑:测试
  [root@test html]# curl 10.0.0.31
  hello web02
  [root@test html]# 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
  --------------------
  [root@salt conf]# curl blog.ls.com
  hello web01
  Windows客户端:
  vim /etc/hosts
  --------------------
  10.0.0.3 blog.ls.com
  --------------------
  浏览器端打开blog.ls.com
  hello web02


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-634464-1-1.html 上篇帖子: Linux下怎么确定Nginx安装目录、版本号信息? 下篇帖子: nginx+双tomcat集群负载均衡(一台机器)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表