首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Kubernetes 1.8.6 集群部署–集群监控(十)

Kubernetes 1.8.6 集群部署–集群监控(十)

作者头像
老七Linux
发布2018-05-31 12:51:30
7430
发布2018-05-31 12:51:30
举报
Grafana+Prometheus打造全方位立体监控系统
架构

还是接着我的K8s架构来:

mark
mark
安装 Exporter

下载并解压:

注意:Exporter 是部署在Node上面的,也就是我的192.168.161.162和192.168.161.163 这两台!

wget https://github.com/prometheus/node_exporter/releases/download/v0.14.0/node_exporter-0.15.0.linux-amd64.tar.gz -O node_exporter-0.15.0.linux-amd64.tar.gz

tar -xvf node_exporter-0.15.0.linux-amd64.tar.gz

根据自己公司的运维规范,解压到指定的位置。

启动&&运行node_exporter:(进入到你解压的目录)
./node_exporter &
Prometheus

官网下载地址:https://prometheus.io/download

执行以下命令:

wget https://github.com/prometheus/prometheus/releases/download/v2.0.0-rc.3/prometheus-2.0.0-rc.3.linux-amd64.tar.gz

tar -xvf prometheus-2.0.0-rc.3.linux-amd64.tar.gz
配置prometheus
备份一下配置文件
mv prometheus.yml prometheus.yml-bak

编辑配置文件:

vi prometheus.yml

global:
  scrape_interval:     15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
        labels:
          instance: prometheus

  - job_name: linux1
    static_configs:
      - targets: ['192.168.161.162:9100']
        labels:
          instance: sys1

  - job_name: linux2
    static_configs:
      - targets: ['192.168.161.163:9100']
        labels:
          instance: sys2

IP对应的是我们内网的服务器,端口则是对应的exporter的监听端口。

运行Prometheus
[[email protected] prometheus-2.0.0-rc.3.linux-amd64]# ./prometheus 
level=info ts=2018-03-28T08:27:46.609788439Z caller=main.go:215 msg="Starting Prometheus" version="(version=2.0.0-rc.3, branch=HEAD, revision=8a9b32d0eb5be05a8066492e8a75c18b90e2d6ff)"
level=info ts=2018-03-28T08:27:46.609898573Z caller=main.go:216 build_context="(go=go1.9.2, [email protected], date=20171104-20:31:56)"
level=info ts=2018-03-28T08:27:46.609918763Z caller=main.go:217 host_details="(Linux 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 master1 (none))"
level=info ts=2018-03-28T08:27:46.673888972Z caller=web.go:380 component=web msg="Start listening for connections" address=0.0.0.0:9090
level=info ts=2018-03-28T08:27:46.680126403Z caller=main.go:314 msg="Starting TSDB"
level=info ts=2018-03-28T08:27:46.686999677Z caller=targetmanager.go:69 component="target manager" msg="Starting target manager..."
level=info ts=2018-03-28T08:27:47.364154262Z caller=main.go:326 msg="TSDB started"
level=info ts=2018-03-28T08:27:47.445946045Z caller=main.go:394 msg="Loading configuration file" filename=prometheus.yml
level=info ts=2018-03-28T08:27:47.581492722Z caller=main.go:371 msg="Server is ready to receive requests."

检查9090端口是否监听,则正常。访问9090端口

[[email protected] prometheus]# netstat -lntp | grep 9090
tcp6       0      0 :::9090                 :::*                    LISTEN      8154/prometheus

访问:

http://192.168.161.161:9090/graph
mark
mark
Grafana
下载
## 安装依赖grafana运行需要go环境
yum install  go -y
## 安装 grafana
yum install https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-4.6.1-1.x86_64.rpm -y
安装包信息:
二进制文件: /usr/sbin/grafana-server
init.d 脚本: /etc/init.d/grafana-server
环境变量文件: /etc/sysconfig/grafana-server
配置文件: /etc/grafana/grafana.ini
启动项: grafana-server.service
日志文件:/var/log/grafana/grafana.log
默认配置的sqlite3数据库:/var/lib/grafana/grafana.db

启动grafana,并设置开机启动:

systemctl daemon-reload
systemctl start grafana-server
systemctl status grafana-server
systemctl enable grafana-server.service

服务器端图像(PNG)渲染是可选的功能,但在共享可视化时非常有用,例如在警报通知中。

如果图像缺少文本,请确保已安装字体包。

yum install fontconfig -y
yum install freetype*  -y
yum install urw-fonts  -y

因为这个未来是需要经常去查看的一个页面:

建议配个nginx:

[[email protected] prometheus-2.0.0-rc.3.linux-amd64]# cd /etc/nginx/conf.d/

[[email protected] conf.d]# vim grafana.conf 

server {
        listen       80;
        server_name  grafana.zhdya.com;

        charset utf-8;

        location / {
            default_type text/html;
            proxy_pass http://127.0.0.1:3000;
        }

}
查看端口:
[[email protected] src]# netstat -lntp | grep 3000
tcp6       0      0 :::3000                 :::*                    LISTEN      4686/grafana-server 

访问地址:(记得修改本地主机的hosts)

http://grafana.zhdya.com
mark
mark
账号默认是admin  
密码默认是admin
mark
mark

编辑配置文件

/etc/grafana/grafana.ini

修改dashboards.json段落下两个参数的值:

[dashboards.json]
enabled = true
path = /var/lib/grafana/dashboards
安装仪表盘JSON模版:

下载 dashboards (https://github.com/percona/grafana-dashboards)

git clone https://github.com/percona/grafana-dashboards.git

cp -r grafana-dashboards/dashboards /var/lib/grafana/
mark
mark

添加成功以后,重启下grafana 服务:

systemctl restart grafana-server

然后我们就可以查看到效果图了。

mark
mark
mark
mark
mark
mark
总结

讲道理,这一套东西还是很强大的,各种开源组间一整合完美搭建出一套监控系统。当然了以上仅仅是系统的一个监控,Grafana以及exporter组间还可以实现对Docker,Nginx、MySql、Redis以及MongDB的监控。

监控不是目的,目的是出现问题能够及时发现并解决问题。

后面更精彩。。。


最后整理一下grafana的各项配置:

默认的配置文件是/etc/grafana/grafana.ini

下面具体看看每个配置段的配置:(后期肯定用得着!!)

app_mode:应用名称,默认是production  
  
[path]  
data:一个grafana用来存储sqlite3、临时文件、回话的地址路径  
logs:grafana存储logs的路径  
  
[server]  
http_addr:监听的ip地址,,默认是0.0.0.0  
http_port:监听的端口,默认是3000  
protocol:http或者https,,默认是http  
domain:这个设置是root_url的一部分,当你通过浏览器访问grafana时的公开的domian名称,默认是localhost  
enforce_domain:如果主机的header不匹配domian,则跳转到一个正确的domain上,默认是false  
root_url:这是一个web上访问grafana的全路径url,默认是%(protocol)s://%(domain)s:%(http_port)s/  
router_logging:是否记录web请求日志,默认是false  
cert_file:如果使用https则需要设置  
cert_key:如果使用https则需要设置  
  
[database]  
grafana默认需要使用数据库存储用户和dashboard信息,默认使用sqlite3来存储,你也可以换成其他数据库  
type:可以是mysql、postgres、sqlite3,默认是sqlite3  
path:只是sqlite3需要,定义sqlite3的存储路径  
host:只是mysql、postgres需要,默认是127.0.0.1:3306  
name:grafana的数据库名称,默认是grafana  
user:连接数据库的用户  
password:数据库用户的密码  
ssl_mode:只是postgres使用  
  
  
[security]  
admin_user:grafana默认的admin用户,默认是admin  
admin_password:grafana admin的默认密码,默认是admin  
login_remember_days:多少天内保持登录状态  
secret_key:保持登录状态的签名  
disable_gravatar:  
  
  
[users]  
allow_sign_up:是否允许普通用户登录,如果设置为false,则禁止用户登录,默认是true,则admin可以创建用户,并登录grafana  
allow_org_create:如果设置为false,则禁止用户创建新组织,默认是true  
auto_assign_org:当设置为true的时候,会自动的把新增用户增加到id为1的组织中,当设置为false的时候,新建用户的时候会新增一个组织  
auto_assign_org_role:新建用户附加的规则,默认是Viewer,还可以是Admin、Editor  
  
  
[auth.anonymous]  
enabled:设置为true,则开启允许匿名访问,默认是false  
org_name:为匿名用户设置组织名称  
org_role:为匿名用户设置的访问规则,默认是Viewer  
  
  
[auth.github]  
针对github项目的,很明显,呵呵  
enabled = false  
allow_sign_up = false  
client_id = some_id  
client_secret = some_secret  
scopes = user:email  
auth_url = https://github.com/login/oauth/authorize  
token_url = https://github.com/login/oauth/access_token  
api_url = https://api.github.com/user  
team_ids =  
allowed_domains =  
allowed_organizations =  
  
  
[auth.google]  
针对google app的,呵呵  
enabled = false  
allow_sign_up = false  
client_id = some_client_id  
client_secret = some_client_secret  
scopes = https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email  
auth_url = https://accounts.google.com/o/oauth2/auth  
token_url = https://accounts.google.com/o/oauth2/token  
api_url = https://www.googleapis.com/oauth2/v1/userinfo  
allowed_domains =  
  
  
[auth.basic]  
enabled:当设置为true,则http api开启基本认证  
  
  
[auth.ldap]  
enabled:设置为true则开启LDAP认证,默认是false  
config_file:如果开启LDAP,指定LDAP的配置文件/etc/grafana/ldap.toml  
  
  
[auth.proxy]  
允许你在一个HTTP反向代理上进行认证设置  
enabled:默认是false  
header_name:默认是X-WEBAUTH-USER  
header_property:默认是个名称username  
auto_sign_up:默认是true。开启自动注册,如果用户在grafana DB中不存在  
  
[analytics]  
reporting_enabled:如果设置为true,则会发送匿名使用分析到stats.grafana.org,主要用于跟踪允许实例、版本、dashboard、错误统计。默认是true  
google_analytics_ua_id:使用GA进行分析,填写你的GA ID即可  
  
  
[dashboards.json]  
如果你有一个系统自动产生json格式的dashboard,则可以开启这个特性试试  
enabled:默认是false  
path:一个全路径用来包含你的json dashboard,默认是/var/lib/grafana/dashboards  
  
  
[session]  
provider:默认是file,值还可以是memory、mysql、postgres  
provider_config:这个值的配置由provider的设置来确定,如果provider是file,则是data/xxxx路径类型,如果provider是mysql,则是user:[email protected](127.0.0.1:3306)/database_name,如果provider是postgres,则是user=a password=b host=localhost port=5432 dbname=c sslmode=disable  
cookie_name:grafana的cookie名称  
cookie_secure:如果设置为true,则grafana依赖https,默认是false  
session_life_time:session过期时间,默认是86400秒,24小时  
  
  
以下是官方文档没有,配置文件中有的  
[smtp]  
enabled = false  
host = localhost:25  
user =  
password =  
cert_file =  
key_file =  
skip_verify = false  
from_address = [email protected]  
  
[emails]  
welcome_email_on_sign_up = false  
templates_pattern = emails/*.html  
  
  
[log]  
mode:可以是console、file,默认是console、file,也可以设置多个,用逗号隔开  
buffer_len:channel的buffer长度,默认是10000  
level:可以是"Trace", "Debug", "Info", "Warn", "Error", "Critical",默认是info  
  
[log.console]  
level:设置级别  
  
[log.file]  
level:设置级别  
log_rotate:是否开启自动轮转  
max_lines:单个日志文件的最大行数,默认是1000000  
max_lines_shift:单个日志文件的最大大小,默认是28,表示256MB  
daily_rotate:每天是否进行日志轮转,默认是true  
max_days:日志过期时间,默认是7,7天后删除  
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018/03/29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Grafana+Prometheus打造全方位立体监控系统
  • 架构
  • 安装 Exporter
  • 启动&&运行node_exporter:(进入到你解压的目录)
  • Prometheus
  • 配置prometheus
    • 备份一下配置文件
    • 运行Prometheus
    • Grafana
      • 下载
        • 安装包信息:
        • 查看端口:
        • 安装仪表盘JSON模版:
        • 总结
          • 默认的配置文件是/etc/grafana/grafana.ini
          相关产品与服务
          容器服务
          腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档