nginx的安装
zabbix的安装
ssl证书生成
环境说明
系统信息 | IP | 服务名称 |
---|---|---|
rhel7.4 | 192.168.20.99 | lnmp zabbix_server zabbix_agentd |
rhel7.4 | 192.168.20.135 | zabbix_agentd nginx |
1.用户认证
//创建可以访问的用户和密码
[root@localhost nginx]# htpasswd -c -m /usr/local/nginx/conf/.password admin
New password:
Re-type new password:
Adding password for user admin
location /abc {
root html;
index index.html;
auth_basic "123";
auth_basic_user_file /usr/local/nginx/conf/.password
}
2.https配置
[root@localhost ssl]# pwd
/usr/local/nginx/ssl
[root@localhost ssl]# ll
总用量 8
-rw-r--r-- 1 root root 1103 8月 11 02:33 www.a.com.crt
-rw-r--r-- 1 root root 1675 8月 11 02:32 www.a.com.key
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
106 server {
107 listen 443 ssl;
108 server_name www.a.com;
109
110 ssl_certificate /usr/local/nginx/ssl/www.a.com.crt; //证书存放路径
111 ssl_certificate_key ../ssl/www.a.com.key; //证书存放路径
112
113 ssl_session_cache shared:SSL:1m;
114 ssl_session_timeout 5m;
115
116 ssl_ciphers HIGH:!aNULL:!MD5;
117 ssl_prefer_server_ciphers on;
118
119 location / {
120 root html;
121 index index.html index.htm;
122 }
123 }
124
:106,123s/#//g //替换106行到123的#
3.zabbix监控
3.1开启状态界面
location /status {
stub_status on; //开启
allow 192.168.20.0/24; //允许这个网段的可以访问
deny all; //拒绝所有
}
状态页面信息详解:
状态码 | 表示的意义 |
---|---|
Active connections 2 | 当前所有处于打开状态的连接数 |
accepts | 总共处理了多少个连接 |
handled | 成功创建多少握手 |
requests | 总共处理了多少个请求 |
Reading | nginx读取到客户端的Header信息数,表示正处于接收请求状态的连接数 |
Writing | nginx返回给客户端的Header信息数,表示请求已经接收完成,且正处于处理请求或发送响应的过程中的连接数 |
Waiting | 开启keep-alive的情况下,这个值等于active - (reading + writing),意思就是Nginx已处理完正在等候下一次请求指令的驻留连接 |
3.2安装zabbix_agent服务
[root@localhost zabbix-5.0.2]# yum -y install gcc pcre*
[root@localhost zabbix-5.0.2]# ./configure --enable-agent
[root@localhost zabbix-5.0.2]# make install
[root@localhost zabbix-5.0.2]# useradd -r -M -s /sbin/nologin zabbix
[root@localhost zabbix-5.0.2]# vim /usr/local/etc/zabbix_agentd.conf
Server=192.168.20.99
ServerActive=192.168.20.99
Hostname=001
3.3添加监控脚本
//监控总共连接各数
[root@localhost ~]# mkdir /scritps
[root@localhost ~]# cd /scritps/
[root@localhost scritps]# vim requests.sh
#!/bin/bash
requests=$(curl -s http://192.168.20.135/status | awk 'NR==3{print $3}')
if [ $requests -gt 200 ];then
echo $requests
else
echo 0
fi
[root@localhost scritps]# chmod +x requests.sh
//修改配置文件启动功能,启动功能
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=requests,/bin/bash /scripts/requests.sh
UserParameter=Reading,/bin/bash /scripts/Reading.sh
UserParameter=Writing,/bin/bash /scripts/Writing.sh
监控正处于接收请求状态的连接数
[root@localhost scritps]# vim Reading.sh
#!/bin/bash
Reading=$(curl -s http://192.168.20.135/status | awk 'NR==4{print $2}')
if [ $Reading -gt 0 ];then
echo $Reading
else
echo 0
fi
[root@localhost scritps]# chmod +x Reading.sh
监控已经接受请求且正在处理的或发生响应过程中的连接数
[root@localhost scritps]# vim Writing.sh
#!/bin/bash
Writing=$(curl -s http://192.168.20.135/status | awk 'NR==4{print $4}')
if [ $Writing -gt 0 ];then
echo $Writing
else
echo 0
fi
[root@localhost scritps]# chmod +x Writing.sh