參考博主:努力哥完成html
一、監控系統,能夠從運營級別(基本配置便可),以及應用級別(二次開發,經過端口進行日誌上報),對服務器、操做系統、中間件、應用進行全面的監控,及報警,對咱們的系統正常運行的做用很是重要。前端
二、基礎監控java
CPU、Load、內存、磁盤、IO、網絡相關、內核參數、ss 統計輸出、端口採集、核心服務的進程存活信息採集、關鍵業務進程資源消耗、NTP offset採集、DNS解析採集,這些指標,都是open-falcon的agent組件直接支持的。python
Linux運維基礎採集項:http://book.open-falcon.org/zh/faq/linux-metrics.htmlmysql
對於這些基礎監控選項所有理解透徹的時刻,也就是對Linux運行原理及命令進階的時刻。linux
三、第三方監控ios
術業有專攻,運行在OS上的應用甚多,Open-Falcon的開發團隊不可能把全部的第三方應用的監控所有作完,這個就須要開源社區提供更多的插件,當前對於不少經常使用的第三方應用都有相關插件了。git
四、JVM監控github
對於Java做爲主要開發語言的大多數公司,對於JVM的監控不可或缺。golang
每一個JVM應用的參數,好比GC、類加載、JVM內存、進程、線程,均可以上報給Falcon,而這些參數的得到,均可以經過MxBeans實現。
使用 Java 平臺管理 bean:http://www.ibm.com/developerworks/cn/java/j-mxbeans/
五、業務應用監控
對於業務須要監控的接口,好比響應時間等。能夠根據業務的須要,上報相關數據到Falcon,並經過Falcon查看結果。
說明:Open-Falcon部署分爲前端(客戶端)和後端(服務端)
參考官方文檔:https://book.open-falcon.org/zh_0_2/quick_install/prepare.html
[root@open-falcon-server ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
#安裝下載軟件
yum install wget -y
#更換aliyun源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
#下載epel源
yum install epel-release.noarch -y rpm -Uvh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm yum clean all yum makecache
#下載經常使用軟件
yum install git telnet net-tools tree nmap sysstat lrzsz dos2unix tcpdump ntpdate -y
#配置時間同步
ntpdate cn.pool.ntp.org
#更改主機名
hostnamectl set-hostname open-falcon-server hostname open-falcon-server
#開啓緩存
sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf grep keepcache /etc/yum.conf
#關閉selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0
#關閉防火牆
systemctl stop firewalld.service systemctl disable firewalld.service
三、軟件環境準備
#安裝 redis
yum install redis -y
#redis經常使用命令
redis-server redis 服務端 redis-cli redis 命令行客戶端 redis-benchmark redis 性能測試工具 redis-check-aof AOF文件修復工具 redis-check-dump RDB文件修復工具 redis-sentinel Sentinel 服務端
#啓動redis
[root@localhost ~]# redis-server & [1] 3222 [root@localhost ~]# 3222:C 26 Feb 15:19:31.280 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf 3222:M 26 Feb 15:19:31.280 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.2.10 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 3222 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-'
[root@localhost ~]# netstat -lntup|grep red tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 3222/redis-server * tcp6 0 0 :::6379 :::* LISTEN 3222/redis-server *
#安裝mysql
[root@open-falcon-server ~]#wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
[root@open-falcon-server ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm
[root@open-falcon-server ~]#yum install -y mysql-server
#啓動mysql並設置開機自啓動
[root@open-falcon-server ~]# systemctl start mysqld.service [root@open-falcon-server ~]# systemctl enable mysqld.service
#檢查3306端口
[root@open-falcon-server ~]# netstat -lntup|grep 3306
cd /tmp/ && git clone https://github.com/open-falcon/falcon-plus.git cd /tmp/falcon-plus/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 rm -rf /tmp/falcon-plus/
#設置數據庫密碼 (備註:用戶名:root ,密碼: password )
[root@open-falcon-server open-falcon]# mysqladmin -uroot password "password" Warning: Using a password on the command line interface can be insecure.
#檢查導入的數據表
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | alarms | | dashboard | | falcon_portal | | graph | | mysql | | performance_schema | | uic | +--------------------+ 8 rows in set (0.00 sec)
#安裝go語言開發包(備註:安裝須要epel源)
yum install golang -y
#檢查版本
[root@open-falcon-server ~]# go version go version go1.8.3 linux/amd64
#查看go的安裝路徑
[root@open-falcon-server ~]# find / -name go /etc/alternatives/go /var/lib/alternatives/go /usr/bin/go /usr/lib/golang/src/cmd/go #須要的是這個路徑 /usr/lib/golang/src/go /usr/lib/golang/bin/go /usr/lib/golang/pkg/linux_amd64/go
#設置環境變量GOROOT和GOPATH
export GOROOT=/usr/lib/golang export GOPATH=/home
直接下載官方編譯好的二進制版本(x86 64位平臺)。
#開始安裝open-falcon
[root@open-falcon-server ~]# export FALCON_HOME=/home/work [root@open-falcon-server ~]# export WORKSPACE=$FALCON_HOME/open-falcon [root@open-falcon-server ~]# mkdir -p $WORKSPACE
#上傳軟件 [root@open-falcon-server ~]# ll -rw-r--r--. 1 root root 40031472 Oct 29 2017 open-falcon-v0.2.1.tar.gz #解壓 [root@open-falcon-server ~]# tar -xf open-falcon-v0.2.1.tar.gz -C $WORKSPACE [root@open-falcon-server ~]# cd $WORKSPACE <br>#查看解壓結果 [root@open-falcon-server open-falcon]# ll total 3896 drwxrwxr-x. 7 501 501 67 Aug 15 19:16 agent drwxrwxr-x. 5 501 501 40 Aug 15 19:16 aggregator drwxrwxr-x. 5 501 501 40 Aug 15 19:16 alarm drwxrwxr-x. 6 501 501 51 Aug 15 19:16 api drwxrwxr-x. 5 501 501 40 Aug 15 19:16 gateway drwxrwxr-x. 6 501 501 51 Aug 15 19:16 graph drwxrwxr-x. 5 501 501 40 Aug 15 19:16 hbs drwxrwxr-x. 5 501 501 40 Aug 15 19:16 judge drwxrwxr-x. 5 501 501 40 Aug 15 19:16 nodata -rwxrwxr-x. 1 501 501 3987469 Aug 15 19:16 open-falcon lrwxrwxrwx. 1 501 501 16 Aug 15 19:16 plugins -> ./agent/plugins/ lrwxrwxrwx. 1 501 501 15 Aug 15 19:16 public -> ./agent/public/ drwxrwxr-x. 5 501 501 40 Aug 15 19:16 transfer
坑:
部分模塊依賴鏈接數據庫,由於若是不修改配置文件,aggregator模塊會出現沒法啓動,graph、hbs、nodata、api、alarm模塊會出現開啓不報錯可是狀態爲開啓失敗的狀況。
若是須要每一個模塊都能正常啓動,須要將上面模塊的cfg.json的數據庫信息進行修改。根據本教程的配置,須要修改配置文件所在的目錄:
模塊 | 配置文件所在路徑 |
aggregator | /home/work/open-falcon/aggregator/config/cfg.json |
graph | /home/work/open-falcon/graph/config/cfg.json |
hbs | /home/work/open-falcon/hbs/config/cfg.json |
nodata | /home/work/open-falcon/nodata/config/cfg.json |
api | /home/work/open-falcon/api/config/cfg.json |
alarm | /home/work/open-falcon/alarm/config/cfg.json |
vim /home/work/open-falcon/aggregator/config/cfg.json
mysql的root密碼爲空,則去掉「password」,若不爲空,則用root密碼替換「password」。
vim /home/work/open-falcon/graph/config/cfg.json
mysql的root密碼爲空,則去掉「password」,若不爲空,則用root密碼替換「password」。
vim /home/work/open-falcon/hbs/config/cfg.json
mysql的root密碼爲空,則去掉「password」,若不爲空,則用root密碼替換「password」。
vim /home/work/open-falcon/nodata/config/cfg.json
mysql的root密碼爲空,則去掉「password」,若不爲空,則用root密碼替換「password」。
vim /home/work/open-falcon/api/config/cfg.json
mysql的root密碼爲空,則去掉「password」,若不爲空,則用root密碼替換「password」。
vim /home/work/open-falcon/alarm/config/cfg.json
mysql的root密碼爲空,則去掉「password」,若不爲空,則用root密碼替換「password」。
[root@open-falcon-server open-falcon]# cd /home/work/open-falcon
#啓動服務
[root@open-falcon-server open-falcon]# ./open-falcon start
#檢查服務啓動狀態
[root@open-falcon-server open-falcon]# ./open-falcon check
[root@open-falcon-server open-falcon]# ./open-falcon check
falcon-graph UP 8945
falcon-hbs UP 8954
falcon-judge UP 8962
falcon-transfer UP 8968
falcon-nodata UP 8974
falcon-aggregator UP 8981
falcon-agent UP 8989
falcon-gateway UP 8995
falcon-api UP 8999
falcon-alarm UP 9004
#更多的命令行工具用法
# ./open-falcon [start|stop|restart|check|monitor|reload] module
./open-falcon start agent
/open-falcon check falcon-graph UP 53007 falcon-hbs UP 53014 falcon-judge UP 53020 falcon-transfer UP 53026 falcon-nodata UP 53032 falcon-aggregator UP 53038 falcon-agent UP 53044 falcon-gateway UP 53050 falcon-api UP 53056 falcon-alarm UP 53063
至此後端部署完成。
#重載配置(備註:修改vi cfg.json配置文件後,能夠用下面命令重載配置)
curl 127.0.0.1:1988/config/reload
export HOME=/home/work export WORKSPACE=$HOME/open-falcon mkdir -p $WORKSPACE cd $WORKSPACE
git clone https://github.com/open-falcon/dashboard.git
yum install -y python-virtualenv yum install -y python-devel yum install -y openldap-devel yum install -y mysql-devel yum groupinstall "Development tools" -y
#下載ez_setup.py wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py python ez_setup.py --insecure #下載pip wget https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9 #解壓並安裝 tar xf pip-9.0.1.tar.gz cd pip-9.0.1 python setup.py install cd ..
#查看須要安裝的軟件
[root@prometheus dashboard]# vim pip_requirements.txt Flask==0.10.1 Flask-Babel==0.9 Jinja2==2.7.2 Werkzeug==0.9.4 gunicorn==19.1.1 python-dateutil==2.2 requests==2.3.0 mysql-python python-ldap
#利用pip安裝上面這些軟件
virtualenv ./env
source env/bin/activate #進入虛擬環境
[root@prometheus]# cd /home/work/open-falcon/dashboard #安裝軟件 [root@prometheus dashboard]# pip install -r pip_requirements.txt
dashboard的配置文件爲: 'rrd/config.py',請根據實際狀況修改 ## API_ADDR 表示後端api組件的地址 API_ADDR = "http://127.0.0.1:8080/api/v1" ## 根據實際狀況,修改PORTAL_DB_*, 默認用戶名爲root,默認密碼爲"" ## 根據實際狀況,修改ALARM_DB_*, 默認用戶名爲root,默認密碼爲""
#修改方法
[root@Open-Falcon-client]#cd /home/work/open-falcon/dashboard/rrd
[root@Open-Falcon-client rrd]# cp config.py config.py.bak
(env)[root@Open-Falcon-client rrd]# vi config.py
#-*-coding:utf8-*-
# Copyright 2017 Xiaomi, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#-*-coding:utf8-*-
# Copyright 2017 Xiaomi, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# app config
import
os
LOG_LEVEL = os.environ.get(
"LOG_LEVEL"
,
'DEBUG'
)
SECRET_KEY = os.environ.get(
"SECRET_KEY"
,
"secret-key"
)
PERMANENT_SESSION_LIFETIME = os.environ.get(
"PERMANENT_SESSION_LIFETIME"
,3600 * 24 * 30)
SITE_COOKIE = os.environ.get(
"SITE_COOKIE"
,
"open-falcon-ck"
)
# Falcon+ API
API_ADDR = os.environ.get(
"API_ADDR"
,
"http://10.0.0.6:8080/api/v1"
)
# portal database
# TODO: read from api instead of db
PORTAL_DB_HOST = os.environ.get(
"PORTAL_DB_HOST"
,
"10.0.0.6"
)
PORTAL_DB_PORT = int(os.environ.get(
"PORTAL_DB_PORT"
,3306))
PORTAL_DB_USER = os.environ.get(
"PORTAL_DB_USER"
,
"root"
)
PORTAL_DB_PASS = os.environ.get(
"PORTAL_DB_PASS"
,
"password"
)
PORTAL_DB_NAME = os.environ.get(
"PORTAL_DB_NAME"
,
"falcon_portal"
)
# alarm database
# TODO: read from api instead of db
ALARM_DB_HOST = os.environ.get(
"ALARM_DB_HOST"
,
"10.0.0.6"
)
ALARM_DB_PORT = int(os.environ.get(
"ALARM_DB_PORT"
,3306))
ALARM_DB_USER = os.environ.get(
"ALARM_DB_USER"
,
"root"
)
ALARM_DB_PASS = os.environ.get(
"ALARM_DB_PASS"
,
"password"
)
ALARM_DB_NAME = os.environ.get(
"ALARM_DB_NAME"
,
"alarms"
)
# ldap config
LDAP_ENABLED = os.environ.get(
"LDAP_ENABLED"
,False)
LDAP_SERVER = os.environ.get(
"LDAP_SERVER"
,
"ldap.forumsys.com:389"
)
LDAP_BASE_DN = os.environ.get(
"LDAP_BASE_DN"
,
"dc=example,dc=com"
)
LDAP_BINDDN_FMT = os.environ.get(
"LDAP_BINDDN_FMT"
,
"uid=%s,dc=example,dc=com"
)
LDAP_SEARCH_FMT = os.environ.get(
"LDAP_SEARCH_FMT"
,
"uid=%s"
)
LDAP_ATTRS = [
"cn"
,
"mail"
,
"telephoneNumber"
]
LDAP_TLS_START_TLS = False
LDAP_TLS_CACERTDIR =
""
LDAP_TLS_CACERTFILE =
"/etc/openldap/certs/ca.crt"
LDAP_TLS_CERTFILE =
""
LDAP_TLS_KEYFILE =
""
LDAP_TLS_REQUIRE_CERT = True
LDAP_TLS_CIPHER_SUITE =
""
# i18n
BABEL_DEFAULT_LOCALE =
'zh_CN'
BABEL_DEFAULT_TIMEZONE =
'Asia/Shanghai'
# aviliable translations
LANGUAGES = {
'en'
:
'English'
,
'zh_CN'
:
'Chinese-Simplified'
,
}
# portal site config
MAINTAINERS = [
'root'
]
CONTACT =
'root@open-falcon.org'
try:
from rrd.local_config
import
*
except:
print
"[warning] no local config file"
#啓動服務
有兩種方法:
法一:
(env)[root@Open-Falcon-client dashboard]# bash control start falcon-dashboard started..., pid=40853
法二:
(env)[root@Open-Falcon-client dashboard]# ./control start falcon-dashboard started..., pid=40853
#查看日誌
(env)[root@Open-Falcon-client dashboard]# ./control tail [2017-10-29 15:30:20 +0000] [40853] [INFO] Starting gunicorn 19.1.1 [2017-10-29 15:30:20 +0000] [40853] [INFO] Listening at: http://0.0.0.0:8081 (40853) [2017-10-29 15:30:20 +0000] [40853] [INFO] Using worker: sync [2017-10-29 15:30:20 +0000] [40858] [INFO] Booting worker with pid: 40858 [2017-10-29 15:30:20 +0000] [40863] [INFO] Booting worker with pid: 40863 [2017-10-29 15:30:20 +0000] [40864] [INFO] Booting worker with pid: 40864 [2017-10-29 15:30:20 +0000] [40866] [INFO] Booting worker with pid: 40866
#退出env環境
(env)[root@Open-Falcon-client dashboard]# deactivate [root@Open-Falcon-client dashboard]#
#訪問網站
http://10.0.0.6:8081
#登陸界面
六、其它用法
#以開發者模式啓動
./env/bin/python wsgi.py open http://127.0.0.1:8081 in your browser.
#開啓8081端口 (備註:若是關閉了防火牆,則直接忽略這步)
1)防火牆添加8081端口永久開放
firewall-cmd --add-port=8081/tcp --permanent
2)從新載入防火牆配置
firewall-cmd --reload
#中止dashboard運行
bash control stop
#查看dashboard運行狀態
bash control status
6、FAQ
signup_disable
配置項修改成true,重啓api便可。endpoint 查看磁盤相關監控信息。