ElasticSearch部署
ElasticSearch是我们常用的搜索引擎,es暴露端口较多且占用内存较高
1 搜索并下载镜像
先搜索并下载elasticsearch的镜像
[root@192 ~]# docker search elasticsearch NAME DESCRIPTION STARS OFFICIAL AUTOMATED elastichq/elasticsearch-hq Official Docker image for ElasticHQ: Elastic… 78 [OK] bitnami/elasticsearch Bitnami Docker Image for Elasticsearch 47 [OK] justwatch/elasticsearch_exporter Elasticsearch stats exporter for Prometheus 17 bitnami/elasticsearch-exporter Bitnami Elasticsearch Exporter Docker Image 4 [OK] barchart/elasticsearch-aws Elasticsearch AWS node 3 rancher/elasticsearch-conf 3 bitnami/elasticsearch-curator 2 ibmcom/elasticsearch Docker Image for IBM Cloud private-CE (Commu… 1 ibmcom/elasticsearch-ppc64le Docker Image for IBM Cloud Private-CE (Commu… 1 rancher/elasticsearch-bootstrap 1 ibmcom/elasticsearch-s390x 1 atlassian/dynamodb-elasticsearch-indexer An indexer for indexing DynamoDB tables in E… 1 ibmcom/elasticsearch-amd64 0 ibmcom/elasticsearch-exporter-amd64 0 ibmcom/elasticsearch-plugin-searchguard-amd64 0 ibmcom/elasticsearch-exporter-ppc64le 0 ibmcom/elasticsearch-plugin-searchguard-s390x 0 ibmcom/elasticsearch-exporter-s390x 0 ibmcom/elasticsearch-plugin-searchguard-ppc64le 0 ibmcom/elasticsearch-dump 0 rancher/elasticsearch 0 amazon/opendistro-for-elasticsearch-data-prepper The Docker image for the Open Distribution f… 0 ibmcom/elasticsearch-exporter 0 ibmcom/elasticsearch-plugin-searchguard 0 kibana Kibana gives shape to any kind of data — str… 0 [OK] [root@192 ~]# docker pull elasticsearch Using default tag: latest latest: Pulling from library/elasticsearch 05d1a5232b46: Pull complete 5cee356eda6b: Pull complete 89d3385f0fd3: Pull complete 65dd87f6620b: Pull complete 78a183a01190: Pull complete 1a4499c85f97: Pull complete 2c9d39b4bfc1: Pull complete 1b1cec2222c9: Pull complete 59ff4ce9df68: Pull complete 1976bc3ee432: Pull complete 5af49e8af381: Pull complete 42c8b75ff7af: Pull complete 7e6902915254: Pull complete 99853874fa54: Pull complete 596fbad6fcff: Pull complete Digest: sha256:a8081d995ef3443dc6d077093172a5931e02cdb8ffddbf05c67e01d348a9770e Status: Downloaded newer image for elasticsearch:latest docker.io/library/elasticsearch:latest [root@192 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 605c77e624dd 7 weeks ago 141MB tomcat latest fb5657adc892 8 weeks ago 680MB mysql latest 3218b38490ce 2 months ago 516MB hello-world latest feb5d9fea6a5 4 months ago 13.3kB centos latest 5d0da3dc9764 5 months ago 231MB elasticsearch latest 5acf0e8da90b 3 years ago 486MB [root@192 ~]#
添加 -e ES_JAVA_OPTS="-Xms128m -Xmx512m"
配置ElasticSearch的虚拟机占用的内存大小
2 运行测试
给es设定最大内存进行启动
[root@192 ~]# docker run -d --name elasticsearch-tml -p 3392:9200 -p 3393:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms128m -Xmx512m" elasticsearch bd6877cd46cebf68c2f9b0571dafde1da474c159b28939d9a24faabe21a86802 [root@192 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES bd6877cd46ce elasticsearch "/docker-entrypoint.…" 13 seconds ago Up 12 seconds 0.0.0.0:3392->9200/tcp, :::3392->9200/tcp, 0.0.0.0:3393->9300/tcp, :::3393->9300/tcp elasticsearch-tml 2f59536a92da tomcat "catalina.sh run" 2 hours ago Up 2 hours 0.0.0.0:3335->8080/tcp, :::3335->8080/tcp tomcat-tml b8ae778bad8c nginx "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:3334->80/tcp, :::3334->80/tcp nginx-tml 4ed9be7f96c8 centos "/bin/bash" 2 weeks ago Up 2 weeks inspiring_rhodes cc886973b2cb centos "/bin/sh -c 'while t…" 2 weeks ago Up 2 weeks
通过命令stats查看内存使用情况:
[root@192 ~]# docker stats bd6877cd46ce CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS bd6877cd46ce elasticsearch-tml 0.02% 184.2MiB / 972.4MiB 18.94% 656B / 0B 941MB / 537kB 31 CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS bd6877cd46ce elasticsearch-tml 0.02% 184.2MiB / 972.4MiB 18.94% 656B / 0B 941MB / 537kB 31 CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS bd6877cd46ce elasticsearch-tml 0.80% 184.7MiB / 972.4MiB 18.99% 656B / 0B 948MB / 537kB 31 CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS bd6877cd46ce elasticsearch-tml 0.80% 184.7MiB / 972.4MiB 18.99% 656B / 0B 948MB / 537kB 31 CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
3 访问测试
我们进行访问测试看下效果:
[root@192 ~]# curl localhost:3392 { "name" : "xcQQz-u", "cluster_name" : "elasticsearch", "cluster_uuid" : "D5CjYDPoQvOzarlg-GY0nQ", "version" : { "number" : "5.6.12", "build_hash" : "cfe3d9f", "build_date" : "2018-09-10T20:12:43.732Z", "build_snapshot" : false, "lucene_version" : "6.6.1" }, "tagline" : "You Know, for Search" } [root@192 ~]#
公网访问效果如下:
当然也可以部署新版本es并访问,很简单:
[root@192 ~]# docker run -d --name elasticsearch-tml-7.6.2 -p 3396:9200 -p 3397:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms128m -Xmx512m" elasticsearch:7.6.2 Unable to find image 'elasticsearch:7.6.2' locally 7.6.2: Pulling from library/elasticsearch ab5ef0e58194: Pull complete c4d1ca5c8a25: Pull complete 941a3cc8e7b8: Pull complete 43ec483d9618: Pull complete c486fd200684: Pull complete 1b960df074b2: Pull complete 1719d48d6823: Pull complete Digest: sha256:1b09dbd93085a1e7bca34830e77d2981521a7210e11f11eda997add1c12711fa Status: Downloaded newer image for elasticsearch:7.6.2 3b66fa35905f90af7d8ddfb37b457f31d9045a9ffebc2f1c9e99c7d0374bae01 [root@192 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3b66fa35905f elasticsearch:7.6.2 "/usr/local/bin/dock…" 14 seconds ago Up 8 seconds 0.0.0.0:3396->9200/tcp, :::3396->9200/tcp, 0.0.0.0:3397->9300/tcp, :::3397->9300/tcp elasticsearch-tml-7.6.2 bd6877cd46ce elasticsearch "/docker-entrypoint.…" 7 minutes ago Up 7 minutes 0.0.0.0:3392->9200/tcp, :::3392->9200/tcp, 0.0.0.0:3393->9300/tcp, :::3393->9300/tcp elasticsearch-tml 2f59536a92da tomcat "catalina.sh run" 2 hours ago Up 2 hours 0.0.0.0:3335->8080/tcp, :::3335->8080/tcp tomcat-tml b8ae778bad8c nginx "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:3334->80/tcp, :::3334->80/tcp nginx-tml 4ed9be7f96c8 centos "/bin/bash" 2 weeks ago Up 2 weeks inspiring_rhodes cc886973b2cb centos "/bin/sh -c 'while t…" 2 weeks ago Up 2 weeks suspicious_borg [root@192 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 605c77e624dd 7 weeks ago 141MB tomcat latest fb5657adc892 8 weeks ago 680MB mysql latest 3218b38490ce 2 months ago 516MB hello-world latest feb5d9fea6a5 4 months ago 13.3kB centos latest 5d0da3dc9764 5 months ago 231MB elasticsearch 7.6.2 f29a1ee41030 23 months ago 791MB elasticsearch latest 5acf0e8da90b 3 years ago 486MB
公网访问如下:
MySQL部署
MySQL是我们的常用的数据库管理软件:
1 搜索并下载镜像
同样的搜索和下载镜像:
[root@192 ~]# docker search mysql NAME DESCRIPTION STARS OFFICIAL AUTOMATED mysql/mysql-server Optimized MySQL Server Docker images. Create… 905 [OK] centos/mysql-57-centos7 MySQL 5.7 SQL database server 92 mysql/mysql-cluster Experimental MySQL Cluster Docker images. Cr… 92 bitnami/mysql Bitnami MySQL Docker Image 65 [OK] circleci/mysql MySQL is a widely used, open-source relation… 24 ubuntu/mysql MySQL open source fast, stable, multi-thread… 23 mysql/mysql-router MySQL Router provides transparent routing be… 23 centos/mysql-56-centos7 MySQL 5.6 SQL database server 21 google/mysql MySQL server for Google Compute Engine 19 [OK] mysqlboy/mydumper mydumper for mysql logcial backups 3 mysqlboy/docker-mydumper docker-mydumper containerizes MySQL logical … 3 ibmcom/mysql-s390x Docker image for mysql-s390x 1 bitnami/mysqld-exporter 1 mysql MySQL is a widely used, open-source relation… 0 [OK] ibmcom/tidb-ppc64le TiDB is a distributed NewSQL database compat… 0 mirantis/mysql 0 mysql/mysql-operator MySQL Operator for Kubernetes 0 cimg/mysql 0 phpmyadmin phpMyAdmin - A web interface for MySQL and M… 0 [OK] mysqlboy/elasticsearch 0 mysqleatmydata/mysql-eatmydata 0 percona Percona Server is a fork of the MySQL relati… 0 [OK] mysqled25519/mysqled25519 0 mariadb MariaDB Server is a high performing open sou… 0 [OK] mysql/ndb-operator MySQL NDB Operator for Kubernetes 0 [root@192 ~]# docker pull mysql Using default tag: latest latest: Pulling from library/mysql Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709 Status: Image is up to date for mysql:latest docker.io/library/mysql:latest [root@192 ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 605c77e624dd 7 weeks ago 141MB tomcat latest fb5657adc892 8 weeks ago 680MB mysql latest 3218b38490ce 2 months ago 516MB hello-world latest feb5d9fea6a5 4 months ago 13.3kB centos latest 5d0da3dc9764 5 months ago 231MB elasticsearch 7.6.2 f29a1ee41030 23 months ago 791MB elasticsearch latest 5acf0e8da90b 3 years ago 486MB [root@192 ~]#
2 运行测试
运行启动mysql并设置账户密码:
[root@192 ~]# docker run -d --name mysql-tml -p 3366:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql b7842800b1cb46a7a79e01531d1e706fd4e54f8a6edadd07c8c32bd3abb41233 [root@192 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b7842800b1cb mysql "docker-entrypoint.s…" 4 seconds ago Up 3 seconds 33060/tcp, 0.0.0.0:3366->3306/tcp, :::3366->3306/tcp mysql-tml 3b66fa35905f elasticsearch:7.6.2 "/usr/local/bin/dock…" 6 minutes ago Up 6 minutes 0.0.0.0:3396->9200/tcp, :::3396->9200/tcp, 0.0.0.0:3397->9300/tcp, :::3397->9300/tcp elasticsearch-tml-7.6.2 bd6877cd46ce elasticsearch "/docker-entrypoint.…" 13 minutes ago Up 13 minutes 0.0.0.0:3392->9200/tcp, :::3392->9200/tcp, 0.0.0.0:3393->9300/tcp, :::3393->9300/tcp elasticsearch-tml 2f59536a92da tomcat "catalina.sh run" 2 hours ago Up 2 hours 0.0.0.0:3335->8080/tcp, :::3335->8080/tcp tomcat-tml b8ae778bad8c nginx "/docker-entrypoint.…" 2 hours ago Up 2 hours 0.0.0.0:3334->80/tcp, :::3334->80/tcp nginx-tml 4ed9be7f96c8 centos "/bin/bash" 2 weeks ago Up 2 weeks inspiring_rhodes cc886973b2cb centos "/bin/sh -c 'while t…" 2 weeks ago Up 2 weeks suspicious_borg [root@192 ~]#
运行命令说明:
-p 3306:3306 :映射容器服务的 3306 端口到宿主机的 3306 端口,外部主机可以直接通过 宿主机ip:3306 访问到 MySQL 的服务。 MYSQL_ROOT_PASSWORD=123456:设置 MySQL 服务 默认账号root 用户的密码。
3 访问测试
进入容器,并通过账号root查看MySQL服务能否正常连接
[root@192 ~]# docker exec -it b7842800b1cb /bin/bash root@b7842800b1cb:/# mysql -h localhost -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.27 MySQL Community Server - GPL Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
Portaniner工具安装
Portaniner是Docker的图形化管理工具,类似的工具还有Rancher(CI/CD再用),使用时下载运行Portaniner镜像并运行,设置本机映射端口为8088,一键拉取镜像并运行容器
[root@192 ~]# docker run -d -p 8088:9000 --restart=always -v /var/run/docker.sock:/var/run/docker.sock --privileged=true portainer/portainer Unable to find image 'portainer/portainer:latest' locally latest: Pulling from portainer/portainer 94cfa856b2b1: Pull complete 49d59ee0881a: Pull complete a2300fd28637: Pull complete Digest: sha256:fb45b43738646048a0a0cc74fcee2865b69efde857e710126084ee5de9be0f3f Status: Downloaded newer image for portainer/portainer:latest 78664208a245f44dd9cb9ea7c1fb8418431a7c36affb7e0dcfd110d21ce95196 [root@192 ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 78664208a245 portainer/portainer "/portainer" 13 seconds ago Up 12 seconds 0.0.0.0:8088->9000/tcp, :::8088->9000/tcp thirsty_gauss b7842800b1cb mysql "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 33060/tcp, 0.0.0.0:3366->3306/tcp, :::3366->3306/tcp mysql-tml 3b66fa35905f elasticsearch:7.6.2 "/usr/local/bin/dock…" 11 minutes ago Up 11 minutes 0.0.0.0:3396->9200/tcp, :::3396->9200/tcp, 0.0.0.0:3397->9300/tcp, :::3397->9300/tcp elasticsearch-tml-7.6.2 bd6877cd46ce elasticsearch "/docker-entrypoint.…" 18 minutes ago Up 18 minutes 0.0.0.0:3392->9200/tcp, :::3392->9200/tcp, 0.0.0.0:3393->9300/tcp, :::3393->9300/tcp elasticsearch-tml 2f59536a92da tomcat "catalina.sh run" 2 hours ago Up 2 hours 0.0.0.0:3335->8080/tcp, :::3335->8080/tcp tomcat-tml b8ae778bad8c nginx "/docker-entrypoint.…" 3 hours ago Up 3 hours 0.0.0.0:3334->80/tcp, :::3334->80/tcp nginx-tml 4ed9be7f96c8 centos "/bin/bash" 2 weeks ago Up 2 weeks inspiring_rhodes cc886973b2cb centos "/bin/sh -c 'while t…" 2 weeks ago Up 2 weeks suspicious_borg [root@192 ~]#
第一次登录设置admin用户的密码:
登录后选择本地连接:
进入就可以看到自己的镜像和容器了:
以及我们刚开启的容器服务:
总结一下
经过之前的命令学习,今天这篇Blog主要是拿几个容器练手来熟悉之前的docker命令、进行一些简单的请求测试,并且通过工具面板可视化的去管理容器。到此为止,学习到的Docker容器的应用概念还是停留在单个组件的功能实现上,大型的分布式服务集群其实是融合了多种中间件去实现的,这到底是如何实现的,容器如何联合起来提供服务,还是比较好奇?所以还是比较期待后续容器编排一些高级概念的学习。