# Linux中如何安裝使用Open-Falcon Agent
## 一、Open-Falcon簡介
Open-Falcon是小米公司開源的一款企業級監控系統,具有以下核心特點:
- 分布式架構設計,支持水平擴展
- 高性能數據采集和處理能力
- 靈活的告警策略配置
- 豐富的可視化功能
- 支持多種數據采集方式
Agent是Open-Falcon監控體系中的數據采集終端,負責:
1. 定期采集主機指標數據(CPU、內存、磁盤等)
2. 執行用戶自定義的監控腳本
3. 將采集數據上報給Transfer組件
## 二、環境準備
### 2.1 系統要求
- 操作系統:主流Linux發行版(CentOS 7+/Ubuntu 16.04+)
- 硬件配置:
- 最低配置:1核CPU/512MB內存
- 推薦配置:2核CPU/2GB內存
- 網絡要求:
- 能訪問Open-Falcon的Transfer服務(默認端口:8433)
### 2.2 依賴安裝
```bash
# CentOS/RHEL
sudo yum install -y git wget curl tar
# Ubuntu/Debian
sudo apt-get update
sudo apt-get install -y git wget curl tar
官方提供兩種安裝方式:
方式一:直接下載二進制包
wget https://github.com/open-falcon/falcon-plus/releases/download/v0.3/open-falcon-v0.3.tar.gz
tar -zxvf open-falcon-v0.3.tar.gz
cd open-falcon-v0.3/
方式二:源碼編譯安裝
git clone https://github.com/open-falcon/falcon-plus.git
cd falcon-plus
make agent
cd open-falcon
修改配置文件agent/config/cfg.json:
{
"debug": true,
"hostname": "", // 自動獲取主機名,建議保持為空
"ip": "", // 自動獲取IP地址
"plugin": {
"enabled": true,
"dir": "./plugin", // 插件目錄
"git": "https://github.com/open-falcon/plugin.git",
"logs": "./logs"
},
"heartbeat": {
"enabled": true,
"addr": "127.0.0.1:6030", // 修改為實際HBS地址
"interval": 60,
"timeout": 1000
},
"transfer": {
"enabled": true,
"addrs": [
"127.0.0.1:8433" // 修改為實際Transfer地址
],
"interval": 60,
"timeout": 1000
}
}
關鍵配置項說明:
- hostname: 建議保持為空,agent會自動獲取
- transfer.addrs: 必須配置為實際的Transfer服務地址
- heartbeat.addr: 配置為HBS服務地址
前臺啟動(測試用):
./agent/bin/falcon-agent -c ./agent/config/cfg.json
后臺啟動(生產環境):
./agent/bin/falcon-agent -c ./agent/config/cfg.json &> agent.log &
檢查進程:
ps aux | grep falcon-agent
檢查端口(默認1988):
netstat -tlnp | grep falcon-agent
測試數據采集:
curl http://127.0.0.1:1988/health
mkdir -p plugin/nginx
vim plugin/nginx/nginx_status.sh
腳本內容:
#!/bin/bash
# 獲取Nginx進程數
count=$(ps aux | grep nginx | grep -v grep | wc -l)
echo -e "nginx.process.num\t$count"
chmod +x plugin/nginx/nginx_status.sh
修改plugin/config/plugin.json:
{
"plugins": [
{
"name": "nginx",
"filePath": "nginx/nginx_status.sh",
"params": [],
"schedule": {
"cron": "*/30 * * * * *",
"startDelay": 10
}
}
]
}
Agent日志默認位置:
- 運行日志:./logs/agent.log
- 插件日志:./logs/plugin/*.log
日志輪轉配置(使用logrotate):
sudo vim /etc/logrotate.d/falcon-agent
添加內容:
/opt/open-falcon/agent/logs/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
create 0640 root root
}
啟動服務:
./open-falcon start agent
停止服務:
./open-falcon stop agent
重啟服務:
./open-falcon restart agent
檢查版本:
./agent/bin/falcon-agent -v
查看運行狀態:
./agent/bin/falcon-agent -h
開啟調試日志:
./agent/bin/falcon-agent -c ./agent/config/cfg.json -d
telnet transfer_host 8433
logs/plugin/*.log
"interval": 60 # 單位:秒
主機命名規范:
監控策略:
安全建議:
性能優化:
wget https://github.com/open-falcon/falcon-plus/releases/download/v0.3.1/open-falcon-v0.3.1.tar.gz
./open-falcon stop agent
cp -r agent/config /tmp/agent_config_backup
tar -zxvf open-falcon-v0.3.1.tar.gz
cp /tmp/agent_config_backup/* new_version/agent/config/
./open-falcon start agent
Open-Falcon Agent作為監控系統的數據采集終端,具有以下優勢: - 輕量級設計,資源占用低 - 支持插件機制,擴展性強 - 配置簡單,易于維護
通過本文介紹的安裝配置方法,您可以快速搭建起主機監控體系。實際生產環境中,建議結合業務需求調整監控策略,并建立完善的告警機制。
注意:本文基于Open-Falcon v0.3版本編寫,不同版本配置可能略有差異,請以官方文檔為準。 “`
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。