docker run

[root@docker-master1 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                         NAMES
7806f7209a00        d29                 "nginx -g 'daemon ..."   9 minutes ago       Up About a minute   0.0.0.0:80->80/tcp, 443/tcp   nginx_t1t2
28dc1294f90c        3d79                "catalina.sh run"        3 hours ago         Up 14 minutes       0.0.0.0:8081->8080/tcp        tomcat2
c28c35f2938c        3d79                "catalina.sh run"        3 hours ago         Up 14 minutes       0.0.0.0:8080->8080/tcp        tomcat1

 

tomcat

docker run -d --name tomcat2 --ip 192.168.210.10 --network mynetwork --restart always --memory 2g --memory-swap 2.5g --oom-kill-disable --cpuset-cpus="1,3" -v /base/webapps:/usr/local/tomcat/webapps:ro -v /base/logs:/usr/local/tomcat/logs -p 8080:8080 3d79 

红色字体表示只有指定自定义的网络时才能指定ip地址。(还可以-v指定tomcat的server.xml等配置文件)

nginx

docker run -d --name nginx_t1t2 --restart always --memory 2g --memory-swap 2.5g --oom-kill-disable --cpuset-cpus="0,2" -v /data/nginx.conf:/etc/nginx/nginx.conf:ro  -v /data/nginxhtml:/usr/share/nginx/html:ro -v /data/nginxlogs:/var/log/nginx --link tomcat1:tomcat1 --link tomcat2:tomcat2 -p 80:80 d29

为了防止tomcat重启ip变动,这里加上--link

nginx.conf 示例 

cat /data/nginx.conf

user nginx nginx;
worker_processes auto;

error_log /var/log/nginx/error_nginx.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;

events {
  use epoll;
  worker_connections 51200;
  multi_accept on;
}

http {
  map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
  }
  include mime.types;
  default_type application/octet-stream;
  server_names_hash_bucket_size 128;
  client_header_buffer_size 32k;
  large_client_header_buffers 4 32k;
  client_max_body_size 1024m;
  client_body_buffer_size 10m;
  sendfile on;
  tcp_nopush on;
  keepalive_timeout 120;
  server_tokens off;
  tcp_nodelay on;

#  fastcgi_connect_timeout 300;
#  fastcgi_send_timeout 300;
#  fastcgi_read_timeout 300;
#  fastcgi_buffer_size 64k;
#  fastcgi_buffers 4 64k;
#  fastcgi_busy_buffers_size 128k;
#  fastcgi_temp_file_write_size 128k;
#  fastcgi_intercept_errors on;

  #Gzip Compression
  gzip on;
  gzip_buffers 16 8k;
  gzip_comp_level 6;
  gzip_http_version 1.1;
  gzip_min_length 256;
  gzip_proxied any;
  gzip_vary on;
  gzip_types
    text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
    text/javascript application/javascript application/x-javascript
    text/x-json application/json application/x-web-app-manifest+json
    text/css text/plain text/x-component
    font/opentype application/x-font-ttf application/vnd.ms-fontobject
    image/x-icon;
  gzip_disable "MSIE [1-6]\.(?!.*SV1)";

  #If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
  open_file_cache max=1000 inactive=20s;
  open_file_cache_valid 30s;
  open_file_cache_min_uses 2;
  open_file_cache_errors on;

  upstream myup {
       server tomcat1:8080  weight=5 max_fails=1 fail_timeout=30s;
       server tomcat2:8080  weight=5 max_fails=1 fail_timeout=30s;
}

server {
        listen 80;
        server_name 192.168.20.210;
        index index.html index.htm index.jsp index.do;
        access_log  /var/log/nginx/myup.logs;

        location /tomcat/ {
                proxy_pass http://myup;
        proxy_connect_timeout 300s;
        proxy_send_timeout 900;
        proxy_read_timeout 900;
        proxy_buffer_size 32k;
        proxy_buffers 4 64k;
        proxy_busy_buffers_size 128k;
        proxy_redirect off;
        proxy_hide_header Vary;
        proxy_set_header Accept-Encoding '';
        proxy_set_header Referer $http_referer;
        proxy_set_header Cookie $http_cookie;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
}

 

  

posted @ 2018-10-24 11:43  面对疾风  阅读(332)  评论(0编辑  收藏  举报