Docker 监控: google/cadvisor 集成grafana
Docker自带了容器监控功能,可以对容器进行相关的性能监控,指标查看;主要包括:
集群 Grafana 监控页面:http://localhost:3000 默认用户名和密码均为 admin
[root@jason ~]# ~/Docker$ docker run -d --name grafana -p 3000:3000 grafana/grafana
[root@jason ~]# ~/Docker$ docker run --volume=/:rootfs:ro --volume=/var/run:/var/run:ro\
--volume=/sys:/sys:ro --volume=/var/lib/docker/:/var/lib/docker:ro\
--volume=/dev/disk/:/dev/disk:ro --volume=/cgroup:/cgroup:ro \
--publish=8080:8080 --detach=true --privileged=true --name=cadvisor \
google/cadvisor:latest\
-storage_driver=influxdb-storage_driver_host=influxdb:8086\
-storage_driver_db=test-storage_driver_user=root\
-storage_driver_password=root
Docker构建管理容器 portainer
( Portainer 是一款轻量级的应用,它提供了图形化界面,用于方便的管理Docker环境,包括单机环境和集群环境 )
[root@jason ~]# ~/Docker$ docker run -p 9001:9000 -p 8000:8000 --name portainer \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /Users/jason/Docker/data/portainer/data:/data \
-d portainer/portainer
7069d309250cff4fd1c131d9086cf380fed1d9f2cc3529a1a55f738cad65cfe6
Docker 构建Consul是一个服务网格
(微服务间的 TCP/IP,负责服务之间的网络调用、限流、熔断和监控)解决方案,它是一个一个分布式的,高度可用的系统,而且开发使用都很简便。它提供了一个功能齐全的控制平面,主要特点是:服务发现、健康检查、键值存储、安全服务通信、多数据中心
[root@jason ~]# ~/Docker$ docker run -d -p 8500:8500 --net=host --restart=always --name=consul -v "/Users/jason/Docker/consul/data:/consul/data" consul agent -server -ui -client=0.0.0.0 -bootstrap-expect=1
c8e05635d084548d14e62c1bbd1a0a4941800dd26efa1c23fc980726a5b1d9c4
Docker构建InfluxDB:
第一种:(包含UI界面
[root@jason ~]# ~/Docker$ docker run -d --name influxdb -p 8086:8086 -p 8083:8083 tutum/influxdb
0da016f3323c7d5eef37f0836d3adbee494dca9bcca109b9342142a2da68e30a
第二种:shell
[root@jason ~]# ~/Docker$ docker pull influxdb
[root@jason ~]# ~/Docker$ docker run -d -p 8083:8083 -p8086:8086 --expose 8090 --expose 8099 --name influxdb influxdb
/Users/jason/Docker docker exec -it dc5dc47f82e5 /bin/sh
# ls
bin dev etc init-influxdb.sh lib64 mnt proc run srv tmp var
boot entrypoint.sh home lib
root@dc5dc47f82e5:/# sh init-influxdb.sh
root@dc5dc47f82e5:/# influx
Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9
> create user "admin" with password 'admin' with all privileges
> create database demo
> use demo
Using database demo
> show retention policies on "demo"
name duration shardGroupDuration replicaN default
---- -------- ------------------ -------- -------
autogen 0s 168h0m0s 1 true
Docker 构建Kong网关
1.首先创建kong-net容器网络,默认设置为bridge
docker network create kong-net
2.先创建 网关对应的数据库: kong-database
$ docker run -d --name kong-database -p 5432:5432 -e "POSTGRES_USER=kong" -e "POSTGRES_DB=kong" -e "POSTGRES_PASSWORD=kong" postgres:9.6
3 连接到数据库,并设置Kong数据库默认配置;bootstrap
$ docker run --rm --link kong-database:kong-database -e "KONG_DATABASE=postgres" -e "KONG_PG_HOST=kong-database" -e "KONG_PG_PASSWORD=kong" -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" kong:latest kong migrations bootstrap
4 启动Kong网关端口 8000;8443 ; 8001;84444
$ docker run -d --name kong \
--link kong-database:kong-database \
-e "KONG_DATABASE=postgres" \
-e "KONG_PG_HOST=kong-database" \
-e "KONG_PG_USER=kong" \
-e "KONG_PG_PASSWORD=kong" \
-e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
-e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
-e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
-e "KONG_ADMIN_LISTEN=0.0.0.0:8001, 0.0.0.0:8444 ssl" \
-p 8000:8000 \
-p 8443:8443 \
-p 8001:8001 \
-p 8444:8444 \
kong
[root@jason ~]# ~/Docker$ docker run -d --name kong-database \
--network=kong-net \
-p 5432:5432 \
-e "POSTGRES_USER=kong" \
-e "POSTGRES_DB=kong” \
-e “POSTGRES_PASSWORD=kong” \
postgres:latest
Docker构建postgresql图形化
[root@jason ~]# ~/Docker$ docker run -p 8009:80 \
-e 'PGADMIN_DEFAULT_EMAIL=kong' \
-e 'PGADMIN_DEFAULT_PASSWORD=kong' \
-d dpage/pgadmin4
4c18c46284a28b6c1db748438b968aad80ad2e91efa1b024771dd51fcf0de63b
Docker 构建 Solr搜索:
[root@jason ~]# ~/Docker$ docker run --name solr_server -d -p 8983:8983 -t solr
15ecb0d35659006979b115183cfbe576c005ac279788c64c769b25e9141a4645
Zookeeper+Kafa分布式(单个Docker镜像构建
[root@jason ~]# ~/Docker$ docker run -d --name zookeeper -p 2181:2181 -t wurstmeister/zookeeper
8b6cbc408bfb5ccb502f09cc7897d576e8c5b7a87bf36c02a4f413d7d80686e1
节点1:
$ docker run -d --name kafka -p 9092:9092 -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=10.4.4.74:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://10.4.4.74:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -t wurstmeister/kafka
节点2:
$ docker run -d --name kafka1 -p 9093:9093 -e KAFKA_BROKER_ID=1 -e KAFKA_ZOOKEEPER_CONNECT=10.4.4.74:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://10.4.4.74:9093 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9093 -t wurstmeister/kafka
节点3:
$ docker run -d --name kafka2 -p 9094:9094 -e KAFKA_BROKER_ID=2 -e KAFKA_ZOOKEEPER_CONNECT=10.4.4.175:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://10.4.4.175:9094 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9094 -t wurstmeister/kafka
[root@jason ~]# ~/Docker$ docker exec -it kafka /bin/bash
bash-4.4# ls
bin dev etc home kafka lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
bash-4.4# ls opt/
kafka kafka_2.12-2.2.0 overrides
bash-4.4#cd /opt/kafka_2.12-2.2.0/
LICENSE NOTICE bin config libs logs site-docs
bash-4.4# bin/kafka-topics.sh --create --zookeeper 10.4.4.175:2181 --replication-factor 2 --partitions 2 --topic partopic
Created topic partopic.
bash-4.4# bin/kafka-topics.sh --create --zookeeper 10.4.4.175:2181 --replication-factor 1 --partitions 2 --topic customtopic
Created topic customtopic.
bash-4.4# bin/kafka-topics.sh --describe --zookeeper 10.4.4.175:2181 --topic partopic
bash-4.4# exit
[root@jason ~]# ~/Docker$ docker run -itd --restart=always --name=kafka-manager -p 9000:9000 -e ZK_HOSTS="10.4.4.74:2181" sheepkiller/kafka-manager
c7e5d8be4057ce7ca08719859733d027a5b22b3c5fa86ba8920fdeee517930d8
查看刚创建的主题:/opt/kafka/bin/kafka-topics.sh --list --zookeeper 10.4.4.175:2181
发送消息:/opt/kafka/bin/kafka-console-producer.sh --broker-list 10.4.4.175:9092 --topic partopic
This is a message
This is another message
读取消息:/opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server 10.4.4.175:9092 --topic partopic --from-beginning
docker-compose构建Zookeeper+Kafa分布式
[root@jason ~]# ~/Docker$ git clone https://github.com/wurstmeister/kafka-docker.git
正克隆到 'kafka-docker'...
remote: Enumerating objects: 975, done.
remote: Total 975 (delta 0), reused 0 (delta 0), pack-reused 975
接收对象中: 100% (975/975), 251.32 KiB | 382.00 KiB/s, 完成.
处理 delta 中: 100% (527/527), 完成.
[root@jason ~]# ~/Docker$ ~/Docker/kafka-docker ls
CHANGELOG.md docker-compose-single-broker.yml start-kafka-shell.sh
Dockerfile docker-compose-swarm.yml start-kafka.sh
LICENSE docker-compose.yml test
README.md docker_push versions.sh
broker-list.sh download-kafka.sh
create-topics.sh overrides
[root@jason ~]# ~/Docker/kafka-docker vim docker-compose.yml (修改127.0.0.1
[root@jason ~]# ~/Docker/kafka-docker docker-compose up -d
Creating network "kafka-docker_default" with the default driver
Pulling zookeeper (wurstmeister/zookeeper:)...
latest: Pulling from wurstmeister/zookeeper
76eea4448d9b: Pull complete
Building kafka
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar
WARNING: Image for service kafka was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating kafka-docker_zookeeper_1 ... done
Creating kafka-docker_kafka_1 ... done
[root@jason ~]# ~/Docker$ docker-compose scale kafka=3
WARNING: The scale command is deprecated. Use the up command with the --scale flag instead.
Starting kafka-docker_kafka_1 ... done
Creating kafka-docker_kafka_2 ... done
Creating kafka-docker_kafka_3 ... done
[root@jason ~]# ~/Docker/kafka-docker docker-compose ps
Name Command State Ports
----------------------------------------------------------------
kafka-docker_kafka_1 start-kafka.sh Up 0.0.0.0:32768->9092/tcp
kafka-docker_kafka_2 start-kafka.sh Up 0.0.0.0:32769->9092/tcp
kafka-docker_kafka_3 start-kafka.sh Up 0.0.0.0:32770->9092/tcp
kafka-docker_zookeeper_1 /bin/sh -c /usr/sbin/sshd ... Up 0.0.0.0:2181->2181/tcp, 22/tcp, 2888/tcp, 3888/tcp
Docker 构建Tomcat 服务器
[root@jason ~]# ~/Docker$ docker run --name tomcat -p 8088:8080 -v /usr/local/tomcat/webapps/:/usr/local/tomcat/webapps/ -d tomcat
c303a5e2ba18d71d4728b9e68cecff087d885dfc7f02198cc35a3fcd620c5162
Docker构建 RabbitMQ (包含UI
[root@jason ~]# ~/Docker$ docker pull rabbitmq:management
management: Pulling from library/rabbitmq
898c46f3b1a1: Already exists
Digest: sha256:a4fcfc7cf432899ffb0f70870460e51587efd4b94f3a1a7bc764c2cd177d99da
Status: Downloaded newer image for rabbitmq:management
[root@jason ~]# ~/Docker$ docker run -d --name rabbitmq --publish 5671:5671 --publish 5672:5672 --publish 4369:4369 --publish 25672:25672 --publish 15671:15671 --publish 15672:15672 rabbitmq:management
71679c464b3b36bfaf8b06af07aab90f2ca98435afe6ecdcb8005f9eb76f687e
Docker 构建MongoDB
[root@jason ~]# ~/Docker$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mongo latest 58477a771fb4 5 days ago 361MB
[root@jason ~]# ~/Docker$ docker run -d -p 27017:27017 -v /Users/limingsheng/mongodb/data:/data --name mongodb mongo
e2b5b37a35cc230c8d225e40839d39880e8165d9bb6a441a939d3565956e2310
Docker构建redis
[root@jason ~]# ~/Docker
$ docker run -d -p 6379:6379 --name redis redis
c663e734d52969ec849c1557e3af5ed3ee27542eb36c27b0fdd56cd87f230fe4