nginx服务之配置https和监控状态页面
目录
1. 配置https
生成证书的操作,这里就不详细操作了,有疑问的可以看看这篇nat模式搭建http和https负载均衡集群,里面有提到怎么生成证书!
生成证书后的配置
[root@longnian ssl]# pwd
/usr/local/nginx/ssl //证书存放的位置
[root@longnian ssl]# ls
nginx.crt nginx.csr nginx.key
//修改配置文件
[root@longnian ssl]# vim /usr/local/nginx/conf/nginx.conf
//修改server
..............
server {
listen 443 ssl;
server_name www.a.com;
ssl_certificate /usr/local/nginx/ssl/nginx.crt;
ssl_certificate_key /usr/local/nginx/ssl/nginx.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
..............
//修改好了,重读下配置文件
[root@longnian ssl]# nginx -s reload
访问网页
成功访问到了网页,到此https就配置完了!
2. zabbix监控状态界面
2.1 开启状态界面
//修改配置文件
//添加以下内容:
..............
location /status {
stub_status on; //开启
allow 192.168.159.0/24; //允许159网段的可以访问!
deny all;
}
..............
//重读配置文件
[root@longnian ssl]# nginx -s reload
在网页上访问
2.2 取出状态的值
在服务器上用curl来访问
[root@longnian ~]# curl -k https://192.168.159.144/status
Active connections: 2
server accepts handled requests
132 132 132
Reading: 0 Writing: 1 Waiting: 1
因为我这里想监控的是requests的值、Reading的值和Writing的值,所以得先取出它们的值,然后写到脚本里去
//取出requests的值
[root@longnian ~]# curl -k https://192.168.159.144/status
Active connections: 1
server accepts handled requests
134 134 134
Reading: 0 Writing: 1 Waiting: 0
[root@longnian ~]# curl -k -s https://192.168.159.144/status | awk 'NR==3{print $3}'
135
//取出Reading的值
[root@longnian ~]# curl -k https://192.168.159.144/status
Active connections: 1
server accepts handled requests
138 138 138
Reading: 0 Writing: 1 Waiting: 0
[root@longnian ~]# curl -k -s https://192.168.159.144/status | awk 'NR==4{print $2}'
0
//取出Writing的值
[root@longnian ~]# curl -k https://192.168.159.144/status
Active connections: 1
server accepts handled requests
140 140 140
Reading: 0 Writing: 1 Waiting: 0
[root@longnian ~]# curl -k -s https://192.168.159.144/status | awk 'NR==4{print $4}'
1
2.3 创建监控脚本
//创建个脚本目录
//创建监控requests的脚本
[root@longnian ~]# mkdir /script
[root@longnian ~]# cd /script/
[root@longnian script]# vim check_requests.sh
[root@longnian script]# cat check_requests.sh
#!/bin/bash
if [ `curl -k -s https://192.168.159.144/status | awk 'NR==3{print \$3}'` -ne 0 ];then
echo "0"
else
echo "1"
fi
[root@longnian script]# ls
check_requests.sh
//执行下脚本,看有没有问题
[root@longnian script]# ./check_requests.sh
0
//创建监控Reading的脚本
[root@longnian script]# vim check_Reading.sh
[root@longnian script]# cat check_Reading.sh
#!/bin/bash
if [ `curl -k -s https://192.168.159.144/status | awk 'NR==4{print \$2}'` -eq 0 ];then
echo "0"
else
echo "1"
fi
[root@longnian script]# ls
check_Reading.sh check_requests.sh
//执行下脚本,看有没有问题
[root@longnian script]# ./check_Reading.sh
0
//创建监控Writing的脚本
[root@longnian script]# vim check_Writing.sh
[root@longnian script]# cat check_Writing.sh
#!/bin/bash
if [ `curl -k -s https://192.168.159.144/status | awk 'NR==4{print \$4}'` -ne 0 ];then
echo "0"
else
echo "1"
fi
[root@longnian script]# chmod +x check_*
[root@longnian script]# ll
total 12
-rwxr-xr-x 1 root root 134 Jul 31 21:06 check_Reading.sh
-rwxr-xr-x 1 root root 134 Jul 31 21:01 check_requests.sh
-rwxr-xr-x 1 root root 134 Jul 31 21:11 check_Writing.sh
//执行下脚本,看有没有问题
[root@longnian script]# ./check_Writing.sh
0
3 安装zabbix(客户端)
主机 | IP地址 | 所需服务 |
---|---|---|
Server端 | 192.168.159.135 | lnmp、zabbix |
Client端 | 192.168.159.144 | zabbix (agent) |
配置server端的lnmp和zabbix,我这里就不过多阐述了,有疑问可以参考Linux项目之部署lnmp架构和Linux监控服务之zabbix
Client端zabbix安装和配置
//安装zabbix
//安装一些常用的工具
[root@longnian ~]# yum -y install vim wget gcc gcc-c++ net-snmp-devel libevent-devel
//下载zabbix安装包,进行编译、安装
[root@longnian ~]# cd /usr/src/
[root@longnian src]# ls
debug kernels zabbix-4.4.7 zabbix-4.4.7.tar.gz
[root@longnian src]# cd zabbix-4.4.7
[root@longnian zabbix-4.4.7]# ./configure --enable-agent
[root@longnian zabbix-4.4.7]# make install
//修改配置文件
[root@longnian ~]# cd /usr/local/etc/
[root@longnian etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d
[root@longnian etc]# vim zabbix_agentd.conf
..........
Server=192.168.159.135
..........
ServerActive=192.168.159.135
..........
Hostname=Zabbix client
..........
UnsafeUserParameters=1
..........
//创建zabbix用户
[root@longnian ~]# useradd -r -M -s /sbin/nologin zabbix
[root@longnian ~]# id zabbix
uid=996(zabbix) gid=994(zabbix) groups=994(zabbix)
[root@longnian ~]# zabbix_agentd
[root@longnian ~]# ss -anlt
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:9000 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:443 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 80 :::3306 :::*
LISTEN 0 100 :::8080 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
LISTEN 0 1 ::ffff:127.0.0.1:8005 :::*
//添加脚本信息到配置文件中去
[root@longnian ~]# vim /usr/local/etc/zabbix_agentd.conf
.............
UserParameter=check_status-one[*],/bin/bash /script/check_requests.sh $1
UserParameter=check_status-two[*],/bin/bash /script/check_Reading.sh $1
UserParameter=check_status-three[*],/bin/bash /script/check_Writing.sh $1
//在server端,手动测试脚本有没有问题
[root@longnian ~]# zabbix_get -s 192.168.159.144 -k check_status-one
0
[root@longnian ~]# zabbix_get -s 192.168.159.144 -k check_status-two
0
[root@longnian ~]# zabbix_get -s 192.168.159.144 -k check_status-three
0
//能看到0就是没错的!!
4. 配置监控
4.1 创建主机组,添加主机
4.2 添加监控项
4.3 添加触发器
4.4 查看监控状态
4.5 同样把另外两个也监控起来
4.6 再次查看监控状态
到此,实验就完成啦!如需发邮件,只需要再配置媒介和动作就行!具体想了解的可以查看这篇Linux项目之zabbix监控脑裂里面有写到发邮件!
作者:酷小年
-------------------------------------------
个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ⁾⁾!