前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Ubantu下实现Tomcat+memcached+nginx多实例部署

Ubantu下实现Tomcat+memcached+nginx多实例部署

作者头像
用户2603479
发布2018-08-16 10:04:20
3020
发布2018-08-16 10:04:20
举报
文章被收录于专栏:JAVA技术站JAVA技术站

 一、nginx安装,命令行安装方便快捷

http://my.oschina.net/u/136848/blog/283599

nginx配置文件如下

代码语言:javascript
复制
 #user  nobody;
 #启动进程,通常设置成和CPU的数量相等
 worker_processes  1;
 #全局错误日志及PID文件
 error_log  /var/log/nginx/error.log;
 pid /var/run/nginx.pid; 
 #工作模式及连接数上限
 events {
     use epoll; #epoll是多路复用IO(I/O Multiplexing)中的一种方式可能提高nginx性能
     worker_connections  1024;#单个后台worker process进程的最大的并发连接数
 } 
 #设计http服务器,利用它的反向代理功能提供负载均衡支持
 http {
     #设定minme类型,类型由mime.type文件定义
     include       mime.types;
     default_type  application/octet-stream; 
     log_format main '$remote_addr - $remote_user [$time_local] '
  '"$request" $status $bytes_sent '
  '"$http_referer" "$http_user_agent" '
  '"$gzip_ratio"';
  log_format download '$remote_addr - $remote_user [$time_local] '
  '"$request" $status $bytes_sent '
  '"$http_referer" "$http_user_agent" '
  '"$http_range" "$sent_http_content_range"';
  log_format post '$remote_addr - $remote_user [$time_local] '
         '"$request" $status $bytes_sent '
         '"$http_referer" "$http_user_agent" $content_type $http_accept_encoding'
         '"$gzip_ratio" $request_body';
     #设计日志格式
     access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log;
     #sendfile 指令指定nginx是否调用sendfile函数(zero copy方式)输出文件
  #必须调为on,如果用来下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的uptime.
     sendfile        on;
     #tcp_nopush     on;
     #连接超时时间
     #keepalive_timeout  0;
     keepalive_timeout  65;
     #设定请求缓冲
     client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  #开永嘉gzip压缩
  gzip on;
  gzip_min_length 1100;
  gzip_buffers 4 8k;
  gzip_types text/plain text/css application/x-javascript application/json; 
  output_buffers 1 32k;
  postpone_output 1460;
  #设定负载均衡的服务器列表,backup代表备份服务器,只有当所有节点都没有返回时,才启用http://hillside.iteye.com/blog/703281
     upstream zxSrv{
   server 127.0.0.1:8080;
   server 127.0.0.1:8288;
  }
     server {
      #侦听80端口
         listen       80;
   #侦听域名
         server_name  www.ruijinzhuangxiu.com;
         #设置编码
         charset utf-8;
         #设置本虚拟机的访问日志
         access_log  /var/log/nginx/8088.log  main;
         #设置转发机置
         location / {
           proxy_pass http://zxSrv;
         } 
         #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;
     #    }
     #} 
 } 

二、安装 memcached

sudo apt-get install memcached

启动memcahche

/opt/memcached/bin/memcached -d -m 10240 -u root -l 127.0.0.1 -p 11211 -c 5000 -P /tmp/memcached11211.pid

以上面用到的常用参数进行说明:

-d 以守护进程方式运行

-m 是分配给Memcache使用的内存数量,单位是MB,默认64MB

-u 是运行Memcache的用户,如果当前为root的话,需要使用此参数指定用户

-l 是监听的服务器IP地址,默认为所有网卡

-p 是设置Memcache的TCP监听的端口,最好是1024以上的端口 

-c 选项是最大运行的并发连接数,默认是1024 

-P 是设置保存Memcache的pid文件

-v 输出警告和错误信息

-vv 打印客户端的请求和返回信息

-h 打印帮助信息

-i 打印 memcached 和 libevent

启动后用telnet 127.0.0.1 10211检测是否启动成功

Trying 127.0.0.1... Connected to 127.0.0.1. Escape character is '^]'.

表示成功安装,ctrl+] 后加q退出

三、布属两个tomcat,配置文件context.xml加入

代码语言:javascript
复制
   <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"    
     memcachedNodes="n1:localhost:11211"    
     requestUriIgnorePattern=".*/.(png|gif|jpg|css|js)$"    
     sessionBackupAsync="false"    
     sessionBackupTimeout="100"    
 transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"    
     copyCollectionsForSerialization="false" /> 

lib中放置包

配置完成http://115.28.141.137 分别配置的是8080端口和8288端口 8288端口实例设置session 8080端口用于显示session值如下

先访问8080端口

再访问8288端口

再访问8080端口

或是直接访问ip

以上是基础配置,初学点东西。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2014/06/25 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
负载均衡
负载均衡(Cloud Load Balancer,CLB)提供安全快捷的流量分发服务,访问流量经由 CLB 可以自动分配到云中的多台后端服务器上,扩展系统的服务能力并消除单点故障。负载均衡支持亿级连接和千万级并发,可轻松应对大流量访问,满足业务需求。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档