dnf install mariadb-server -y
systemctl start mariadb
systemctl enable mariadb
mysql
create database metabasedb;
create user metabaseuser@'localhost' identified by 'password';
grant all on metabasedb.* to metabaseuser@'localhost' with grant option;
flush privileges;
exit
nano /etc/systemd/system/metabase.service
#Thêm dòng
[Unit]
Description=Metabase server
After=syslog.target
After=network.target
[Service]
WorkingDirectory=/var/metabase
ExecStart=/usr/bin/java -jar /var/metabase/metabase.jar
ExecReload=/usr/bin/kill -HUP $MAINPID
EnvironmentFile=/etc/default/metabase
User=metabase
Type=simple
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=metabase
SuccessExitStatus=143
TimeoutStopSec=120
Restart=always
[Install]
WantedBy=multi-user.target
#Reload
systemctl daemon-reload
#Start khi reboot lại server
systemctl start metabase
systemctl enable metabase
#check status
systemctl status metabase
vào link: http://localhost:3000;
# Nếu muốn setup thành link có domain khác thì setup apache or nginx rồi dùng proxy_pass
proxy_pass http://localhost:3000;
#Ví dụ Nginx:
server {
listen 80;
server_name yourdomain.com;
return 301 https://$server_name$request_uri;
}
server {
include ssl/xxxx;
server_name yourdomain.com;
client_max_body_size 20M;
location / {
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:3000;
}
}
==============Install Mongod=====================
#Install Mongod trên server để lưu log
vi /etc/mongod.conf
#comment lại để tạo acc mới
#security:
# authorization: enabled
#Restart mongo
systemctl restart mongod
#connect vào Mongod
mongo localhost:27017
#checkdata:
show dbs
#dropDB
use db_name
db.dropDatabase();
#createDB
db = db.getSiblingDB('db_name')
#createUser
use db_name;
db.createUser({user:"user_name",pwd:"password",roles:[{ role: "readWrite", db: "db_name" }]});
#dropUser
db.dropUser("user_name", {w: "majority", wtimeout: 5000});
#List all collections
show collections
#createCollection
db.createCollection("collection_name")
#dropCollection
db.collection_name.drop()
#connect Mongod by user
mongo -u user_name localhost:27017/db_name
use db_name
# check log
less /var/log/mongodb/mongod.log
===============Setup td-agent=====================
# Check OS để chọn phiên bản cho phù hợp: https://docs.fluentd.org/installation/before-install
cat /etc/os-release
hoặc
lsb_release -a
# Có nhiều cách setup fluenttd dưới đây là cách install
# Cách setup qua Ruby https://docs.fluentd.org/installation/install-by-gem
Sau khi cài theo hướng dẫn cần tạo file service để khởi động cùng daemon
#Check link service được setup từ đâu (VD: /opt/fluent/bin/fluentd)
systemctl status fluentd.service
#Tạo file serveice(thay đổi đường dẫn /opt/fluent/bin/fluentd nếu bên trên check )
vi /etc/systemd/system/fluentd.service
[Unit]
Description=Fluentd Service
After=network.target
[Service]
Type=simple
ExecStart=/opt/fluent/bin/fluentd -c /etc/fluent/fluentd.conf -vv
Restart=on-failure
User=root
Group=root
[Install]
WantedBy=multi-user.target
#Sau khi xong thì Run
systemctl daemon-reload
systemctl restart fluentd.service
systemctl status fluentd.service
# Setup td-agent(version 0.12) qua Package của hệ điều hành đối với version fluent lớn hơn cũng tương tự
install: curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent2.5.sh | sh
check status
chkconfig td-agent on
/etc/init.d/td-agent status
/etc/init.d/td-agent restart
===============Config td-agent=====================
# Config td-agent để chạy với quyền root
vi /etc/init.d/td-agent
Change to:
TD_AGENT_USER=root
TD_AGENT_GROUP=root
=================td-agent.conf server===================
# Config td-agent Server chính nhận log
less /etc/td-agent/td-agent.conf
# local logging
type tail
path /var/log/httpd/mng_access_log.%Y%m%d
pos_file /var/log/td-agent/httpd-access_log.pos
tag mng.apache.access
format /^\[(?
type mongo
database xxxxx(tự đặt)
user xxxxx(tự đặt)
password xxxxx(tự đặt)
collection mng_apache_access
host localhost:27017
capped
capped_size 1024m
flush_interval 10s
# remote logging
type forward
port 24224
include web1_access.conf
# Sửa file web1_access.conf
vi /etc/td-agent/web1_access.conf
type mongo
database xxxxx(tự đặt)
user xxxxx(tự đặt)
password xxxxx(tự đặt)
collection collection_name(web1_access)
host localhost:27017
capped
capped_size 1024m
flush_interval 10s
=======================================================================
Các server Client khác thì setup
=================td-agent.conf Client===================
1. Setup td-agent như server chính
2. Config td-ganet Client
# Cách phân tích format log để lấy dữ liệu
vi /etc/td-agent/td-agent.conf
type tail
path /var/log/httpd/ssl_web01_access_log.%Y%m%d
pos_file /var/log/td-agent/httpd-access_log.pos
tag web1_access.apache.access
format /^\[(?
# Cách dùng parse để phân tích log lấy dữ liệu
vi /etc/td-agent/td-agent.conf
type tail
path /var/log/httpd/ssl_web01_access_log.%Y%m%d
pos_file /var/log/td-agent/httpd-access_log.pos
tag web1_access.apache.access
time_format %d/%b/%Y:%H:%M:%S %z
expression /^\[(?
# Cách dùng parse để phân tích log lấy dữ liệu json
# https://betterstack.com/community/guides/logging/fluentd-explained/
vi /etc/td-agent/td-agent.conf
type tail
path /var/log/httpd/ssl_web01_access_log.%Y%m%d
pos_file /var/log/td-agent/httpd-access_log.pos
tag web1_access.apache.access
time_format %d/%b/%Y:%H:%M:%S %z
expression /^\[(?
# cách dùng parse json
format none
@type json
@type record_transformer
enable_ruby true
remove_keys emailAddress
hostname "#{Socket.gethostname}"
timestamp ${Time.at(record["timestamp"]).strftime("%Y-%m-%dT%H:%M:%S.%L%z")}
is_successful ${record["status"] == 200 ? "true" : "false"}
ip ${record["ip"].gsub(/(\d+\.\d+\.\d+\.\d+)/, 'REDACTED')}
ssn ${record["ssn"].gsub(/(\d{3}-\d{2}-\d{4})/, 'REDACTED')}
type forward
host 192.168.245.71(ip của server chính phía trên)
port 24224
#check log
tail -f -n100 /var/log/td-agent/td-agent.log
Câu hỏi/câu trả lời này có giải quyết được sự cố của bạn không?
Cảm ơn bạn đã trả lời.