• CAT 监控搭建


    简介

    CAT 是基于 Java 开发的实时应用监控平台,为美团点评提供了全面的实时监控告警服务。

    已经在美团点评的基础架构中间件框架(MVC框架,RPC框架,数据库框架,缓存框架等,消息队列,配置系统等)深度集成,为美团点评各业务线提供系统丰富的性能指标、健康状况、实时告警等。

    开源地址:https://github.com/dianping/cat/

    Docker 部署CAT

    一、环境

    已安装服务

    • 服务1:docker-compose Version 1.25.0-rc2
    • 服务2:Docker Version: 19.03.4
    • 服务3:Mysql 5.7
    • 服务4:git 1.8.3.1

    二、通过Docker安装

    1、创建CAT目录、进入到该目录下

    mkdir -p /opt/cat/
    cd /opt/cat

    2、下载cat

    git clone https://github.com/dianping/cat.git

    3、进入到Docker目录

    /cat/docker

    4、创建Dockerfile文件

    vim Dockerfile

    FROM centos:centos6
    
    USER root
    
    #UTILITIES
    RUN    yum install -y wget
    RUN    yum install -y tar
    
    #JAVA (OPENJDK 7)
    ENV JAVA_VERSION 1.7.0
    
    RUN yum install -y java-1.7.0-openjdk java-1.7.0-openjdk-devel
    
    ENV JAVA_HOME /usr/lib/jvm/java
    
    #TOMCAT 7
    ENV CATALINA_HOME /usr/local/tomcat
    ENV PATH $CATALINA_HOME/bin:$PATH
    RUN mkdir -p "$CATALINA_HOME"
    WORKDIR $CATALINA_HOME
    
    
    ENV TOMCAT_MAJOR_VERSION 7
    ENV TOMCAT_MINOR_VERSION 7.0.79
    
    RUN wget -q https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_MAJOR_VERSION}/v${TOMCAT_MINOR_VERSION}/bin/apache-tomcat-${TOMCAT_MINOR_VERSION}.tar.gz && 
        wget -qO- https://archive.apache.org/dist/tomcat/tomcat-${TOMCAT_MAJOR_VERSION}/v${TOMCAT_MINOR_VERSION}/bin/apache-tomcat-${TOMCAT_MINOR_VERSION}.tar.gz.md5 | md5sum -c - && 
        tar zxf apache-tomcat-*.tar.gz && 
        mv apache-tomcat-${TOMCAT_MINOR_VERSION}/* . && 
        rm -rf apache-tomcat-*
    
    #MAVEN
    ENV MAVEN_VERSION_MAJOR 3
    ENV MAVEN_VERSION_MINOR 5.2
    
    RUN wget http://archive.apache.org/dist/maven/maven-${MAVEN_VERSION_MAJOR}/${MAVEN_VERSION_MAJOR}.${MAVEN_VERSION_MINOR}/binaries/apache-maven-${MAVEN_VERSION_MAJOR}.${MAVEN_VERSION_MINOR}-bin.tar.gz
    RUN tar xvf apache-maven-${MAVEN_VERSION_MAJOR}.${MAVEN_VERSION_MINOR}-bin.tar.gz
    RUN rm apache-maven-${MAVEN_VERSION_MAJOR}.${MAVEN_VERSION_MINOR}-bin.tar.gz
    RUN mv apache-maven-${MAVEN_VERSION_MAJOR}.${MAVEN_VERSION_MINOR}  /usr/local/apache-maven
    ENV M2_HOME=/usr/local/apache-maven
    ENV M2=$M2_HOME/bin
    ENV PATH=$M2:$PATH
    CMD java -version && mvn -version
    
    COPY . /root/workspace/cat
    WORKDIR /root/workspace/cat
    
    RUN set -ex && mvn clean install -DskipTests
    RUN cp cat-home/target/*.war $CATALINA_HOME/webapps/cat.war
    ADD docker/datasources.xml /data/appdatas/cat/datasources.xml
    ADD docker/datasources.sh /datasources.sh
    RUN sed -i "s/port="8080"/port="8080" URIEncoding="utf-8"/g" $CATALINA_HOME/conf/server.xml
    
    EXPOSE 8080
    Dockerfile

    5、创建docker-compose文件

    vim docker-compose.yaml

    version: '2.2'
    
    services:
      cat:
        container_name: cat
    
        ######## build from Dockerfile ###########
        build:
          context: ../
          dockerfile: ./docker/Dockerfile
        ######## End -> build from Dockerfile ###########
    
        environment:
          # if you have your own mysql, config it here, and disable the 'mysql' config blow
          - MYSQL_URL=192.168.0.197  # links will maintain /etc/hosts, just use 'container_name'
          - MYSQL_PORT=3306
          - MYSQL_USERNAME=cat
          - MYSQL_PASSWD=cat123
          - MYSQL_SCHEMA=cat
    
        working_dir: /app
        volumes:
          # 默认127.0.0.1,可以修改为自己真实的服务器集群地址
          - "./client.xml:/data/appdatas/cat/client.xml"
          # 默认使用环境变量设置。可以启用本注解,并修改为自己的配置
          - "./datasources.xml:/data/appdatas/cat/datasources.xml"
          - "/etc/localtime:/etc/localtime"
            #command: /bin/sh -c 'chmod +x /datasources.sh && /datasources.sh && catalina.sh run'
        command: /bin/sh -c 'catalina.sh run'
        ports:
          - "8080:8080"
          - "2280:2280"
        network_mode: "host"
    docker-compose.yaml

    6、修改datasources.xml配置文件链接数据库使用

    vim datasources.xml

    <?xml version="1.0" encoding="utf-8"?>
    
    <data-sources>
        <data-source id="cat">
            <maximum-pool-size>3</maximum-pool-size>
            <connection-timeout>1s</connection-timeout>
            <idle-timeout>10m</idle-timeout>
            <statement-cache-size>1000</statement-cache-size>
            <properties>
                <driver>com.mysql.jdbc.Driver</driver>
                <url><![CDATA[jdbc:mysql://192.168.0.9:3306/cat]]></url>
                <user>cat</user>
                <password>xxxxxxx</password>
                <connectionProperties><![CDATA[useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&socketTimeout=120000]]></connectionProperties>
            </properties>
        </data-source>
    </data-sources>
    datasources.xml

    7、修改client.xml配置文件用于指定监控端

    vim client.xml

    <?xml version="1.0" encoding="utf-8"?>
    <config mode="client">
        <servers>
            <server ip="192.168.0.9" port="2280" http-port="8080"/>
        </servers>
    </config>
    client.xml

    8、将cat数据库导入sql文件

    数据库位置:/cat/script/CatApplication.sql 

    9、执行命令构建启动服务

    docker-compose up

    10、设置开机自启动

    docker update --restart=always cat

    11、开启防火墙端口

    firewall-cmd --zone=public  --permanent --add-port=2280/tcp
    firewall-cmd --zone=public  --permanent --add-port=8080/tcp

    12、测试访问

    http://ip:8080/cat

    13、配置cat

    config 默认用户名:admin 密码:admin

    <?xml version="1.0" encoding="utf-8"?>
    <router-config backup-server="192.168.0.9" backup-server-port="2280">
       <default-server id="192.168.0.9" weight="1.0" port="2280" enable="true"/>
       <network-policy id="default" title="默认" block="false" server-group="default_group">
       </network-policy>
       <server-group id="default_group" title="default-group">
          <group-server id="192.168.0.9"/>
       </server-group>
       <domain id="cat">
          <group id="default">
             <server id="192.168.0.9" port="2280" weight="1.0"/>
          </group>
       </domain>
    </router-config>
    路由配置

    参考文章:https://www.cnblogs.com/provence666/p/11029329.html

    参考文章:https://article.itxueyuan.com/BJ2KdG

    参考文章:https://zhuanlan.zhihu.com/p/46399761

    参考文章:https://www.cnblogs.com/softidea/p/5719331.html

  • 相关阅读:
    Mysql数据备份命令
    git命令大全
    git 安装及普通命令
    git学习资料
    php 魔术方法 和 魔术常量
    react事件处理(绑定)
    java父类、子类构造函数调用过程
    java字符串String的intern()方法,举例说明
    java关键字static使用的“坑”(准备、初始化)
    java虚拟机
  • 原文地址:https://www.cnblogs.com/xiangsikai/p/12010876.html
Copyright © 2020-2023  润新知