Ang pagiging nakasulat sa wikang Rust, ito ay nailalarawan sa pamamagitan ng mataas na pagganap at mababang pagkonsumo ng RAM kumpara sa mga analogue nito. Bilang karagdagan, maraming pansin ang binabayaran sa mga function na may kaugnayan sa kawastuhan, sa partikular, ang kakayahang mag-save ng mga hindi naipadalang kaganapan sa isang buffer sa disk at i-rotate ang mga file.
Sa arkitektura, ang Vector ay isang event router na tumatanggap ng mga mensahe mula sa isa o higit pa mga mapagkukunan, opsyonal na inilalapat sa mga mensaheng ito mga pagbabagong-anyo, at pagpapadala sa kanila sa isa o higit pa drains.
Ang Vector ay isang kapalit para sa filebeat at logstash, maaari itong kumilos sa parehong mga tungkulin (tumanggap at magpadala ng mga log), higit pang mga detalye sa mga ito Online.
Kung sa Logstash ang chain ay binuo bilang input → filter → output pagkatapos ay sa Vector ito pinagkukunan → nagbabago → lababo
Ang mga halimbawa ay matatagpuan sa dokumentasyon.
Ang tagubiling ito ay isang binagong tagubilin mula sa Vyacheslav Rakhinsky. Ang orihinal na mga tagubilin ay naglalaman ng geoip processing. Kapag sinusubukan ang geoip mula sa isang panloob na network, nagbigay ng error ang vector.
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
Kung kailangan ng sinuman na magproseso ng geoip, sumangguni sa orihinal na mga tagubilin mula sa Vyacheslav Rakhinsky.
Iko-configure namin ang kumbinasyon ng Nginx (Access logs) → Vector (Client | Filebeat) → Vector (Server | Logstash) → hiwalay sa Clickhouse at hiwalay sa Elasticsearch. Mag-i-install kami ng 4 na server. Bagama't maaari mong i-bypass ito gamit ang 3 server.
Ang scheme ay isang bagay tulad nito.
Huwag paganahin ang Selinux sa lahat ng iyong mga server
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
reboot
Nag-i-install kami ng HTTP server emulator + utility sa lahat ng server
Ginagamit ng ClickHouse ang set ng pagtuturo ng SSE 4.2, kaya maliban kung tinukoy, ang suporta para dito sa processor na ginamit ay nagiging karagdagang kinakailangan ng system. Narito ang utos upang suriin kung sinusuportahan ng kasalukuyang processor ang SSE 4.2:
Pag-configure ng Elasticsearch para sa single-node mode 1 shard, 0 replica. Malamang na magkakaroon ka ng isang kumpol ng isang malaking bilang ng mga server at hindi mo kailangang gawin ito.
Para sa mga index sa hinaharap, i-update ang default na template:
Pagkatapos gawin ang mga talahanayan, maaari mong patakbuhin ang Vector
systemctl enable vector
systemctl start vector
Ang mga vector log ay maaaring matingnan nang ganito:
journalctl -f -u vector
Dapat may mga entry na ganito sa logs
INFO vector::topology::builder: Healthcheck: Passed.
INFO vector::topology::builder: Healthcheck: Passed.
Sa client (Web server) - 1st server
Sa server na may nginx, kailangan mong i-disable ang ipv6, dahil ang logs table sa clickhouse ay gumagamit ng field upstream_addr IPv4, dahil hindi ako gumagamit ng ipv6 sa loob ng network. Kung hindi naka-off ang ipv6, magkakaroon ng mga error:
DB::Exception: Invalid IPv4 value.: (while read the value of key upstream_addr)
Marahil mga mambabasa, magdagdag ng suporta sa ipv6.
Lumikha ng file /etc/sysctl.d/98-disable-ipv6.conf
Una, kailangan nating i-configure ang format ng log sa Nginx sa file /etc/nginx/nginx.conf
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;
}
Upang hindi masira ang iyong kasalukuyang configuration, pinapayagan ka ng Nginx na magkaroon ng ilang access_log na mga direktiba
access_log /var/log/nginx/access.log main; # Стандартный лог
access_log /var/log/nginx/access.json.log vector; # Новый лог в формате json
Huwag kalimutang magdagdag ng panuntunan upang mag-logrotate para sa mga bagong log (kung ang log file ay hindi nagtatapos sa .log)
Alisin ang default.conf mula sa /etc/nginx/conf.d/
rm -f /etc/nginx/conf.d/default.conf
Magdagdag ng virtual host /etc/nginx/conf.d/vhost1.conf
At i-configure ang kapalit na Filebeat sa /etc/vector/vector.toml config. Ang IP address na 172.26.10.108 ay ang IP address ng log server (Vector-Server)
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"
Huwag kalimutang idagdag ang vector user sa kinakailangang pangkat upang mabasa niya ang mga log file. Halimbawa, ang nginx sa centos ay gumagawa ng mga log na may mga karapatan sa adm group.
usermod -a -G adm vector
Simulan natin ang serbisyo ng vector
systemctl enable vector
systemctl start vector
Ang mga vector log ay maaaring matingnan nang ganito:
journalctl -f -u vector
Dapat may entry na ganito sa logs
INFO vector::topology::builder: Healthcheck: Passed.
Pagsusuri ng Stress
Nagsasagawa kami ng pagsubok gamit ang benchmark ng Apache.
Ang pakete ng httpd-tools ay na-install sa lahat ng mga server
Sinimulan namin ang pagsubok gamit ang Apache benchmark mula sa 4 na magkakaibang server sa screen. Una, inilunsad namin ang screen terminal multiplexer, at pagkatapos ay sisimulan namin ang pagsubok gamit ang Apache benchmark. Paano gumana sa screen na makikita mo sa Artikulo.
Mula sa 1st server
while true; do ab -H "User-Agent: 1server" -c 100 -n 10 -t 10 http://vhost1/; sleep 1; done
Mula sa 2st server
while true; do ab -H "User-Agent: 2server" -c 100 -n 10 -t 10 http://vhost2/; sleep 1; done
Mula sa 3st server
while true; do ab -H "User-Agent: 3server" -c 100 -n 10 -t 10 http://vhost3/; sleep 1; done
Mula sa 4st server
while true; do ab -H "User-Agent: 4server" -c 100 -n 10 -t 10 http://vhost4/; sleep 1; done
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;
Alamin natin kung gaano karaming mga log ang kinuha sa Clickhouse.
Ang laki ng talahanayan ng mga log ay 857.19 MB.
Ang laki ng parehong data sa index sa Elasticsearch ay 4,5GB.
Kung hindi mo tinukoy ang data sa vector sa mga parameter, ang Clickhouse ay tumatagal ng 4500/857.19 = 5.24 beses na mas mababa kaysa sa Elasticsearch.
Sa vector, ang compression field ay ginagamit bilang default.