在CentOS 7上搭建日志服務器可以使用Elasticsearch、Logstash和Kibana(ELK)組合來實現。下面是一個簡單的步驟:
sudo yum install java-1.8.0-openjdk
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
sudo yum install https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.15.0-x86_64.rpm
sudo systemctl enable elasticsearch
sudo systemctl start elasticsearch
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
sudo yum install https://artifacts.elastic.co/downloads/logstash/logstash-7.15.0-x86_64.rpm
創建一個配置文件 /etc/logstash/conf.d/logstash.conf
,內容如下:
input {
file {
path => "/var/log/messages"
start_position => "beginning"
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
index => "logs-%{+YYYY.MM.dd}"
}
}
啟動Logstash服務:
sudo systemctl enable logstash
sudo systemctl start logstash
sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
sudo yum install https://artifacts.elastic.co/downloads/kibana/kibana-7.15.0-x86_64.rpm
編輯配置文件 /etc/kibana/kibana.yml
,修改以下內容:
server.host: "0.0.0.0"
elasticsearch.hosts: ["http://localhost:9200"]
啟動Kibana服務:
sudo systemctl enable kibana
sudo systemctl start kibana
現在,你已經成功搭建了一個基本的ELK日志服務器。你可以通過瀏覽器訪問Kibana的Web界面(默認端口為5601),來查看和分析收集到的日志數據。