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

[经验分享] nginx+upstream+sticky---jetty

[复制链接]

尚未签到

发表于 2018-11-8 07:48:21 | 显示全部楼层 |阅读模式
  jetty昨天的帖子里面已经安装完成,运行一个jetty对于服务太不稳定或者安全,在实际运营中有很少见到,今天的想法是使用两个NG 代理多个jetty。
  一、下载与编译安装
  
mginx---主程序
  
upstream---上游服务健康检查,实现和后端服务器(php/jboss等)进行通信。
  
sticky---使用cookie代替客户端连接的IP,基于一个“最佳”算法。它的目标不是处理安全以某种方式。这是被作出保证正常用户永远都重定向到同一后端服务器
  
mkdir /ftp    //习惯性在根下面建立一个ftp目录,ng或者jetty之后的LVS是放在/web下的
  
cd /ftp
  
wget http://nginx.org/download/nginx-1.2.2.tar.gz
  
wget http://nginx-sticky-module.googlecode.com/files/nginx-sticky-module-1.0.tar.gz
  
wget https://github.com/yaoweibin/nginx_upstream_check_module/zipball/master/
  
mv master master.zip
  
yaoweibin 写的upstream 介绍:
  
https://github.com/yaoweibin/nginx_upstream_check_module
  

  unzip master.zip
  
tar -zxvf nginx-sticky-module-1.0.tar.gz
  
tar -zxvf nginx-1.2.2.tar.gz
  
[root@res02 nginx-1.2.2]#patch -p1 < ../yaoweibin-nginx_upstream_check_module-be97c70/check_1.2.2+.patch
  
[root@res02 nginx-1.2.2]#mkdir /web/nginx
  
[root@res02 nginx-1.2.2]# yum install gd-devel openssh-clients openssl-devel gcc make pcre-devel -y
  
[root@res02 nginx-1.2.2]# rpm -qa  gd-devel openssh-clients openssl-devel gcc make pcre-devel
  
openssh-clients-5.3p1-81.el6.x86_64
  
gd-devel-2.0.35-10.el6.x86_64
  
make-3.81-20.el6.x86_64
  
gcc-4.4.6-4.el6.x86_64
  
pcre-devel-7.8-4.el6.x86_64
  
openssl-devel-1.0.0-20.el6_2.5.x86_64
  
[root@res02 nginx-1.2.2]# useradd nginx -d /dev/null -s /sbin/nologin
  
[root@res02 nginx-1.2.2]# ./configure --user=www --group=www --prefix=/web/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/lock/subsys/nginx --user=nginx --group=nginx --with-poll_module --with-http_ssl_module --with-http_image_filter_module --with-http_sub_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_realip_module --with-http_image_filter_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/ftp/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --add-module=../yaoweibin-nginx_upstream_check_module-be97c70 --add-module=../nginx-sticky-module-1.0
  
[root@res02 nginx-1.2.2]# make
  
[root@res02 nginx-1.2.2]# make install
  
[root@res02 nginx-1.2.2]# cd /etc/sysconfig/
  
[root@res02 sysconfig]# echo 'NGINX_CONF_FILE=&quot;/etc/nginx/nginx.conf&quot;'  > nginx
  [root@res02 sysconfig]# cd /etc/nginx/
  
上传附件启动脚本到该目录。
  
[root@res02 nginx]# chmod 755 /etc/nginx/nginx.sh
  
[root@res02 nginx]#ln -s /etc/nginx/nginx.sh /etc/init.d/nginx
  
[root@res02 nginx]# mkdir -p /var/tmp/nginx/proxy
  安装到这里nginx 已经安装完毕,输入命令:service nginx start 即可启动。默认端口80
  
后面是整合jetty 的配置。
  

  
二、配置nginx 负载均衡
  
[root@res02 nginx]# vim /etc/nginx/nginx.conf
  
注释掉默认server 的配置,加入代码:
  


  • proxy_headers_hash_bucket_size 1024;
  • proxy_headers_hash_max_size 512;

  • upstream res {
  •      sticky;
  •      server 10.10.15.230:8080 down;
  •      server 10.10.15.220:8080;
  •              check interval=3000 rise=2 fall=5 timeout=1000 type=http;
  •              check_http_send &quot;GET / HTTP/1.0\r\n\r\n&quot;;
  •              check_http_expect_alive http_2xx http_3xx;
  •     }

  •     server {
  •         listen       80;
  •         server_name  res.888jk.net;

  •          location / {
  •          proxy_set_header Host $host;
  •          proxy_set_header X-Real-IP $remote_addr;
  •          proxy_set_header X-Forwarded-For $http_x_forwarded_for;
  •          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  •          proxy_pass http://res;
  •          }

  • location /status {
  •              check_status;
  •              access_log      /var/log/nginx/res.log;
  •              auth_basic &quot;RES-Nginx-Status&quot;;
  •              auth_basic_user_file &quot;/usr/local/nginx/html/.htpasswd&quot;;
  •              }
  

  [root@res02 nginx]# mkdir -p /usr/local/nginx/html
  
[root@res02 nginx]# vim /usr/local/nginx/html/.htpasswd
  
blueway:4hInEbbTbERQ
  
密码是由htpasswd 生成的。
  
比如在安装有apache 的服务器上生成MD5密码:
  
htpasswd -bc .passwd blueway php!
  
注释:生成一个.passwd文件,用户名blueway,密码:php!,默认采用MD5加密方式
  




运维网声明 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.iyunv.com/thread-632128-1-1.html 上篇帖子: 利用nginx加速web访问 下篇帖子: nginx+awstats 统计web服务器log
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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