文章目錄
一、主機準備
操作系統
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
主機名 | IP | 服務 |
---|---|---|
nginx_master | 192.168.1.171 | Nginx、open-falcon-agent |
nginx_backup | 192.168.1.172 | Nginx、open-falcon-agent、 |
tomcat_server1 | 192.168.1.173 | Tomcat、open-falcon-agent、Redis |
tomcat_server2 | 192.168.1.174 | Tomcat、open-falcon-agent、MySQL |
open-falcon_server | 192.168.1.175 | open-falcon-server |
二、參考文檔
官方文檔
官方中文社區
運維監控系統之Open-Falcon
運維監控系統之Open-Falcon
小米運維架構服務監控Open-Falcon
三 、環境配置
3.1 配置阿里YUM源、安裝基本工具
yum install -y wget \
&& mkdir -p /etc/yum.repos.d/repo_bak \
&& mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/repo_bak/ \
&& wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo \
&& wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo \
&& yum install -y vim git net-tools lrzsz ntp unzip \
&& yum makecache && yum clean all
3.2 關閉防火牆、Selinux
# 關閉防火牆
systemctl stop firewalld && systemctl disable firewalld
# 關閉Selinux
setenforce 0 && sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
3.3 修改主機名
hostnamectl set-hostname open-falcon_server && echo "192.168.1.175 open-falcon_server" >> /etc/hosts
3.4 配置時間同步
關閉chrony服務
systemctl stop chronyd && systemctl disable chronyd
設置NTP服務
vim /etc/ntp.conf
# 將時鐘服務器更改爲如下4個
server 0.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 3.cn.pool.ntp.org
啓動時間同步服務器
systemctl start ntpd \
&& systemctl enable ntpd \
&& ntpdate -u 0.cn.pool.ntp.org \
&& hwclock --systohc \
&& date
3.5 安裝go環境
yum install -y golang && go version
3.6 安裝pip環境
wget https://bootstrap.pypa.io/get-pip.py
# 這一步ERROR報錯的話多試幾次
python get-pip.py
3.7 安裝Redis
yum install -y redis \
&& systemctl start redis \
&& systemctl enable redis
3.8 安裝Mariadb
yum安裝mariadb
yum install -y mariadb mariadb-server \
&& systemctl start mariadb \
&& systemctl enable mariadb
導入open-falcon數據庫
mkdir -p /home/work/open-falcon \
&& cd /home/work/open-falcon \
&& git clone https://github.com/open-falcon/falcon-plus.git
執行MySQL腳本
cd ./scripts/mysql/db_schema/
mysql -h 127.0.0.1 -u root -p < 1_uic-db-schema.sql
mysql -h 127.0.0.1 -u root -p < 2_portal-db-schema.sql
mysql -h 127.0.0.1 -u root -p < 3_dashboard-db-schema.sql
mysql -h 127.0.0.1 -u root -p < 4_graph-db-schema.sql
mysql -h 127.0.0.1 -u root -p < 5_alarms-db-schema.sql
# 查看數據庫
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| alarms |
| dashboard |
| falcon_portal |
| graph |
| mysql |
| performance_schema |
| test |
| uic |
+--------------------+
9 rows in set (0.00 sec)
設置數據庫密碼
mysqladmin -uroot password "123456"
四、安裝後端
4.1 下載安裝包
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 -C /home/work/open-falcon/
4.2 修改配置文件
每個模塊都修改連接數據庫的配置
模塊 | 路徑 |
---|---|
aggregator | ./aggregator/config/cfg.json |
graph | ./graph/config/cfg.json |
hbs | ./hbs/config/cfg.json |
nodata | ./nodata/config/cfg.json |
api | ./api/config/cfg.json |
alarm | ./alarm/config/cfg.json |
快捷修改腳本
sed -i 's#root:@tcp(127.0.0.1:3306)#root:123456@tcp(127.0.0.1:3306)#g' `find ./ -type f -name "cfg.json"|egrep "alarm|api|nodata|hbs|graph|aggregator"`
查看是否修改成功
cat `find ./ -type f -name "cfg.json"|egrep "alarm|api|nodata|hbs|graph|aggregator"` |grep 'root:123456@tcp(127.0.0.1:3306)'
顯示如下內容
"addr": "root:123456@tcp(127.0.0.1:3306)/falcon_portal?loc=Local&parseTime=true",
"dsn": "root:123456@tcp(127.0.0.1:3306)/graph?loc=Local&parseTime=true",
"database": "root:123456@tcp(127.0.0.1:3306)/falcon_portal?loc=Local&parseTime=true",
"dsn": "root:123456@tcp(127.0.0.1:3306)/falcon_portal?loc=Local&parseTime=true&wait_timeout=604800",
"falcon_portal": "root:123456@tcp(127.0.0.1:3306)/falcon_portal?charset=utf8&parseTime=True&loc=Local",
"graph": "root:123456@tcp(127.0.0.1:3306)/graph?charset=utf8&parseTime=True&loc=Local",
"uic": "root:123456@tcp(127.0.0.1:3306)/uic?charset=utf8&parseTime=True&loc=Local",
"dashboard": "root:123456@tcp(127.0.0.1:3306)/dashboard?charset=utf8&parseTime=True&loc=Local",
"alarms": "root:123456@tcp(127.0.0.1:3306)/alarms?charset=utf8&parseTime=True&loc=Local",
"addr": "root:123456@tcp(127.0.0.1:3306)/alarms?charset=utf8&loc=Local",
4.3 啓動
使用腳本啓動
[root@open-falcon_server open-falcon]# ./open-falcon start
[falcon-graph] 28776
[falcon-hbs] 28787
[falcon-judge] 28798
[falcon-transfer] 28805
[falcon-nodata] 28814
[falcon-aggregator] 28823
[falcon-agent] 28833
[falcon-gateway] 28843
[falcon-api] 28852
[falcon-alarm] 28867
使用腳本檢查
[root@open-falcon_server open-falcon]# ./open-falcon check
falcon-graph UP 28776
falcon-hbs UP 28787
falcon-judge UP 28798
falcon-transfer UP 28805
falcon-nodata UP 28814
falcon-aggregator UP 28823
falcon-agent UP 28833
falcon-gateway UP 28843
falcon-api UP 28852
falcon-alarm UP 28867
更多命令行工具用法
./open-falcon [start|stop|restart|check|monitor|reload] module
啓動agent監控自身主機
[root@localhost open-falcon]# ./open-falcon start agent
[falcon-agent] 8357
五、安裝前端
5.1 下載前端代碼
mkdir - p /home/work/dashboard
cd /home/work/dashboard
git clone https://github.com/open-falcon/dashboard.git
5.2 安裝依賴包
cd /home/work/dashboard/dashboard \
&& yum install -y python-virtualenv python-devel openldap-devel mysql-devel \
&& yum groupinstall -y "Development tools" \
&& virtualenv ./env \
&& ./env/bin/pip install -r pip_requirements.txt -i https://pypi.douban.com/simple
5.4 修改配置
修改數據庫連接密碼,dashboard的配置文件爲: 'rrd/config.py'
## API_ADDR 表示後端api組件的地址
API_ADDR = "http://127.0.0.1:8080/api/v1"
5.5 啓動前端
[root@open-falcon_server dashboard-master]# ./control start
falcon-dashboard started..., pid=32055
[root@open-falcon_server dashboard-master]# ./control tail
[2020-03-12 15:23:17 +0000] [32055] [INFO] Starting gunicorn 19.9.0
[2020-03-12 15:23:17 +0000] [32055] [INFO] Listening at: http://0.0.0.0:8081 (32055)
[2020-03-12 15:23:17 +0000] [32055] [INFO] Using worker: sync
[2020-03-12 15:23:17 +0000] [32060] [INFO] Booting worker with pid: 32060
[2020-03-12 15:23:17 +0000] [32061] [INFO] Booting worker with pid: 32061
[2020-03-12 15:23:17 +0000] [32070] [INFO] Booting worker with pid: 32070
[2020-03-12 15:23:17 +0000] [32071] [INFO] Booting worker with pid: 32071
更多命令行工具用法
./control start|stop|restart|status|tail|kill9|version|pack
登陸Web頁面:http://192.168.1.175:8081/
注意事項
dashbord沒有默認創建任何賬號包括管理賬號,需要你通過頁面進行註冊賬號。
想擁有管理全局的超級管理員賬號,需要手動註冊用戶名爲root的賬號(第一個帳號名稱爲root的用戶會被自動設置爲超級管理員)。
超級管理員可以給普通用戶分配權限管理。
小提示:註冊賬號能夠被任何打開dashboard頁面的人註冊,所以當給相關的人註冊完賬號後,需要去關閉註冊賬號功能。只需要去修改api組件的配置文件cfg.json,將signup_disable配置項修改爲true,重啓api即可。當需要給人開賬號的時候,再將配置選項改回去,用完再關掉即可。
六、監控其他主機
將後端安裝包中的agent目錄和open-falcon腳本發送到需要被監控的主機
scp -r agent/ open-falcon 192.168.1.171:/root/
登陸被監控主機
6.1 配置環境
yum install -y vim ntp
修改主機名
hostnamectl set-hostname nginx_master && echo "192.168.1.171 nginx_master" >> /etc/hosts
關閉chrony服務
systemctl stop chronyd && systemctl disable chronyd
設置NTP服務
vim /etc/ntp.conf
# 將時鐘服務器更改爲如下4個
server 0.cn.pool.ntp.org
server 1.cn.pool.ntp.org
server 2.cn.pool.ntp.org
server 3.cn.pool.ntp.org
啓動時間同步服務器
systemctl start ntpd \
&& systemctl enable ntpd \
&& ntpdate -u 0.cn.pool.ntp.org \
&& hwclock --systohc \
&& date
6.2 修改agent配置
vim agent/config/cfg.json
修改爲監控主機的IP
{
"debug": true,
"hostname": "",
"ip": "",
"plugin": {
"enabled": false,
"dir": "./plugin",
"git": "https://github.com/open-falcon/plugin.git",
"logs": "./logs"
},
"heartbeat": {
"enabled": true,
"addr": "192.168.1.175:6030",
"interval": 60,
"timeout": 1000
},
"transfer": {
"enabled": true,
"addrs": [
"192.168.1.175:8433"
],
"interval": 60,
"timeout": 1000
},
"http": {
"enabled": true,
"listen": ":1988",
"backdoor": false
},
"collector": {
"ifacePrefix": ["eth", "em"],
"mountPoint": []
},
"default_tags": {
},
"ignore": { #該項爲忽略監控項,存在ignore中的參數將不被監控
"cpu.busy": true,
"df.bytes.free": true,
"df.bytes.total": true,
"df.bytes.used": true,
"df.bytes.used.percent": true,
"df.inodes.total": true,
"df.inodes.free": true,
"df.inodes.used": true,
"df.inodes.used.percent": true,
"mem.memtotal": true,
"mem.memused": true,
"mem.memused.percent": true,
"mem.memfree": true,
"mem.swaptotal": true,
"mem.swapused": true,
"mem.swapfree": true
}
}
6.3 啓動服務
[root@localhost ~]# ./open-falcon start agent
[falcon-agent] 7538
# 停止進程
./open-falcon stop agent
# 查看日誌
./open-falcon monitor agent