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

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

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

nginx配置文件以下 css

#user  nobody;
#启动进程,一般设置成和CPU的数量相等
worker_processes  1;
#全局错误日志及PID文件
error_log  /var/log/nginx/error.log;
pid /var/run/nginx.pid; html

#工做模式及链接数上限
events {
    use epoll; #epoll是多路复用IO(I/O Multiplexing)中的一种方式可能提升nginx性能
    worker_connections  1024;#单个后台worker process进程的最大的并发链接数
} java

#设计http服务器,利用它的反向代理功能提供负载均衡支持
http {
    #设定minme类型,类型由mime.type文件定义
    include       mime.types;
    default_type  application/octet-stream; nginx

    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;
        } web

        #error_page  404              /404.html; json

        # redirect server error pages to the static page /50x.html
        # 设置错误页面
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        } tomcat

        # 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;
    #    }
    #}

}

2、安装 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 是设置MemcacheTCP监听的端口,最好是1024以上的端口 

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

-P 是设置保存Memcachepid文件

-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退出

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

  <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

以上是基础配置,初学点东西,能够加群164297299一块儿进步学习99

相关文章
相关标签/搜索