安装部分:
server端:192.168.99.135
安装程序:InfluxDB Grafana
Client端:192.168.99.136
安装程序:Collectd
server端
一、influxdb安装
(1)配置YUM源
cat <
name = InfluxDB Repository - RHEL \$releasever
baseurl = https://repos.influxdata.com/rhel/\$releasever/\$basearch/stable
enabled = 1
gpgcheck = 1
gpgkey = https://repos.influxdata.com/influxdb.key
EOF
(2)安装和启动
#yum install -y influxdb
#service influxdb start
(3)相关信息
web后台http://192.168.99.135:8083/
API接口 192.168.99.135:8086
配置文件路径:/etc/influxdb/influxdb.conf
# 找到admin,将前面的#号去掉,开放它的UI端口
[admin] # Determines whether the admin service is enabled. enabled = true # The default bind address used by the admin service. bind-address = ":8083" #service influxdb restart
二、grafana安装
http://docs.grafana.org/installation/rpm/
Install via YUM Repository
Add the following to a new file at /etc/yum.repos.d/grafana.repo
[grafana]
name=grafana
baseurl=https://packagecloud.io/grafana/stable/el/6/$basearch
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packagecloud.io/gpg.key https://grafanarel.s3.amazonaws.com/RPM-GPG-KEY-grafana
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
yum install grafana
注:
1.从官网下载最新的软件包
2.若系统中使用yum安装较慢的话,可以使用迅雷下载完成之后上传至服务器中。
(2)修改配置
日志路径:
/var/log/grafana/grafana.log
配置文件路径:
/etc/grafana/grafana.ini
#vim /etc/grafana/grafana.ini
//由于默认端口3000和我测试环境的一个程序冲突,所以修改默认服务端口为
http_port = 3001
#/etc/init.d/grafana-server restart
# netstat -an|grep 3001
tcp 0 0 :::3001 :::* LISTEN
启动服务后访问 http://192.168.99.135:3001
Client端
collectd安装,大部分Linux版本自带的YUM源都有此软件
# yum install epel-release # yum install collectd
配置部分:
InfluxDB开启collectd插件
InfluxDB 现在自带一个 collectd 插件来获取 collectd 客户端发来的数据,以前可没这么方便哦,0.8.4 版本以前只能通过 influxdb-collectd-proxy 这样的第三方程序来连接 collectd 和 InfluxDB.
InfluxDB 自带的 collectd 插件默认是关闭的,需要手动配置打开 enabled = true,并填上 database = “collectd” 这一行,这里的 “collectd” 就是我们上面创建的那个数据库,更改配置后记得重启 InfluxDB
修改配置重启后会发现 influxdb 插件启动了一个 25826 端口,如果发现 InfluxDB 数据库里没有(收集到)数据,务必检查这个 25826 端口是否正常启动了。
编辑 InfluxDB 的配置文件 /etc/opt/influxdb.conf,将 [collectd] 标签下的内容修改为:
#vim /etc/influxdb/influxdb.conf
`collectd` //这里需要两个括号,不然启动会报错
enabled = true
bind-address = ":25826"
database = "collectd"
typesdb = "/usr/share/collectd/types.db"
batch-size = 5000 # will flush if this many points get buffered
batch-pending = 10 # number of batches that may be pending in memory
batch-timeout = "10s" # will flush at least this often even if we haven't hit buffer limit
read-buffer = 0 # UDP Read buffer size, 0 means OS default. UDP listener will fail if set above OS max.
#service influxdb restart
# tail -f /var/log/influxdb/influxd.log
[collectd] 2016/12/12 17:52:52 Starting collectd service
[collectd] 2016/12/12 17:52:52 Loading /usr/share/collectd/types.db
[collectd] 2016/12/12 17:52:52 Listening on UDP: [::]:25826
[run] 2016/12/12 17:52:52 Listening for signals
[monitor] 2016/12/12 17:52:52 Storing statistics in database '_internal' retention policy 'monitor', at interval 10s
2016/12/12 17:52:52 Sending usage statistics to usage.influxdata.com
# netstat -an|grep 25826
udp 0 0 :::25826 :::*
你可以验证下 InfluxDB 是否已经收到了 Collectd 发送的监控信息:
# influx
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connected to http://localhost:8086 version 1.1.1
InfluxDB shell version: 1.1.1
> show databases;
name: databases
name
----
_internal
testdb
collectd
grafana
> use collectd;
Using database collectd
> show measurements
name: measurements
name
----
cpu_value
interface_rx
interface_tx
load_longterm
load_midterm
load_shortterm
memory_value
二、创建collectd数据库
登录 http://192.168.99.135:8083/ 创建数据库名为collectd和grafana的数据库,输入语句按下回车即可
client端配置collectd
FQDNLookup true BaseDir "/var/lib/collectd" PIDFile "/var/run/collectd.pid" PluginDir "/usr/lib64/collectd" TypesDB "/usr/share/collectd/types.db" LoadPlugin syslog LoadPlugin interface LoadPlugin load LoadPlugin networkInterface "eth0" IgnoreSelected false ReportRelative true Server "127.0.0.1" "25826"
最关键的是 “network” plugin,这部分设定监控信息将要发送到 127.0.0.1 的 25826 端口。稍后我们将要指定 InfluxDB 监听此端口以接收 collectd 的发包。
现在启动这个守护程序,并且将它加入到开机自启动中。
# /etc/init.d/collectd restart # chkconfig collectd on # chkconfig collectd --list collectd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
客户端启动服务:
/etc/init.d/collectd restart
这时候可以上influxdb数据库服务器上查看是否有数据传输过来,可以命令行查看也可上WEB页面查看
http://192.168.99.135:8083/
命令行查看:
# influx
Visit https://enterprise.influxdata.com to register for updates, InfluxDB server management, and monitoring.
Connected to http://localhost:8086 version 1.1.1
InfluxDB shell version: 1.1.1
> show databases;
name: databases
name
----
_internal
collectd
grafana
> use collectd
Using database collectd
> show measurements
name: measurements
name
----
cpu_value
interface_rx
interface_tx
load_longterm
load_midterm
load_shortterm
memory_value
> select * from /load/;
name: load_longterm
time host type value
---- ---- ---- -----
1481536366000000000 node01.example.com load 0
1481536376000000000 node01.example.com load 0
1481536386000000000 node01.example.com load 0
1481536396000000000 node01.example.com load 0
1481536406000000000 node01.example.com load 0
1481536416000000000 node01.example.com load 0
1481536426000000000 node01.example.com load 0
1481536436000000000 node01.example.com load 0
grafana配置数据源
点击 Data Source 然后 Add new,填写如下配置项
官网参考文档:http://docs.grafana.org/
官方演示地址:http://play.grafana.org/
未完待续。。。