Võ Đức Chính
Intern
Mô hình triển khai:
Chú thích: Các node Management + Agent Management; Log pipeline + Load Blancing sẽ được gộp lại để giảm chi phí triển khai.
| VM | IP |
| Data01 | 10.30.194.181 |
| Data02 | 10.30.194.182 |
| Data03 | 10.30.194.183 |
| Dashboard | 10.30.194.184 |
| Manager01 | 10.30.194.185 |
| Manager02 | 10.30.194.186 |
| Pipeline01 | 10.30.194.187 |
| Pipeline02 | 10.30.194.188 |
Data node Opensearch (Opensearch):
Vì chỉ cluster HA 3 node nên để tối ưu thì cả 3 node đều giữ vai trò:- cluster_manager: Tham gia bầu chọn quản lý cụm.
- data: Lưu trữ dữ liệu log và sự kiện bảo mật.
- ingest: Xử lý dữ liệu đầu vào từ Vector và Wazuh Manager.
Chi tiết triển khai:
Triển khai tương trên cả 3 node: 10.30.194.181, 10.30.194.182, 10.30.194.183Cập nhật danh sách gói phần mềm hệ thống và cài package cần thiết:
| sudo apt-get update && sudo apt-get -y install lsb-release ca-certificates curl gnupg2 |
| curl -fsSL https://artifacts.opensearch.org/publickeys/opensearch-release.pgp \ | sudo gpg --dearmor -o /etc/apt/keyrings/opensearch.gpg |
| echo "deb [signed-by=/etc/apt/keyrings/opensearch.gpg] https://artifacts.opensearch.org/releases/bundle/opensearch/3.x/apt stable main" \ | sudo tee /etc/apt/sources.list.d/opensearch-3.x.list |
| sudo apt-get update |
| sudo env OPENSEARCH_INITIAL_ADMIN_PASSWORD=<custom-admin-password> apt-get install opensearch=3.3.2 |
| gpg --no-default-keyring --keyring /etc/apt/trusted.gpg.d/opensearch.gpg --fingerprint sudo systemctl enable opensearch sudo systemctl start opensearch |
| curl -X GET https://<ip-node>:9200 -u 'admin:<custom-admin-password>' --insecure |
| cluster.name: poptech node.name: node-1 node.roles: [cluster_manager, data, ingest] path.data: /var/lib/opensearch path.logs: /var/log/opensearch network.host: 10.30.194.181 discovery.seed_hosts: ["10.30.194.181", "10.30.194.182", "10.30.194.183"] cluster.initial_cluster_manager_nodes: ["node-1", "node-2", "node-3"] plugins.security.ssl.transport.pemcert_filepath: esnode.pem plugins.security.ssl.transport.pemkey_filepath: esnode-key.pem plugins.security.ssl.transport.pemtrustedcas_filepath: root-ca.pem plugins.security.ssl.transport.enforce_hostname_verification: false plugins.security.ssl.http.enabled: true plugins.security.ssl.http.pemcert_filepath: esnode.pem plugins.security.ssl.http.pemkey_filepath: esnode-key.pem plugins.security.ssl.http.pemtrustedcas_filepath: root-ca.pem plugins.security.allow_unsafe_democertificates: true plugins.security.allow_default_init_securityindex: true plugins.security.authcz.admin_dn: ['CN=kirk,OU=client,O=client,L=test,C=de'] plugins.security.audit.type: internal_opensearch plugins.security.enable_snapshot_restore_privilege: true plugins.security.check_snapshot_restore_write_privileges: true plugins.security.restapi.roles_enabled: [all_access, security_rest_api_access] plugins.security.system_indices.enabled: true plugins.security.system_indices.indices: [.plugins-ml-agent, .plugins-ml-config, .plugins-ml-connector, .plugins-ml-controller, .plugins-ml-model-group, .plugins-ml-model, .plugins-ml-task, .plugins-ml-conversation-meta, .plugins-ml-conversation-interactions, .plugins-ml-memory-meta, .plugins-ml-memory-message, .plugins-ml-stop-words, .opendistro-alerting-config, .opendistro-alerting-alert*, .opendistro-anomaly-results*, .opendistro-anomaly-detector*, .opendistro-anomaly-checkpoints, .opendistro-anomaly-detection-state, .opendistro-reports-*, .opensearch-notifications-*, .opensearch-notebooks, .opensearch-observability, .ql-datasources, .opendistro-asynchronous-search-response*, .replication-metadata-store, .opensearch-knn-models, .geospatial-ip2geo-data*, .plugins-flow-framework-config, .plugins-flow-framework-templates, .plugins-flow-framework-state, .plugins-search-relevance-experiment, .plugins-search-relevance-judgment-cache] node.max_local_storage_nodes: 3 |
| -Xms4g -Xmx4g |
| curl -XGET https://<ip-node>:9200/_cat/nodes?v -u 'admin:<custom-admin-password>' --insecure |
Dashboard node (Opensearch Dashboard):
Node này chỉ hiển thị Dashboard lấy dữ liệu từ cluster Opensearch.Cập nhật danh sách gói phần mềm hệ thống và cài package cần thiết:
| sudo apt-get update && sudo apt-get -y install lsb-release ca-certificates curl gnupg2 |
| curl -o- https://artifacts.opensearch.org/publickeys/opensearch-release.pgp | sudo gpg --dearmor --batch --yes -o /etc/apt/keyrings/opensearch-release-keyring |
| echo "deb [signed-by=/etc/apt/keyrings/opensearch-release-keyring] https://artifacts.opensearch.org/releases/bundle/opensearch-dashboards/3.x/apt stable main" | sudo tee /etc/apt/sources.list.d/opensearch-dashboards-3.x.list |
| sudo apt-get update |
| sudo apt-get install opensearch-dashboards=3.3.0 |
| server.port: 5601 server.host: "0.0.0.0" server.name: "poptech" opensearch.hosts: ["https://10.30.194.181:9200", "https://10.30.194.182:9200", "https://10.30.194.183:9200"] opensearch.username: "admin" opensearch.password: "<custom-admin-password>" opensearch.ssl.verificationMode: none opensearch.requestHeadersWhitelist: [authorization, securitytenant] opensearch_security.multitenancy.enabled: true opensearch_security.multitenancy.tenants.preferred: [Private, Global] opensearch_security.readonly_mode.roles: [kibana_read_only] opensearch_security.cookie.secure: false |
| sudo systemctl enable opensearch-dashboards sudo systemctl start opensearch-dashboards |
Manager node (Wazuh Manager + Vector):
Để 2 Wazuh Manager cùng quản lý các agent và đảm bảo tính dự phòng (HA), phải cấu hình chúng theo mô hình Wazuh Cluster (1 Master - 1 Worker).- Node 1 (Master): Quản lý cơ sở dữ liệu khóa của Agent (client.keys), đồng bộ rule/conf xuống Worker, thu thập log từ agent.
- Node 2 (Worker): Lấy dữ liệu khóa của Agent, thu thập log agent.
Chi tiết triển khai
Cài Wazuh Manager:
Cài các package cần thiết:| sudo apt-get install gnupg apt-transport-https curl -s https://packages.wazuh.com/key/GPG-KEY-WAZUH | gpg --no-default-keyring --keyring gnupg-ring:/usr/share/keyrings/wazuh.gpg --import && chmod 644 /usr/share/keyrings/wazuh.gpg echo "deb [signed-by=/usr/share/keyrings/wazuh.gpg] https://packages.wazuh.com/4.x/apt/ stable main" | tee -a /etc/apt/sources.list.d/wazuh.list apt-get update apt-get -y install wazuh-manager apt-get -y install filebeat |
| curl -so /etc/filebeat/filebeat.yml https://packages.wazuh.com/4.12/tpl/wazuh/filebeat/filebeat.yml |
| <alerts_log>no</alerts_log> <logall>no</logall> <logall_json>yes</logall_json> |
Khởi động Wazuh manager:
| systemctl daemon-reload systemctl enable wazuh-manager systemctl start wazuh-manager |
| openssl rand -hex 16 |
Chỉnh lại cấu hình /var/ossec/etc/ossec.conf để cấu hình cluster:
| <cluster> <name>wazuh</name> <node_name>master-node</node_name> <node_type>master</node_type> <key>c98b62a9b6169ac5f67dae55ae4a9088</key> <port>1516</port> <bind_addr>0.0.0.0</bind_addr> <nodes> <node>10.30.194.185</node> </nodes> <hidden>no</hidden> <disabled>no</disabled> </cluster> |
- Địa chỉ IP trong <node> là địa chỉ IP của node Master.
- <key> là 32 ký tự tạo ở trên
| systemctl restart wazuh-manager |
Chỉnh lại cấu hình /var/ossec/etc/ossec.conf để cấu hình cluster:
| <cluster> <name>wazuh</name> <node_name>worker-node01</node_name> <node_type>worker</node_type> <key>c98b62a9b6169ac5f67dae55ae4a9088</key> <port>1516</port> <bind_addr>0.0.0.0</bind_addr> <nodes> <node>10.30.194.185</node> </nodes> <hidden>no</hidden> <disabled>no</disabled> </cluster> |
| systemctl restart wazuh-manager |
| /var/ossec/bin/cluster_control -l |
Cài Vector:
Cài Vector trên cả 2 node:| bash -c "$(curl -L https://setup.vector.dev)" sudo apt-get install vector |
| sources: wazuh_logs: type: file include: - "/var/ossec/logs/archives/archives.json" ignore_older: 0 transforms: parse_logs: type: remap inputs: ["wazuh_logs"] source: | . = parse_json!(string!(.message)) .index_name = "manager1" sinks: to_nginx_lb: type: http inputs: ["parse_logs"] uri: "http://10.30.194.200:9000" encoding: codec: "json" |
Thêm user vector vào group wazuh để đọc được log trong file:
| sudo usermod -aG wazuh vector |
| sudo systemctl enable vector sudo systemctl start vector |
Node Pipeline (Vector + Keepalived):
Giới thiệu về cơ chế HA:Giải pháp HA active-passive dựa trên keepalived và sử dụng giao thức VRRP (Virtual Router Redundancy Protocol). Sau khi cài đặt gói nginx-ha-keepalived và cấu hình keepalived, gói này sẽ chạy riêng biệt trên mỗi máy chủ NGINX trong cụm và quản lý một địa chỉ IP ảo dùng chung, toàn bộ server sẽ dùng chinh VIP và gia nhập vào một nhóm multicast (nhóm này dùng để gửi nhận các gói tin quảng bá VRRP).
Keepalived chỉ định một địa chỉ “chính” (MASTER) và gán địa chỉ IP ảo cho nó. Bản chính chịu trách nhiệm gửi gói tin quảng bá VRRP đến bản “sao lưu” (BACKUP) theo định kỳ, xác nhận rằng bản sao lưu vẫn hoạt động bình thường và đã xác minh rằng cả keepalived và NGINX đều đang chạy. Nếu bản sao lưu không nhận được ba quảng bá liên tiếp, nó sẽ trở thành bản chính mới và chiếm địa chỉ IP ảo.
Chi tiết triển khai:
Cài và cấu hình nginx:| sudo apt-get update sudo apt-get install nginx keepalived -y |
Chọn node 10.30.194.187 làm MASTER:
| vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 55 priority 150 advert_int 1 unicast_src_ip 10.30.194.187 unicast_peer { 10.30.194.188 } authentication { auth_type PASS auth_pass <custom-admin-password> } virtual_ipaddress { 10.30.194.200/24 } } |
| vrrp_instance VI_1 { state BACKUP interface ens33 virtual_router_id 55 priority 100 advert_int 1 unicast_src_ip 10.30.194.188 unicast_peer { 10.30.194.187 } authentication { auth_type PASS auth_pass <custom-admin-password> } virtual_ipaddress { 10.30.194.200/24 } } |
- vrrp_instance: thông tin chi tiết về một server trong nhóm dùng chung VRRP
- state (MASTER | BACKUP): chỉ trạng thái MASTER hoặc BACKUP được sử dụng bởi máy chủ.
- interface: chỉ định cổng mạng sẽ sử dụng trong hoạt động VRRP
- virtual_router_id: là số định danh cho các router trong cùng 1 nhóm VRRP (dùng đer phân biệt nhiều phiên keepalived đang chạy trên cùng 1 interface)
- priority: chỉ định độ ưu tiên cho VRRP router (giá trị từ 0-255), priority cao nhất thì nó sẽ lad MASTER, nếu priority bằng nhau thì IP cao hơn sẽ là MASTER
- advert_int: thời gian giữa các lần gửi gói VRRP, đơn vị là 1s
- authentication: chỉ định phương thức xác thực (auth_type) và mật khẩu (auth_pass ) trong VRRP
| sudo systemctl restart keepalived sudo systemctl enable keepalived |
Tạo và chỉnh sửa file cấu hình/etc/nginx/conf.d/vector_lb.conf
| upstream vector_cluster { server 10.30.194.187:8080; server 10.30.194.188:8080; keepalive 64; } server { listen 9000; access_log off; error_log /var/log/nginx/vector_error.log warn; location / { proxy_pass http://vector_cluster; proxy_http_version 1.1; proxy_set_header Connection ""; proxy_buffering off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } |
| sudo nginx -t sudo systemctl restart nginx sudo systemctl enable nginx |
| bash -c "$(curl -L https://setup.vector.dev)" sudo apt-get install vector |
Cấu hình file /etc/vector/vector.yaml
| sources: nginx_logs: type: http_server address: 0.0.0.0:8080 transforms: parse_logs: type: remap inputs: ["nginx_logs"] source: | . = parse_json!(string!(.message)) sinks: to_opensearch: type: elasticsearch inputs: ["parse_logs"] endpoints: - "https://10.30.194.181:9200" - "https://10.30.194.182:9200" - "https://10.30.194.183:9200" api_version: "v7" bulk: index: "{{ index_name }}" request: concurrency: 2 auth: strategy: basic user: admin password: "<custom-admin-password>" tls: verify_certificate: false verify_hostname: false |
| sudo systemctl enable vector sudo systemctl start vector |
Bài viết liên quan
Được quan tâm
Bài viết mới