Docker 安装nigix、tomcat、es+kibana和portainer可视化

1、 nigix 安装

#1、查看当前镜像
[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE                                                                                             
mysql         latest    3218b38490ce   2 weeks ago    516MB                                                                                            
hello-world   latest    feb5d9fea6a5   3 months ago   13.3kB                                                                                           
centos        latest    5d0da3dc9764   3 months ago   231MB                                                      
#2、搜索nginx镜像
[root@localhost ~]# docker search nginx
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED                                       
nginx                             Official build of Nginx.                        16098     [OK]                                                       
jwilder/nginx-proxy               Automated Nginx reverse proxy for docker con…   2106                 [OK]                                            
richarvey/nginx-php-fpm           Container running Nginx + PHP-FPM capable of820                  [OK]                                            
jc21/nginx-proxy-manager          Docker container for managing Nginx proxy ho…   307                                                                  
linuxserver/nginx                 An Nginx container, brought to you by LinuxS…   161                                                                  
tiangolo/nginx-rtmp               Docker image with Nginx using the nginx-rtmp…   149                  [OK]                                            
jlesage/nginx-proxy-manager       Docker container for Nginx Proxy Manager        148                  [OK]                                            
alfg/nginx-rtmp                   NGINX, nginx-rtmp-module and FFmpeg from sou…   112                  [OK]                                            
nginxdemos/hello                  NGINX webserver that serves a simple page co…   81                   [OK]                                            
privatebin/nginx-fpm-alpine       PrivateBin running on an Nginx, php-fpm & Al…   61                   [OK]                                            
nginx/nginx-ingress               NGINX and  NGINX Plus Ingress Controllers fo…   59                                                                   
nginxinc/nginx-unprivileged       Unprivileged NGINX Dockerfiles                  56                   
nginxproxy/nginx-proxy            Automated Nginx reverse proxy for docker con…   33                   
staticfloat/nginx-certbot         Opinionated setup for automatic TLS certs lo…   25                   [OK]
nginx/nginx-prometheus-exporter   NGINX Prometheus Exporter for NGINX and NGIN22                   
schmunk42/nginx-redirect          A very simple container to redirect HTTP tra…   19                   [OK]
centos/nginx-112-centos7          Platform for running nginx 1.12 or building …   16                   
centos/nginx-18-centos7           Platform for running nginx 1.8 or building n…   13                   
bitwarden/nginx                   The Bitwarden nginx web server acting as a r…   12                   
flashspys/nginx-static            Super Lightweight Nginx Image                   11                   [OK]
mailu/nginx                       Mailu nginx frontend                            10                   [OK]
sophos/nginx-vts-exporter         Simple server that scrapes Nginx vts stats a…   7                    [OK]
ansibleplaybookbundle/nginx-apb   An APB to deploy NGINX                          3                    [OK]
wodby/nginx                       Generic nginx                                   1                    [OK]
arnau/nginx-gate                  Docker image with Nginx with Lua enabled on …   1                    [OK]
[root@localhost ~]#

#3、pull nginx镜像
[root@localhost ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pull complete 
a9edb18cadd1: Pull complete 
589b7251471a: Pull complete 
186b1aaa4aa6: Pull complete 
b4df32aa5a72: Pull complete 
a0bcbecc962e: Pull complete 
Digest: sha256:0d17b565c37bcbd895e9d92315a05c1c3c9a29f762b011a10c54a66cd53c9b31
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
nginx         latest    605c77e624dd   9 days ago     141MB
mysql         latest    3218b38490ce   2 weeks ago    516MB
hello-world   latest    feb5d9fea6a5   3 months ago   13.3kB
centos        latest    5d0da3dc9764   3 months ago   231MB
#5、运行ngnix
#-d后台运行
#--name 给容器命名
#宿主机端口:容器内部端口
[root@localhost ~]# docker run -d --name nginx01 -p 8080:80 nginx
add0a85b143131d46267fcdb953f0c6e7a2b0da0cb74b1a08f13d58a5d7ae7d8
[root@localhost ~]# curl localhost:8080
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
[root@localhost ~]# 

#进入容器内部

[root@localhost /]# docker exec -it add0a85b1431 /bin/bash
root@add0a85b1431:/# ls
bin  boot  dev	docker-entrypoint.d  docker-entrypoint.sh  etc	home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

#查看容器文件位置
root@add0a85b1431:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@add0a85b1431:/# cd etc/nginx/
root@add0a85b1431:/etc/nginx# ls
conf.d	fastcgi_params	mime.types  modules  nginx.conf  scgi_params  uwsgi_params
root@add0a85b1431:/etc/nginx# 

端口暴露的地址
在这里插入图片描述每次修改nginx配置文件,都需要进入容器内部?十分的麻烦,要是可以在容器外部提供一个映射的路径,达到容器修改文件名,容器内部就可以自动修改?-v数据卷

# 再次pull ngin发现没有存储空间
[root@localhost ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a2abf6c4d29d: Pulling fs layer 
a9edb18cadd1: Pulling fs layer 
589b7251471a: Pulling fs layer 
186b1aaa4aa6: Pulling fs layer 
b4df32aa5a72: Pulling fs layer 
a0bcbecc962e: Pulling fs layer 
latest: Pulling from library/nginx
a2abf6c4d29d: Pulling fs layer 
a9edb18cadd1: Pulling fs layer 
589b7251471a: Pulling fs layer 
186b1aaa4aa6: Pulling fs layer 
b4df32aa5a72: Pulling fs layer 
a0bcbecc962e: Pulling fs layer 
open /var/lib/docker/tmp/GetImageBlob876263017: no space left on device
#这个时候可以用df -hl,查看目录存储情况
#可以看到/dev/mapper/centos-root 存储空间100%,,是因为之前测试centos,跑了一个while死循环,导致日志占满

[root@localhost ~]# df -hl
文件系统                 容量  已用  可用 已用% 挂载点
devtmpfs                 475M     0  475M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M   51M  436M   11% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   17G   17G   20K  100% /
/dev/sda1               1014M  138M  877M   14% /boot
tmpfs                     98M     0   98M    0% /run/user/0

#3、找到docke的日志文件路径,清除日志,一般docker默认安装路径是/var/lib/docker/containers

[root@localhost /]# cd /var/lib/docker/containers
[root@localhost containers]# ls
clean_containers_logs.sh  e0f4bc7d37e77bb5803cfa994ec73f361be0a8cee6a8a3291a4a022eb56f366e
[root@localhost containers]# cd e0f4bc7d37e77bb5803cfa994ec73f361be0a8cee6a8a3291a4a022eb56f366e
[root@localhost e0f4bc7d37e77bb5803cfa994ec73f361be0a8cee6a8a3291a4a022eb56f366e]# ls
checkpoints     e0f4bc7d37e77bb5803cfa994ec73f361be0a8cee6a8a3291a4a022eb56f366e-json.log  hostname  mounts       resolv.conf.hash
config.v2.json  hostconfig.json                                                            hosts     resolv.conf
[root@localhost e0f4bc7d37e77bb5803cfa994ec73f361be0a8cee6a8a3291a4a022eb56f366e]# rm -rf e0f4bc7d37e77bb5803cfa994ec73f361be0a8cee6a8a3291a4a022eb56f366e-json.log

#日志占满硬盘是很常见的情况,所以想新建一个文件来进行快速清理
#这时发现没有执行文件的权限
[root@localhost containers]# touch clean_containers_logs.sh
[root@localhost containers]# vi clean_containers_logs.sh

echo "======== start clean docker containers logs ========"

logs=$(find /var/lib/docker/containers/*/*-json.log)

for log in $logs
        do
                echo "clean logs : $log"
                cat /dev/null > $log
        done

echo "======== end clean docker containers logs ========"

#执行文件
[root@localhost containers]# ./clean_containers_logs.sh
-bash: ./clean_containers_logs.sh: 权限不够
#于是设置文件权限
[root@localhost containers]# chmod 700 //var/lib/docker/containers/clean_containers_logs.sh
[root@localhost containers]# ls
2a153a15ffa25e5b85acab283fa02b7888565bb3336fc803354cd3a951465e4c  e0f4bc7d37e77bb5803cfa994ec73f361be0a8cee6a8a3291a4a022eb56f366e
clean_containers_logs.sh
#执行清初日志文件
root@localhost containers]# ./clean_containers_logs.sh 
======== start clean docker containers logs ========
clean logs : /var/lib/docker/containers/2a153a15ffa25e5b85acab283fa02b7888565bb3336fc803354cd3a951465e4c/2a153a15ffa25e5b85acab283fa02b7888565bb3336fc803354cd3a951465e4c-json.log
======== end clean docker containers logs ========

2、tomcat 安装

#搜索tomcat镜像
[root@localhost ~]# docker search tomcat
NAME                          DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
tomcat                        Apache Tomcat is an open source implementati…   3212      [OK]       
tomee                         Apache TomEE is an all-Apache Java EE certif…   95        [OK]       
dordoka/tomcat                Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 base…   57                   [OK]
kubeguide/tomcat-app          Tomcat image for Chapter 1                      32                   
consol/tomcat-7.0             Tomcat 7.0.57, 8080, "admin/admin"              18                   [OK]
cloudesire/tomcat             Tomcat server, 6/7/8                            15                   [OK]
aallam/tomcat-mysql           Debian, Oracle JDK, Tomcat & MySQL              13                   [OK]
arm32v7/tomcat                Apache Tomcat is an open source implementati…   11                   
andreptb/tomcat               Debian Jessie based image with Apache Tomcat…   10                   [OK]
arm64v8/tomcat                Apache Tomcat is an open source implementati…   7                    
rightctrl/tomcat              CentOS , Oracle Java, tomcat application ssl…   7                    [OK]
unidata/tomcat-docker         Security-hardened Tomcat Docker container.      5                    [OK]
amd64/tomcat                  Apache Tomcat is an open source implementati…   3                    
jelastic/tomcat               An image of the Tomcat Java application serv…   3                    
oobsri/tomcat8                Testing CI Jobs with different names.           2                    
cfje/tomcat-resource          Tomcat Concourse Resource                       2                    
fabric8/tomcat-8              Fabric8 Tomcat 8 Image                          2                    [OK]
ppc64le/tomcat                Apache Tomcat is an open source implementati…   1                    
picoded/tomcat7               tomcat7 with jre8 and MANAGER_USER / MANAGER1                    [OK]
camptocamp/tomcat-logback     Docker image for tomcat with logback integra…   1                    [OK]
99taxis/tomcat7               Tomcat7                                         1                    [OK]
chenyufeng/tomcat-centos      tomcat基于centos6的镜像                              1                    [OK]
secoresearch/tomcat-varnish   Tomcat and Varnish 5.0                          0                    [OK]
softwareplant/tomcat          Tomcat images for jira-cloud testing            0                    [OK]
s390x/tomcat                  Apache Tomcat is an open source implementati…   0                    
#拉取tomcat镜像
[root@localhost ~]# docker pull tomcat
Using default tag: latest
latest: Pulling from library/tomcat
0e29546d541c: Pull complete 
9b829c73b52b: Pull complete 
cb5b7ae36172: Pull complete 
6494e4811622: Pull complete 
668f6fcc5fa5: Pull complete 
dc120c3e0290: Pull complete 
8f7c0eebb7b1: Pull complete 
77b694f83996: Pull complete 
0f611256ec3a: Pull complete 
4f25def12f23: Pull complete 
Digest: sha256:9dee185c3b161cdfede1f5e35e8b56ebc9de88ed3a79526939701f3537a52324
Status: Downloaded newer image for tomcat:latest
docker.io/library/tomcat:latest
#查看镜像
[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
nginx         latest    605c77e624dd   9 days ago     141MB
tomcat        latest    fb5657adc892   2 weeks ago    680MB
mysql         latest    3218b38490ce   2 weeks ago    516MB
hello-world   latest    feb5d9fea6a5   3 months ago   13.3kB
centos        latest    5d0da3dc9764   3 months ago   231MB

#启动运行
[root@localhost ~]# docker run -d -p 3355:8080 --name tomcat01 tomcat
005d746f224fec5771463ad9d844ab56211d2d75903d20fc9ac1e3e5d79773f9

#进入容器
[root@localhost ~]# docker exec -it tomcat01 /bin/bash                                          
root@005d746f224f:/usr/local/tomcat# ls
BUILDING.txt  CONTRIBUTING.md  LICENSE	NOTICE	README.md  RELEASE-NOTES  RUNNING.txt  bin  conf  lib  logs  native-jni-lib  temp  webapps  webapps.dist  work

#拷贝文件,项目部署文件webapps为空
root@005d746f224f:/usr/local/tomcat# cp -r webapps.dist/* webapps
root@005d746f224f:/usr/local/tomcat# ls
BUILDING.txt  CONTRIBUTING.md  LICENSE	NOTICE	README.md  RELEASE-NOTES  RUNNING.txt  bin  conf  lib  logs  native-jni-lib  temp  webapps  webapps.dist  work
root@005d746f224f:/usr/local/tomcat# cd webapps
root@005d746f224f:/usr/local/tomcat/webapps# ls
ROOT  docs  examples  host-manager  manager


#发现问题:1、linux命令少了。2、没有webapps,阿里云镜像的原因。默认是最小的镜像,所以不必要的都剔除掉了。
#保证最小可运行的环境!

测试截图
在这里插入图片描述我们以后要部署项目,如果每次都要进入容器十分麻烦?我要是可以在容器外部提供一个映射路径,webapps,我们放在外部放置项目,就自动同步到内部就好!

tomcat 启动报错问题排查

[root@localhost ~]# docker run -d -p 3355:8080 --name tomcat01 tomcat
e2219c7e35f6564a11751d26fd8501ac06f854576098652e90b1a226edb24f03
docker: Error response from daemon: driver failed programming external connectivity on endpoint tomcat01 (a7b010ef4b4087f6c3df83d6ff84f9aff3fcab230b71e1424fc9e66e0ef3396b):  (iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 3355 -j DNAT --to-destination 172.17.0.3:8080 ! -i docker0: iptables: No chain/target/match by that name.
 (exit status 1)).

#重启动docker容器
 
[root@localhost ~]# service docker restart
Redirecting to /bin/systemctl restart docker.service
[root@localhost ~]# docker run -d -p 3355:8080 --name tomcat01 tomcat
005d746f224fec5771463ad9d844ab56211d2d75903d20fc9ac1e3e5d79773f9

3、部署es+kibana

#es暴露 端口很多
#es 十分的耗内存
#es的数据一般需要放置到安全目录挂载!
#--net somenetwork 网络配置
#启动 elasticsearch
 docker run -d --name elasticsearch  -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.6.2

#启动Linux就卡住,docker 	stats 查看cpu的状态

# docker stats查看cpu

#测试es
{
  "name" : "e42bfa9c45ad",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "2H_QeMbSSLKKi4_Peo7-eA",
  "version" : {
    "number" : "7.6.2",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
    "build_date" : "2020-03-26T06:34:37.794943Z",
    "build_snapshot" : false,
    "lucene_version" : "8.4.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

#停止es。增加内存限制

在这里插入图片描述

#增加内存的限制,修改配置文件。-e环境变量配置
 docker run -d --name elasticsearch  -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx512m" elasticsearch:7.6.2

在这里插入图片描述网络如何连接
在这里插入图片描述

4、可视化

  • portainer

说明是portainer?

docker图形化界面管理工具!提供一个后台的面板供我们操作!

docker run -d -p 9000:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer

访问测试
登陆
在这里插入图片描述选择仓库
在这里插入图片描述进入面板之后的页面
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是在Docker安装Elasticsearch和Kibana的步骤: 1. 安装DockerDocker Compose 2. 创建一个文件夹并在其中创建一个名为docker-compose.yml的文件 3. 在docker-compose.yml文件中添加以下内容: ``` version: '3' services: es01: image: docker.elastic.co/elasticsearch/elasticsearch:7.15.1 container_name: es01 environment: - node.name=es01 - discovery.seed_hosts=es02 - cluster.initial_master_nodes=es01,es02 - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" ulimits: memlock: soft: -1 hard: -1 volumes: - esdata01:/usr/share/elasticsearch/data ports: - 9200:9200 networks: - esnet es02: image: docker.elastic.co/elasticsearch/elasticsearch:7.15.1 container_name: es02 environment: - node.name=es02 - discovery.seed_hosts=es01 - cluster.initial_master_nodes=es01,es02 - bootstrap.memory_lock=true - "ES_JAVA_OPTS=-Xms512m -Xmx512m" ulimits: memlock: soft: -1 hard: -1 volumes: - esdata02:/usr/share/elasticsearch/data networks: - esnet kibana: image: docker.elastic.co/kibana/kibana:7.15.1 container_name: kibana environment: ELASTICSEARCH_URL: http://es01:9200 ports: - 5601:5601 networks: - esnet volumes: esdata01: driver: local esdata02: driver: local networks: esnet: ``` 4. 保存并关闭文件 5. 在终端中导航到该文件夹并运行以下命令: ``` docker-compose up -d ``` 6. 等待一段时间,直到所有容器都启动并运行 7. 打开浏览器并输入以下地址来访问Kibana: ``` http://localhost:5601 ``` 8. 你现在可以开始使用Elasticsearch和Kibana进行数据分析和可视化了。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值