highlight: androidstudio
theme: channing-cyan
106 /apps/nginx/sbin/nginx -s stop
报错
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 ```
查看文件是否创建、发现已经有了 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 ```
停止服务 ``` /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 ```
或者网页一直刷新
创建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 ``` 新建模板
关联模板
图形
查看是否有数据
导入模板
模板下载:Template Linux TCP_CONN Status.xml.xml
添加模板
配置模板