Zipkin is a used for capturing timing data, it also has a centralized repository, and a microweb server that allows you to display, and search through spans and traces of your distributed programs or websites.

We can configure Zipkin by deploying it in a Docker container. Using this approach, we can match the latest version of Zipkin by just pulling down the latest images. You can Isolate the Docker service and dependencies to just the container(s), and chose where you want your data to persist. Most importantly, by using Docker, you can spend more time focused on data analysis, instead of spending time on configuring a Zipkin as a service.

The Target Scenario

Our main task is setting up a Zipkin server with MySQL, so that the spans/traces persist on the host file.

Zipkin Server Configuration

Install Package Dependencies

  1. Log into your Zipkin host machine and make sure your system is up to date:

     
    sudo dnf update && sudo dnf upgrade
  2. Add the Docker repository:

     
    sudo dnf install dnf-plugins-core
    sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
  3. Install Docker CE:

     
    sudo dnf install docker-ce
  4. Enable Docker as a service:

     
    sudo systemctl enable docker.service
    sudo systemctl start docker.service
  5. (Optional) Add your limited user account to the docker group, so that you can run Docker commands without using sudo:

     
    sudo usermod -aG docker username

    You can test your Docker installation by running docker run hello-world.

  6. Install Docker Compose:

     
    curl -LO https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m`
    sudo mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
    sudo chmod +x /usr/local/bin/docker-compose

    You can test the installation with docker-compose --version.

    Note

    The current stable version of Docker Compose is 1.16.1. Check for the latest version at the releases pageand update the version in the curl command accordingly.
  7. Install git:

     
    sudo dnf install git
  8. Use git to retrieve the Zipkin Docker-compose YAML files at openzipkin/docker-zipkin. This is one of the powerful features of Docker, these files hold all of the system level configurations we need, to run several different Zipkin configurations. Like, Zipkin with MySQL, Zipkin with elasticsearch, and Zipkin with Kakfa.

     
    cd ~
    git clone https://github.com/openzipkin/docker-zipkin.git
  9. Install MySQL:

     
    sudo dnf install mysql

Configure Docker

The Docker service will manage your containers, the container’s host, Zipkin services, and your MYSQL server.

Docker is in charge of starting and stopping these services automatically when the host system is rebooted. it’ll help us to map the ports from the container to the host’s ports and it’ll manage exporting the MySQL database files onto the host system. Docker can check to see if the container has failed, and restart it for us too. The host is in charge of running the actual Docker service and setting the firewall correctly.

Notice that the Zipkin container will expose port 9411 for its service, and the MySQL container will expose port 3306. We’ll use the Docker-compose YAML files to forward port 9411 to the host’s port 9411, so that the container will be accessible on the internet.

Zipkin Server Firewall Concepts

To avoid the server being compromised, limit the exposure of our Zipkin server to just our analyst and client machines.

The default Fedora 26 firewall rules block all ports as a safety precaution. Create a new firewall zone to handle the Zipkin services without exposing too much of the system:

Our goal is to set up the Zipkin Server for:

  • Thrift service: receiving data from clients
  • Web service: showing searches of time data
  • lock down access to only our web and analyst machines.

Zipkin Server Firewall

  1. Create a new zone in our firewall called zipkin

     
    sudo firewall-cmd --new-zone=zipkin --permanent
  2. Reload the firewall and refresh your zone list.

     
    sudo firewall-cmd --reload
  3. Add an analyst machine IP (If you forget to define any source IPs, you will have no filtering on your IPs. You need at least 1 source IP to start filtering on IPs. If there are no source IPs defined, any machine can connect to your server.)

     
    sudo firewall-cmd --zone=zipkin --add-source=203.0.113.0/32  --permanent
  4. Open a port through your firewall.

     
    sudo firewall-cmd --zone=zipkin --add-port=9411/tcp  --permanent
  5. (Optional) Since we may want to access our machine from the analyst machine, it may be a good idea to add an ssh port.

     
    sudo firewall-cmd --zone=zipkin --add-service=ssh --permanent
  6. Reload your firewall rules to activate them in your new zone.

     
    sudo firewall-cmd --reload
  7. View your new zone:

     
    sudo firewall-cmd --zone=zipkin --list-all

Docker-Compose Configuration

The docker-compose yml files will control which system configuration we can use. We’re going to select a MySQL configuration for storage.

  1. Copy the MySQL docker-compose YAML file to your home directory and rename it docker-init.yml as we’re going to need to make a few changes:

     
    cd ~
    cp docker-zipkin/docker-compose.yml docker-init.yml
  2. Open docker-init.yml in a text editor and edit the content as follows:

    ~/docker-init.yml
     1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
     
    version: '2'
    
    services:
    storage:
    image: openzipkin/zipkin-mysql
    container_name: mysql
    # Uncomment to expose the storage port for testing
    ports:
    - 3306:3306
    volumes:
    - dbfiles:/mysql/data
    restart: unless-stopped zipkin:
    image: openzipkin/zipkin
    container_name: zipkin
    # Environment settings are defined here https://github.com/openzipkin/zipkin/tree/1.19.0/zipkin-server#environment-variables
    environment:
    - STORAGE_TYPE=mysql
    # Point the zipkin at the storage backend
    - MYSQL_HOST=mysql
    # Uncomment to enable scribe
    # - SCRIBE_ENABLED=true
    # Uncomment to enable self-tracing
    # - SELF_TRACING_ENABLED=true
    # Uncomment to enable debug logging
    # - JAVA_OPTS=-Dlogging.level.zipkin=DEBUG
    ports:
    # Port used for the Zipkin UI and HTTP Api
    - 9411:9411
    depends_on:
    - storage
    restart: unless-stopped dependencies:
    image: openzipkin/zipkin-dependencies
    container_name: dependencies
    entrypoint: crond -f
    environment:
    - STORAGE_TYPE=mysql
    - MYSQL_HOST=mysql
    # Add the baked-in username and password for the zipkin-mysql image
    - MYSQL_USER=zipkin
    - MYSQL_PASS=zipkin
    # Uncomment to adjust memory used by the dependencies job
    - JAVA_OPTS=-verbose:gc -Xms512m -Xmx512m
    depends_on:
    - storage
    restart: unless-stopped volumes:
    dbfiles:
    • In the MySQL container section in the docker-init.yml, export the MySQL data directory, forward the MySQL port to the host, and add the restart command so that this service is automatically restarted if it goes down.

    • In the Zipkin container section in the docker-init.yml, make sure the port 9411 is forwarded to the host machine and add the restart command so that this service is automatically restarted if it goes down.

    • In the dependencies container, we uncomment the JAVA_OPTS and set it to at least 512M. This setting is optimized for a 1G Linode. However, if in the future this container needs more memory, you can increase this value. Add a restart command to the end of this section.

  3. You can now update your Zipkin Docker images by performing a docker pull command. This will check the web for the images we need (the first time), and all other times it’ll update the images to the latest version if need be.

     
    docker-compose -f docker-init.yml pull
  4. Run your Docker services by using the docker-compose up command. Conversely there is also a docker-compose down command that can be used to shutdown your Zipkin services.

     
    docker-compose -f docker-init.yml up -d

    Notice the -d flag at the end of the command, this detaches the container. Now it’s running as its own process. If we just left the machine, it would continue to run, even if we rebooted the machine, it would run when the Docker service started it, because we didn’t explicitly issue a docker-compose down command. Just for reference, to shutdown the Zipkin services:

     
    docker-compose -f docker-init.yml down

Backup Span/Trace Data

There are 2 different backup methods: using MySQL , and using sysadmin.

MySQL Backup

  1. Ensure that the MySQL service is running on a container. You can check this with a docker pscommand. The docker ps command displays the active containers:

    docker -ps
    1
    2
    3
    4
     
    CONTAINER ID        IMAGE                            COMMAND                  CREATED             STATUS              PORTS                              NAMES
    023d14e6193d openzipkin/zipkin-dependencies "crond -f" 3 days ago Up 3 days dependencies
    ee0c255b7765 openzipkin/zipkin "/bin/sh -c 'test ..." 3 days ago Up 3 days 9410/tcp, 0.0.0.0:9411->9411/tcp zipkin
    43f659b36f17 openzipkin/zipkin-mysql "/bin/sh -c /mysql..." 3 days ago Up 3 days 0.0.0.0:3306->3306/tcp mysql
  2. If isn’t running, make sure you start the Zipkin services with the docker-compose up command first. Then issue the MySQLdump with the following parameters from your Zipkin host machine.

     
     mysqldump --protocol=tcp -A -pzipkin -uzipkin > ~/database.bak

    This command will dump the entire MySQL database from your MySQL container into the file called database.bak in your home directory. Alternatively, you can just dump your Zipkin span/trace data with:

     
    mysqldump --protocol=tcp -pzipkin -uzipkin zipkin > ~/db_zipkin.bak

Database Backups

We can just zip or tar the exported database files on the host system. Since we don’t know if the container is writing information to these files at any given time, we need to make sure that the container is stopped.

  1. We can check the status with a docker ps command or just perform a docker down command.

     
    docker-compose -f docker-init.yml down

    After the docker down command, we can perform a docker ps command and see that there are no containers running. That should look like this:

     
    CONTAINER ID        IMAGE      COMMAND    CREATED      STATUS       PORTS         NAMES
  2. At this point, we can create a zip backup of your files. The db files will be prepended with the name of your user. If you are running as root it would be root_dbfiles, but running as root isn’t recommended.

    sudo zip -r ~/db_files.zip /var/lib/docker/volumes/_dbfiles/

  3. Remember to start your Zipkin services if they’re still needed. They will not restart even on a reboot because we have explicitly shut them down.

Testing the Zipkin Service

  1. Easiest way to do this is by using your web browser on your analyst machine. Log into your analyst machine, bring up your browser, and type in the following URL:

     
    http://192.0.2.0:9411/zipkin/

    If you see the Zipkin web page, you’re done.

  2. If you don’t see a web page, log into the Zipkin host machine, and make sure your containers are up by running either docker ps command or docker-compose up command. If the containers are not all running, it’s possible that your Linode has run out of memory.

  3. Make sure your firewall port is open by typing:

     
    sudo firewall-cmd --add-port 9411/tcp --permanent
  4. At this point, what might have happened is that we added the wrong IP address of our analyst machine. We can check this by logging into our analyst machine. If our analyst machine is a Fedora workstation, we can install nmap and perform a network port status check to our Zipkin host machine like so:

     
    sudo dnf install -y nmap
    nmap 192.0.2.0 -p 9411 -Pn

    A good return has an open for the STATE of the port, anything else and we probably don’t have the right analyst machine IP address in our firewall rules:

     
    Starting Nmap 7.40 (https://nmap.org) at 2017-09-24 18:34 MDT
    Nmap scan report for zipkin (192.0.2.0)
    Host is up (0.10s latency).
    PORT STATE SERVICE
    9411/tcp open unknown

    Review your firewall rules and try again.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

Zipkin Server Configuration Using Docker and MySQL[转]的更多相关文章

  1. docker nginx mysql

    docker run -p 9000:9000 --name myphp -v /docker/www/:/var/www/html/ -v /docker/php/php.ini:/usr/loca ...

  2. docker安装MySQL 8.0及初始化错误处理

      Preface          Several days ago,I've implement a docker environmnet,I'm gonna Install a MySQL 8. ...

  3. linux记录-docker配置mysql

    docker部署mysql 1.拉取镜像 docker pull mysql 2.docker  rm   containerID  删除镜像iD 3.创建镜像 docker run --name=m ...

  4. 阿里云服务器centos7,docker部署mysql+Redis+vue+springboot+Nginx+fastdfs,亲测可用

    一.购买云服务器 我是今年双十一期间在阿里云购买的服务器, 简单配置2核_4G_40G_3M,三年用了不到800块,不过当时我记得腾讯云更便宜,个人感觉,阿里的云服务器更加的稳定, 毕竟身经百战, 经 ...

  5. docker 部署mysql连接问题

    发现windows上有一个docker descktop(虽然不怎么好用), 安装之后准备直接用docker搭本地测试环境的基础设施(比如MySQL,Redis,MongoDB,ES啥的), 虽然比去 ...

  6. springboot多数据源配合docker部署mysql主从实现读写分离

    本篇主要有两部分: 1.使用docker部署mysql主从 实现主从复制 2.springboot项目多数据源配置,实现读写分离 一.使用docker部署mysql主从 实现主从复制 此次使用的是wi ...

  7. Docker 安装 MySQL、Redis

    1 Docker 中安装 Redis 1.1 创建目录 在硬盘上创建 redis 的数据目录: mkdir -p /Users/yygnb/dockerMe/redis/data 为该目录添加权限: ...

  8. Docker搭建MySQL服务

    Docker开源镜像 前面我们已经安装好了Docker,也简单了解了Docker.那么我们可以尝试搭建一个MySQL服务. 要搭建服务就要启动服务容器,要创建容易就要有镜像,Docker提供了一个类似 ...

  9. 使用Docker安装Mysql

    最近使用阿里云服务器,学习一下Docker,今天学着使用Docker安装MySQL. 首先,从阿里云的Docker Hub 上pull一个MySQL的image. [centos@loovelj~]$ ...

随机推荐

  1. [转] 为什么说 Java 程序员必须掌握 Spring Boot ?

    Spring Boot 2.0 的推出又激起了一阵学习 Spring Boot 热,那么, Spring Boot 诞生的背景是什么?Spring 企业又是基于什么样的考虑创建 Spring Boot ...

  2. 定制起始url(scrapy_redis)

    爬虫:(在这里不用配置start_url,直接可以取redis里面取start_url,可以多个) from scrapy_redis.spiders import RedisSpider # cla ...

  3. Codeforces 1117G Recursive Queries [线段树]

    Codeforces 洛谷:咕咕咕 思路 设\(L_i,R_i\)为\(i\)左右第一个大于它的位置. 对于每一个询问\(l,r\),考虑区间每一个位置的贡献就是\(\min(r,R_i-1)-\ma ...

  4. JAVA 语言如何进行异常处理,关键字: throws,throw,try,catch,finally分别代表什么意义? 在try块中可以抛 出异常吗?

    Java通过面向对象的方法进行异常处理,把各种不同的异常进行分类, 并提供了良好的接口.        在 Java中,每个异常都是一个对象,它是 Throwable 类或其它子类的实例.当一个方法出 ...

  5. ionic3 点击input 弹出白色遮罩 遮挡上部内容

    在Manifest中的activity里设置android:windowSoftInputMode为adjustPan,默认为adjustResize,当前窗口的内容将自动移动以便当前焦点从不被键盘覆 ...

  6. Feign服务消费者

    Feign的优点:面向接口,完全不用管实现,传入规定格式的数据就可以了 搭建消费者项目(FeignDemo) 1.创建pom.xml <project xmlns="http://ma ...

  7. php可变数量的参数

    PHP 在用户自定义函数中支持可变数量的参数列表.在 PHP 5.6 及以上的版本中,由 ... 语法实现:在 PHP 5.5 及更早版本中,使用函数 func_num_args(),func_get ...

  8. 渗透测试(theharvester >>steghide)

    1.不喜欢自己搭建平台来做测试,所以啦..... 网络信息安全漏洞的威胁总结起来就是人的漏洞,拿DNS服务器来说,一般不出现问题就不会管他,所以很多会被黑客利用,DNS服务器保存了企业内部的IP地址列 ...

  9. ServerSocket实现超简单HTTP服务器

    1.相关知识简介 HTTP协议 HTTP是常用的应用层协议之一,是面向文本的协议.HTTP报文传输基于TCP协议,TCP协议包含头部与数据部分,而HTTP则是包含在TCP协议的数据部分,如下图 HTT ...

  10. Python数据分析几个比较常用的方法

    1,表头或是excel的索引如果是中文的话,输出会出错 ​​解决方法:python的版本问题!换成python3就自动解决了!当然也有其他的方法,这里就不再深究 2,如果有很多列,如何输出指定的列? ...