日志系统 - Garylog 一键部署

使用Garylog收集日志

安装最新版本




在这里能找到最新的版本,我自己改了一个yml

安装V3 版本

# vim docker-compose.yml
# vim docker-compose.yml
version: '3'
services:
    # MongoDB: https://hub.docker.com/_/mongo/
    mongo:
      image: mongo:4.2
      networks:
        - graylog
    # Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/7.10/docker.html
    elasticsearch:
      image: docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2
      environment:
        - http.host=0.0.0.0
        - transport.host=localhost
        - network.host=0.0.0.0
        - "ES_JAVA_OPTS=-Dlog4j2.formatMsgNoLookups=true -Xms4g -Xmx4g"
        - "discovery.type=single-node"
      # 挂载数据卷,注意创建的文件夹是需要读写和操作权限的
      volumes:
        - ./eldata:/usr/share/elasticsearch/data
      ulimits:
        memlock:
          soft: -1
          hard: -1
      deploy:
        resources:
          limits:
            memory: 1g
      networks:
        - graylog
      restart: always
    # Graylog: https://hub.docker.com/r/graylog/graylog/
    graylog:
      image: graylog/graylog:4.2
      environment:
        # CHANGE ME (must be at least 16 characters)!
        - GRAYLOG_PASSWORD_SECRET=somepasswordpepper
        # Password: 填入密码SHA256后的结果
        - GRAYLOG_ROOT_PASSWORD_SHA2=xxx
        - GRAYLOG_HTTP_EXTERNAL_URI=http://127.0.0.1:9000/
        - GRAYLOG_ROOT_TIMEZONE=Asia/Shanghai
      entrypoint: /usr/bin/tini -- wait-for-it elasticsearch:9200 --  /docker-entrypoint.sh
      networks:
        - graylog
      restart: always
      depends_on:
        - mongo
        - elasticsearch
      ports:
        # Graylog web interface and REST API
        - 9000:9000
        # Syslog TCP
        - 1514:1514
        - 5044:5044
        # Syslog UDP
        - 1514:1514/udp
        # GELF TCP
        - 12201:12201
        # GELF UDP
        - 12201:12201/udp
networks:
    graylog:
      driver: bridge
  1. - GRAYLOG_ROOT_TIMEZONE=Asia/Shanghai 不设置会导致时区错误
  2. - GRAYLOG_ROOT_PASSWORD_SHA2=xxx 设置密码,密码sha256加密的自己加密一下就好

安装

  1. 装好 dockerdocker-compose
  2. 运行docker-compose up -d 自动会安装相应的东西

简易配置




除了title 其他不用改

http上传日志

简易封装上传

 * @param data
 */
const graylog = (data : LogModelReq) => {
  data.project = projectName
  return http.post<ApiResult<PageModelRes<WebSiteRes>>>({
    baseURL: 'http://localhost:12201',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    url: '/gelf',
    data: JSON.stringify(data)
  })
}

export const LogDebug = async (message : string) => {
  const s: LogModelReq = {
    level: 1,
    message: message
  }
  return graylog(s)
}


posted @ 2022-03-09 14:48  Z_DK  阅读(342)  评论(0编辑  收藏  举报