वेक्टर का उपयोग करके Clickhouse और Elasticsearch पर Nginx json लॉग भेजना

वेक्टर का उपयोग करके Clickhouse और Elasticsearch पर Nginx json लॉग भेजना

वेक्टर, लॉग डेटा, मेट्रिक्स और ईवेंट एकत्र करने, बदलने और भेजने के लिए डिज़ाइन किया गया है।

→ Github

रस्ट भाषा में लिखे जाने के कारण, यह अपने एनालॉग्स की तुलना में उच्च प्रदर्शन और कम रैम खपत की विशेषता रखता है। इसके अलावा, शुद्धता से संबंधित कार्यों पर बहुत ध्यान दिया जाता है, विशेष रूप से, डिस्क पर बफर में न भेजी गई घटनाओं को सहेजने और फ़ाइलों को घुमाने की क्षमता।

वास्तुकला की दृष्टि से, वेक्टर एक इवेंट राउटर है जो एक या अधिक से संदेश प्राप्त करता है सूत्रों का कहना है, वैकल्पिक रूप से इन संदेशों पर लागू करना परिवर्तनों, और उन्हें एक या अधिक को भेजना नालियों.

वेक्टर फ़ाइलबीट और लॉगस्टैश का प्रतिस्थापन है, यह दोनों भूमिकाओं में कार्य कर सकता है (लॉग प्राप्त करें और भेजें), उन पर अधिक विवरण ऑनलाइन.

यदि लॉगस्टैश में श्रृंखला इनपुट → फ़िल्टर → आउटपुट के रूप में बनाई गई है तो वेक्टर में यह है स्त्रोतरूपांतरणडूब

उदाहरण दस्तावेज़ में पाए जा सकते हैं।

यह निर्देश से संशोधित निर्देश है व्याचेस्लाव राखिंस्की. मूल निर्देशों में जियोआईपी प्रोसेसिंग शामिल है। आंतरिक नेटवर्क से जियोआईपी का परीक्षण करते समय, वेक्टर ने एक त्रुटि दी।

Aug 05 06:25:31.889 DEBUG transform{name=nginx_parse_rename_fields type=rename_fields}: vector::transforms::rename_fields: Field did not exist field=«geoip.country_name» rate_limit_secs=30

यदि किसी को जियोआईपी संसाधित करने की आवश्यकता है, तो मूल निर्देश देखें व्याचेस्लाव राखिंस्की.

हम Nginx (एक्सेस लॉग) → वेक्टर (क्लाइंट | फाइलबीट) → वेक्टर (सर्वर | लॉगस्टैश) → के संयोजन को क्लिकहाउस में अलग से और Elasticsearch में अलग से कॉन्फ़िगर करेंगे। हम 4 सर्वर स्थापित करेंगे. हालाँकि आप इसे 3 सर्वर से बायपास कर सकते हैं।

वेक्टर का उपयोग करके Clickhouse और Elasticsearch पर Nginx json लॉग भेजना

स्कीम कुछ इस प्रकार है.

अपने सभी सर्वर पर सेलिनक्स अक्षम करें

sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
reboot

हम सभी सर्वरों पर एक HTTP सर्वर एमुलेटर + उपयोगिताएँ स्थापित करते हैं

HTTP सर्वर एमुलेटर के रूप में हम इसका उपयोग करेंगे नोडज-स्टब-सर्वर से मैक्सिम इग्नाटेंको

नोडज-स्टब-सर्वर में आरपीएम नहीं है। यहां इसके लिए आरपीएम बनाएं। आरपीएम का उपयोग करके बनाया जाएगा फेडोरा कॉपर

antonpatsev/nodejs-stub-server रिपॉजिटरी जोड़ें

yum -y install yum-plugin-copr epel-release
yes | yum copr enable antonpatsev/nodejs-stub-server

सभी सर्वरों पर नोडज-स्टब-सर्वर, अपाचे बेंचमार्क और स्क्रीन टर्मिनल मल्टीप्लेक्सर स्थापित करें

yum -y install stub_http_server screen mc httpd-tools screen

मैंने /var/lib/stub_http_server/stub_http_server.js फ़ाइल में stub_http_server प्रतिक्रिया समय को ठीक किया ताकि अधिक लॉग हों।

var max_sleep = 10;

आइए stub_http_server लॉन्च करें।

systemctl start stub_http_server
systemctl enable stub_http_server

क्लिकहाउस स्थापना सर्वर पर 3

ClickHouse SSE 4.2 निर्देश सेट का उपयोग करता है, इसलिए जब तक अन्यथा निर्दिष्ट न हो, उपयोग किए गए प्रोसेसर में इसके लिए समर्थन एक अतिरिक्त सिस्टम आवश्यकता बन जाता है। यहां यह जांचने का आदेश दिया गया है कि वर्तमान प्रोसेसर एसएसई 4.2 का समर्थन करता है या नहीं:

grep -q sse4_2 /proc/cpuinfo && echo "SSE 4.2 supported" || echo "SSE 4.2 not supported"

सबसे पहले आपको आधिकारिक रिपॉजिटरी को कनेक्ट करना होगा:

sudo yum install -y yum-utils
sudo rpm --import https://repo.clickhouse.tech/CLICKHOUSE-KEY.GPG
sudo yum-config-manager --add-repo https://repo.clickhouse.tech/rpm/stable/x86_64

पैकेज स्थापित करने के लिए आपको निम्नलिखित कमांड चलाने की आवश्यकता है:

sudo yum install -y clickhouse-server clickhouse-client

क्लिकहाउस-सर्वर को /etc/clickhouse-server/config.xml फ़ाइल में नेटवर्क कार्ड को सुनने की अनुमति दें

<listen_host>0.0.0.0</listen_host>

लॉगिंग स्तर को ट्रेस से डीबग में बदलना

डिबग

मानक संपीड़न सेटिंग्स:

min_compress_block_size  65536
max_compress_block_size  1048576

Zstd संपीड़न को सक्रिय करने के लिए, यह सलाह दी गई थी कि कॉन्फ़िगरेशन को न छुएं, बल्कि DDL का उपयोग करें।

वेक्टर का उपयोग करके Clickhouse और Elasticsearch पर Nginx json लॉग भेजना

मुझे Google में DDL के माध्यम से zstd संपीड़न का उपयोग करने का तरीका नहीं मिला। इसलिए मैंने इसे वैसे ही छोड़ दिया।

सहकर्मी जो Clickhouse में zstd संपीड़न का उपयोग करते हैं, कृपया निर्देश साझा करें।

सर्वर को डेमॉन के रूप में प्रारंभ करने के लिए, चलाएँ:

service clickhouse-server start

अब क्लिकहाउस की स्थापना के लिए आगे बढ़ते हैं

क्लिकहाउस पर जाएं

clickhouse-client -h 172.26.10.109 -m

172.26.10.109 — सर्वर का आईपी जहां क्लिकहाउस स्थापित है।

आइए एक वेक्टर डेटाबेस बनाएं

CREATE DATABASE vector;

आइए जांचें कि डेटाबेस मौजूद है या नहीं।

show databases;

एक वेक्टर.लॉग तालिका बनाएं।

/* Это таблица где хранятся логи как есть */

CREATE TABLE vector.logs
(
    `node_name` String,
    `timestamp` DateTime,
    `server_name` String,
    `user_id` String,
    `request_full` String,
    `request_user_agent` String,
    `request_http_host` String,
    `request_uri` String,
    `request_scheme` String,
    `request_method` String,
    `request_length` UInt64,
    `request_time` Float32,
    `request_referrer` String,
    `response_status` UInt16,
    `response_body_bytes_sent` UInt64,
    `response_content_type` String,
    `remote_addr` IPv4,
    `remote_port` UInt32,
    `remote_user` String,
    `upstream_addr` IPv4,
    `upstream_port` UInt32,
    `upstream_bytes_received` UInt64,
    `upstream_bytes_sent` UInt64,
    `upstream_cache_status` String,
    `upstream_connect_time` Float32,
    `upstream_header_time` Float32,
    `upstream_response_length` UInt64,
    `upstream_response_time` Float32,
    `upstream_status` UInt16,
    `upstream_content_type` String,
    INDEX idx_http_host request_http_host TYPE set(0) GRANULARITY 1
)
ENGINE = MergeTree()
PARTITION BY toYYYYMMDD(timestamp)
ORDER BY timestamp
TTL timestamp + toIntervalMonth(1)
SETTINGS index_granularity = 8192;

हम जाँचते हैं कि तालिकाएँ बनाई गई हैं। आइए लॉन्च करें clickhouse-client और एक अनुरोध करें.

चलिए वेक्टर डेटाबेस पर चलते हैं।

use vector;

Ok.

0 rows in set. Elapsed: 0.001 sec.

आइए तालिकाओं को देखें.

show tables;

┌─name────────────────┐
│ logs                │
└─────────────────────┘

क्लिकहाउस के साथ तुलना के लिए इलास्टिक्स खोज को समान डेटा भेजने के लिए चौथे सर्वर पर इलास्टिक खोज स्थापित करना

एक सार्वजनिक आरपीएम कुंजी जोड़ें

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

आइए 2 रेपो बनाएं:

/etc/yum.repos.d/elasticsearch.repo

[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md

/etc/yum.repos.d/kibana.repo

[kibana-7.x]
name=Kibana repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

इलास्टिक्स खोज और किबाना स्थापित करें

yum install -y kibana elasticsearch

चूँकि यह 1 प्रति में होगा, आपको निम्नलिखित को /etc/elasticsearch/elasticsearch.yml फ़ाइल में जोड़ना होगा:

discovery.type: single-node

ताकि वेक्टर दूसरे सर्वर से इलास्टिक्स खोज को डेटा भेज सके, आइए नेटवर्क.होस्ट को बदलें।

network.host: 0.0.0.0

किबाना से कनेक्ट करने के लिए, /etc/kibana/kibana.yml फ़ाइल में सर्वर.होस्ट पैरामीटर बदलें

server.host: "0.0.0.0"

पुराना और ऑटोस्टार्ट में इलास्टिक्स खोज शामिल करें

systemctl enable elasticsearch
systemctl start elasticsearch

और किबाना

systemctl enable kibana
systemctl start kibana

सिंगल-नोड मोड 1 शार्ड, 0 प्रतिकृति के लिए इलास्टिक्स खोज को कॉन्फ़िगर करना। सबसे अधिक संभावना है कि आपके पास बड़ी संख्या में सर्वरों का एक क्लस्टर होगा और आपको ऐसा करने की आवश्यकता नहीं है।

भविष्य के इंडेक्स के लिए, डिफ़ॉल्ट टेम्पलेट अपडेट करें:

curl -X PUT http://localhost:9200/_template/default -H 'Content-Type: application/json' -d '{"index_patterns": ["*"],"order": -1,"settings": {"number_of_shards": "1","number_of_replicas": "0"}}' 

स्थापना वेक्टर सर्वर 2 पर लॉगस्टैश के प्रतिस्थापन के रूप में

yum install -y https://packages.timber.io/vector/0.9.X/vector-x86_64.rpm mc httpd-tools screen

आइए वेक्टर को लॉगस्टैश के प्रतिस्थापन के रूप में स्थापित करें। /etc/vector/vector.toml फ़ाइल का संपादन

# /etc/vector/vector.toml

data_dir = "/var/lib/vector"

[sources.nginx_input_vector]
  # General
  type                          = "vector"
  address                       = "0.0.0.0:9876"
  shutdown_timeout_secs         = 30

[transforms.nginx_parse_json]
  inputs                        = [ "nginx_input_vector" ]
  type                          = "json_parser"

[transforms.nginx_parse_add_defaults]
  inputs                        = [ "nginx_parse_json" ]
  type                          = "lua"
  version                       = "2"

  hooks.process = """
  function (event, emit)

    function split_first(s, delimiter)
      result = {};
      for match in (s..delimiter):gmatch("(.-)"..delimiter) do
          table.insert(result, match);
      end
      return result[1];
    end

    function split_last(s, delimiter)
      result = {};
      for match in (s..delimiter):gmatch("(.-)"..delimiter) do
          table.insert(result, match);
      end
      return result[#result];
    end

    event.log.upstream_addr             = split_first(split_last(event.log.upstream_addr, ', '), ':')
    event.log.upstream_bytes_received   = split_last(event.log.upstream_bytes_received, ', ')
    event.log.upstream_bytes_sent       = split_last(event.log.upstream_bytes_sent, ', ')
    event.log.upstream_connect_time     = split_last(event.log.upstream_connect_time, ', ')
    event.log.upstream_header_time      = split_last(event.log.upstream_header_time, ', ')
    event.log.upstream_response_length  = split_last(event.log.upstream_response_length, ', ')
    event.log.upstream_response_time    = split_last(event.log.upstream_response_time, ', ')
    event.log.upstream_status           = split_last(event.log.upstream_status, ', ')

    if event.log.upstream_addr == "" then
        event.log.upstream_addr = "127.0.0.1"
    end

    if (event.log.upstream_bytes_received == "-" or event.log.upstream_bytes_received == "") then
        event.log.upstream_bytes_received = "0"
    end

    if (event.log.upstream_bytes_sent == "-" or event.log.upstream_bytes_sent == "") then
        event.log.upstream_bytes_sent = "0"
    end

    if event.log.upstream_cache_status == "" then
        event.log.upstream_cache_status = "DISABLED"
    end

    if (event.log.upstream_connect_time == "-" or event.log.upstream_connect_time == "") then
        event.log.upstream_connect_time = "0"
    end

    if (event.log.upstream_header_time == "-" or event.log.upstream_header_time == "") then
        event.log.upstream_header_time = "0"
    end

    if (event.log.upstream_response_length == "-" or event.log.upstream_response_length == "") then
        event.log.upstream_response_length = "0"
    end

    if (event.log.upstream_response_time == "-" or event.log.upstream_response_time == "") then
        event.log.upstream_response_time = "0"
    end

    if (event.log.upstream_status == "-" or event.log.upstream_status == "") then
        event.log.upstream_status = "0"
    end

    emit(event)

  end
  """

[transforms.nginx_parse_remove_fields]
    inputs                              = [ "nginx_parse_add_defaults" ]
    type                                = "remove_fields"
    fields                              = ["data", "file", "host", "source_type"]

[transforms.nginx_parse_coercer]

    type                                = "coercer"
    inputs                              = ["nginx_parse_remove_fields"]

    types.request_length = "int"
    types.request_time = "float"

    types.response_status = "int"
    types.response_body_bytes_sent = "int"

    types.remote_port = "int"

    types.upstream_bytes_received = "int"
    types.upstream_bytes_send = "int"
    types.upstream_connect_time = "float"
    types.upstream_header_time = "float"
    types.upstream_response_length = "int"
    types.upstream_response_time = "float"
    types.upstream_status = "int"

    types.timestamp = "timestamp"

[sinks.nginx_output_clickhouse]
    inputs   = ["nginx_parse_coercer"]
    type     = "clickhouse"

    database = "vector"
    healthcheck = true
    host = "http://172.26.10.109:8123" #  Адрес Clickhouse
    table = "logs"

    encoding.timestamp_format = "unix"

    buffer.type = "disk"
    buffer.max_size = 104900000
    buffer.when_full = "block"

    request.in_flight_limit = 20

[sinks.elasticsearch]
    type = "elasticsearch"
    inputs   = ["nginx_parse_coercer"]
    compression = "none"
    healthcheck = true
    # 172.26.10.116 - сервер где установен elasticsearch
    host = "http://172.26.10.116:9200" 
    index = "vector-%Y-%m-%d"

आप transforms.nginx_parse_add_defaults अनुभाग को समायोजित कर सकते हैं।

जैसा व्याचेस्लाव राखिंस्की एक छोटे सीडीएन के लिए इन कॉन्फ़िगरेशन का उपयोग करता है और अपस्ट्रीम_* में कई मान हो सकते हैं

उदाहरण के लिए:

"upstream_addr": "128.66.0.10:443, 128.66.0.11:443, 128.66.0.12:443"
"upstream_bytes_received": "-, -, 123"
"upstream_status": "502, 502, 200"

यदि यह आपकी स्थिति नहीं है, तो इस अनुभाग को सरल बनाया जा सकता है

आइए systemd /etc/systemd/system/vector.service के लिए सेवा सेटिंग बनाएं

# /etc/systemd/system/vector.service

[Unit]
Description=Vector
After=network-online.target
Requires=network-online.target

[Service]
User=vector
Group=vector
ExecStart=/usr/bin/vector
ExecReload=/bin/kill -HUP $MAINPID
Restart=no
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=vector

[Install]
WantedBy=multi-user.target

टेबल बनाने के बाद, आप वेक्टर चला सकते हैं

systemctl enable vector
systemctl start vector

वेक्टर लॉग को इस तरह देखा जा सकता है:

journalctl -f -u vector

लॉग में इस प्रकार की प्रविष्टियाँ होनी चाहिए

INFO vector::topology::builder: Healthcheck: Passed.
INFO vector::topology::builder: Healthcheck: Passed.

क्लाइंट (वेब ​​सर्वर) पर - पहला सर्वर

Nginx वाले सर्वर पर, आपको IPv6 को अक्षम करना होगा, क्योंकि क्लिकहाउस में लॉग तालिका फ़ील्ड का उपयोग करती है upstream_addr आईपीवी4, चूँकि मैं नेटवर्क के अंदर आईपीवी6 का उपयोग नहीं करता। यदि IPv6 बंद नहीं किया गया है, तो त्रुटियाँ होंगी:

DB::Exception: Invalid IPv4 value.: (while read the value of key upstream_addr)

शायद पाठक, IPv6 समर्थन जोड़ें।

फ़ाइल /etc/sysctl.d/98-disable-ipv6.conf बनाएँ

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

सेटिंग्स लागू करना

sysctl --system

आइए nginx इंस्टॉल करें।

nginx रिपोजिटरी फ़ाइल /etc/yum.repos.d/nginx.repo जोड़ी गई

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true

nginx पैकेज स्थापित करें

yum install -y nginx

सबसे पहले, हमें फ़ाइल /etc/nginx/nginx.conf में Nginx में लॉग प्रारूप को कॉन्फ़िगर करना होगा

user  nginx;
# you must set worker processes based on your CPU cores, nginx does not benefit from setting more than that
worker_processes auto; #some last versions calculate it automatically

# number of file descriptors used for nginx
# the limit for the maximum FDs on the server is usually set by the OS.
# if you don't set FD's then OS settings will be used which is by default 2000
worker_rlimit_nofile 100000;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

# provides the configuration file context in which the directives that affect connection processing are specified.
events {
    # determines how much clients will be served per worker
    # max clients = worker_connections * worker_processes
    # max clients is also limited by the number of socket connections available on the system (~64k)
    worker_connections 4000;

    # optimized to serve many clients with each thread, essential for linux -- for testing environment
    use epoll;

    # accept as many connections as possible, may flood worker connections if set too low -- for testing environment
    multi_accept on;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

log_format vector escape=json
    '{'
        '"node_name":"nginx-vector",'
        '"timestamp":"$time_iso8601",'
        '"server_name":"$server_name",'
        '"request_full": "$request",'
        '"request_user_agent":"$http_user_agent",'
        '"request_http_host":"$http_host",'
        '"request_uri":"$request_uri",'
        '"request_scheme": "$scheme",'
        '"request_method":"$request_method",'
        '"request_length":"$request_length",'
        '"request_time": "$request_time",'
        '"request_referrer":"$http_referer",'
        '"response_status": "$status",'
        '"response_body_bytes_sent":"$body_bytes_sent",'
        '"response_content_type":"$sent_http_content_type",'
        '"remote_addr": "$remote_addr",'
        '"remote_port": "$remote_port",'
        '"remote_user": "$remote_user",'
        '"upstream_addr": "$upstream_addr",'
        '"upstream_bytes_received": "$upstream_bytes_received",'
        '"upstream_bytes_sent": "$upstream_bytes_sent",'
        '"upstream_cache_status":"$upstream_cache_status",'
        '"upstream_connect_time":"$upstream_connect_time",'
        '"upstream_header_time":"$upstream_header_time",'
        '"upstream_response_length":"$upstream_response_length",'
        '"upstream_response_time":"$upstream_response_time",'
        '"upstream_status": "$upstream_status",'
        '"upstream_content_type":"$upstream_http_content_type"'
    '}';

    access_log  /var/log/nginx/access.log  main;
    access_log  /var/log/nginx/access.json.log vector;      # Новый лог в формате json

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

आपके वर्तमान कॉन्फ़िगरेशन को न तोड़ने के लिए, Nginx आपको कई एक्सेस_लॉग निर्देश देने की अनुमति देता है

access_log  /var/log/nginx/access.log  main;            # Стандартный лог
access_log  /var/log/nginx/access.json.log vector;      # Новый лог в формате json

नए लॉग के लिए लॉगरोटेट करने के लिए एक नियम जोड़ना न भूलें (यदि लॉग फ़ाइल .log के साथ समाप्त नहीं होती है)

/etc/nginx/conf.d/ से default.conf हटाएँ

rm -f /etc/nginx/conf.d/default.conf

वर्चुअल होस्ट /etc/nginx/conf.d/vhost1.conf जोड़ें

server {
    listen 80;
    server_name vhost1;
    location / {
        proxy_pass http://172.26.10.106:8080;
    }
}

वर्चुअल होस्ट /etc/nginx/conf.d/vhost2.conf जोड़ें

server {
    listen 80;
    server_name vhost2;
    location / {
        proxy_pass http://172.26.10.108:8080;
    }
}

वर्चुअल होस्ट /etc/nginx/conf.d/vhost3.conf जोड़ें

server {
    listen 80;
    server_name vhost3;
    location / {
        proxy_pass http://172.26.10.109:8080;
    }
}

वर्चुअल होस्ट /etc/nginx/conf.d/vhost4.conf जोड़ें

server {
    listen 80;
    server_name vhost4;
    location / {
        proxy_pass http://172.26.10.116:8080;
    }
}

/etc/hosts फ़ाइल के सभी सर्वरों में वर्चुअल होस्ट (सर्वर का 172.26.10.106 आईपी जहां nginx स्थापित है) जोड़ें:

172.26.10.106 vhost1
172.26.10.106 vhost2
172.26.10.106 vhost3
172.26.10.106 vhost4

और अगर सब कुछ तैयार है तो

nginx -t 
systemctl restart nginx

अब आइए इसे स्वयं स्थापित करें वेक्टर

yum install -y https://packages.timber.io/vector/0.9.X/vector-x86_64.rpm

आइए systemd /etc/systemd/system/vector.service के लिए एक सेटिंग फ़ाइल बनाएं

[Unit]
Description=Vector
After=network-online.target
Requires=network-online.target

[Service]
User=vector
Group=vector
ExecStart=/usr/bin/vector
ExecReload=/bin/kill -HUP $MAINPID
Restart=no
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=vector

[Install]
WantedBy=multi-user.target

और फ़ाइलबीट प्रतिस्थापन को /etc/vector/vector.toml कॉन्फ़िगरेशन में कॉन्फ़िगर करें। आईपी ​​पता 172.26.10.108 लॉग सर्वर (वेक्टर-सर्वर) का आईपी पता है

data_dir = "/var/lib/vector"

[sources.nginx_file]
  type                          = "file"
  include                       = [ "/var/log/nginx/access.json.log" ]
  start_at_beginning            = false
  fingerprinting.strategy       = "device_and_inode"

[sinks.nginx_output_vector]
  type                          = "vector"
  inputs                        = [ "nginx_file" ]

  address                       = "172.26.10.108:9876"

वेक्टर उपयोगकर्ता को आवश्यक समूह में जोड़ना न भूलें ताकि वह लॉग फ़ाइलें पढ़ सके। उदाहरण के लिए, सेंटोज़ में nginx एडम समूह अधिकारों के साथ लॉग बनाता है।

usermod -a -G adm vector

आइए वेक्टर सेवा शुरू करें

systemctl enable vector
systemctl start vector

वेक्टर लॉग को इस तरह देखा जा सकता है:

journalctl -f -u vector

लॉग में इस प्रकार की प्रविष्टि होनी चाहिए

INFO vector::topology::builder: Healthcheck: Passed.

तनाव परीक्षण

अपाचे बेंचमार्क का उपयोग करके परीक्षण किया जाता है।

httpd-tools पैकेज सभी सर्वरों पर स्थापित किया गया था

हम स्क्रीन में 4 अलग-अलग सर्वरों से अपाचे बेंचमार्क का उपयोग करके परीक्षण शुरू करते हैं। सबसे पहले, हम स्क्रीन टर्मिनल मल्टीप्लेक्सर लॉन्च करते हैं, और फिर हम अपाचे बेंचमार्क का उपयोग करके परीक्षण शुरू करते हैं। स्क्रीन के साथ कैसे काम करें आप इसमें पा सकते हैं लेख.

पहले सर्वर से

while true; do ab -H "User-Agent: 1server" -c 100 -n 10 -t 10 http://vhost1/; sleep 1; done

पहले सर्वर से

while true; do ab -H "User-Agent: 2server" -c 100 -n 10 -t 10 http://vhost2/; sleep 1; done

पहले सर्वर से

while true; do ab -H "User-Agent: 3server" -c 100 -n 10 -t 10 http://vhost3/; sleep 1; done

पहले सर्वर से

while true; do ab -H "User-Agent: 4server" -c 100 -n 10 -t 10 http://vhost4/; sleep 1; done

आइए Clickhouse में डेटा की जाँच करें

क्लिकहाउस पर जाएं

clickhouse-client -h 172.26.10.109 -m

SQL क्वेरी बनाना

SELECT * FROM vector.logs;

┌─node_name────┬───────────timestamp─┬─server_name─┬─user_id─┬─request_full───┬─request_user_agent─┬─request_http_host─┬─request_uri─┬─request_scheme─┬─request_method─┬─request_length─┬─request_time─┬─request_referrer─┬─response_status─┬─response_body_bytes_sent─┬─response_content_type─┬───remote_addr─┬─remote_port─┬─remote_user─┬─upstream_addr─┬─upstream_port─┬─upstream_bytes_received─┬─upstream_bytes_sent─┬─upstream_cache_status─┬─upstream_connect_time─┬─upstream_header_time─┬─upstream_response_length─┬─upstream_response_time─┬─upstream_status─┬─upstream_content_type─┐
│ nginx-vector │ 2020-08-07 04:32:42 │ vhost1      │         │ GET / HTTP/1.0 │ 1server            │ vhost1            │ /           │ http           │ GET            │             66 │        0.028 │                  │             404 │                       27 │                       │ 172.26.10.106 │       45886 │             │ 172.26.10.106 │             0 │                     109 │                  97 │ DISABLED              │                     0 │                0.025 │                       27 │                  0.029 │             404 │                       │
└──────────────┴─────────────────────┴─────────────┴─────────┴────────────────┴────────────────────┴───────────────────┴─────────────┴────────────────┴────────────────┴────────────────┴──────────────┴──────────────────┴─────────────────┴──────────────────────────┴───────────────────────┴───────────────┴─────────────┴─────────────┴───────────────┴───────────────┴─────────────────────────┴─────────────────────┴───────────────────────┴───────────────────────┴──────────────────────┴──────────────────────────┴────────────────────────┴─────────────────┴───────────────────────

क्लिकहाउस में तालिकाओं का आकार पता करें

select concat(database, '.', table)                         as table,
       formatReadableSize(sum(bytes))                       as size,
       sum(rows)                                            as rows,
       max(modification_time)                               as latest_modification,
       sum(bytes)                                           as bytes_size,
       any(engine)                                          as engine,
       formatReadableSize(sum(primary_key_bytes_in_memory)) as primary_keys_size
from system.parts
where active
group by database, table
order by bytes_size desc;

आइए जानें कि क्लिकहाउस में कितने लॉग लगे।

वेक्टर का उपयोग करके Clickhouse और Elasticsearch पर Nginx json लॉग भेजना

लॉग तालिका का आकार 857.19 एमबी है।

वेक्टर का उपयोग करके Clickhouse और Elasticsearch पर Nginx json लॉग भेजना

Elasticsearch में इंडेक्स में समान डेटा का आकार 4,5GB है।

यदि आप पैरामीटर में वेक्टर में डेटा निर्दिष्ट नहीं करते हैं, तो Clickhouse Elasticsearch की तुलना में 4500/857.19 = 5.24 गुना कम लेता है।

वेक्टर में, संपीड़न फ़ील्ड का उपयोग डिफ़ॉल्ट रूप से किया जाता है।

टेलीग्राम चैट द्वारा clickhouse
टेलीग्राम चैट द्वारा Elasticsearch
टेलीग्राम चैट "प्रणाली का संग्रह और विश्लेषण संदेशों"

स्रोत: www.habr.com

एक टिप्पणी जोड़ें