欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Docker如何使用nginx搭建tomcat集群(圖文詳解)

 更新時(shí)間:2019年12月30日 17:03:11   作者:魏小哥  
這篇文章主要介紹了Docker使用nginx搭建tomcat集群的教程,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

首先創(chuàng)建tomcat的文件夾 ,為了方便docker的配置 我這里直接在根目錄中創(chuàng)建第一步:創(chuàng)建文件夾:發(fā)布文件夾

mkdir -p /docker/tomcat/webapp8081

mkdir -p /docker/tomcat/webapp8082

mkdir -p /docker/tomcat/webapp8083

第二步:創(chuàng)建Tomcat容器(端口 可以根據(jù)自己的實(shí)際更換)

docker run -d --name tomcat8081 -p 8081:8080 -v /docker/tomcat/webapp8081:/usr/local/tomcat/webapps/ tomcat
docker run -d --name tomcat8082 -p 8082:8080 -v /docker/tomcat/webapp8082:/usr/local/tomcat/webapps/ tomcat
docker run -d --name tomcat8083 -p 8083:8080 -v /docker/tomcat/webapp8083:/usr/local/tomcat/webapps/ tomcat

創(chuàng)建完成后使用 docker ps 命令進(jìn)行查看是否創(chuàng)建成功 并且使用

第三步:查看tomcat的IP 使用命令依次查詢 這里只使用第一個(gè)舉例

docker inspect tomcat8081

第四步:為了方便測試 我這里就不上傳war包了,直接 在里面創(chuàng)建了一個(gè)hello/index.html 文件

注意:如果Nginx為Docker容器,必須使用Tomact容器IP,否則連不上

首先在官網(wǎng)上下載nginx的官方版本

官網(wǎng):http://nginx.org/en/

點(diǎn)擊右邊導(dǎo)航欄的download,進(jìn)入下載界面 選擇對應(yīng)的版本 進(jìn)行下載,我這里就使用nginx-1.6.2.tar

下載完成后,將文件放到自定義的文件夾,我這里放到/usr/local/tools/nginx-1.6.2

使用 這個(gè)命令將nginx 解壓:

tar vxf nginx-1.6.2.tar.gz

解壓完成后,我這里是返回根目錄,在根目錄創(chuàng)建一個(gè)宿主文件夾,目的是為了創(chuàng)建文件,使得nginx可以掛載(你也可以自定義)

創(chuàng)建宿主文件夾 這里

mkdir -p /docker/nginx/
vim /docker/nginx/nginx.conf
mkdir -p /docker/nginx/html

拷貝頁面你解壓的negix中的html文件夾中的index.html 50x.html到/docker/nginx/html文件夾中

這里提供一種negix的conf文件,以為加上注解 所以格式可能會發(fā)生改變 記得把注解刪了

Nginx.conf:

user root;

worker_processes 2; #這里設(shè)置你的線程數(shù)

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024; #最大連接數(shù)量
}
http {
include mime.types;
default_type application/octet-stream;
upstream mytomcat{
server 172.17.0.3:8080 weight=10;
# 另外mytomcat 這里名字和下方的名字保持一致 這里需要和你的tomcat IP保持一致
server 172.17.0.4:8080 weight=50;
server 172.17.0.5:8080 weight=10;
}
#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;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name mytomcat;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# root html;
# index index.html index.htm;
proxy_connect_timeout 50;
proxy_read_timeout 10;
proxy_send_timeout 20;
proxy_pass http://mytomcat;
}
#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;
# }
#}
}

使用docker 啟動

創(chuàng)建并運(yùn)行容器

81:是外網(wǎng)訪問的端口 這里可以根據(jù)實(shí)際做修改

/docker/nginx/nginx.conf 本地的宿主文件

/etc/nginx/nginx.conf 解壓的目錄(也可以不更改)

/docker/nginx/html 本地的宿主文件

/usr/share/nginx/html 解壓的目錄

docker run -d --name nginx81 -p 81:80 -v /docker/nginx/nginx.conf:/etc/nginx/nginx.conf -v /docker/nginx/html:/usr/share/nginx/html nginx

測試

http://39.106.147.162:8085/hello/index.html 我這里配置的是8085端口

直接訪問

總結(jié)

以上所述是小編給大家介紹的Docker使用nginx搭建tomcat集群的教程,希望對大家有所幫助!

相關(guān)文章

  • docker安裝postgresql的圖文教程

    docker安裝postgresql的圖文教程

    PostgreSQL也稱為?Postgres,是領(lǐng)先的對象關(guān)系數(shù)據(jù)庫系統(tǒng),下面這篇文章主要給大家介紹了關(guān)于docker安裝postgresql的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-07-07
  • docker的WARNING:bridge-nf-call-iptables is disabled的解決方案

    docker的WARNING:bridge-nf-call-iptables is disabled

    這篇文章主要介紹了docker的WARNING:bridge-nf-call-iptables is disabled的解決方案,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • MySQL容器中docker-entrypoint-initdb.d目錄的使用

    MySQL容器中docker-entrypoint-initdb.d目錄的使用

    這篇文章主要介紹了MySQL容器中docker-entrypoint-initdb.d目錄的使用方式,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • docker構(gòu)建nginx?alpine鏡像實(shí)現(xiàn)步驟

    docker構(gòu)建nginx?alpine鏡像實(shí)現(xiàn)步驟

    這篇文章主要介紹了docker構(gòu)建nginx?alpine鏡像實(shí)現(xiàn)步驟,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08
  • 寫給前端的nginx配置指南基于docker所有配置秒級運(yùn)行(最新講解)

    寫給前端的nginx配置指南基于docker所有配置秒級運(yùn)行(最新講解)

    這篇文章主要介紹了寫給前端的nginx配置指南基于docker所有配置秒級運(yùn)行,通過?docker?高效學(xué)習(xí)?nginx?配置,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2022-06-06
  • docker-compose管理容器network與ip問題

    docker-compose管理容器network與ip問題

    這篇文章主要介紹了docker-compose管理容器network與ip問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-01-01
  • 使用Docker Compose搭建 Confluence的教程

    使用Docker Compose搭建 Confluence的教程

    本文將介紹如何使用 Docker Compose 快速搭建 Confluence 、以及如何和 Traefik 一同使用,如果你看過之前的內(nèi)容,跟隨本文應(yīng)該能在十分鐘內(nèi)解決戰(zhàn)斗,感興趣的朋友快來看看吧
    2021-06-06
  • docker-compose安裝db2數(shù)據(jù)庫操作

    docker-compose安裝db2數(shù)據(jù)庫操作

    這篇文章主要介紹了docker-compose安裝db2數(shù)據(jù)庫操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-12-12
  • Docker中Dockerfile之容器中運(yùn)行MyEclipse搭建的JavaWeb項(xiàng)目

    Docker中Dockerfile之容器中運(yùn)行MyEclipse搭建的JavaWeb項(xiàng)目

    本篇文章主要介紹了Docker中Dockerfile之容器中運(yùn)行MyEclipse搭建的JavaWeb項(xiàng)目,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-02-02
  • Docker容器動態(tài)加載掛載目錄的實(shí)踐

    Docker容器動態(tài)加載掛載目錄的實(shí)踐

    本文主要介紹了Docker容器中動態(tài)加載掛載目錄的實(shí)踐,通過掛載目錄,可以將主機(jī)上的文件或目錄與容器中的文件或目錄進(jìn)行關(guān)聯(lián),實(shí)現(xiàn)應(yīng)用程序的靈活性和可擴(kuò)展性,這種方法可以避免容器重啟,減少應(yīng)用程序的停機(jī)時(shí)間,并簡化應(yīng)用程序的部署和管理,使應(yīng)用程序的遷移和擴(kuò)展更加容易
    2024-10-10

最新評論