监控

为什么监控。有哪些监控,区别,优缺点
监控对象:
    1. 监控对象的理解:CPU是怎么工作的,原理
    2. 监控对象的指标:CPU使用率 CPU负载 CPU个数 上下文切换
    3. 确定性能基准线:怎么样才算故障?CPU负载多上才算高
监控范围:
    1.硬件监控服务器的硬件故障
    2.操作系统监控 CPU、内存、硬盘、IO、进程
    3.应用服务监控 nginx、MySQL、等服务
    4.业务监控


硬件监控:

1.使用IPMI
2.机房巡检
远程控制卡:
    DELL服务器:iDRAC
    HP服务器:ILO ————-Linux就可以使用IPMI(依赖于BMC控制器)
    IBM服务器:IMM |
    Linux是管理IPMI工具
    ‘ipmitool’(监控和控制)

1.硬件要支持

2.操作系统 ‘Linux IPMI’

ipmitool安装:

  1. [root@localhost ~]# yum install OpenIPMI ipmitool -y
  2. [root@localhost ~]# rpm -qa OpenIPMI ipmitool
  3. ipmitool-1.8.13-8.el7_1.x86_64
  4. OpenIPMI-2.0.19-11.el7.x86_64

使用IPMI有两种方式
1、本地进行调用
2、远程调用 (IP地址 用户名和密码)

  1. [root@localhost ~]# systemctl start ipmi #启动
  2. 本次以Centos7进行演示

IPMI相关命令

  1. [root@localhost ~]# ipmitool --help
  2. ipmitool: invalid option -- '-'
  3. ipmitool version 1.8.13
  4. usage: ipmitool [options...] <command>
  5. -h This help
  6. -V Show version information
  7. -v Verbose (can use multiple times)
  8. -c Display output in comma separated format
  9. -d N Specify a /dev/ipmiN device to use (default=0)
  10. -I intf Interface to use
  11. -H hostname Remote host name for LAN interface
  12. -p port Remote RMCP port [default=623]
  13. -U username Remote session username
  14. -f file Read remote session password from file
  15. -z size Change Size of Communication Channel (OEM)
  16. -S sdr Use local file for remote SDR cache
  17. -D tty:b[:s] Specify the serial device, baud rate to use
  18. and, optionally, specify that interface is the system one
  19. -a Prompt for remote password
  20. -Y Prompt for the Kg key for IPMIv2 authentication
  21. -e char Set SOL escape character
  22. -C ciphersuite Cipher suite to be used by lanplus interface
  23. -k key Use Kg key for IPMIv2 authentication
  24. -y hex_key Use hexadecimal-encoded Kg key for IPMIv2 authentication
  25. -L level Remote session privilege level [default=ADMINISTRATOR]
  26. Append a '+' to use name/privilege lookup in RAKP1
  27. -A authtype Force use of auth type NONE, PASSWORD, MD2, MD5 or OEM
  28. -P password Remote session password
  29. -E Read password from IPMI_PASSWORD environment variable
  30. -K Read kgkey from IPMI_KGKEY environment variable
  31. -m address Set local IPMB address
  32. -b channel Set destination channel for bridged request
  33. -t address Bridge request to remote target address
  34. -B channel Set transit channel for bridged request (dual bridge)
  35. -T address Set transit address for bridge request (dual bridge)
  36. -l lun Set destination lun for raw commands
  37. -o oemtype Setup for OEM (use 'list' to see available OEM types)
  38. -O seloem Use file for OEM SEL event descriptions
  39. -N seconds Specify timeout for lan [default=2] / lanplus [default=1] interface
  40. -R retry Set the number of retries for lan/lanplus interface [default=4]
  41. Interfaces:
  42. open Linux OpenIPMI Interface [default]
  43. imb Intel IMB Interface
  44. lan IPMI v1.5 LAN Interface
  45. lanplus IPMI v2.0 RMCP+ LAN Interface
  46. serial-terminal Serial Interface, Terminal Mode
  47. serial-basic Serial Interface, Basic Mode
  48. Commands:
  49. raw Send a RAW IPMI request and print response
  50. i2c Send an I2C Master Write-Read command and print response
  51. spd Print SPD info from remote I2C device
  52. lan Configure LAN Channels
  53. chassis Get chassis status and set power state
  54. power Shortcut to chassis power commands
  55. event Send pre-defined events to MC
  56. mc Management Controller status and global enables
  57. sdr Print Sensor Data Repository entries and readings
  58. sensor Print detailed sensor information
  59. fru Print built-in FRU and scan SDR for FRU locators
  60. gendev Read/Write Device associated with Generic Device locators sdr
  61. sel Print System Event Log (SEL)
  62. pef Configure Platform Event Filtering (PEF)
  63. sol Configure and connect IPMIv2.0 Serial-over-LAN
  64. tsol Configure and connect with Tyan IPMIv1.5 Serial-over-LAN
  65. isol Configure IPMIv1.5 Serial-over-LAN
  66. user Configure Management Controller users
  67. channel Configure Management Controller channels
  68. session Print session information
  69. dcmi Data Center Management Interface
  70. sunoem OEM Commands for Sun servers
  71. kontronoem OEM Commands for Kontron devices
  72. picmg Run a PICMG/ATCA extended cmd
  73. fwum Update IPMC using Kontron OEM Firmware Update Manager
  74. firewall Configure Firmware Firewall
  75. delloem OEM Commands for Dell systems
  76. shell Launch interactive IPMI shell
  77. exec Run list of commands from file
  78. set Set runtime variable for shell and exec
  79. hpm Update HPM components using PICMG HPM.1 file
  80. ekanalyzer run FRU-Ekeying analyzer using FRU files
  81. ime Update Intel Manageability Engine Firmware

IPMI配置网络,有两种方式:
ipmi over lan(大体意思是通过网卡来进行连接)
独立 (给服务器单独插一个网线) DELL服务器可以在小面板中设置ipmi 云主机我们不需要考虑IPMI

对于路由器和交换机:SNMP
对于这些设备,就不做具体描述了,毕竟没有接触过

系统监控

做为系统运维来说系统监控是重点

  1. - CPU
  2. - 内存
  3. - IO Input/Ouput(网络、磁盘)

CPU三个重要的概念:

1.上下文切换:CPU调度器实施的进程的切换过程,上下文切换
  2.运行队列(负载):运行队列,排队 可以参考我是一个进程文章
  3.使用率
监控CPU需要确定服务类型:
(1) IO密集型 (数据库)
(2) CPU密集型(Web/mail)

确定性能的基准线
  运行队列:1-3个线程 1CPU 4核 负载不超过12
  CPU使用:65%-70%用户态利用率
###        30%-35%内核态利用率
       0%-5% 空闲
  上下文切换: 越少越好

Zabbix监控什么?

分类 监控项
硬件监控 温度、硬件故障等
系统监控 CPU、内存、硬盘、网卡流量、TCP状态、进程数
应用监控 Nginx、Tomcat、PHP、MySQL、Redis等
日志监控 系统日志、服务日志、访问日志、错误日志
安全监控 WAF、敏感文件监控
API监控 可用性、接口请求、响应时间
业务监控 例如电商网站每分钟产生多少订单、注册多少用户、多少活跃用户、推广效果如何
流量监控 根据流量获取用户相关信息。例如用户地理位置、某页面访问状况、页面停留时间等

zabbix常用监控项

zabbix自带的常用监控项agent.ping 检测客户端可达性、返回nothing表示不可达。1表示可达
system.cpu.load —检测cpu负载。返回浮点数
system.cpu.load[all,avg1] 1分钟内的平均负载
[all,avg5] 5分钟内的平均负载
[all,avg15] 15分钟内的平均负载
system.cpu.util — 检测cpu使用率。返回浮点数
vfs.dev.read — 检测硬盘读取数据,返回是sps.ops.bps浮点类型,需要定义1024倍
vfs.dev.write — 检测硬盘写入数据。返回是sps.ops.bps浮点类型,需要定义1024倍
net.if.out[br0] —检测网卡流速、流出方向,时间间隔为60S
net-if-in[br0] —检测网卡流速,流入方向(单位:字节) 时间间隔60S
proc.num[] 目前系统中的进程总数,时间间隔60s
proc.num[,,run] 目前正在运行的进程总数,时间间隔60S

处理器信息

通过zabbix_get 获取负载值
合理的控制用户态、系统态、IO等待时间剋保证进程高效率的运行
系统态运行时间较高说明进程进行系统调用的次数比较多,一般的程序如果系统态运行时间占用过高就需要优化程序,减少系统调用
io等待时间过高则表明硬盘的io性能差,如果是读写文件比较频繁、读写效率要求比较高,可以考虑更换硬盘,或者使用多磁盘做raid的方案
system.cpu.swtiches —cpu的进程上下文切换,单位sps,表示每秒采样次数,api中参数history需指定为3
system.cpu.intr —cpu中断数量、api中参数history需指定为3
system.cpu.load[percpu,avg1] —cpu每分钟的负载值,按照核数做平均值(Processor load (1 min average per core)),api中参数history需指定为0
system.cpu.load[percpu,avg5] —cpu每5分钟的负载值,按照核数做平均值(Processor load (5 min average per core)),api中参数history需指定为0
system.cpu.load[percpu,avg15] —cpu每5分钟的负载值,按照核数做平均值(Processor load (15 min average per core)),api中参数history需指定为0

自定义

内存
  1. vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/catcarm.conf
  2. UserParameter=ram.info[*],/bin/cat /proc/meminfo |awk '/^$1:{print $2}'
  3. ram.info[Cached] --检测内存的缓存使用量、返回整数,需要定义1024
  4. ram.info[MemFree] --检测内存的空余量,返回整数,需要定义1024
  5. ram.info[Buffers] --检测内存的使用量,返回整数,需要定义1024

TCP
  1. vim /usr/local/zabbix/share/zabbix/alertscripts/tcp_connection.sh
  2. #!/bin/bash
  3. function ESTAB {
  4. /usr/sbin/ss -ant |awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'ESTAB' | awk '{print $2}'
  5. }
  6. function TIMEWAIT {
  7. /usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'TIME-WAIT' | awk '{print $2}'
  8. }
  9. function LISTEN {
  10. /usr/sbin/ss -ant | awk '{++s[$1]} END {for(k in s) print k,s[k]}' | grep 'LISTEN' | awk '{print $2}'
  11. }
  12. $1
  13. vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/cattcp.conf
  14. UserParameter=tcp[*],/usr/local/zabbix/share/zabbix/alertscripts/tcp_connection.sh $1
  15. tcp[TIMEWAIT] --检测TCP的驻留数,返回整数
  16. tcp[ESTAB] --检测tcp的连接数、返回整数
  17. tcp[LISTEN] --检测TCP的监听数,返回整数

nginx
  1. vim /etc/nginx/conf.d/default.conf
  2. location /nginx-status
  3. {
  4. stub_status on;
  5. access_log off;
  6. allow 127.0.0.1;
  7. deny all;
  8. }
  9. vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/nginx.conf
  10. UserParameter=Nginx.active,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | awk '/Active/ {print $NF}'
  11. UserParameter=Nginx.read,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | grep 'Reading' | cut -d" " -f2
  12. UserParameter=Nginx.wrie,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | grep 'Writing' | cut -d" " -f4
  13. UserParameter=Nginx.wait,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | grep 'Waiting' | cut -d" " -f6
  14. UserParameter=Nginx.accepted,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | awk '/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $1}'
  15. UserParameter=Nginx.handled,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | awk '/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $2}'
  16. UserParameter=Nginx.requests,/usr/bin/curl -s "http://127.0.0.1:80/nginx-status" | awk '/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $3}'
  17. PHP.listenqueue --检测PHP队列数,返回整数
  18. PHP.idle --检测PHP空闲进程数,返回整数
  19. PHP.active --检测PHP活动进程数,返回整数
  20. PHP.conn --检测PHP请求数,返回整数
  21. PHP.reached --检测PHP达到限制次数,返回整数
  22. PHP.requets --检测PHP慢请求书,返回整数

redis
  1. vim /usr/local/zabbix/etc/zabbix_agentd.conf.d/redis.conf
  2. UserParameter=Redis.Status,/usr/local/redis/bin/redis-cli -h 127.0.0.1 -p 6379 ping |grep -c PONG
  3. UserParameter=Redis_conn[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "connected_clients" | awk -F':' '{print $2}'
  4. UserParameter=Redis_rss_mem[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "used_memory_rss" | awk -F':' '{print $2}'
  5. UserParameter=Redis_lua_mem[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "used_memory_lua" | awk -F':' '{print $2}'
  6. UserParameter=Redis_cpu_sys[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "used_cpu_sys" | awk -F':' '{print $2}'
  7. UserParameter=Redis_cpu_user[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "used_cpu_user" | awk -F':' '{print $2}'
  8. UserParameter=Redis_cpu_sys_cline[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "used_cpu_sys_children" | awk -F':' '{print $2}'
  9. UserParameter=Redis_cpu_user_cline[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "used_cpu_user_children" | awk -F':' '{print $2}'
  10. UserParameter=Redis_keys_num[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep -w "$$1" | grep -w "keys" | grep db$3 | awk -F'=' '{print $2}' | awk -F',' '{print $1}'
  11. UserParameter=Redis_loading[*],/usr/local/redis/bin/redis-cli -h $1 -p $2 info | grep loading | awk -F':' '{print $$2}'
  12. Redis.Status --检测Redis运行状态, 返回整数
  13. Redis_conn --检测Redis成功连接数,返回整数
  14. Redis_rss_mem --检测Redis系统分配内存,返回整数
  15. Redis_lua_mem --检测Redis引擎消耗内存,返回整数
  16. Redis_cpu_sys --检测Redis主程序核心CPU消耗率,返回整数
  17. Redis_cpu_user --检测Redis主程序用户CPU消耗率,返回整数
  18. Redis_cpu_sys_cline --检测Redis后台核心CPU消耗率,返回整数
  19. Redis_cpu_user_cline --检测Redis后台用户CPU消耗率,返回整数
  20. Redis_keys_num --检测库键值数,返回整数
  21. Redis_loding --检测Redis持久化文件状态,返回整数

mysql:
  1. version:数据库版本
  2. key_buffer_size:myisam的索引buffer大小
  3. sort_buffer_size:会话的排序空间(每个线程会申请一个)
  4. join_buffer_size:这是为链接操作分配的最小缓存大小,这些连接使用普通索引扫描、范围扫描、或者连接不适用索引
  5. max_connections:最大允许同时连接的数量
  6. max_connect_errors:允许一个主机最多的错误链接次数,如果超过了就会拒绝之后链接(默认100)。可以使用flush hosts命令去解除拒绝
  7. open_files_limits:操作系统允许mysql打开的文件数量,可以通过opened_tables状态确定是否需要增大table_open_cache,如果opened_tables比较大且一直还在增大说明需要增大table_open_cache
  8. max-heap_tables_size:建立的内存表的最大大小(默认16M)这个参数和tmp_table_size一起限制内部临时表的最大值(取这两个参数的小的一个),如果超过限制,则表会变为innodbmyisam引擎,(5.7.5之前是默认是myisam5.7.6开始是innodb,可以通过internal_tmp_disk_storage_engine参数调整)。
  9. max_allowed_packet:一个包的最大大小
  10. ##########GET INNODB INFO
  11. #INNODB variables
  12. innodb_version:
  13. innodb_buffer_pool_instances:将innodb缓冲池分为指定的多个(默认为1
  14. innodb_buffer_pool_size:innodb缓冲池大小、5.7.5引入了innodb_buffer_pool_chunk_size,
  15. innodb_doublewrite:是否开启doublewrite(默认开启)
  16. innodb_read_io_threads:IO读线程的数量
  17. innodb_write_io_threads:IO写线程的数量
  18. ########innodb status
  19. innodb_buffer_pool_pages_total:innodb缓冲池页的数量、大小等于innodb_buffer_pool_size/(16*1024)
  20. innodb_buffer_pool_pages_data:innodb缓冲池中包含数据的页的数量
  21. ########## GET MYSQL HITRATE
  22. 1、查询缓存命中率
  23. 如果Qcache_hits+Com_select<>0则为 Qcache_hits/(Qcache_hits+Com_select),否则为0
  24. 2、线程缓存命中率
  25. 如果Connections<>0,则为1-Threads_created/Connections,否则为0
  26. 3myisam键缓存命中率
  27. 如果Key_read_requests<>0,则为1-Key_reads/Key_read_requests,否则为0
  28. 4myisam键缓存写命中率
  29. 如果Key_write_requests<>0,则为1-Key_writes/Key_write_requests,否则为0
  30. 5、键块使用率
  31. 如果Key_blocks_used+Key_blocks_unused<>0,则Key_blocks_used/(Key_blocks_used+Key_blocks_unused),否则为0
  32. 6、创建磁盘存储的临时表比率
  33. 如果Created_tmp_disk_tables+Created_tmp_tables<>0,则Created_tmp_disk_tables/(Created_tmp_disk_tables+Created_tmp_tables),否则为0
  34. 7、连接使用率
  35. 如果max_connections<>0,则threads_connected/max_connections,否则为0
  36. 8、打开文件比率
  37. 如果open_files_limit<>0,则open_files/open_files_limit,否则为0
  38. 9、表缓存使用率
  39. 如果table_open_cache<>0,则open_tables/table_open_cache,否则为0

zabbix其他须掌握技能

自定义监控

自动发现 —> 匹配模板

自动注册 —> 匹配模板

分段监控

细化报警收件人

Nginx

nginx配置的结构

  1. 全局配置
  2. events {
  3. }
  4. log_format ;
  5. logs ;
  6. http { //只能有一个
  7. upstream name { //可以多个
  8. }
  9. server { //可以多个,在http里边
  10. listen ;
  11. server_name _
  12. location 匹配项 { //可以多个,在server里边
  13. }
  14. location 匹配项 {
  15. proxy_pass http://name ;
  16. }
  17. }
  18. }
  19. include
  20. 以上未nginx配置文档的结构,必知必会
  21. 重点复习
  22. https ssl 443
  23. tcp
  24. status
  25. 验证
  26. 防盗链
  27. 地址重写 rewrite
  28. 流量控制
  29. 配置文件过多,使用include,进行拆分
  30. nginx -t
  31. nginx -s reload
  32. nginx -c 文件路径
  33. nginx -v

nginx负载均衡

upstream 、 proxy_pass 权重、算法、(down、backup、) 、timeout、次数

upstream —> proxy_pass

带端口的负载均衡

nginx反向代理

参考负载均衡

nginx

  1. https ssl 443
  2. tcp
  3. status
  4. 验证
  5. 防盗链
  6. 地址重写 rewrite
  7. 流量控制
  8. nginx优势
  9. 第三方模块 --add-module=
  10. 会话保持 -- hash cookiejvm_route
  11. 动静分离