云计算第二阶段:----监控与服务安全SECURITY

本模块内容,主要讲述 服务器的安全防护与配置软件相关知识。分为网络防护软件介绍、配置与使用用,网络安全相关知识浅度解析。

涉及软件有prometheus ,graphna,zabbix。

网络安全方面涉及基于debian linux系统的kali版本liunx的介绍与简单使用。


SECURITY DAY1

环境准备:

主机名 地址
zabbixserver 192.168.88.5/24
web1 192.168.88.100/24
web2 192.168.88.200/24

一、zabbix基础配置

监控概述

  • 对服务的管理,不能仅限于可用性。

  • 还需要服务可以安全、稳定、高效地运行。

  • 监控的目的:早发现、早治疗。

  • 被监控的资源类型:

    • 公开数据:对外开放的,不需要认证即可获取的数据
    • 私有数据:对外不开放,需要认证、权限才能获得的数据

zabbix

  • 实施监控的几个方面:

    • 数据采集:使用agent(可安装软件的系统上)、SNMP(简单网络管理协议,用于网络设备的数据采集)
    • 数据存储:使用mysql数据库
    • 数据展示:通过web页面
  • zabbix通过在远程主机上安装agent进行数据采集,存储到mysql数据库,通过web页面进行展示。

安装zabbix 6.0

1. 拷贝zabbix软件包到pubserver 目录的 /var/ftp/rpms 位置

2. 更新yum仓库配置

root@pubserver \~\]# createrepo -v /var/ftp/rpms/ # 3. 在pubserver上创建ansible工作环境 \[root@pubserver \~\]# mkdir -p zabbix/files \[root@pubserver \~\]# cd zabbix/ \[root@pubserver zabbix\]# vim ansible.cfg \[defaults

inventory = inventory

host_key_checking = false

root@pubserver zabbix\]# vim inventory \[zabbix

zabbixserver ansible_host=192.168.88.5

webservers

web1 ansible_host=192.168.88.100

web2 ansible_host=192.168.88.200

all:vars

ansible_ssh_user=root

ansible_ssh_pass=a

4. 为各台主机配置yum

root@pubserver zabbix\]# vim files/local88.repo \[BaseOS

name = BaseOS

baseurl = ftp://192.168.88.240/dvd/BaseOS

enabled = 1

gpgcheck = 0

AppStream

name = AppStream

baseurl = ftp://192.168.88.240/dvd/AppStream

enabled = 1

gpgcheck = 0

rpms

name = rpms

baseurl = ftp://192.168.88.240/rpms

enabled = 1

gpgcheck = 0

root@pubserver zabbix\]# vim 01-upload-repo.yml --- - name: config repos.d hosts: all tasks: - name: delete repos.d file: path: /etc/yum.repos.d state: absent - name: create repos.d file: path: /etc/yum.repos.d state: directory mode: '0755' - name: upload local88 copy: src: files/local88.repo dest: /etc/yum.repos.d/ \[root@pubserver zabbix\]# ansible-playbook 01-upload-repo.yml # 5. 在zabbixserver上安装相应软件包 \[root@pubserver zabbix\]# vim 02-inst-zabbix.yml --- - name: install zabbix hosts: zabbix tasks: - name: install zabbix # 安装软件包 yum: name: - zabbix-server-mysql - zabbix-web-mysql - zabbix-nginx-conf - zabbix-sql-scripts - zabbix-selinux-policy - zabbix-agent - mysql-server - langpacks-zh_CN state: present \[root@pubserver zabbix\]# ansible-playbook 02-inst-zabbix.yml # 6. 启动mysqld服务 \[root@pubserver zabbix\]# vim 03-start-mysqld.yml --- - name: config mysqld hosts: zabbix tasks: - name: start mysqld # 启动mysqld服务 service: name: mysqld state: started enabled: yes \[root@pubserver zabbix\]# ansible-playbook 03-start-mysqld.yml # 7. 在zabbix上创建连接数据库的用户 \[root@zabbixserver \~\]# mysql mysql\> create database zabbix character set utf8mb4 collate utf8mb4_bin; # 在binlog日志开启的情况下,打开函数生成器 mysql\> set global log_bin_trust_function_creators = 1; mysql\> create user zabbix@localhost identified by 'zabbix'; mysql\> grant all privileges on zabbix.\* to zabbix@localhost; mysql\> quit; # 8. 验证数据库配置,如果登陆不到数据库表示上一步配置不正确 \[root@zabbixserver \~\]# mysql -uzabbix -pzabbix -hlocalhost zabbix # 9. 在数据库中创建表并导入数据 \[root@zabbixserver \~\]# cp /usr/share/zabbix-sql-scripts/mysql/server.sql.gz . \[root@zabbixserver \~\]# gzip -d server.sql.gz \[root@zabbixserver \~\]# mysql -uzabbix -pzabbix zabbix \< server.sql # 10. 配置zabbix_server \[root@zabbixserver \~\]# vim +129 /etc/zabbix/zabbix_server.conf DBPassword=zabbix # 11. 配置zabbix_agent \[root@zabbixserver \~\]# vim /etc/zabbix/zabbix_agentd.conf 182 Hostname=zabbixserver # 12. 配置nginx展示zabbix \[root@zabbixserver \~\]# vim /etc/nginx/conf.d/zabbix.conf # 打开第2、3行的注释,结果如下所示: server { listen 8080; server_name example.com; ...以下省略... # 13. 启动相关服务 \[root@pubserver zabbix\]# vim 04-start-zabbix.yml --- - name: config zabbix hosts: zabbix tasks: - name: start service # 循环启动多个服务 service: name: "{{item}}" state: started enabled: yes loop: - zabbix-server - zabbix-agent - nginx - php-fpm \[root@pubserver zabbix\]# ansible-playbook 04-start-zabbix.yml 访问zabbixserver的8080端口,进行初始化 ![](https://i-blog.csdnimg.cn/direct/a826e94e4ead4bb59d38debad74f23af.png) ### ![](https://i-blog.csdnimg.cn/direct/6d930009bb704f9a97eccf40323c66d3.png) ### ![](https://i-blog.csdnimg.cn/direct/6a9567056d8640af9ee01b29e9732926.png) ### ![](https://i-blog.csdnimg.cn/direct/32e698da3de44e81a01c2e495213d4a7.png) ### 密码也是:zabbix ### ![](https://i-blog.csdnimg.cn/direct/fa1067fb1c694aaebb462acf08d7efd4.png) ### ![](https://i-blog.csdnimg.cn/direct/c571d68734f44857b11551435bba2f24.png) ### ![](https://i-blog.csdnimg.cn/direct/0546dd12b30348fe8055338449abc52d.png) **这个用户和密码是zabbix网页的。** ### **二、zabbix 监控服务使用** 在web1上安装agent # 1. 安装agent \[root@pubserver zabbix\]# vim 05-inst-agent.yml --- - name: install agent hosts: webservers tasks: - name: install agent # 安装agent yum: name: zabbix-agent state: present \[root@pubserver zabbix\]# ansible-playbook 05-inst-agent.yml # 2. 修改web1配置文件 \[root@web1 \~\]# vim /etc/zabbix/zabbix_agentd.conf 117 Server=127.0.0.1,192.168.88.5 182 Hostname=web1 # 3. 起动服务 \[root@pubserver zabbix\]# vim 06-start-agent.yml --- - name: config agent hosts: web1 tasks: - name: start agent # 启动服务 service: name: zabbix-agent state: started enabled: yes \[root@pubserver zabbix\]# ansible-playbook 06-start-agent.yml 在web页面中添加对web1的监控 主机:安装了agent,被监控的主机 主机组:根据需求,将多台主机加入到一个主机组中,方便管理。系统默认已经创建了一些主机组。 模板:是监控项的集合。将模板应用到主机,主机就可以直接拥有模板中的所有监控项。系统中默认已经创建了一些模板。 ![](https://i-blog.csdnimg.cn/direct/8db60046b455426796fb2cdf13a23f83.png) ![](https://i-blog.csdnimg.cn/direct/bda4d91c548e43349789f4c12545b3ee.png) ![](https://i-blog.csdnimg.cn/direct/63a326bba2a44dda8784bae0deebda0e.png) ![](https://i-blog.csdnimg.cn/direct/81825d596aba4c49ac707eac1c2fa821.png) ![](https://i-blog.csdnimg.cn/direct/4a3c55ddaf59483eb5a020eb6c6f9e71.png) ![](https://i-blog.csdnimg.cn/direct/9b4ab3a2238a46e29dfcc3f1a8b8def9.png) ![](https://i-blog.csdnimg.cn/direct/d6a7008e6e23472d93a2346949d7a19d.png) **常用监控指标** Space utilization:以百分比显示的磁盘利用率 Used space:已用磁盘空间 Available memory:可用内存 CPU idle time:CPU空闲时间。不宜过低。 Load average (1m avg)、Load average (5m avg)、Load average (15m avg):CPU1分钟、5分钟、15分钟的平均负载。这个值不应长期大于核心数。 Interface eth0: Bits received:网卡接收到的数据量 Interface eth0: Bits sent:网卡发送的数据量 Number of processes:系统运行的进程数 Number of logged in users:已登陆的用户数 **自定义监控项** 实现监控web1用户数量的监控项 在被控端创建key。被控端被监控的内容叫作key,可以理解为它就是一个变量名,具体的名字自己决定。 在web页面中创建监控项。监控项对应key值。 在被控端创建key **语法** ++UserParameter=自定义key值,命令++ # 命令的执行结果,是key的value 创建自定义配置文件。文件名自定义。 \[root@web1 \~\]# vim /etc/zabbix/zabbix_agentd.d/usercnt.conf UserParameter=usercnt,sed -n '$=' /etc/passwd \[root@web1 \~\]# systemctl restart zabbix-agent.service 验证自定义监控项 # 1. 安装zabbix-get \[root@zabbixserver \~\]# yum install -y zabbix-get \[root@web1 \~\]# yum install -y zabbix-get # 2. 获取监控项的值 \[root@web1 \~\]# zabbix_get -s 127.0.0.1 -k usercnt 46 \[root@zabbixserver \~\]# zabbix_get -s 192.168.88.100 -k usercnt **创建模版** ![](https://i-blog.csdnimg.cn/direct/fa8bcd27c6ec42da8b9b06eed6b27710.png)![](https://i-blog.csdnimg.cn/direct/b63879cd1fda4f6e849421f18fe95643.png) * 创建监控项 * ![](https://i-blog.csdnimg.cn/direct/045e36f8ff474eebbaa7581d8d995839.png)![](https://i-blog.csdnimg.cn/direct/21a548b8546f43dbb27569f690acffda.png)![](https://i-blog.csdnimg.cn/direct/a892638e8fcc469cb1e812e834c77525.png)**应用模板到主机** * ![](https://i-blog.csdnimg.cn/direct/df97ead50577430e958d4094b3f3c685.png)![](https://i-blog.csdnimg.cn/direct/cbe88af960014214b3e623d5b80bc840.png)查看结果 * ![](https://i-blog.csdnimg.cn/direct/4ed15a9876dc4d1b96befd3ce0c54e80.png) ### **三、总结** **zabbix配置时,需要注意配置主机的监控项和触发器。** **![](https://i-blog.csdnimg.cn/direct/6cf7f98d94ed4d5593d5f6d4af18ab06.jpeg)** ![](https://i-blog.csdnimg.cn/direct/d2ddbe1aeb1a4887b3800a7b161d74b2.jpeg) **新建动作时,类型分为Trigger 触发器类型,autoregistration 自动注册,internal 内部触发。** **抽象来说:好比一个3D动画捕捉演员。** **![](https://i-blog.csdnimg.cn/direct/f33268800c4f40e58b3e98ffefa2f606.png)** *** ** * ** *** ## **SECURITY DAY2** ### 一、zabbix报警机制 ### 配置告警 * 默认情况下,监控项不会自动发送告警消息 * 需要配置触发器与告警,并且通过通知方式发送信息给联系人 * 触发器:设置条件,当条件达到时,将会执行某个动作 * 动作:触发器条件达到之后要采取的行为,比如发邮件或执行命令 #### 用户数超过50,发送告警邮件 * 当web1的用户数超过50时,认为这是一个问题(Problem) * 当出现问题时,将会执行动作。 * 执行的动作是给管理员发邮件。 * 给管理员发邮件,还要配置邮件服务器的地址,以及管理员的email地址 ##### 实施 * 创建触发器规则 ![](https://i-blog.csdnimg.cn/direct/a5f979ad6d1d48ef92534777322bd1fd.png) ### ![](https://i-blog.csdnimg.cn/direct/411eec9d81fd4bdf96dd5d71e112dfad.png) ### ![](https://i-blog.csdnimg.cn/direct/cec76bf74b3842559ecf81d20c21147c.png) ### ![](https://i-blog.csdnimg.cn/direct/8b5c5332bada477c8b207cf3895576a3.png) ### ![](https://i-blog.csdnimg.cn/direct/849817f0d8724cf18f91aaf4c939a100.png) * 创建邮件类型的报警媒介 ### ![](https://i-blog.csdnimg.cn/direct/dd9e63fcd9514f33856def206d4ac641.png) ### ![](https://i-blog.csdnimg.cn/direct/cfae61d0b4104df69b36c817ed1e8ef3.png) ### ![](https://i-blog.csdnimg.cn/direct/cd57ced1a16a4f5bb838934b7256567c.png) ### ![](https://i-blog.csdnimg.cn/direct/488f7230aed94817b37f981dbef5b6cc.png) ### ![](https://i-blog.csdnimg.cn/direct/4b2083221c274632bf8ce2c683da24fe.png) ### ![](https://i-blog.csdnimg.cn/direct/90c92e5b64cc447f8b2c1282fe6d564e.png) ### ![](https://i-blog.csdnimg.cn/direct/2aa7b81ec87b4cdf8e9f770016c62f47.png) ### ![](https://i-blog.csdnimg.cn/direct/e8502a47dfc7472daf1002bc008dc56e.png) ### ![](https://i-blog.csdnimg.cn/direct/5ff03073f2a04e288fb24f6269941aa6.png) ### ![](https://i-blog.csdnimg.cn/direct/36857880a1424e5a8b0ecf07e4869628.png) ![](https://i-blog.csdnimg.cn/direct/1391671716304a789915e1b699e79ec2.png) ### ![](https://i-blog.csdnimg.cn/direct/57559a60d5284731b1d620efbdfc1a80.png) ### ![](https://i-blog.csdnimg.cn/direct/37176228d5b04a42b2793c4969509de5.png) ### ![](https://i-blog.csdnimg.cn/direct/bfc4e02d84bb42528a0e996ef5ce016e.png) ### ![](https://i-blog.csdnimg.cn/direct/10aa308f3d65497caaedf4a02ea2a2cc.png) **验证告警配置** 在zabbixserver上配置邮件服务 # 配置postfix邮件服务和mailx邮件客户端 \[root@pubserver zabbix\]# vim 07-config-mail.yml --- - name: config mail hosts: zabbix tasks: - name: install mail # 安装postfix和mailx yum: name: postfix,mailx state: present - name: start postfix # 启动邮件服务postfix service: name: postfix state: started enabled: yes \[root@pubserver zabbix\]# ansible-playbook 07-config-mail.yml 在web1创建用户,使总用户数超过50 \[root@web1 \~\]# for user in user{1..5} \> do \> useradd $user \> done 在zabbix web页面中查看 ![](https://i-blog.csdnimg.cn/direct/93a8e072c71d4f3b9879b4554d179c3d.png) ### ![](https://i-blog.csdnimg.cn/direct/94cb8f51bf4f42568e677aa2cdd4e16e.png) **在zabbixserver上查看邮件** \[root@zabbixserver \~\]# mail # 查看邮件 Heirloom Mail version 12.5 7/5/10. Type ? for help. "/var/spool/mail/root": 2 messages 2 new \>N 1 zzg@tedu.cn Sat Dec 31 16:47 21/932 "Problem: usercnt_gt_50" N 2 zzg@tedu.cn Sat Dec 31 16:48 21/932 "Problem: usercnt_gt_50" \& 1 # 查看1号邮件 Message 1: From zzg@tedu.cn Sat Dec 31 16:47:59 2022 Return-Path: \ X-Original-To: root@localhost.localdomain Delivered-To: root@localhost.localdomain From: \ To: \ Date: Sat, 31 Dec 2022 16:47:59 +0800 Subject: Problem: usercnt_gt_50 Content-Type: text/plain; charset="UTF-8" Status: R Problem started at 16:47:56 on 2022.12.31 Problem name: usercnt_gt_50 Host: web1 Severity: Warning Operational data: 51 Original problem ID: 102 \& q # 输入q退出 ### 二、zabbix 进阶操作 #### 配置自动发现 ![](https://i-blog.csdnimg.cn/direct/d44ba878b235441f9dd5579bb226cea5.png) ![](https://i-blog.csdnimg.cn/direct/26032266f89445c69c7fbe47aefce197.png) ### ![](https://i-blog.csdnimg.cn/direct/acd1f42e2a83446eb2212ea185ef3e00.png) ### ![](https://i-blog.csdnimg.cn/direct/8fcf4a25161a49978c551c37512d63f1.png) ### ![](https://i-blog.csdnimg.cn/direct/7ebb6e78723b45149d8e5b90119780d0.png) ### ![](https://i-blog.csdnimg.cn/direct/a2afa628baaa4cd38e8b8afa044e910b.png) ### ![](https://i-blog.csdnimg.cn/direct/d089efc05b2b410dbdff8bbf12c9047a.png) ### ![](https://i-blog.csdnimg.cn/direct/152f4d8791954ae2b34f35233c49b660.png) ### ![](https://i-blog.csdnimg.cn/direct/879bb4c7dbb54da3888155733bc9fd4f.png) ### ![](https://i-blog.csdnimg.cn/direct/eef3f95b987b4186a0dbabbf58e6ecbf.png) ### ![](https://i-blog.csdnimg.cn/direct/65cecd6a090b48e7aa91c69ad30388cb.png) ### ![](https://i-blog.csdnimg.cn/direct/9127d57cf18342d199d649b7945cda75.png) ### ![](https://i-blog.csdnimg.cn/direct/1df6e156a0e34f868b4ab1caf089a420.png) ### ![](https://i-blog.csdnimg.cn/direct/09f6b217fc1046f7bb703b9330c02ec6.png) * 在web2上配置agent ``` [root@web2 ~]# vim /etc/zabbix/zabbix_agentd.conf ``` ``` 117 Server=127.0.0.1,192.168.88.5 ``` ``` 182 Hostname=web2 ``` ``` [root@web2 ~]# systemctl enable zabbix-agent.service --now ``` ![](https://i-blog.csdnimg.cn/direct/8f1cf8e1c01242cc8b0ff954bba7a67f.png) ### 主动监控 默认zabbix使用的是被动监控,主被动监控都是针对被监控主机而言的。 被动监控:Server向Agent发起请求,索取监控数据。此种模式常用 主动监控:Agent向Server发起连接,向Server汇报 **配置web2使用主动监控** 修改配置文件,只使用主动监控 \[root@web2 \~\]# vim /etc/zabbix/zabbix_agentd.conf 117 # Server=127.0.0.1,192.168.88.5 142 StartAgents=0 171 ServerActive=192.168.88.5 242 RefreshActiveChecks=120 # 重启服务 \[root@web2 \~\]# systemctl restart zabbix-agent.service \[root@web2 \~\]# ss -tlnp \| grep :10050 # 端口号消失 ![](https://i-blog.csdnimg.cn/direct/24f5fb121c8b4af7a84ed63e303afd89.png) ### ![](https://i-blog.csdnimg.cn/direct/15324fc3b0a04a6ebb728dece49d0cfc.png) ### ![](https://i-blog.csdnimg.cn/direct/beab2935143f493e8d63d628eb71c7d5.png) ### ![](https://i-blog.csdnimg.cn/direct/986b112ae3d34593966641a8823fbca9.png) ### 三、监控案例解析 #### 配置钉钉机器人告警 ##### 创建钉钉机器人 * 登陆钉钉网页版:[阿里巴巴-钉钉,是一个工作方式!超过1000w家企业正在使用钉钉!](https://im.dingtalk.com/ "阿里巴巴-钉钉,是一个工作方式!超过1000w家企业正在使用钉钉!") (或者在windows系统上下载电脑版钉钉) * 下面以钉钉电脑版为例,配置钉钉群聊机器人 * 在群聊中点击设置,以新建机器人 * 自己创建一个公司企业群测试。 * ![](https://i-blog.csdnimg.cn/direct/d0fa9b071d6345c9a146768c6d768cdf.png)![](https://i-blog.csdnimg.cn/direct/b139cdea7ce7487ab7d55f6de6391429.png) * ![](https://i-blog.csdnimg.cn/direct/d163212c5d5f414ba0614e4758d629e3.png)![](https://i-blog.csdnimg.cn/direct/0fde23f57913494cb9e5e0c1b04595de.png) 机器人名称自己写一个,提示关键词为warn ![](https://i-blog.csdnimg.cn/direct/5003347cdacf4663bc7994524de5097d.png)![](https://i-blog.csdnimg.cn/direct/b296afc9f67a499d8f4340b452fea560.png) 注意上面的Webhook地址,不要泄露,谁拥有此地址,谁就可以控制机器人说话。 编写脚本并测试 # 安装钉钉机器人脚本需要用到的模块 \[root@zabbixserver \~\]# yum install -y python3-requests #windows运行不了,直接就下 python-3。说明依赖软件不太够。 # 编写钉钉机器人脚本 \[root@zabbixserver \~\]# vim /usr/lib/zabbix/alertscripts/dingalert.py #!/usr/bin/env python3 import json import requests import sys def send_msg(url, remiders, msg): headers = {'Content-Type': 'application/json; charset=utf-8'} data = { "msgtype": "text", "at": { "atMobiles": remiders, "isAtAll": False, }, "text": { "content": msg, } } r = requests.post(url, data=json.dumps(data), headers=headers) return r.text if __name__ == '__main__': msg = sys.argv\[1

remiders = []

url = '++钉钉机器人Webhook地址++ ' # 注意此处需输入机器人的webhook地址

print(send_msg(url, remiders, msg))

root@zabbixserver \~\]# chmod +x /usr/lib/zabbix/alertscripts/dingalert.py \[root@zabbixserver \~\]# /usr/lib/zabbix/alertscripts/dingalert.py 'warn: 测试消息' # 注意消息中要包含关键字warn {"errcode":0,"errmsg":"ok"} ##### 验证 创建用户,使用户数超过55 ,太大了就把条件设小点。 \[root@web1 \~\]# for user in user{6..10}; do useradd $user; done \[root@web1 \~\]# zabbix_get -s 127.0.0.1 -k usercnt 56 ![](https://i-blog.csdnimg.cn/direct/1ebc0d4ea7754dbc808af3417e20b457.png) ##### 添加报警媒介类型 ![](https://i-blog.csdnimg.cn/direct/f64960dd4bc74c84ab202a6289d1ebe9.png) ![](https://i-blog.csdnimg.cn/direct/20de4e91e2b54b92b959827c749a875c.png) #### 监控Nginx stub_status模块 用于实时监控nginx的网络连接,这个模块是nginx官方提供的一个模块。 配置nginx \[root@pubserver zabbix\]# vim 08-config-nginx.yml --- - name: config nginx hosts: webservers tasks: - name: install nginx # 安装nginx yum: name: nginx state: present - name: start nginx # 启动nginx service: name: nginx state: started enabled: yes \[root@pubserver zabbix\]# ansible-playbook 08-config-nginx.yml # 修改配置文件,启用stub_status功能 \[root@web1 \~\]# vim /etc/nginx/nginx.conf ...略... 47 location / { 48 } 49 50 location /status { # 在此处添加3行 51 stub_status on; 52 } 53 54 error_page 404 /404.html; 55 location = /40x.html { 56 } ...略... \[root@web1 \~\]# systemctl restart nginx # 访问监控页面 \[root@zabbixserver \~\]# curl http://192.168.88.100/status Active connections: 1 server accepts handled requests 2 2 2 Reading: 0 Writing: 1 Waiting: 0 # Active connections:当前客户端与nginx之间的连接数。它等于下面Reading / Writing / Waiting之和 # accepts:自nginx启动之后,客户端访问的总量 # handled:自nginx启动之后,处理过的客户端连接总数,通常等于accepts的值。 # requests:自nginx启动之后,处理过的客户端请求总数。 # Reading:正在读取客户端的连接总数。 # Writing:正在向客户端发送响应的连接总数。 # Waiting:空闲连接。 # 使用工具向服务器发起多个请求 \[root@zabbixserver \~\]# yum install -y httpd-tools # 一共发1000个请求,每次并发数200 \[root@zabbixserver \~\]# ab -n1000 -c200 http://192.168.88.100/ \[root@zabbixserver \~\]# curl http://192.168.88.100/status Active connections: 1 server accepts handled requests 1097 1097 1003 Reading: 0 Writing: 1 Waiting: 0 编写脚本,用于获取各项数据 \[root@web1 \~\]# vim /usr/local/bin/nginx_status.sh #!/bin/bash case $1 in active) curl -s http://192.168.88.100/status \| awk '/Active/{print $NF}';; waiting) curl -s http://192.168.88.100/status \| awk '/Waiting/{print $NF}';; accepts) curl -s http://192.168.88.100/status \| awk 'NR==3{print $1}';; esac \[root@web1 \~\]# chmod +x /usr/local/bin/nginx_status.sh \[root@web1 \~\]# nginx_status.sh active 1 \[root@web1 \~\]# nginx_status.sh accepts 1099 \[root@web1 \~\]# nginx_status.sh waiting 0 创建zabbix用到的key,获取各项数据 # key的语法格式 UserParameter=key\[\*\],\ $1 # key\[\*\]中的\*是参数,将会传给后面的位置变量$1 # 创建声明key的文件 \[root@web1 \~\]# vim /etc/zabbix/zabbix_agentd.d/nginx_status.conf UserParameter=nginx_status\[\*\],/usr/local/bin/nginx_status.sh $1 # 测试 \[root@web1 \~\]# systemctl restart zabbix-agent.service \[root@web1 \~\]# zabbix_get -s 127.0.0.1 -k nginx_status\[active

1

root@web1 \~\]# zabbix_get -s 127.0.0.1 -k nginx_status\[waiting

0

root@web1 \~\]# zabbix_get -s 127.0.0.1 -k nginx_status\[accepts

1103

四、总结

监控的目的是:报告系统的运行情况,提前发现问题。O(∩_∩)O

监控类别:

公有:FTP,WEB,数据库,SSH远程连接服务等

私有:机器的CPU、内存、磁盘、网卡流量、用户、进程运行信息等

zabbix基于分布式监控。cacti 基于snmp协议。 nagios 基于agent。


相关推荐
小赖同学啊4 分钟前
基于区块链的物联网(IoT)安全通信与数据共享的典型实例
物联网·安全·区块链
云资源服务商5 小时前
解锁阿里云日志服务SLS:云时代的日志管理利器
服务器·阿里云·云计算
朱包林6 小时前
day45-nginx复杂跳转与https
linux·运维·服务器·网络·云计算
安全系统学习7 小时前
网络安全之SQL RCE漏洞
安全·web安全·网络安全·渗透测试
聚铭网络12 小时前
案例精选 | 某省级税务局AI大数据日志审计中台应用实践
大数据·人工智能·web安全
GLAB-Mary13 小时前
AI会取代网络工程师吗?理解AI在网络安全中的角色
网络·人工智能·web安全
hanniuniu1313 小时前
AI时代API挑战加剧,API安全厂商F5护航企业数字未来
人工智能·安全
zhulangfly13 小时前
API接口安全-1:身份认证之传统Token VS JWT
安全
时时三省15 小时前
【时时三省】vectorcast使用教程
安全·安全架构
galaxylove15 小时前
Gartner发布最新指南:企业要构建防御性强且敏捷的网络安全计划以平衡安全保障与业务运营
网络·安全·web安全