Centos7部署Open-Falcon監控


參考博主:努力哥完成

一、Open-Falcon介紹

1、監控系統,可以從運營級別(基本配置即可),以及應用級別(二次開發,通過端口進行日志上報),對服務器、操作系統、中間件、應用進行全面的監控,及報警,對我們的系統正常運行的作用非常重要。

2、基礎監控

CPU、Load、內存、磁盤、IO、網絡相關、內核參數、ss 統計輸出、端口采集、核心服務的進程存活信息采集、關鍵業務進程資源消耗、NTP offset采集、DNS解析采集,這些指標,都是open-falcon的agent組件直接支持的。

Linux運維基礎采集項:http://book.open-falcon.org/zh/faq/linux-metrics.html

對於這些基礎監控選項全部理解透徹的時刻,也就是對Linux運行原理及命令進階的時刻。

3、第三方監控

術業有專攻,運行在OS上的應用甚多,Open-Falcon的開發團隊不可能把所有的第三方應用的監控全部做完,這個就需要開源社區提供更多的插件,當前對於很多常用的第三方應用都有相關插件了。

4、JVM監控

對於Java作為主要開發語言的大多數公司,對於JVM的監控不可或缺。

每個JVM應用的參數,比如GC、類加載、JVM內存、進程、線程,都可以上報給Falcon,而這些參數的獲得,都可以通過MxBeans實現。

使用 Java 平台管理 bean:http://www.ibm.com/developerworks/cn/java/j-mxbeans/

5、業務應用監控

對於業務需要監控的接口,比如響應時間等。可以根據業務的需要,上報相關數據到Falcon,並通過Falcon查看結果。

二、Zabbix、Nagios、Open-Falcon這3大開源運維監控工具的比較

說明:Open-Falcon部署分為前端(客戶端)和后端(服務端)

三、后端部署(服務端)

參考官方文檔:https://book.open-falcon.org/zh_0_2/quick_install/prepare.html

1、系統環境

[root@open-falcon-server ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core)

2、系統優化

#安裝下載軟件
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

3、軟件環境准備

#安裝 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

4、初始化MySQL表結構(備注:導入表結構后,注意檢查)

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)

5、配置Go語言開發環境

#安裝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

6、下載編譯好的二進制版本

下載地址:

直接下載官方編譯好的二進制版本(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

7、修改配置文件cfg.json

坑:

部分模塊依賴連接數據庫,因為如果不修改配置文件,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

1)修改aggregator的配置文件

vim /home/work/open-falcon/aggregator/config/cfg.json

 

 

mysql的root密碼為空,則去掉“password”,若不為空,則用root密碼替換“password”。

2)修改graph的配置文件

vim /home/work/open-falcon/graph/config/cfg.json

 

 

mysql的root密碼為空,則去掉“password”,若不為空,則用root密碼替換“password”。

3)修改hbs的配置文件

vim /home/work/open-falcon/hbs/config/cfg.json

 

 

mysql的root密碼為空,則去掉“password”,若不為空,則用root密碼替換“password”。

4)修改nodata的配置文件

vim /home/work/open-falcon/nodata/config/cfg.json

 

 

mysql的root密碼為空,則去掉“password”,若不為空,則用root密碼替換“password”。

5)修改api的配置文件

vim /home/work/open-falcon/api/config/cfg.json

 

 

mysql的root密碼為空,則去掉“password”,若不為空,則用root密碼替換“password”。

6)修改alarm的配置文件

vim /home/work/open-falcon/alarm/config/cfg.json

mysql的root密碼為空,則去掉“password”,若不為空,則用root密碼替換“password”。 

 

 

8、啟動后端模塊

[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

至此后端部署完成。

9、其它用法

#重載配置(備注:修改vi cfg.json配置文件后,可以用下面命令重載配置)

curl 127.0.0.1:1988/config/reload

五、前端部署 (備注:在另外一台服務器上面操作)

1、創建工作目錄

export HOME=/home/work
export WORKSPACE=$HOME/open-falcon
mkdir -p $WORKSPACE
cd $WORKSPACE

2、克隆前端組件代碼

git clone https://github.com/open-falcon/dashboard.git

3、安裝依賴包

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

4、先安裝ez_setup.py,再安裝pip

#下載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

5、修改配置

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

#登錄界面

 

 

 6、其它用法

#以開發者模式啟動

./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

六、FAQ

  • Q: open-falcon v0.2 有管理員帳號嗎?
  • A: 可以通過dashboard自行注冊新用戶,第一個用戶名為root的帳號會被認為是超級管理員,超級管理員可以設置其他用戶為管理員。

  • Q: open-falcon v0.2 dashboard 可以禁止用戶自己注冊嗎?
  • A: 可以的,在api組件的配置文件中,將signup_disable配置項修改為true,重啟api即可。

endpoint 查看磁盤相關監控信息。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM