Nginx 故障自治愈及监控linux tcp连接数(小节7)


highlight: androidstudio

theme: channing-cyan

图片.png

图片.png

图片.png

图片.png

图片.png

106 /apps/nginx/sbin/nginx -s stop 报错 图片.png

106 /apps/nginx/sbin/nginx

``` vim /etc/zabbix/zabbix_agentd.conf

EnableRemoteCommands=1 <--开启远程命令、1允许、0拒绝 UnsafeUserParameters=1 <--允许特殊字符、1允许、0拒绝 重启服务 systemctl restart zabbix-agent 停止服务 /apps/nginx/sbin/nginx -s stop ```

图片.png

查看文件是否创建、发现已经有了 ll /tmp/linux01.txt -rw-rw-r-- 1 zabbix zabbix 0 Jan 12 01:11 /tmp/linux01.txt 修改后强制保存 ``` vim /etc/sudoers

zabbix ALL=(ALL) NOPASSWD: ALL 启动服务 /apps/nginx/sbin/nginx ```

图片.png

图片.png

停止服务 ``` /apps/nginx/sbin/nginx -s stop

一直过滤nginx、可以看到重新启动

ps -ef|grep nginx root 58430 1 0 01:32 ? 00:00:00 nginx: master process /apps/nginx/sbin/nginx nobody 58431 58430 0 01:32 ? 00:00:00 nginx: worker process root 58433 2113 0 01:32 pts/0 00:00:00 grep --color=auto nginx ```

或者网页一直刷新 图片.png

创建nginx用户 ``` useradd nginx -u 2019

id nginx uid=2019(nginx) gid=2019(nginx) groups=2019(nginx) 将nginx改为默认用户 vim /apps/nginx/conf/nginx.conf

user nginx; <-- /apps/nginx/sbin/nginx -s reload ```

ps -ef|grep nginx root 58430 1 0 01:32 ? 00:00:00 nginx: master process /apps/nginx/sbin/nginx nginx 63122 58430 0 01:39 ? 00:00:00 nginx: worker process root 63363 2113 0 01:39 pts/0 00:00:00 grep --color=auto nginx

/apps/nginx/sbin/nginx -s stop

ps -ef|grep nginx root 65946 1 0 01:43 ? 00:00:00 nginx: master process /apps/nginx/sbin/nginx nginx 65947 65946 0 01:43 ? 00:00:00 nginx: worker process root 65954 2113 0 01:43 pts/0 00:00:00 grep --color=auto nginx

监控TCP脚本

106 ``` cd /etc/zabbix/zabbix_agentd.conf.d/

监控脚本

cat tcp_conn.sh

!/bin/bash

tcpconnstatus(){ TCPSTAT=$1 ss -ant | awk 'NR>1 {++s[$1]} END {for(k in s) print k,s[k]}' > /tmp/tcpconn.txt TCPNUM=$(grep "$TCPSTAT" /tmp/tcpconn.txt | cut -d ' ' -f2) if [ -z $TCPNUM ];then TCPNUM=0 fi echo $TCPNUM }

main(){ case $1 in tcpstatus) tcpconn_status $2; ;; esac }

main $1 $2 ```

``` ss -nat

链接数

bash tcpconn.sh tcpstatus LISTEN 13 bash tcpconn.sh tcpstatus TIME-WAIT2 0 添加执行权限 chmod a+x tcp_conn.sh ```

``` pwd /etc/zabbix/zabbix_agentd.conf.d <--当前所在目录

注释掉文件中信息、写到下面文件中

vim ../zabbix_agentd.conf

UserParameter=nginx.status[*],/etc/zabbix/zabbixagentd.conf.d/nginxstatus.sh "$1" "$2" "$3"

vim linux01.conf UserParameter=nginx.status[],/etc/zabbix/zabbix_agentd.conf.d/nginx_status.sh "$1" "$2" "$3" UserParameter=linux_status[],/etc/zabbix/zabbixagentd.conf.d/tcpconn.sh "$1" "$2" 重启服务 systemctl restart zabbix-agent **101**

权限解决

zabbixget -s 192.168.37.106 -p 10050 -k linuxstatus[tcpstatus,ESTAB] /etc/zabbix/zabbixagentd.conf.d/tcpconn.sh: line 4: /tmp/tcpconn.txt: Permission denied 4 ```

106

删除重新创建、或更改目录属主属组权限 rm -rf /tmp/tcp_conn.txt

101 ``` zabbixget -s 192.168.37.106 -p 10050 -k linuxstatus[tcp_status,ESTAB] 4

zabbixget -s 192.168.37.106 -p 10050 -k linuxstatus[tcp_status,LISTEN] 13 ``` 新建模板

图片.png

图片.png

图片.png

图片.png

图片.png 关联模板

图片.png

图形

图片.png

图片.png

图片.png

查看是否有数据 图片.png

导入模板

模板下载:Template Linux TCP_CONN Status.xml.xml

图片.png

添加模板 图片.png

配置模板

图片.png

图片.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值